@real-router/core 0.56.0 → 0.57.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.
Files changed (108) hide show
  1. package/dist/cjs/Router-BSGzVINO.js +6 -0
  2. package/dist/cjs/Router-BSGzVINO.js.map +1 -0
  3. package/dist/cjs/api.d.ts +1 -1
  4. package/dist/cjs/api.js +1 -1
  5. package/dist/cjs/{cloneRouter-DRieJvam.js → cloneRouter-7z-60z_f.js} +2 -2
  6. package/dist/cjs/{cloneRouter-DRieJvam.js.map → cloneRouter-7z-60z_f.js.map} +1 -1
  7. package/dist/cjs/{index-C-i6vx5Y.d.ts → index-BWUmnecT.d.ts} +1 -2
  8. package/dist/cjs/index-BWUmnecT.d.ts.map +1 -0
  9. package/dist/cjs/index.d.ts +1 -1
  10. package/dist/cjs/index.js +1 -1
  11. package/dist/cjs/utils.js +1 -1
  12. package/dist/cjs/validation.d.ts +1 -1
  13. package/dist/esm/Router-B7txWo9N.mjs +6 -0
  14. package/dist/esm/Router-B7txWo9N.mjs.map +1 -0
  15. package/dist/esm/api.d.mts +1 -1
  16. package/dist/esm/api.mjs +1 -1
  17. package/dist/esm/{cloneRouter-DHrH6D_z.mjs → cloneRouter-BNCQ7tIa.mjs} +2 -2
  18. package/dist/esm/{cloneRouter-DHrH6D_z.mjs.map → cloneRouter-BNCQ7tIa.mjs.map} +1 -1
  19. package/dist/esm/{index-C-i6vx5Y.d.mts → index-BWUmnecT.d.mts} +1 -2
  20. package/dist/esm/index-BWUmnecT.d.mts.map +1 -0
  21. package/dist/esm/index.d.mts +1 -1
  22. package/dist/esm/index.mjs +1 -1
  23. package/dist/esm/utils.mjs +1 -1
  24. package/dist/esm/validation.d.mts +1 -1
  25. package/package.json +2 -3
  26. package/dist/cjs/Router-IEGavTKk.js +0 -6
  27. package/dist/cjs/Router-IEGavTKk.js.map +0 -1
  28. package/dist/cjs/index-C-i6vx5Y.d.ts.map +0 -1
  29. package/dist/esm/Router-B3aeavRb.mjs +0 -6
  30. package/dist/esm/Router-B3aeavRb.mjs.map +0 -1
  31. package/dist/esm/index-C-i6vx5Y.d.mts.map +0 -1
  32. package/src/Router.ts +0 -737
  33. package/src/RouterError.ts +0 -324
  34. package/src/api/cloneRouter.ts +0 -159
  35. package/src/api/getDependenciesApi.ts +0 -160
  36. package/src/api/getLifecycleApi.ts +0 -65
  37. package/src/api/getPluginApi.ts +0 -228
  38. package/src/api/getRoutesApi.ts +0 -831
  39. package/src/api/helpers.ts +0 -10
  40. package/src/api/index.ts +0 -16
  41. package/src/api/types.ts +0 -12
  42. package/src/constants.ts +0 -101
  43. package/src/createRouter.ts +0 -32
  44. package/src/fsm/index.ts +0 -5
  45. package/src/fsm/routerFSM.ts +0 -130
  46. package/src/getNavigator.ts +0 -30
  47. package/src/guards.ts +0 -46
  48. package/src/helpers.ts +0 -197
  49. package/src/index.ts +0 -66
  50. package/src/internals.ts +0 -228
  51. package/src/namespaces/DependenciesNamespace/dependenciesStore.ts +0 -30
  52. package/src/namespaces/DependenciesNamespace/index.ts +0 -5
  53. package/src/namespaces/EventBusNamespace/EventBusNamespace.ts +0 -522
  54. package/src/namespaces/EventBusNamespace/index.ts +0 -5
  55. package/src/namespaces/EventBusNamespace/types.ts +0 -11
  56. package/src/namespaces/NavigationNamespace/NavigationNamespace.ts +0 -552
  57. package/src/namespaces/NavigationNamespace/constants.ts +0 -55
  58. package/src/namespaces/NavigationNamespace/index.ts +0 -5
  59. package/src/namespaces/NavigationNamespace/transition/completeTransition.ts +0 -108
  60. package/src/namespaces/NavigationNamespace/transition/errorHandling.ts +0 -124
  61. package/src/namespaces/NavigationNamespace/transition/guardPhase.ts +0 -283
  62. package/src/namespaces/NavigationNamespace/types.ts +0 -110
  63. package/src/namespaces/OptionsNamespace/OptionsNamespace.ts +0 -28
  64. package/src/namespaces/OptionsNamespace/constants.ts +0 -19
  65. package/src/namespaces/OptionsNamespace/helpers.ts +0 -50
  66. package/src/namespaces/OptionsNamespace/index.ts +0 -7
  67. package/src/namespaces/OptionsNamespace/validators.ts +0 -13
  68. package/src/namespaces/PluginsNamespace/PluginsNamespace.ts +0 -291
  69. package/src/namespaces/PluginsNamespace/constants.ts +0 -34
  70. package/src/namespaces/PluginsNamespace/index.ts +0 -7
  71. package/src/namespaces/PluginsNamespace/types.ts +0 -22
  72. package/src/namespaces/PluginsNamespace/validators.ts +0 -28
  73. package/src/namespaces/RouteLifecycleNamespace/RouteLifecycleNamespace.ts +0 -558
  74. package/src/namespaces/RouteLifecycleNamespace/index.ts +0 -5
  75. package/src/namespaces/RouteLifecycleNamespace/types.ts +0 -10
  76. package/src/namespaces/RouterLifecycleNamespace/RouterLifecycleNamespace.ts +0 -81
  77. package/src/namespaces/RouterLifecycleNamespace/constants.ts +0 -25
  78. package/src/namespaces/RouterLifecycleNamespace/index.ts +0 -5
  79. package/src/namespaces/RouterLifecycleNamespace/types.ts +0 -30
  80. package/src/namespaces/RoutesNamespace/RoutesNamespace.ts +0 -582
  81. package/src/namespaces/RoutesNamespace/constants.ts +0 -6
  82. package/src/namespaces/RoutesNamespace/forwardChain.ts +0 -34
  83. package/src/namespaces/RoutesNamespace/helpers.ts +0 -204
  84. package/src/namespaces/RoutesNamespace/index.ts +0 -11
  85. package/src/namespaces/RoutesNamespace/routeGuards.ts +0 -62
  86. package/src/namespaces/RoutesNamespace/routesStore.ts +0 -566
  87. package/src/namespaces/RoutesNamespace/types.ts +0 -81
  88. package/src/namespaces/StateNamespace/StateNamespace.ts +0 -224
  89. package/src/namespaces/StateNamespace/helpers.ts +0 -24
  90. package/src/namespaces/StateNamespace/index.ts +0 -5
  91. package/src/namespaces/StateNamespace/types.ts +0 -15
  92. package/src/namespaces/index.ts +0 -35
  93. package/src/stateMetaStore.ts +0 -15
  94. package/src/transitionPath.ts +0 -440
  95. package/src/typeGuards.ts +0 -59
  96. package/src/types/RouterValidator.ts +0 -156
  97. package/src/types.ts +0 -77
  98. package/src/utils/createRequestScope.ts +0 -174
  99. package/src/utils/getStaticPaths.ts +0 -50
  100. package/src/utils/hydrateRouter.ts +0 -89
  101. package/src/utils/index.ts +0 -27
  102. package/src/utils/serializeRouterState.ts +0 -120
  103. package/src/utils/serializeState.ts +0 -63
  104. package/src/validation.ts +0 -12
  105. package/src/wiring/RouterWiringBuilder.ts +0 -275
  106. package/src/wiring/index.ts +0 -7
  107. package/src/wiring/types.ts +0 -47
  108. package/src/wiring/wireRouter.ts +0 -26
