@real-router/core 0.44.2 → 0.45.1

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 (79) hide show
  1. package/dist/cjs/api.js +1 -1
  2. package/dist/cjs/api.js.map +1 -1
  3. package/dist/esm/api.mjs +1 -1
  4. package/dist/esm/api.mjs.map +1 -1
  5. package/package.json +6 -7
  6. package/src/Router.ts +0 -684
  7. package/src/RouterError.ts +0 -324
  8. package/src/api/cloneRouter.ts +0 -77
  9. package/src/api/getDependenciesApi.ts +0 -168
  10. package/src/api/getLifecycleApi.ts +0 -65
  11. package/src/api/getPluginApi.ts +0 -167
  12. package/src/api/getRoutesApi.ts +0 -562
  13. package/src/api/helpers.ts +0 -10
  14. package/src/api/index.ts +0 -16
  15. package/src/api/types.ts +0 -12
  16. package/src/constants.ts +0 -87
  17. package/src/createRouter.ts +0 -32
  18. package/src/fsm/index.ts +0 -5
  19. package/src/fsm/routerFSM.ts +0 -120
  20. package/src/getNavigator.ts +0 -30
  21. package/src/guards.ts +0 -46
  22. package/src/helpers.ts +0 -179
  23. package/src/index.ts +0 -50
  24. package/src/internals.ts +0 -173
  25. package/src/namespaces/DependenciesNamespace/dependenciesStore.ts +0 -30
  26. package/src/namespaces/DependenciesNamespace/index.ts +0 -5
  27. package/src/namespaces/EventBusNamespace/EventBusNamespace.ts +0 -311
  28. package/src/namespaces/EventBusNamespace/index.ts +0 -5
  29. package/src/namespaces/EventBusNamespace/types.ts +0 -11
  30. package/src/namespaces/NavigationNamespace/NavigationNamespace.ts +0 -405
  31. package/src/namespaces/NavigationNamespace/constants.ts +0 -55
  32. package/src/namespaces/NavigationNamespace/index.ts +0 -5
  33. package/src/namespaces/NavigationNamespace/transition/completeTransition.ts +0 -100
  34. package/src/namespaces/NavigationNamespace/transition/errorHandling.ts +0 -124
  35. package/src/namespaces/NavigationNamespace/transition/guardPhase.ts +0 -221
  36. package/src/namespaces/NavigationNamespace/types.ts +0 -100
  37. package/src/namespaces/OptionsNamespace/OptionsNamespace.ts +0 -28
  38. package/src/namespaces/OptionsNamespace/constants.ts +0 -19
  39. package/src/namespaces/OptionsNamespace/helpers.ts +0 -50
  40. package/src/namespaces/OptionsNamespace/index.ts +0 -7
  41. package/src/namespaces/OptionsNamespace/validators.ts +0 -13
  42. package/src/namespaces/PluginsNamespace/PluginsNamespace.ts +0 -291
  43. package/src/namespaces/PluginsNamespace/constants.ts +0 -34
  44. package/src/namespaces/PluginsNamespace/index.ts +0 -7
  45. package/src/namespaces/PluginsNamespace/types.ts +0 -22
  46. package/src/namespaces/PluginsNamespace/validators.ts +0 -28
  47. package/src/namespaces/RouteLifecycleNamespace/RouteLifecycleNamespace.ts +0 -377
  48. package/src/namespaces/RouteLifecycleNamespace/index.ts +0 -5
  49. package/src/namespaces/RouteLifecycleNamespace/types.ts +0 -10
  50. package/src/namespaces/RouterLifecycleNamespace/RouterLifecycleNamespace.ts +0 -81
  51. package/src/namespaces/RouterLifecycleNamespace/constants.ts +0 -25
  52. package/src/namespaces/RouterLifecycleNamespace/index.ts +0 -5
  53. package/src/namespaces/RouterLifecycleNamespace/types.ts +0 -26
  54. package/src/namespaces/RoutesNamespace/RoutesNamespace.ts +0 -535
  55. package/src/namespaces/RoutesNamespace/constants.ts +0 -6
  56. package/src/namespaces/RoutesNamespace/forwardChain.ts +0 -34
  57. package/src/namespaces/RoutesNamespace/helpers.ts +0 -126
  58. package/src/namespaces/RoutesNamespace/index.ts +0 -11
  59. package/src/namespaces/RoutesNamespace/routeGuards.ts +0 -62
  60. package/src/namespaces/RoutesNamespace/routesStore.ts +0 -346
  61. package/src/namespaces/RoutesNamespace/types.ts +0 -81
  62. package/src/namespaces/StateNamespace/StateNamespace.ts +0 -211
  63. package/src/namespaces/StateNamespace/helpers.ts +0 -24
  64. package/src/namespaces/StateNamespace/index.ts +0 -5
  65. package/src/namespaces/StateNamespace/types.ts +0 -15
  66. package/src/namespaces/index.ts +0 -35
  67. package/src/stateMetaStore.ts +0 -15
  68. package/src/transitionPath.ts +0 -436
  69. package/src/typeGuards.ts +0 -59
  70. package/src/types/RouterValidator.ts +0 -154
  71. package/src/types.ts +0 -69
  72. package/src/utils/getStaticPaths.ts +0 -50
  73. package/src/utils/index.ts +0 -5
  74. package/src/utils/serializeState.ts +0 -22
  75. package/src/validation.ts +0 -12
  76. package/src/wiring/RouterWiringBuilder.ts +0 -261
  77. package/src/wiring/index.ts +0 -7
  78. package/src/wiring/types.ts +0 -47
  79. package/src/wiring/wireRouter.ts +0 -26
