@real-router/core 0.45.0 → 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 (75) hide show
  1. package/package.json +6 -7
  2. package/src/Router.ts +0 -684
  3. package/src/RouterError.ts +0 -324
  4. package/src/api/cloneRouter.ts +0 -77
  5. package/src/api/getDependenciesApi.ts +0 -168
  6. package/src/api/getLifecycleApi.ts +0 -65
  7. package/src/api/getPluginApi.ts +0 -167
  8. package/src/api/getRoutesApi.ts +0 -573
  9. package/src/api/helpers.ts +0 -10
  10. package/src/api/index.ts +0 -16
  11. package/src/api/types.ts +0 -12
  12. package/src/constants.ts +0 -87
  13. package/src/createRouter.ts +0 -32
  14. package/src/fsm/index.ts +0 -5
  15. package/src/fsm/routerFSM.ts +0 -120
  16. package/src/getNavigator.ts +0 -30
  17. package/src/guards.ts +0 -46
  18. package/src/helpers.ts +0 -179
  19. package/src/index.ts +0 -50
  20. package/src/internals.ts +0 -173
  21. package/src/namespaces/DependenciesNamespace/dependenciesStore.ts +0 -30
  22. package/src/namespaces/DependenciesNamespace/index.ts +0 -5
  23. package/src/namespaces/EventBusNamespace/EventBusNamespace.ts +0 -311
  24. package/src/namespaces/EventBusNamespace/index.ts +0 -5
  25. package/src/namespaces/EventBusNamespace/types.ts +0 -11
  26. package/src/namespaces/NavigationNamespace/NavigationNamespace.ts +0 -405
  27. package/src/namespaces/NavigationNamespace/constants.ts +0 -55
  28. package/src/namespaces/NavigationNamespace/index.ts +0 -5
  29. package/src/namespaces/NavigationNamespace/transition/completeTransition.ts +0 -100
  30. package/src/namespaces/NavigationNamespace/transition/errorHandling.ts +0 -124
  31. package/src/namespaces/NavigationNamespace/transition/guardPhase.ts +0 -221
  32. package/src/namespaces/NavigationNamespace/types.ts +0 -100
  33. package/src/namespaces/OptionsNamespace/OptionsNamespace.ts +0 -28
  34. package/src/namespaces/OptionsNamespace/constants.ts +0 -19
  35. package/src/namespaces/OptionsNamespace/helpers.ts +0 -50
  36. package/src/namespaces/OptionsNamespace/index.ts +0 -7
  37. package/src/namespaces/OptionsNamespace/validators.ts +0 -13
  38. package/src/namespaces/PluginsNamespace/PluginsNamespace.ts +0 -291
  39. package/src/namespaces/PluginsNamespace/constants.ts +0 -34
  40. package/src/namespaces/PluginsNamespace/index.ts +0 -7
  41. package/src/namespaces/PluginsNamespace/types.ts +0 -22
  42. package/src/namespaces/PluginsNamespace/validators.ts +0 -28
  43. package/src/namespaces/RouteLifecycleNamespace/RouteLifecycleNamespace.ts +0 -377
  44. package/src/namespaces/RouteLifecycleNamespace/index.ts +0 -5
  45. package/src/namespaces/RouteLifecycleNamespace/types.ts +0 -10
  46. package/src/namespaces/RouterLifecycleNamespace/RouterLifecycleNamespace.ts +0 -81
  47. package/src/namespaces/RouterLifecycleNamespace/constants.ts +0 -25
  48. package/src/namespaces/RouterLifecycleNamespace/index.ts +0 -5
  49. package/src/namespaces/RouterLifecycleNamespace/types.ts +0 -26
  50. package/src/namespaces/RoutesNamespace/RoutesNamespace.ts +0 -535
  51. package/src/namespaces/RoutesNamespace/constants.ts +0 -6
  52. package/src/namespaces/RoutesNamespace/forwardChain.ts +0 -34
  53. package/src/namespaces/RoutesNamespace/helpers.ts +0 -126
  54. package/src/namespaces/RoutesNamespace/index.ts +0 -11
  55. package/src/namespaces/RoutesNamespace/routeGuards.ts +0 -62
  56. package/src/namespaces/RoutesNamespace/routesStore.ts +0 -346
  57. package/src/namespaces/RoutesNamespace/types.ts +0 -81
  58. package/src/namespaces/StateNamespace/StateNamespace.ts +0 -211
  59. package/src/namespaces/StateNamespace/helpers.ts +0 -24
  60. package/src/namespaces/StateNamespace/index.ts +0 -5
  61. package/src/namespaces/StateNamespace/types.ts +0 -15
  62. package/src/namespaces/index.ts +0 -35
  63. package/src/stateMetaStore.ts +0 -15
  64. package/src/transitionPath.ts +0 -436
  65. package/src/typeGuards.ts +0 -59
  66. package/src/types/RouterValidator.ts +0 -154
  67. package/src/types.ts +0 -69
  68. package/src/utils/getStaticPaths.ts +0 -50
  69. package/src/utils/index.ts +0 -5
  70. package/src/utils/serializeState.ts +0 -22
  71. package/src/validation.ts +0 -12
  72. package/src/wiring/RouterWiringBuilder.ts +0 -261
  73. package/src/wiring/index.ts +0 -7
  74. package/src/wiring/types.ts +0 -47
  75. package/src/wiring/wireRouter.ts +0 -26