@@ -1,275 +0,0 @@
1
- // packages/core/src/wiring/RouterWiringBuilder.ts
2
-
3
- import { normalizeParams } from "../helpers";
4
- import { getInternals } from "../internals";
5
- import { resolveOption } from "../namespaces/OptionsNamespace";
6
-
7
- import type { EventBusNamespace } from "../namespaces";
8
- import type { WiringOptions } from "./types";
9
- import type { NavigationDependencies } from "../namespaces/NavigationNamespace";
10
- import type { PluginsDependencies } from "../namespaces/PluginsNamespace";
11
- import type { RouteLifecycleDependencies } from "../namespaces/RouteLifecycleNamespace";
12
- import type { RouterLifecycleDependencies } from "../namespaces/RouterLifecycleNamespace";
13
- import type { RoutesDependencies } from "../namespaces/RoutesNamespace";
14
- import type { DefaultDependencies, Params } from "@real-router/types";
15
-
16
- export class RouterWiringBuilder<
17
- Dependencies extends DefaultDependencies = DefaultDependencies,
18
- > {
19
- private readonly router: WiringOptions<Dependencies>["router"];
20
- private readonly options: WiringOptions<Dependencies>["options"];
21
- private readonly limits: WiringOptions<Dependencies>["limits"];
22
- private readonly dependenciesStore: WiringOptions<Dependencies>["dependenciesStore"];
23
- private readonly state: WiringOptions<Dependencies>["state"];
24
- private readonly routes: WiringOptions<Dependencies>["routes"];
25
- private readonly routeLifecycle: WiringOptions<Dependencies>["routeLifecycle"];
26
- private readonly plugins: WiringOptions<Dependencies>["plugins"];
27
- private readonly navigation: WiringOptions<Dependencies>["navigation"];
28
- private readonly lifecycle: WiringOptions<Dependencies>["lifecycle"];
29
- private readonly eventBus: EventBusNamespace;
30
-
31
- constructor(wiringOptions: WiringOptions<Dependencies>) {
32
- this.router = wiringOptions.router;
33
- this.options = wiringOptions.options;
34
- this.limits = wiringOptions.limits;
35
- this.dependenciesStore = wiringOptions.dependenciesStore;
36
- this.state = wiringOptions.state;
37
- this.routes = wiringOptions.routes;
38
- this.routeLifecycle = wiringOptions.routeLifecycle;
39
- this.plugins = wiringOptions.plugins;
40
- this.navigation = wiringOptions.navigation;
41
- this.lifecycle = wiringOptions.lifecycle;
42
- this.eventBus = wiringOptions.eventBus;
43
- }
44
-
45
- wireLimits(): void {
46
- this.dependenciesStore.limits = this.limits;
47
- this.plugins.setLimits(this.limits);
48
- this.eventBus.setLimits({
49
- maxListeners: this.limits.maxListeners,
50
- warnListeners: this.limits.warnListeners,
51
- maxEventDepth: this.limits.maxEventDepth,
52
- });
53
- this.routeLifecycle.setLimits(this.limits);
54
- }
55
-
56
- wireRouteLifecycleDeps(): void {
57
- const routeLifecycleDeps: RouteLifecycleDependencies<Dependencies> = {
58
- compileFactory: this.createCompileFactory(),
59
- };
60
-
61
- this.routeLifecycle.setDependencies(routeLifecycleDeps);
62
- this.routeLifecycle.setValidatorGetter(
63
- /* v8 ignore next 3 -- @preserve: returns null during construction (before registerInternals) */
64
- () => {
65
- try {
66
- return getInternals(this.router).validator;
67
- } catch {
68
- return null;
69
- }
70
- },
71
- );
72
- }
73
-
74
- wireRoutesDeps(): void {
75
- const routesDeps: RoutesDependencies<Dependencies> = {
76
- addActivateGuard: (name, handler) => {
77
- this.routeLifecycle.addCanActivate(name, handler, true);
78
- },
79
- addDeactivateGuard: (name, handler) => {
80
- this.routeLifecycle.addCanDeactivate(name, handler, true);
81
- },
82
- makeState: (name, params, path, meta) =>
83
- this.state.makeState(name, params, path, meta),
84
- getState: () => this.state.get(),
85
- areStatesEqual: (state1, state2, ignoreQueryParams) =>
86
- this.state.areStatesEqual(state1, state2, ignoreQueryParams),
87
- getDependency: (name) =>
88
- this.dependenciesStore.dependencies[name] as Dependencies[typeof name],
89
- forwardState: <P extends Params = Params>(name: string, params: P) => {
90
- const ctx = getInternals(this.router);
91
-
92
- ctx.validator?.routes.validateStateBuilderArgs(
93
- name,
94
- params,
95
- "forwardState",
96
- );
97
-
98
- return ctx.forwardState(name, params);
99
- },
100
- };
101
-
102
- this.routes.setDependencies(routesDeps);
103
- this.routes.setLifecycleNamespace(this.routeLifecycle);
104
- }
105
-
106
- wirePluginsDeps(): void {
107
- const pluginsDeps: PluginsDependencies<Dependencies> = {
108
- addEventListener: (eventName, cb) =>
109
- this.eventBus.addEventListener(eventName, cb),
110
- canNavigate: () => this.eventBus.canBeginTransition(),
111
- compileFactory: this.createCompileFactory(),
112
- };
113
-
114
- this.plugins.setDependencies(pluginsDeps);
115
- this.plugins.setValidatorGetter(
116
- /* v8 ignore next 3 -- @preserve: returns null during construction (before registerInternals) */
117
- () => {
118
- try {
119
- return getInternals(this.router).validator;
120
- } catch {
121
- return null;
122
- }
123
- },
124
- );
125
- }
126
-
127
- wireNavigationDeps(): void {
128
- const navigationDeps: NavigationDependencies = {
129
- getOptions: () => this.options.get(),
130
- hasRoute: (name) => this.routes.hasRoute(name),
131
- getState: () => this.state.get(),
132
- setState: (state) => {
133
- this.state.set(state);
134
- },
135
- buildNavigateState: (routeName, routeParams) => {
136
- const ctx = getInternals(this.router);
137
-
138
- ctx.validator?.routes.validateStateBuilderArgs(
139
- routeName,
140
- routeParams,
141
- "navigate",
142
- );
143
-
144
- const forwarded = ctx.forwardState(routeName, routeParams);
145
- const name = forwarded.name;
146
- const params = normalizeParams(forwarded.params);
147
- const meta = this.routes.getMetaForState(name);
148
-
149
- if (meta === undefined) {
150
- return;
151
- }
152
-
153
- const path = ctx.buildPath(name, params);
154
-
155
- return this.state.makeState(name, params, path, meta, true);
156
- },
157
- resolveDefault: () => {
158
- const options = this.options.get();
159
- const ctx = getInternals(this.router);
160
-
161
- const route = resolveOption(
162
- options.defaultRoute,
163
- (name: string) =>
164
- this.dependenciesStore.dependencies[name as keyof Dependencies],
165
- );
166
- const params = resolveOption(
167
- options.defaultParams,
168
- /* v8 ignore next -- @preserve: unreachable unless defaultParams is a callback that calls getDependency */
169
- (name: string) =>
170
- this.dependenciesStore.dependencies[name as keyof Dependencies],
171
- );
172
-
173
- if (typeof options.defaultRoute === "function") {
174
- ctx.validator?.options.validateResolvedDefaultRoute(
175
- route,
176
- ctx.routeGetStore(),
177
- );
178
- }
179
-
180
- return { route, params };
181
- },
182
- startTransition: (toState, fromState) => {
183
- this.eventBus.sendNavigate(toState, fromState);
184
- },
185
- cancelNavigation: () => {
186
- const toState = this.eventBus.getCurrentToState();
187
-
188
- /* v8 ignore next -- @preserve: getCurrentToState() guaranteed set before TRANSITION_STARTED */
189
- if (toState === undefined) {
190
- return;
191
- }
192
-
193
- this.eventBus.sendCancel(toState, this.state.get());
194
- },
195
- sendTransitionDone: (state, fromState, opts) => {
196
- this.eventBus.sendComplete(state, fromState, opts);
197
- },
198
- sendTransitionFail: (toState, fromState, error) => {
199
- this.eventBus.sendFail(toState, fromState, error);
200
- },
201
- emitTransitionError: (toState, fromState, error) => {
202
- this.eventBus.sendFailSafe(toState, fromState, error);
203
- },
204
- emitTransitionSuccess: (toState, fromState, opts) => {
205
- this.eventBus.emitTransitionSuccess(toState, fromState, opts);
206
- },
207
- sendLeaveApprove: (toState, fromState) => {
208
- this.eventBus.sendLeaveApprove(toState, fromState);
209
- },
210
- canNavigate: () => this.eventBus.canBeginTransition(),
211
- getLifecycleFunctions: () => this.routeLifecycle.getFunctions(),
212
- isActive: () => this.router.isActive(),
213
- isTransitioning: () => this.eventBus.isTransitioning(),
214
- clearCanDeactivate: (name: string) => {
215
- this.routeLifecycle.clearCanDeactivate(name);
216
- },
217
- hasLeaveListeners: () => this.eventBus.hasLeaveListeners(),
218
- awaitLeaveListeners: (toState, fromState, signal) =>
219
- this.eventBus.awaitLeaveListeners(toState, fromState, signal),
220
- };
221
-
222
- this.navigation.setDependencies(navigationDeps);
223
- }
224
-
225
- wireLifecycleDeps(): void {
226
- const lifecycleDeps: RouterLifecycleDependencies = {
227
- getOptions: () => this.options.get(),
228
- navigateToState: (state, opts) =>
229
- this.navigation.navigateToState(state, opts),
230
- navigateToNotFound: (path) => this.navigation.navigateToNotFound(path),
231
- clearState: () => {
232
- this.state.set(undefined);
233
- },
234
- matchPath: (path) => this.routes.matchPath(path, this.options.get()),
235
- completeStart: () => {
236
- this.eventBus.sendStarted();
237
- },
238
- emitTransitionError: (toState, fromState, error) => {
239
- this.eventBus.sendFail(toState, fromState, error);
240
- },
241
- };
242
-
243
- this.lifecycle.setDependencies(lifecycleDeps);
244
- }
245
-
246
- wireStateDeps(): void {
247
- this.state.setDependencies({
248
- getDefaultParams: () => this.routes.getStore().config.defaultParams,
249
- buildPath: (name, params) => {
250
- const ctx = getInternals(this.router);
251
-
252
- return ctx.buildPath(name, params);
253
- },
254
- getUrlParams: (name) => this.routes.getUrlParams(name),
255
- });
256
- }
257
-
258
- private createCompileFactory() {
259
- const { router, dependenciesStore } = this;
260
-
261
- return <T>(
262
- factory: (
263
- router: WiringOptions<Dependencies>["router"],
264
- getDependency: <K extends keyof Dependencies>(
265
- name: K,
266
- ) => Dependencies[K],
267
- ) => T,
268
- ): T =>
269
- factory(
270
- router,
271
- <K extends keyof Dependencies>(name: K) =>
272
- dependenciesStore.dependencies[name] as Dependencies[K],
273
- );
274
- }
275
- }
@@ -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
- }