@real-router/core 0.36.0 → 0.36.2

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.
Files changed (35) hide show
  1. package/dist/cjs/api.js +1 -1
  2. package/dist/cjs/api.js.map +1 -1
  3. package/dist/cjs/index.js +1 -1
  4. package/dist/cjs/index.js.map +1 -1
  5. package/dist/cjs/metafile-cjs.json +1 -1
  6. package/dist/esm/api.mjs +1 -1
  7. package/dist/esm/api.mjs.map +1 -1
  8. package/dist/esm/chunk-PKKD6URG.mjs +1 -0
  9. package/dist/esm/chunk-PKKD6URG.mjs.map +1 -0
  10. package/dist/esm/index.mjs +1 -1
  11. package/dist/esm/metafile-esm.json +1 -1
  12. package/package.json +4 -4
  13. package/src/Router.ts +33 -12
  14. package/src/api/getPluginApi.ts +10 -4
  15. package/src/constants.ts +2 -0
  16. package/src/fsm/routerFSM.ts +2 -21
  17. package/src/internals.ts +21 -2
  18. package/src/namespaces/EventBusNamespace/EventBusNamespace.ts +50 -39
  19. package/src/namespaces/NavigationNamespace/NavigationNamespace.ts +221 -153
  20. package/src/namespaces/NavigationNamespace/constants.ts +55 -0
  21. package/src/namespaces/NavigationNamespace/transition/completeTransition.ts +100 -0
  22. package/src/namespaces/NavigationNamespace/transition/errorHandling.ts +34 -0
  23. package/src/namespaces/NavigationNamespace/transition/guardPhase.ts +214 -0
  24. package/src/namespaces/NavigationNamespace/types.ts +14 -30
  25. package/src/namespaces/RouteLifecycleNamespace/RouteLifecycleNamespace.ts +6 -1
  26. package/src/namespaces/RoutesNamespace/RoutesNamespace.ts +36 -35
  27. package/src/namespaces/RoutesNamespace/forwardToValidation.ts +2 -5
  28. package/src/namespaces/RoutesNamespace/types.ts +1 -2
  29. package/src/namespaces/StateNamespace/StateNamespace.ts +13 -17
  30. package/src/transitionPath.ts +68 -39
  31. package/src/wiring/RouterWiringBuilder.ts +8 -11
  32. package/dist/esm/chunk-AP4ME3HM.mjs +0 -1
  33. package/dist/esm/chunk-AP4ME3HM.mjs.map +0 -1
  34. package/src/namespaces/NavigationNamespace/transition/executeLifecycleGuards.ts +0 -52
  35. package/src/namespaces/NavigationNamespace/transition/index.ts +0 -93
