@real-router/core 0.7.0 → 0.8.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.
package/README.md CHANGED
@@ -40,8 +40,8 @@ Creates a new router instance. [Wiki](https://github.com/greydragon888/real-rout
40
40
 
41
41
  ```typescript
42
42
  const router = createRouter(
43
- routes, // Route[] - route definitions
44
- options, // Partial<Options> - router options
43
+ routes, // Route[] - route definitions
44
+ options, // Partial<Options> - router options
45
45
  dependencies, // object - dependency injection
46
46
  );
47
47
  ```
@@ -159,9 +159,12 @@ Adds an event listener. Returns an unsubscribe function. [Wiki](https://github.c
159
159
  ```typescript
160
160
  import { events } from "@real-router/core";
161
161
 
162
- const unsubscribe = router.addEventListener(events.TRANSITION_START, (toState, fromState) => {
163
- console.log("Starting:", toState.name);
164
- });
162
+ const unsubscribe = router.addEventListener(
163
+ events.TRANSITION_START,
164
+ (toState, fromState) => {
165
+ console.log("Starting:", toState.name);
166
+ },
167
+ );
165
168
 
166
169
  // To remove listener, call the returned unsubscribe function
167
170
  unsubscribe();
@@ -213,35 +216,41 @@ Returns: `void`\
213
216
  ### Routes
214
217
 
215
218
  #### `router.addRoute(route: Route): void`
219
+
216
220
  Add a route definition at runtime.\
217
221
  `route: Route` — route configuration object\
218
222
  Returns: `void`\
219
223
  [Wiki](https://github.com/greydragon888/real-router/wiki/addRoute)
220
224
 
221
225
  #### `router.removeRoute(name: string): void`
226
+
222
227
  Remove a route by name.\
223
228
  `name: string` — route name to remove\
224
229
  Returns: `void`\
225
230
  [Wiki](https://github.com/greydragon888/real-router/wiki/removeRoute)
226
231
 
227
232
  #### `router.getRoute(name: string): Route | undefined`
233
+
228
234
  Get route definition by name.\
229
235
  `name: string` — route name\
230
236
  Returns: `Route | undefined`\
231
237
  [Wiki](https://github.com/greydragon888/real-router/wiki/getRoute)
232
238
 
233
239
  #### `router.hasRoute(name: string): boolean`
240
+
234
241
  Check if a route exists.\
235
242
  `name: string` — route name\
236
243
  Returns: `boolean`\
237
244
  [Wiki](https://github.com/greydragon888/real-router/wiki/hasRoute)
238
245
 
239
246
  #### `router.clearRoutes(): void`
247
+
240
248
  Remove all routes.
241
249
  Returns: `void`\
242
250
  [Wiki](https://github.com/greydragon888/real-router/wiki/clearRoutes)
243
251
 
244
252
  #### `router.updateRoute(name: string, updates: Partial<Route>): void`
253
+
245
254
  Update route configuration.\
246
255
  `name: string` — route name\
247
256
  `updates: Partial<Route>` — properties to update\
@@ -261,17 +270,20 @@ router.updateRoute("old-url", { forwardTo: "new-url" });
261
270
  ### State Utilities
262
271
 
263
272
  #### `router.getPreviousState(): State | undefined`
273
+
264
274
  Get previous router state.\
265
275
  Returns: `State | undefined`\
266
276
  [Wiki](https://github.com/greydragon888/real-router/wiki/getPreviousState)
267
277
 
268
278
  #### `router.shouldUpdateNode(nodeName: string): (toState, fromState?) => boolean`
279
+
269
280
  Create a predicate to check if a route node should update during transition.\
270
281
  `nodeName: string` — route node name\
271
282
  Returns: predicate function\
272
283
  [Wiki](https://github.com/greydragon888/real-router/wiki/shouldUpdateNode)
273
284
 
274
285
  #### `router.areStatesEqual(state1: State, state2: State, ignoreQueryParams?: boolean): boolean`
286
+
275
287
  Compare two states for equality.\
276
288
  `state1: State` — first state\
277
289
  `state2: State` — second state\
@@ -284,6 +296,7 @@ Returns: `boolean`\
284
296
  ### Path Operations
285
297
 
286
298
  #### `router.buildPath(name: string, params?: Params): string`
299
+
287
300
  Build URL path from route name.\
288
301
  `name: string` — route name\
289
302
  `params?: Params` — route parameters\
@@ -291,6 +304,7 @@ Returns: `string`\
291
304
  [Wiki](https://github.com/greydragon888/real-router/wiki/buildPath)
292
305
 
293
306
  #### `router.buildUrl(name: string, params?: Params, options?: object): string`
307
+
294
308
  Build full URL from route name (includes base path and query string).\
295
309
  `name: string` — route name\
296
310
  `params?: Params` — route parameters\
@@ -299,6 +313,7 @@ Returns: `string`\
299
313
  [Wiki](https://github.com/greydragon888/real-router/wiki/buildUrl)
300
314
 
301
315
  #### `router.isActiveRoute(name: string, params?: Params, strictEquality?: boolean, ignoreQueryParams?: boolean): boolean`
316
+
302
317
  Check if route is currently active.\
303
318
  `name: string` — route name\
304
319
  `params?: Params` — route parameters\
@@ -312,17 +327,20 @@ Returns: `boolean`\
312
327
  ### Dependencies
313
328
 
314
329
  #### `router.getDependency(name: string): unknown`
330
+
315
331
  Get a dependency by name.\
316
332
  `name: string` — dependency name\
317
333
  Returns: `unknown`\
318
334
  [Wiki](https://github.com/greydragon888/real-router/wiki/getDependency)
319
335
 
320
336
  #### `router.getDependencies(): Dependencies`
337
+
321
338
  Get all dependencies.\
322
339
  Returns: `Dependencies`\
323
340
  [Wiki](https://github.com/greydragon888/real-router/wiki/getDependencies)
324
341
 
325
342
  #### `router.setDependency(name: string, value: unknown): void`
343
+
326
344
  Set a dependency.\
327
345
  `name: string` — dependency name\
328
346
  `value: unknown` — dependency value\
@@ -330,24 +348,28 @@ Returns: `void`\
330
348
  [Wiki](https://github.com/greydragon888/real-router/wiki/setDependency)
331
349
 
332
350
  #### `router.setDependencies(deps: Dependencies): void`
351
+
333
352
  Set multiple dependencies.\
334
353
  `deps: Dependencies` — dependencies object\
335
354
  Returns: `void`\
336
355
  [Wiki](https://github.com/greydragon888/real-router/wiki/setDependencies)
337
356
 
338
357
  #### `router.hasDependency(name: string): boolean`
358
+
339
359
  Check if dependency exists.\
340
360
  `name: string` — dependency name\
341
361
  Returns: `boolean`\
342
362
  [Wiki](https://github.com/greydragon888/real-router/wiki/hasDependency)
343
363
 
344
364
  #### `router.removeDependency(name: string): void`
365
+
345
366
  Remove a dependency.\
346
367
  `name: string` — dependency name\
347
368
  Returns: `void`\
348
369
  [Wiki](https://github.com/greydragon888/real-router/wiki/removeDependency)
349
370
 
350
371
  #### `router.resetDependencies(): void`
372
+
351
373
  Remove all dependencies.\
352
374
  Returns: `void`\
353
375
  [Wiki](https://github.com/greydragon888/real-router/wiki/resetDependencies)
@@ -357,17 +379,20 @@ Returns: `void`\
357
379
  ### Options
358
380
 
359
381
  #### `router.getOptions(): Options`
382
+
360
383
  Get all router options.\
361
384
  Returns: `Options`\
362
385
  [Wiki](https://github.com/greydragon888/real-router/wiki/getOptions)
363
386
 
364
387
  #### `router.getOption(name: keyof Options): unknown`
388
+
365
389
  Get a single router option by name.\
366
390
  `name: keyof Options` — option name\
367
391
  Returns: option value\
368
392
  [Wiki](https://github.com/greydragon888/real-router/wiki/getOption)
369
393
 
370
394
  #### `router.setOption(name: string, value: unknown): void`
395
+
371
396
  Set a router option. Must be called before `start()`.\
372
397
  `name: string` — option name\
373
398
  `value: unknown` — option value\
@@ -379,12 +404,14 @@ Returns: `void`\
379
404
  ### Other
380
405
 
381
406
  #### `router.clone(dependencies?: Dependencies): Router`
407
+
382
408
  Clone router for SSR.\
383
409
  `dependencies?: Dependencies` — override dependencies\
384
410
  Returns: `Router`\
385
411
  [Wiki](https://github.com/greydragon888/real-router/wiki/clone)
386
412
 
387
413
  #### `router.cancel(): void`
414
+
388
415
  Cancel the current navigation in progress.\
389
416
  Returns: `void`\
390
417
  [Wiki](https://github.com/greydragon888/real-router/wiki/cancel)
@@ -398,6 +425,7 @@ The following methods are designed for **plugin authors**. They provide low-leve
398
425
  These methods are stable but intended for plugin development, not application code.
399
426
 
400
427
  #### `router.matchPath(path: string, source?: string): State | undefined`
428
+
401
429
  Match URL path to route state.\
402
430
  `path: string` — URL path to match\
403
431
  `source?: string` — navigation source identifier\
@@ -405,6 +433,7 @@ Returns: `State | undefined`\
405
433
  [Wiki](https://github.com/greydragon888/real-router/wiki/matchPath)
406
434
 
407
435
  #### `router.makeState(name, params?, path?, meta?, forceId?): State`
436
+
408
437
  Create State with custom `meta.id` for history restoration.\
409
438
  `name: string` — route name\
410
439
  `params?: Params` — route parameters\
@@ -415,6 +444,7 @@ Returns: `State`\
415
444
  [Wiki](https://github.com/greydragon888/real-router/wiki/makeState)
416
445
 
417
446
  #### `router.buildState(name: string, params?: Params): State | undefined`
447
+
418
448
  Validate route and build state with segment metadata.\
419
449
  `name: string` — route name\
420
450
  `params?: Params` — route parameters\
@@ -422,6 +452,7 @@ Returns: `State | undefined`\
422
452
  [Wiki](https://github.com/greydragon888/real-router/wiki/buildState)
423
453
 
424
454
  #### `router.forwardState(name: string, params: Params): { name: string; params: Params }`
455
+
425
456
  Resolve route forwarding and merge default params.\
426
457
  `name: string` — route name\
427
458
  `params: Params` — route parameters\
@@ -429,6 +460,7 @@ Returns: `{ name, params }` — resolved route name and merged params\
429
460
  [Wiki](https://github.com/greydragon888/real-router/wiki/forwardState)
430
461
 
431
462
  #### `router.navigateToState(toState, fromState, opts, done, emitSuccess): CancelFn`
463
+
432
464
  Navigate with pre-built State object.\
433
465
  `toState: State` — target state\
434
466
  `fromState: State | undefined` — current state\
@@ -439,12 +471,14 @@ Returns: `CancelFn`\
439
471
  [Wiki](https://github.com/greydragon888/real-router/wiki/navigateToState)
440
472
 
441
473
  #### `router.setRootPath(rootPath: string): void`
474
+
442
475
  Dynamically modify router base path.\
443
476
  `rootPath: string` — new root path prefix\
444
477
  Returns: `void`\
445
478
  [Wiki](https://github.com/greydragon888/real-router/wiki/setRootPath)
446
479
 
447
480
  #### `router.getRootPath(): string`
481
+
448
482
  Read current base path.\
449
483
  Returns: `string`\
450
484
  [Wiki](https://github.com/greydragon888/real-router/wiki/getRootPath)
@@ -455,16 +489,16 @@ Returns: `string`\
455
489
 
456
490
  ```typescript
457
491
  interface Options {
458
- defaultRoute: string; // Default route name (default: "")
459
- defaultParams: Params; // Default route params (default: {})
460
- trailingSlash: "strict" | "never" | "always" | "preserve"; // (default: "preserve")
461
- caseSensitive: boolean; // Case-sensitive matching (default: false)
462
- urlParamsEncoding: "default" | "uri" | "uriComponent" | "none"; // (default: "default")
463
- queryParamsMode: "default" | "strict" | "loose"; // (default: "loose")
492
+ defaultRoute: string; // Default route name (default: "")
493
+ defaultParams: Params; // Default route params (default: {})
494
+ trailingSlash: "strict" | "never" | "always" | "preserve"; // (default: "preserve")
495
+ caseSensitive: boolean; // Case-sensitive matching (default: false)
496
+ urlParamsEncoding: "default" | "uri" | "uriComponent" | "none"; // (default: "default")
497
+ queryParamsMode: "default" | "strict" | "loose"; // (default: "loose")
464
498
  queryParams?: QueryParamsOptions; // Query parameter parsing options
465
- allowNotFound: boolean; // Allow navigation to unknown routes (default: true)
466
- rewritePathOnMatch: boolean; // Rewrite path on successful match (default: false)
467
- logger?: Partial<LoggerConfig>; // Logger configuration
499
+ allowNotFound: boolean; // Allow navigation to unknown routes (default: true)
500
+ rewritePathOnMatch: boolean; // Rewrite path on successful match (default: false)
501
+ logger?: Partial<LoggerConfig>; // Logger configuration
468
502
  }
469
503
  ```
470
504
 
@@ -474,17 +508,8 @@ See [RouterOptions](https://github.com/greydragon888/real-router/wiki/RouterOpti
474
508
 
475
509
  ## Observable Support
476
510
 
477
- The router implements the [TC39 Observable](https://github.com/tc39/proposal-observable) interface:
478
-
479
- ```typescript
480
- import { from } from "rxjs";
481
-
482
- from(router).subscribe(({ route, previousRoute }) => {
483
- console.log("Route changed:", route.name);
484
- });
485
- ```
486
-
487
- See [Symbol.observable](https://github.com/greydragon888/real-router/wiki/observable) for details.
511
+ > **Note**: Observable API has been moved to `@real-router/rx` package for zero bundle cost.
512
+ > See [@real-router/rx](../rx/README.md) for reactive stream APIs including `state$()`, `events$()`, operators, and TC39 Observable support.
488
513
 
489
514
  ---
490
515
 
@@ -1,4 +1,4 @@
1
- import { EventToPluginMap, EventToNameMap, ErrorCodeKeys, ErrorCodeValues, ErrorCodeToValueMap, EventsKeys, State, DefaultDependencies, Options, Params, StateMetaInput, SimpleState, RouteTreeState, DoneFn, Unsubscribe, EventName, Plugin, NavigationOptions, CancelFn, SubscribeFn, Navigator, Middleware, ActivationFn } from '@real-router/types';
1
+ import { EventToPluginMap, EventToNameMap, ErrorCodeKeys, ErrorCodeValues, ErrorCodeToValueMap, EventsKeys, DefaultDependencies, Options, Params, State, StateMetaInput, SimpleState, RouteTreeState, DoneFn, Unsubscribe, EventName, Plugin, NavigationOptions, CancelFn, SubscribeFn, Navigator, Middleware, ActivationFn } from '@real-router/types';
2
2
  export { ActivationFn, CancelFn, Config, DefaultDependencies, DoneFn, Listener, Middleware, NavigationOptions, Navigator, Options, Params, Plugin, SimpleState, State, StateMeta, SubscribeFn, SubscribeState, Subscription, Unsubscribe } from '@real-router/types';
3
3
 
4
4
  type ConstantsKeys = "UNKNOWN_ROUTE";
@@ -29,55 +29,6 @@ declare const events: EventToNameMap;
29
29
  type EventMethodMap = {
30
30
  [K in EventsKeys as (typeof events)[K]]: (typeof plugins)[K];
31
31
  };
32
- /**
33
- * Observable state passed to subscribers
34
- */
35
- interface SubscribeState {
36
- route: State;
37
- previousRoute: State | undefined;
38
- }
39
- /**
40
- * Observer interface per Observable spec
41
- */
42
- interface Observer {
43
- next?: (value: SubscribeState) => void;
44
- error?: (err: unknown) => void;
45
- complete?: () => void;
46
- }
47
- /**
48
- * Subscription interface per Observable spec
49
- */
50
- interface Subscription {
51
- unsubscribe: () => void;
52
- readonly closed: boolean;
53
- }
54
- /**
55
- * Observable options for enhanced control
56
- */
57
- interface ObservableOptions {
58
- /** AbortSignal for automatic unsubscription */
59
- signal?: AbortSignal;
60
- /** Replay current state to new subscribers (default: true) */
61
- replay?: boolean;
62
- }
63
- /**
64
- * Observable interface for TC39 compliance
65
- */
66
- interface RouterObservable {
67
- [key: symbol]: () => RouterObservable;
68
- subscribe: (observer: Observer | ((value: SubscribeState) => void), options?: ObservableOptions) => Subscription;
69
- }
70
-
71
- /**
72
- * Symbol.observable polyfill declaration for TC39 proposal
73
- *
74
- * @see https://github.com/tc39/proposal-observable
75
- */
76
- declare global {
77
- interface SymbolConstructor {
78
- readonly observable: unique symbol;
79
- }
80
- }
81
32
 
82
33
  /**
83
34
  * Router class with integrated namespace architecture.
@@ -146,14 +97,6 @@ declare class Router<Dependencies extends DefaultDependencies = DefaultDependenc
146
97
  navigateToDefault(optsOrDone?: NavigationOptions | DoneFn, done?: DoneFn): CancelFn;
147
98
  navigateToState(toState: State, fromState: State | undefined, opts: NavigationOptions, callback: DoneFn, emitSuccess: boolean): CancelFn;
148
99
  subscribe(listener: SubscribeFn): Unsubscribe;
149
- /**
150
- * TC39 Observable spec: router[Symbol.observable]() returns observable
151
- */
152
- [Symbol.observable](): RouterObservable;
153
- /**
154
- * RxJS compatibility: router["@@observable"]() returns observable
155
- */
156
- ["@@observable"](): RouterObservable;
157
100
  clone(dependencies?: Dependencies): Router<Dependencies>;
158
101
  getNavigator(): Navigator;
159
102
  }