@@ -1,154 +0,0 @@
1
- /**
2
- * RouterValidator interface - defines all validation methods used by the router.
3
- *
4
- * This interface is implemented by the validation plugin and injected into RouterInternals.
5
- * When ctx.validator is null (default), validation is skipped.
6
- * When ctx.validator is set (by validation plugin), all methods are called.
7
- *
8
- * All parameters use `unknown` type to avoid coupling to internal type names.
9
- */
10
-
11
- export interface RouterValidator {
12
- /**
13
- * Route validation methods
14
- */
15
- routes: {
16
- validateBuildPathArgs: (route: unknown) => void;
17
- validateMatchPathArgs: (path: unknown) => void;
18
- validateIsActiveRouteArgs: (
19
- name: unknown,
20
- params: unknown,
21
- strict: unknown,
22
- ignoreQP: unknown,
23
- ) => void;
24
- validateShouldUpdateNodeArgs: (name: unknown) => void;
25
- validateStateBuilderArgs: (
26
- name: unknown,
27
- params: unknown,
28
- caller: string,
29
- ) => void;
30
- validateAddRouteArgs: (routes: unknown) => void;
31
- validateRoutes: (routes: unknown[], tree: unknown) => void;
32
- validateRemoveRouteArgs: (name: unknown) => void;
33
- validateUpdateRouteBasicArgs: (name: unknown, updates: unknown) => void;
34
- validateUpdateRoutePropertyTypes: (name: string, updates: unknown) => void;
35
- validateUpdateRoute: (
36
- name: string,
37
- updates: unknown,
38
- tree: unknown,
39
- ) => void;
40
- validateParentOption: (parent: unknown, tree: unknown) => void;
41
- validateRouteName: (name: unknown, caller: string) => void;
42
- throwIfInternalRoute: (name: unknown, caller: string) => void;
43
- throwIfInternalRouteInArray: (routes: unknown[], caller: string) => void;
44
- // Retrospective validation
45
- validateExistingRoutes: (store: unknown) => void;
46
- validateForwardToConsistency: (store: unknown) => void;
47
- validateSetRootPathArgs: (rootPath: unknown) => void;
48
- guardRouteCallbacks: (route: unknown) => void;
49
- guardNoAsyncCallbacks: (route: unknown) => void;
50
- };
51
-
52
- /**
53
- * Options validation methods
54
- */
55
- options: {
56
- validateLimitValue: (name: string, value: unknown) => void;
57
- validateLimits: (limits: unknown) => void;
58
- validateOptions: (options: unknown, methodName: string) => void;
59
- };
60
-
61
- /**
62
- * Dependencies validation methods
63
- */
64
- dependencies: {
65
- validateDependencyName: (name: unknown, caller: string) => void;
66
- validateSetDependencyArgs: (
67
- name: unknown,
68
- value: unknown,
69
- caller: string,
70
- ) => void;
71
- validateDependenciesObject: (deps: unknown, caller: string) => void;
72
- validateDependencyExists: (name: string, store: unknown) => void;
73
- validateDependencyLimit: (store: unknown, limits: unknown) => void;
74
- // Retrospective validation
75
- validateDependenciesStructure: (store: unknown) => void;
76
- validateDependencyCount: (store: unknown, methodName: string) => void;
77
- validateCloneArgs: (dependencies: unknown) => void;
78
- warnOverwrite: (name: string, methodName: string) => void;
79
- warnBatchOverwrite: (keys: string[], methodName: string) => void;
80
- warnRemoveNonExistent: (name: unknown) => void;
81
- };
82
-
83
- /**
84
- * Plugin validation methods
85
- */
86
- plugins: {
87
- validatePluginLimit: (count: number, limits: unknown) => void;
88
- validateNoDuplicatePlugins: (
89
- factory: unknown,
90
- factories: unknown[],
91
- ) => void;
92
- validatePluginKeys: (plugin: unknown) => void;
93
- validateCountThresholds: (count: number) => void;
94
- warnBatchDuplicates: (plugins: unknown[]) => void;
95
- warnPluginMethodType: (methodName: string) => void;
96
- warnPluginAfterStart: (methodName: string) => void;
97
- validateAddInterceptorArgs: (method: unknown, fn: unknown) => void;
98
- };
99
-
100
- /**
101
- * Lifecycle guard validation methods
102
- */
103
- lifecycle: {
104
- validateHandler: (handler: unknown, caller: string) => void;
105
- validateNotRegistering: (
106
- name: string,
107
- guards: unknown,
108
- caller: string,
109
- ) => void;
110
- validateHandlerLimit: (
111
- count: number,
112
- limits: unknown,
113
- caller: string,
114
- ) => void;
115
- validateCountThresholds: (count: number, methodName: string) => void;
116
- warnOverwrite: (name: string, type: string, methodName: string) => void;
117
- warnAsyncGuardSync: (name: string, methodName: string) => void;
118
- };
119
-
120
- /**
121
- * Navigation validation methods
122
- */
123
- navigation: {
124
- validateNavigateArgs: (name: unknown) => void;
125
- validateNavigateToDefaultArgs: (options: unknown) => void;
126
- validateNavigationOptions: (options: unknown, caller: string) => void;
127
- validateParams: (params: unknown, methodName: string) => void;
128
- validateStartArgs: (path: unknown) => void;
129
- };
130
-
131
- /**
132
- * State validation methods
133
- */
134
- state: {
135
- validateMakeStateArgs: (
136
- name: unknown,
137
- params: unknown,
138
- path: unknown,
139
- ) => void;
140
- validateAreStatesEqualArgs: (
141
- s1: unknown,
142
- s2: unknown,
143
- ignoreQP: unknown,
144
- ) => void;
145
- };
146
-
147
- /**
148
- * Event bus validation methods
149
- */
150
- eventBus: {
151
- validateEventName: (name: unknown) => void;
152
- validateListenerArgs: (name: unknown, cb: unknown) => void;
153
- };
154
- }
package/src/types.ts DELETED
@@ -1,69 +0,0 @@
1
- // packages/core/src/types.ts
2
-
3
- /**
4
- * Core-internal types + re-exports from @real-router/types.
5
- *
6
- * Factory types (PluginFactory, GuardFnFactory) and
7
- * route config types (Route, RouteConfigUpdate) are canonical in @real-router/types
8
- * and re-exported here for backward compatibility.
9
- */
10
-
11
- import type {
12
- LimitsConfig,
13
- NavigationOptions,
14
- Params,
15
- RouterError as RouterErrorType,
16
- RouteTreeState,
17
- State,
18
- } from "@real-router/types";
19
-
20
- // Re-export from @real-router/types (canonical source)
21
- export type {
22
- GuardFnFactory,
23
- PluginFactory,
24
- Route,
25
- RouteConfigUpdate,
26
- EventMethodMap,
27
- } from "@real-router/types";
28
-
29
- /**
30
- * Event argument tuples for the router's 7 events.
31
- *
32
- * Uses explicit `| undefined` unions (not optional `?`) to satisfy
33
- * `exactOptionalPropertyTypes` when passing undefined args from FSM payloads.
34
- */
35
- // eslint-disable-next-line @typescript-eslint/consistent-type-definitions -- must be `type` for Record<string, unknown[]> constraint
36
- export type RouterEventMap = {
37
- $start: [];
38
- $stop: [];
39
- $$start: [toState: State, fromState: State | undefined];
40
- $$leaveApprove: [toState: State, fromState: State | undefined];
41
- $$success: [
42
- toState: State,
43
- fromState: State | undefined,
44
- opts: NavigationOptions | undefined,
45
- ];
46
- $$error: [
47
- toState: State | undefined,
48
- fromState: State | undefined,
49
- error: RouterErrorType | undefined,
50
- ];
51
- $$cancel: [toState: State, fromState: State | undefined];
52
- };
53
-
54
- /**
55
- * Immutable limits configuration type.
56
- */
57
- export type Limits = Readonly<LimitsConfig>;
58
-
59
- /**
60
- * Extended build result that includes segments for path building.
61
- * Used internally to avoid duplicate getSegmentsByName calls.
62
- *
63
- * @param segments - Route segments from getSegmentsByName (typed as unknown[] for cross-package compatibility)
64
- * @internal
65
- */
66
- export interface BuildStateResultWithSegments<P extends Params = Params> {
67
- readonly state: RouteTreeState<P>;
68
- readonly segments: readonly unknown[];
69
- }
@@ -1,50 +0,0 @@
1
- import { getPluginApi } from "../api/getPluginApi";
2
-
3
- import type { DefaultDependencies, Router } from "@real-router/types";
4
- import type { RouteTree } from "route-tree";
5
-
6
- export type StaticPathEntries = Record<
7
- string,
8
- () => Promise<Record<string, string>[]>
9
- >;
10
-
11
- function getLeafRouteNames(node: RouteTree): string[] {
12
- const result: string[] = [];
13
-
14
- for (const child of node.children.values()) {
15
- if (child.children.size === 0) {
16
- result.push(child.fullName);
17
- } else {
18
- result.push(...getLeafRouteNames(child));
19
- }
20
- }
21
-
22
- return result;
23
- }
24
-
25
- export async function getStaticPaths<
26
- Dependencies extends DefaultDependencies = DefaultDependencies,
27
- >(
28
- router: Router<Dependencies>,
29
- entries?: StaticPathEntries,
30
- ): Promise<string[]> {
31
- const tree = getPluginApi(router).getTree();
32
- const leafRoutes = getLeafRouteNames(tree);
33
- const paths: string[] = [];
34
-
35
- for (const routeName of leafRoutes) {
36
- const entryFn = entries?.[routeName];
37
-
38
- if (entryFn) {
39
- const paramSets = await entryFn();
40
-
41
- for (const params of paramSets) {
42
- paths.push(router.buildPath(routeName, params));
43
- }
44
- } else {
45
- paths.push(router.buildPath(routeName, {}));
46
- }
47
- }
48
-
49
- return paths;
50
- }
@@ -1,5 +0,0 @@
1
- export { getStaticPaths } from "./getStaticPaths";
2
-
3
- export { serializeState } from "./serializeState";
4
-
5
- export type { StaticPathEntries } from "./getStaticPaths";
@@ -1,22 +0,0 @@
1
- /**
2
- * XSS-safe JSON serialization for embedding data in HTML `<script>` tags.
3
- *
4
- * Escapes `<`, `>`, and `&` to their Unicode equivalents to prevent
5
- * injection via `</script>` or HTML entities inside inline scripts.
6
- *
7
- * @example
8
- * ```typescript
9
- * const json = serializeState({ name: "home", path: "/" });
10
- * const html = `<script>window.__STATE__=${json}</script>`;
11
- * ```
12
- */
13
- export function serializeState(data: unknown): string {
14
- if (data === undefined) {
15
- return "null";
16
- }
17
-
18
- return JSON.stringify(data)
19
- .replaceAll("<", String.raw`\u003c`)
20
- .replaceAll(">", String.raw`\u003e`)
21
- .replaceAll("&", String.raw`\u0026`);
22
- }
package/src/validation.ts DELETED
@@ -1,12 +0,0 @@
1
- /**
2
- * Subpath export for @real-router/validation-plugin.
3
- *
4
- * Provides access to router internals so the plugin can install
5
- * ctx.validator and run retrospective validation at registration time.
6
- */
7
-
8
- export type { RouterValidator } from "./types/RouterValidator";
9
-
10
- export { getInternals } from "./internals";
11
-
12
- export type { RouterInternals } from "./internals";
@@ -1,261 +0,0 @@
1
- // packages/core/src/wiring/RouterWiringBuilder.ts
2
-
3
- import { getInternals } from "../internals";
4
- import { resolveOption } from "../namespaces/OptionsNamespace";
5
-
6
- import type { EventBusNamespace } from "../namespaces";
7
- import type { WiringOptions } from "./types";
8
- import type { NavigationDependencies } from "../namespaces/NavigationNamespace";
9
- import type { PluginsDependencies } from "../namespaces/PluginsNamespace";
10
- import type { RouteLifecycleDependencies } from "../namespaces/RouteLifecycleNamespace";
11
- import type { RouterLifecycleDependencies } from "../namespaces/RouterLifecycleNamespace";
12
- import type { RoutesDependencies } from "../namespaces/RoutesNamespace";
13
- import type { DefaultDependencies, Params } from "@real-router/types";
14
-
15
- export class RouterWiringBuilder<
16
- Dependencies extends DefaultDependencies = DefaultDependencies,
17
- > {
18
- private readonly router: WiringOptions<Dependencies>["router"];
19
- private readonly options: WiringOptions<Dependencies>["options"];
20
- private readonly limits: WiringOptions<Dependencies>["limits"];
21
- private readonly dependenciesStore: WiringOptions<Dependencies>["dependenciesStore"];
22
- private readonly state: WiringOptions<Dependencies>["state"];
23
- private readonly routes: WiringOptions<Dependencies>["routes"];
24
- private readonly routeLifecycle: WiringOptions<Dependencies>["routeLifecycle"];
25
- private readonly plugins: WiringOptions<Dependencies>["plugins"];
26
- private readonly navigation: WiringOptions<Dependencies>["navigation"];
27
- private readonly lifecycle: WiringOptions<Dependencies>["lifecycle"];
28
- private readonly eventBus: EventBusNamespace;
29
-
30
- constructor(wiringOptions: WiringOptions<Dependencies>) {
31
- this.router = wiringOptions.router;
32
- this.options = wiringOptions.options;
33
- this.limits = wiringOptions.limits;
34
- this.dependenciesStore = wiringOptions.dependenciesStore;
35
- this.state = wiringOptions.state;
36
- this.routes = wiringOptions.routes;
37
- this.routeLifecycle = wiringOptions.routeLifecycle;
38
- this.plugins = wiringOptions.plugins;
39
- this.navigation = wiringOptions.navigation;
40
- this.lifecycle = wiringOptions.lifecycle;
41
- this.eventBus = wiringOptions.eventBus;
42
- }
43
-
44
- wireLimits(): void {
45
- this.dependenciesStore.limits = this.limits;
46
- this.plugins.setLimits(this.limits);
47
- this.eventBus.setLimits({
48
- maxListeners: this.limits.maxListeners,
49
- warnListeners: this.limits.warnListeners,
50
- maxEventDepth: this.limits.maxEventDepth,
51
- });
52
- this.routeLifecycle.setLimits(this.limits);
53
- }
54
-
55
- wireRouteLifecycleDeps(): void {
56
- const routeLifecycleDeps: RouteLifecycleDependencies<Dependencies> = {
57
- compileFactory: this.createCompileFactory(),
58
- };
59
-
60
- this.routeLifecycle.setDependencies(routeLifecycleDeps);
61
- this.routeLifecycle.setValidatorGetter(
62
- /* v8 ignore next 3 -- @preserve: returns null during construction (before registerInternals) */
63
- () => {
64
- try {
65
- return getInternals(this.router).validator;
66
- } catch {
67
- return null;
68
- }
69
- },
70
- );
71
- }
72
-
73
- wireRoutesDeps(): void {
74
- const routesDeps: RoutesDependencies<Dependencies> = {
75
- addActivateGuard: (name, handler) => {
76
- this.routeLifecycle.addCanActivate(name, handler, true);
77
- },
78
- addDeactivateGuard: (name, handler) => {
79
- this.routeLifecycle.addCanDeactivate(name, handler, true);
80
- },
81
- makeState: (name, params, path, meta) =>
82
- this.state.makeState(name, params, path, meta),
83
- getState: () => this.state.get(),
84
- areStatesEqual: (state1, state2, ignoreQueryParams) =>
85
- this.state.areStatesEqual(state1, state2, ignoreQueryParams),
86
- getDependency: (name) =>
87
- this.dependenciesStore.dependencies[name] as Dependencies[typeof name],
88
- forwardState: <P extends Params = Params>(name: string, params: P) => {
89
- const ctx = getInternals(this.router);
90
-
91
- ctx.validator?.routes.validateStateBuilderArgs(
92
- name,
93
- params,
94
- "forwardState",
95
- );
96
-
97
- return ctx.forwardState(name, params);
98
- },
99
- };
100
-
101
- this.routes.setDependencies(routesDeps);
102
- this.routes.setLifecycleNamespace(this.routeLifecycle);
103
- }
104
-
105
- wirePluginsDeps(): void {
106
- const pluginsDeps: PluginsDependencies<Dependencies> = {
107
- addEventListener: (eventName, cb) =>
108
- this.eventBus.addEventListener(eventName, cb),
109
- canNavigate: () => this.eventBus.canBeginTransition(),
110
- compileFactory: this.createCompileFactory(),
111
- };
112
-
113
- this.plugins.setDependencies(pluginsDeps);
114
- this.plugins.setValidatorGetter(
115
- /* v8 ignore next 3 -- @preserve: returns null during construction (before registerInternals) */
116
- () => {
117
- try {
118
- return getInternals(this.router).validator;
119
- } catch {
120
- return null;
121
- }
122
- },
123
- );
124
- }
125
-
126
- wireNavigationDeps(): void {
127
- const navigationDeps: NavigationDependencies = {
128
- getOptions: () => this.options.get(),
129
- hasRoute: (name) => this.routes.hasRoute(name),
130
- getState: () => this.state.get(),
131
- setState: (state) => {
132
- this.state.set(state);
133
- },
134
- buildNavigateState: (routeName, routeParams) => {
135
- const ctx = getInternals(this.router);
136
-
137
- ctx.validator?.routes.validateStateBuilderArgs(
138
- routeName,
139
- routeParams,
140
- "navigate",
141
- );
142
-
143
- const { name, params } = ctx.forwardState(routeName, routeParams);
144
- const meta = this.routes.getMetaForState(name);
145
-
146
- if (meta === undefined) {
147
- return;
148
- }
149
-
150
- const path = ctx.buildPath(name, params);
151
-
152
- return this.state.makeState(name, params, path, meta, true);
153
- },
154
- resolveDefault: () => {
155
- const options = this.options.get();
156
-
157
- return {
158
- route: resolveOption(
159
- options.defaultRoute,
160
- (name: string) =>
161
- this.dependenciesStore.dependencies[name as keyof Dependencies],
162
- ),
163
- params: resolveOption(
164
- options.defaultParams,
165
- /* v8 ignore next -- @preserve: unreachable unless defaultParams is a callback that calls getDependency */
166
- (name: string) =>
167
- this.dependenciesStore.dependencies[name as keyof Dependencies],
168
- ),
169
- };
170
- },
171
- startTransition: (toState, fromState) => {
172
- this.eventBus.sendNavigate(toState, fromState);
173
- },
174
- cancelNavigation: () => {
175
- const toState = this.eventBus.getCurrentToState();
176
-
177
- /* v8 ignore next -- @preserve: getCurrentToState() guaranteed set before TRANSITION_STARTED */
178
- if (toState === undefined) {
179
- return;
180
- }
181
-
182
- this.eventBus.sendCancel(toState, this.state.get());
183
- },
184
- sendTransitionDone: (state, fromState, opts) => {
185
- this.eventBus.sendComplete(state, fromState, opts);
186
- },
187
- sendTransitionFail: (toState, fromState, error) => {
188
- this.eventBus.sendFail(toState, fromState, error);
189
- },
190
- emitTransitionError: (toState, fromState, error) => {
191
- this.eventBus.sendFailSafe(toState, fromState, error);
192
- },
193
- emitTransitionSuccess: (toState, fromState, opts) => {
194
- this.eventBus.emitTransitionSuccess(toState, fromState, opts);
195
- },
196
- sendLeaveApprove: (toState, fromState) => {
197
- this.eventBus.sendLeaveApprove(toState, fromState);
198
- },
199
- canNavigate: () => this.eventBus.canBeginTransition(),
200
- getLifecycleFunctions: () => this.routeLifecycle.getFunctions(),
201
- isActive: () => this.router.isActive(),
202
- isTransitioning: () => this.eventBus.isTransitioning(),
203
- clearCanDeactivate: (name: string) => {
204
- this.routeLifecycle.clearCanDeactivate(name);
205
- },
206
- };
207
-
208
- this.navigation.setDependencies(navigationDeps);
209
- }
210
-
211
- wireLifecycleDeps(): void {
212
- const lifecycleDeps: RouterLifecycleDependencies = {
213
- getOptions: () => this.options.get(),
214
- navigate: (name, params, opts) =>
215
- this.navigation.navigate(name, params, opts),
216
- navigateToNotFound: (path) => this.navigation.navigateToNotFound(path),
217
- clearState: () => {
218
- this.state.set(undefined);
219
- },
220
- matchPath: (path) => this.routes.matchPath(path, this.options.get()),
221
- completeStart: () => {
222
- this.eventBus.sendStarted();
223
- },
224
- emitTransitionError: (toState, fromState, error) => {
225
- this.eventBus.sendFail(toState, fromState, error);
226
- },
227
- };
228
-
229
- this.lifecycle.setDependencies(lifecycleDeps);
230
- }
231
-
232
- wireStateDeps(): void {
233
- this.state.setDependencies({
234
- getDefaultParams: () => this.routes.getStore().config.defaultParams,
235
- buildPath: (name, params) => {
236
- const ctx = getInternals(this.router);
237
-
238
- return ctx.buildPath(name, params);
239
- },
240
- getUrlParams: (name) => this.routes.getUrlParams(name),
241
- });
242
- }
243
-
244
- private createCompileFactory() {
245
- const { router, dependenciesStore } = this;
246
-
247
- return <T>(
248
- factory: (
249
- router: WiringOptions<Dependencies>["router"],
250
- getDependency: <K extends keyof Dependencies>(
251
- name: K,
252
- ) => Dependencies[K],
253
- ) => T,
254
- ): T =>
255
- factory(
256
- router,
257
- <K extends keyof Dependencies>(name: K) =>
258
- dependenciesStore.dependencies[name] as Dependencies[K],
259
- );
260
- }
261
- }
@@ -1,7 +0,0 @@
1
- // packages/core/src/wiring/index.ts
2
-
3
- export { RouterWiringBuilder } from "./RouterWiringBuilder";
4
-
5
- export { wireRouter } from "./wireRouter";
6
-
7
- export type { WiringOptions } from "./types";
@@ -1,47 +0,0 @@
1
- // packages/core/src/wiring/types.ts
2
-
3
- import type {
4
- EventBusNamespace,
5
- NavigationNamespace,
6
- OptionsNamespace,
7
- PluginsNamespace,
8
- RouteLifecycleNamespace,
9
- RouterLifecycleNamespace,
10
- RoutesNamespace,
11
- StateNamespace,
12
- } from "../namespaces";
13
- import type { DependenciesStore } from "../namespaces/DependenciesNamespace/dependenciesStore";
14
- import type { Router } from "../Router";
15
- import type { Limits } from "../types";
16
- import type { DefaultDependencies } from "@real-router/types";
17
-
18
- /**
19
- * Constructor options bag for RouterWiringBuilder.
20
- *
21
- * Contains all namespaces, FSM, emitter, and accessors needed to wire
22
- * inter-namespace dependencies.
23
- */
24
- export interface WiringOptions<Dependencies extends DefaultDependencies> {
25
- /** Router instance — passed to namespaces for factory initialization */
26
- router: Router<Dependencies>;
27
- /** Options namespace */
28
- options: OptionsNamespace;
29
- /** Immutable limits configuration */
30
- limits: Limits;
31
- /** Dependencies store */
32
- dependenciesStore: DependenciesStore<Dependencies>;
33
- /** State namespace */
34
- state: StateNamespace;
35
- /** Routes namespace */
36
- routes: RoutesNamespace<Dependencies>;
37
- /** Route lifecycle namespace (canActivate/canDeactivate guards) */
38
- routeLifecycle: RouteLifecycleNamespace<Dependencies>;
39
- /** Plugins namespace */
40
- plugins: PluginsNamespace<Dependencies>;
41
- /** Navigation namespace */
42
- navigation: NavigationNamespace;
43
- /** Router lifecycle namespace (start/stop) */
44
- lifecycle: RouterLifecycleNamespace;
45
- /** EventBus namespace — unified FSM + EventEmitter abstraction */
46
- eventBus: EventBusNamespace;
47
- }
@@ -1,26 +0,0 @@
1
- // packages/core/src/wiring/wireRouter.ts
2
-
3
- import type { RouterWiringBuilder } from "./RouterWiringBuilder";
4
- import type { DefaultDependencies } from "@real-router/types";
5
-
6
- /**
7
- * Director function — calls RouterWiringBuilder methods in the correct dependency order.
8
- *
9
- * ORDER MATTERS:
10
- * - `wireLimits()` first: all namespaces must have limits before any other setup
11
- * - `wireRouteLifecycleDeps()` BEFORE `wireRoutesDeps()`: RoutesNamespace.setDependencies()
12
- * registers pending canActivate handlers which require RouteLifecycleNamespace to be ready
13
- * - `wireNavigationDeps()` BEFORE `wireLifecycleDeps()`: lifecycle deps reference
14
- * NavigationNamespace.navigate() which requires navigation deps to be set
15
- */
16
- export function wireRouter<Dependencies extends DefaultDependencies>(
17
- builder: RouterWiringBuilder<Dependencies>,
18
- ): void {
19
- builder.wireLimits();
20
- builder.wireRouteLifecycleDeps();
21
- builder.wireRoutesDeps();
22
- builder.wirePluginsDeps();
23
- builder.wireNavigationDeps();
24
- builder.wireLifecycleDeps();
25
- builder.wireStateDeps();
26
- }