@@ -1,311 +0,0 @@
1
- // packages/core/src/namespaces/EventBusNamespace/EventBusNamespace.ts
2
-
3
- import { events } from "../../constants";
4
- import { routerEvents, routerStates } from "../../fsm";
5
-
6
- import type { EventBusOptions } from "./types";
7
- import type { RouterEvent, RouterPayloads, RouterState } from "../../fsm";
8
- import type { RouterError } from "../../RouterError";
9
- import type { EventMethodMap, RouterEventMap } from "../../types";
10
- import type { FSM } from "@real-router/fsm";
11
- import type {
12
- EventName,
13
- LeaveFn,
14
- NavigationOptions,
15
- Plugin,
16
- State,
17
- SubscribeFn,
18
- Unsubscribe,
19
- } from "@real-router/types";
20
- import type { EventEmitter } from "event-emitter";
21
-
22
- export class EventBusNamespace {
23
- readonly #fsm: FSM<RouterState, RouterEvent, null, RouterPayloads>;
24
- readonly #emitter: EventEmitter<RouterEventMap>;
25
-
26
- #currentToState: State | undefined;
27
- #pendingToState: State | undefined;
28
- #pendingFromState: State | undefined;
29
- #pendingError: unknown;
30
-
31
- constructor(options: EventBusOptions) {
32
- this.#fsm = options.routerFSM;
33
- this.#emitter = options.emitter;
34
- this.#currentToState = undefined;
35
- this.#setupFSMActions();
36
- }
37
-
38
- static validateSubscribeListener(listener: unknown): void {
39
- if (typeof listener !== "function") {
40
- throw new TypeError(
41
- "[router.subscribe] Expected a function. " +
42
- "For Observable pattern use @real-router/rx package",
43
- );
44
- }
45
- }
46
-
47
- static validateSubscribeLeaveListener(listener: unknown): void {
48
- if (typeof listener !== "function") {
49
- throw new TypeError("[router.subscribeLeave] Expected a function");
50
- }
51
- }
52
-
53
- emitRouterStart(): void {
54
- this.#emitter.emit(events.ROUTER_START);
55
- }
56
-
57
- emitRouterStop(): void {
58
- this.#emitter.emit(events.ROUTER_STOP);
59
- }
60
-
61
- emitTransitionStart(toState: State, fromState?: State): void {
62
- this.#emitter.emit(events.TRANSITION_START, toState, fromState);
63
- }
64
-
65
- emitTransitionSuccess(
66
- toState: State,
67
- fromState?: State,
68
- opts?: NavigationOptions,
69
- ): void {
70
- this.#emitter.emit(events.TRANSITION_SUCCESS, toState, fromState, opts);
71
- }
72
-
73
- emitTransitionError(
74
- toState?: State,
75
- fromState?: State,
76
- error?: RouterError,
77
- ): void {
78
- this.#emitter.emit(events.TRANSITION_ERROR, toState, fromState, error);
79
- }
80
-
81
- emitTransitionCancel(toState: State, fromState?: State): void {
82
- this.#emitter.emit(events.TRANSITION_CANCEL, toState, fromState);
83
- }
84
-
85
- emitTransitionLeaveApprove(toState: State, fromState?: State): void {
86
- this.#emitter.emit(events.TRANSITION_LEAVE_APPROVE, toState, fromState);
87
- }
88
-
89
- sendStart(): void {
90
- this.#fsm.send(routerEvents.START);
91
- }
92
-
93
- sendStop(): void {
94
- this.#fsm.send(routerEvents.STOP);
95
- }
96
-
97
- sendDispose(): void {
98
- this.#fsm.send(routerEvents.DISPOSE);
99
- }
100
-
101
- sendStarted(): void {
102
- this.#fsm.send(routerEvents.STARTED);
103
- }
104
-
105
- sendNavigate(toState: State, fromState?: State): void {
106
- this.#currentToState = toState;
107
- // Bypass FSM dispatch — forceState + direct emit (no action lookup, no rest params)
108
- this.#fsm.forceState(routerStates.TRANSITION_STARTED);
109
- this.emitTransitionStart(toState, fromState);
110
- }
111
-
112
- sendComplete(
113
- state: State,
114
- fromState?: State,
115
- opts: NavigationOptions = {},
116
- ): void {
117
- // Bypass FSM dispatch — forceState + direct emit
118
- this.#fsm.forceState(routerStates.READY);
119
- this.emitTransitionSuccess(state, fromState, opts);
120
-
121
- if (this.#currentToState === state) {
122
- this.#currentToState = undefined;
123
- }
124
- }
125
-
126
- sendLeaveApprove(toState: State, fromState?: State): void {
127
- // Bypass FSM dispatch — forceState + direct emit (no action lookup, no rest params)
128
- this.#fsm.forceState(routerStates.LEAVE_APPROVED);
129
- this.emitTransitionLeaveApprove(toState, fromState);
130
- }
131
-
132
- sendFail(toState?: State, fromState?: State, error?: unknown): void {
133
- const prev = this.#currentToState;
134
-
135
- this.#pendingToState = toState;
136
- this.#pendingFromState = fromState;
137
- this.#pendingError = error;
138
- this.#fsm.send(routerEvents.FAIL);
139
-
140
- if (this.#currentToState === prev) {
141
- this.#currentToState = undefined;
142
- }
143
- }
144
-
145
- sendFailSafe(toState?: State, fromState?: State, error?: unknown): void {
146
- if (this.isReady()) {
147
- this.sendFail(toState, fromState, error);
148
- } else {
149
- this.emitTransitionError(toState, fromState, error as RouterError);
150
- }
151
- }
152
-
153
- sendCancel(toState: State, fromState?: State): void {
154
- const prev = this.#currentToState;
155
-
156
- this.#pendingToState = toState;
157
- this.#pendingFromState = fromState;
158
- this.#fsm.send(routerEvents.CANCEL);
159
-
160
- if (this.#currentToState === prev) {
161
- this.#currentToState = undefined;
162
- }
163
- }
164
-
165
- canBeginTransition(): boolean {
166
- return this.#fsm.canSend(routerEvents.NAVIGATE);
167
- }
168
-
169
- canStart(): boolean {
170
- return this.#fsm.canSend(routerEvents.START);
171
- }
172
-
173
- canCancel(): boolean {
174
- return this.#fsm.canSend(routerEvents.CANCEL);
175
- }
176
-
177
- isActive(): boolean {
178
- const fsmState = this.#fsm.getState();
179
-
180
- return fsmState !== routerStates.IDLE && fsmState !== routerStates.DISPOSED;
181
- }
182
-
183
- isDisposed(): boolean {
184
- return this.#fsm.getState() === routerStates.DISPOSED;
185
- }
186
-
187
- isTransitioning(): boolean {
188
- const state = this.#fsm.getState();
189
-
190
- return (
191
- state === routerStates.TRANSITION_STARTED ||
192
- state === routerStates.LEAVE_APPROVED
193
- );
194
- }
195
-
196
- isLeaveApproved(): boolean {
197
- return this.#fsm.getState() === routerStates.LEAVE_APPROVED;
198
- }
199
-
200
- isReady(): boolean {
201
- return this.#fsm.getState() === routerStates.READY;
202
- }
203
-
204
- getCurrentToState(): State | undefined {
205
- return this.#currentToState;
206
- }
207
-
208
- addEventListener<E extends EventName>(
209
- eventName: E,
210
- cb: Plugin[EventMethodMap[E]],
211
- ): Unsubscribe {
212
- return this.#emitter.on(
213
- eventName,
214
- cb as (...args: RouterEventMap[typeof eventName]) => void,
215
- );
216
- }
217
-
218
- subscribe(listener: SubscribeFn): Unsubscribe {
219
- return this.#emitter.on(
220
- events.TRANSITION_SUCCESS,
221
- (toState: State, fromState?: State) => {
222
- listener({ route: toState, previousRoute: fromState });
223
- },
224
- );
225
- }
226
-
227
- subscribeLeave(listener: LeaveFn): Unsubscribe {
228
- return this.#emitter.on(
229
- events.TRANSITION_LEAVE_APPROVE,
230
- (toState: State, fromState?: State) => {
231
- if (fromState !== undefined) {
232
- listener({ route: fromState, nextRoute: toState });
233
- }
234
- },
235
- );
236
- }
237
-
238
- clearAll(): void {
239
- this.#emitter.clearAll();
240
- }
241
-
242
- setLimits(limits: {
243
- maxListeners: number;
244
- warnListeners: number;
245
- maxEventDepth: number;
246
- }): void {
247
- this.#emitter.setLimits(limits);
248
- }
249
-
250
- sendCancelIfPossible(fromState: State | undefined): void {
251
- const toState = this.#currentToState;
252
-
253
- if (!this.canCancel() || toState === undefined) {
254
- return;
255
- }
256
-
257
- this.sendCancel(toState, fromState);
258
- }
259
-
260
- #emitPendingError(): void {
261
- this.emitTransitionError(
262
- this.#pendingToState,
263
- this.#pendingFromState,
264
- this.#pendingError as RouterError | undefined,
265
- );
266
- }
267
-
268
- #setupFSMActions(): void {
269
- const fsm = this.#fsm;
270
-
271
- fsm.on(routerStates.STARTING, routerEvents.STARTED, () => {
272
- this.emitRouterStart();
273
- });
274
-
275
- fsm.on(routerStates.READY, routerEvents.STOP, () => {
276
- this.emitRouterStop();
277
- });
278
-
279
- // NAVIGATE and COMPLETE actions bypassed — sendNavigate/sendComplete
280
- // use fsm.forceState() + direct emit for zero-allocation hot path.
281
- const handleCancel = () => {
282
- const toState = this.#pendingToState;
283
-
284
- /* v8 ignore next -- @preserve: #pendingToState guaranteed set by sendCancel before send() */
285
- if (toState === undefined) {
286
- return;
287
- }
288
-
289
- this.emitTransitionCancel(toState, this.#pendingFromState);
290
- };
291
-
292
- fsm.on(routerStates.TRANSITION_STARTED, routerEvents.CANCEL, handleCancel);
293
- fsm.on(routerStates.LEAVE_APPROVED, routerEvents.CANCEL, handleCancel);
294
-
295
- fsm.on(routerStates.LEAVE_APPROVED, routerEvents.FAIL, () => {
296
- this.#emitPendingError();
297
- });
298
-
299
- fsm.on(routerStates.STARTING, routerEvents.FAIL, () => {
300
- this.#emitPendingError();
301
- });
302
-
303
- fsm.on(routerStates.READY, routerEvents.FAIL, () => {
304
- this.#emitPendingError();
305
- });
306
-
307
- fsm.on(routerStates.TRANSITION_STARTED, routerEvents.FAIL, () => {
308
- this.#emitPendingError();
309
- });
310
- }
311
- }
@@ -1,5 +0,0 @@
1
- // packages/core/src/namespaces/EventBusNamespace/index.ts
2
-
3
- export { EventBusNamespace } from "./EventBusNamespace";
4
-
5
- export type { EventBusOptions } from "./types";
@@ -1,11 +0,0 @@
1
- // packages/core/src/namespaces/EventBusNamespace/types.ts
2
-
3
- import type { RouterEvent, RouterPayloads, RouterState } from "../../fsm";
4
- import type { RouterEventMap } from "../../types";
5
- import type { FSM } from "@real-router/fsm";
6
- import type { EventEmitter } from "event-emitter";
7
-
8
- export interface EventBusOptions {
9
- routerFSM: FSM<RouterState, RouterEvent, null, RouterPayloads>;
10
- emitter: EventEmitter<RouterEventMap>;
11
- }