@@ -1,52 +0,0 @@
1
- // packages/core/src/namespaces/NavigationNamespace/transition/executeLifecycleGuards.ts
2
-
3
- import { rethrowAsRouterError } from "./errorHandling";
4
- import { errorCodes } from "../../../constants";
5
- import { RouterError } from "../../../RouterError";
6
-
7
- import type { GuardFn, State } from "@real-router/types";
8
-
9
- // Helper: execution of the Lifecycle Guards group
10
- export async function executeLifecycleGuards(
11
- guard: Map<string, GuardFn>,
12
- toState: State,
13
- fromState: State | undefined,
14
- segments: string[],
15
- errorCode: string,
16
- isCancelled: () => boolean,
17
- signal: AbortSignal,
18
- ): Promise<void> {
19
- const segmentsToProcess = segments.filter((name) => guard.has(name));
20
-
21
- if (segmentsToProcess.length === 0) {
22
- return;
23
- }
24
-
25
- let result: boolean | undefined;
26
-
27
- for (const segment of segmentsToProcess) {
28
- if (isCancelled()) {
29
- throw new RouterError(errorCodes.TRANSITION_CANCELLED);
30
- }
31
-
32
- // Safe cast: segmentsToProcess only contains names that exist in guard (filtered above)
33
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion -- guaranteed by filter
34
- const guardFn = guard.get(segment)!;
35
-
36
- try {
37
- result = await guardFn(toState, fromState, signal);
38
- } catch (error: unknown) {
39
- if (error instanceof DOMException && error.name === "AbortError") {
40
- throw new RouterError(errorCodes.TRANSITION_CANCELLED, {
41
- reason: signal.reason,
42
- });
43
- }
44
-
45
- rethrowAsRouterError(error, errorCode, segment);
46
- }
47
-
48
- if (!result) {
49
- throw new RouterError(errorCode, { segment });
50
- }
51
- }
52
- }
@@ -1,93 +0,0 @@
1
- // packages/core/src/namespaces/NavigationNamespace/transition/index.ts
2
-
3
- import { executeLifecycleGuards } from "./executeLifecycleGuards";
4
- import { constants, errorCodes } from "../../../constants";
5
- import { RouterError } from "../../../RouterError";
6
- import { getTransitionPath } from "../../../transitionPath";
7
-
8
- import type { NavigationDependencies, TransitionOutput } from "../types";
9
- import type { NavigationOptions, State } from "@real-router/types";
10
-
11
- export async function transition(
12
- deps: Pick<
13
- NavigationDependencies,
14
- "getLifecycleFunctions" | "isActive" | "clearCanDeactivate"
15
- >,
16
- toState: State,
17
- fromState: State | undefined,
18
- opts: NavigationOptions,
19
- signal: AbortSignal,
20
- ): Promise<TransitionOutput> {
21
- // We're caching the necessary data
22
- const [canDeactivateFunctions, canActivateFunctions] =
23
- deps.getLifecycleFunctions();
24
- const isUnknownRoute = toState.name === constants.UNKNOWN_ROUTE;
25
-
26
- // State management functions
27
- // Issue #36: Check both explicit cancellation AND router shutdown
28
- const isCancelled = () => signal.aborted || !deps.isActive();
29
-
30
- const { toDeactivate, toActivate, intersection } = getTransitionPath(
31
- toState,
32
- fromState,
33
- opts.reload === undefined ? undefined : { reload: opts.reload },
34
- );
35
-
36
- // determine the necessary steps
37
- const shouldDeactivate =
38
- fromState && !opts.forceDeactivate && toDeactivate.length > 0;
39
- const shouldActivate = !isUnknownRoute && toActivate.length > 0;
40
-
41
- if (shouldDeactivate) {
42
- await executeLifecycleGuards(
43
- canDeactivateFunctions,
44
- toState,
45
- fromState,
46
- toDeactivate,
47
- errorCodes.CANNOT_DEACTIVATE,
48
- isCancelled,
49
- signal,
50
- );
51
- }
52
-
53
- if (isCancelled()) {
54
- throw new RouterError(errorCodes.TRANSITION_CANCELLED);
55
- }
56
-
57
- if (shouldActivate) {
58
- await executeLifecycleGuards(
59
- canActivateFunctions,
60
- toState,
61
- fromState,
62
- toActivate,
63
- errorCodes.CANNOT_ACTIVATE,
64
- isCancelled,
65
- signal,
66
- );
67
- }
68
-
69
- if (isCancelled()) {
70
- throw new RouterError(errorCodes.TRANSITION_CANCELLED);
71
- }
72
-
73
- // Automatic cleaning of inactive segments
74
- if (fromState) {
75
- for (const name of toDeactivate) {
76
- if (!toActivate.includes(name) && canDeactivateFunctions.has(name)) {
77
- deps.clearCanDeactivate(name);
78
- }
79
- }
80
- }
81
-
82
- return {
83
- state: toState,
84
- meta: {
85
- phase: "activating",
86
- segments: {
87
- deactivated: toDeactivate,
88
- activated: toActivate,
89
- intersection,
90
- },
91
- },
92
- };
93
- }