@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,204 +0,0 @@
1
- // packages/core/src/namespaces/RoutesNamespace/helpers.ts
2
-
3
- import type { RouteConfig } from "./types";
4
- import type { Route } from "../../types";
5
- import type {
6
- DefaultDependencies,
7
- ForwardToCallback,
8
- Params,
9
- } from "@real-router/types";
10
- import type { RouteDefinition } from "route-tree";
11
-
12
- /**
13
- * Creates an empty RouteConfig.
14
- */
15
- export function createEmptyConfig(): RouteConfig {
16
- return {
17
- decoders: Object.create(null) as Record<string, (params: Params) => Params>,
18
- encoders: Object.create(null) as Record<string, (params: Params) => Params>,
19
- defaultParams: Object.create(null) as Record<string, Params>,
20
- forwardMap: Object.create(null) as Record<string, string>,
21
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
22
- forwardFnMap: Object.create(null) as Record<string, ForwardToCallback<any>>,
23
- };
24
- }
25
-
26
- // ============================================================================
27
- // Route Tree Helpers
28
- // ============================================================================
29
-
30
- /**
31
- * Checks if all params from source exist with same values in target.
32
- * Small function body allows V8 inlining.
33
- */
34
- export function paramsMatch(source: Params, target: Params): boolean {
35
- for (const key in source) {
36
- if (source[key] !== target[key]) {
37
- return false;
38
- }
39
- }
40
-
41
- return true;
42
- }
43
-
44
- /**
45
- * Checks params match, skipping keys present in skipKeys.
46
- */
47
- export function paramsMatchExcluding(
48
- source: Params,
49
- target: Params,
50
- skipKeys: Params,
51
- ): boolean {
52
- for (const key in source) {
53
- if (key in skipKeys) {
54
- continue;
55
- }
56
- if (source[key] !== target[key]) {
57
- return false;
58
- }
59
- }
60
-
61
- return true;
62
- }
63
-
64
- /**
65
- * Returns a copy of `defaultParams` with query-typed keys removed, based on
66
- * `ownMeta` (the per-route paramTypeMap from the matcher). When no query keys
67
- * are present, returns the input by reference (zero-allocation fast path).
68
- *
69
- * `ownMeta` may be `undefined` for non-registered route names — this is the
70
- * caller's escape hatch (e.g. `getMetaByName(name)?.[name]`); a missing meta
71
- * means no query type information is available, so defaults pass through
72
- * unchanged.
73
- */
74
- export function stripQueryDefaults(
75
- defaultParams: Params,
76
- ownMeta: Record<string, "url" | "query"> | undefined,
77
- ): Params {
78
- if (!ownMeta || !hasQueryDefault(defaultParams, ownMeta)) {
79
- return defaultParams;
80
- }
81
-
82
- const filtered: Params = {};
83
-
84
- for (const key in defaultParams) {
85
- if (ownMeta[key] !== "query") {
86
- filtered[key] = defaultParams[key];
87
- }
88
- }
89
-
90
- return filtered;
91
- }
92
-
93
- function hasQueryDefault(
94
- defaultParams: Params,
95
- ownMeta: Record<string, "url" | "query">,
96
- ): boolean {
97
- for (const key in defaultParams) {
98
- if (ownMeta[key] === "query") {
99
- return true;
100
- }
101
- }
102
-
103
- return false;
104
- }
105
-
106
- /**
107
- * Sanitizes a route by keeping only essential properties.
108
- */
109
- export function sanitizeRoute<Dependencies extends DefaultDependencies>(
110
- route: Route<Dependencies>,
111
- ): RouteDefinition {
112
- const sanitized: RouteDefinition = {
113
- name: route.name,
114
- path: route.path,
115
- };
116
-
117
- if (route.children) {
118
- sanitized.children = route.children.map((child) => sanitizeRoute(child));
119
- }
120
-
121
- return sanitized;
122
- }
123
-
124
- /**
125
- * Recursively removes a route from definitions array.
126
- */
127
- export function removeFromDefinitions(
128
- definitions: RouteDefinition[],
129
- routeName: string,
130
- parentPrefix = "",
131
- ): boolean {
132
- for (let i = 0; i < definitions.length; i++) {
133
- const route = definitions[i];
134
- const fullName = parentPrefix
135
- ? `${parentPrefix}.${route.name}`
136
- : route.name;
137
-
138
- if (fullName === routeName) {
139
- definitions.splice(i, 1);
140
-
141
- return true;
142
- }
143
-
144
- if (
145
- route.children &&
146
- routeName.startsWith(`${fullName}.`) &&
147
- removeFromDefinitions(route.children, routeName, fullName)
148
- ) {
149
- return true;
150
- }
151
- }
152
-
153
- return false;
154
- }
155
-
156
- /**
157
- * Clears configuration entries that match the predicate.
158
- */
159
- export function clearConfigEntries<T>(
160
- config: Record<string, T>,
161
- matcher: (key: string) => boolean,
162
- ): void {
163
- for (const key of Object.keys(config)) {
164
- if (matcher(key)) {
165
- delete config[key];
166
- }
167
- }
168
- }
169
-
170
- /**
171
- * Used by matchPath() when trailingSlash is "preserve": the matcher's
172
- * buildPath() with an unset trailingSlash mode strips trailing slashes,
173
- * but "preserve" means the source path's trailing-slash choice wins.
174
- * If the source had a trailing slash, re-attach it to the rewritten path.
175
- * The reverse case (rewritten has trailing, source does not) is not
176
- * reachable with the current matcher — it never adds a trailing slash
177
- * with undefined mode.
178
- */
179
- export function matchSourceTrailingSlash(
180
- sourcePath: string,
181
- rewrittenPath: string,
182
- ): string {
183
- const queryIndex = rewrittenPath.search(/[?#]/);
184
- const pathPart =
185
- queryIndex === -1 ? rewrittenPath : rewrittenPath.slice(0, queryIndex);
186
-
187
- if (pathPart === "/" || pathPart.endsWith("/")) {
188
- return rewrittenPath;
189
- }
190
-
191
- const sourceQueryIndex = sourcePath.search(/[?#]/);
192
- const sourcePathPart =
193
- sourceQueryIndex === -1
194
- ? sourcePath
195
- : sourcePath.slice(0, sourceQueryIndex);
196
-
197
- if (!(sourcePathPart.length > 1 && sourcePathPart.endsWith("/"))) {
198
- return rewrittenPath;
199
- }
200
-
201
- const querySuffix = queryIndex === -1 ? "" : rewrittenPath.slice(queryIndex);
202
-
203
- return `${pathPart}/${querySuffix}`;
204
- }
@@ -1,11 +0,0 @@
1
- // packages/core/src/namespaces/RoutesNamespace/index.ts
2
-
3
- export { RoutesNamespace } from "./RoutesNamespace";
4
-
5
- export { DEFAULT_ROUTE_NAME } from "./constants";
6
-
7
- export { createEmptyConfig } from "./helpers";
8
-
9
- export type { RouteConfig, RoutesDependencies } from "./types";
10
-
11
- export type { RoutesStore } from "./routesStore";
@@ -1,62 +0,0 @@
1
- import { logger } from "@real-router/logger";
2
-
3
- /**
4
- * Validates removeRoute constraints.
5
- * Returns false if removal should be blocked (route is active).
6
- * Logs warnings for edge cases.
7
- *
8
- * @param name - Route name to remove
9
- * @param currentStateName - Current active route name (or undefined)
10
- * @param isNavigating - Whether navigation is in progress
11
- * @returns true if removal can proceed, false if blocked
12
- */
13
- export function validateRemoveRoute(
14
- name: string,
15
- currentStateName: string | undefined,
16
- isNavigating: boolean,
17
- ): boolean {
18
- if (currentStateName) {
19
- const isExactMatch = currentStateName === name;
20
- const isParentOfCurrent = currentStateName.startsWith(`${name}.`);
21
-
22
- if (isExactMatch || isParentOfCurrent) {
23
- const suffix = isExactMatch ? "" : ` (current: "${currentStateName}")`;
24
-
25
- logger.warn(
26
- "router.removeRoute",
27
- `Cannot remove route "${name}" — it is currently active${suffix}. Navigate away first.`,
28
- );
29
-
30
- return false;
31
- }
32
- }
33
-
34
- if (isNavigating) {
35
- logger.warn(
36
- "router.removeRoute",
37
- `Route "${name}" removed while navigation is in progress. This may cause unexpected behavior.`,
38
- );
39
- }
40
-
41
- return true;
42
- }
43
-
44
- /**
45
- * Validates clearRoutes operation.
46
- * Returns false if operation should be blocked (navigation in progress).
47
- *
48
- * @param isNavigating - Whether navigation is in progress
49
- * @returns true if clearRoutes can proceed, false if blocked
50
- */
51
- export function validateClearRoutes(isNavigating: boolean): boolean {
52
- if (isNavigating) {
53
- logger.error(
54
- "router.clearRoutes",
55
- "Cannot clear routes while navigation is in progress. Wait for navigation to complete.",
56
- );
57
-
58
- return false;
59
- }
60
-
61
- return true;
62
- }