@real-router/core 0.55.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.
- package/dist/cjs/Router-BSGzVINO.js +6 -0
- package/dist/cjs/Router-BSGzVINO.js.map +1 -0
- package/dist/{esm/Router-Dg-zk8AS.d.mts → cjs/Router-hW6ivqrX.d.ts} +2 -2
- package/dist/cjs/Router-hW6ivqrX.d.ts.map +1 -0
- package/dist/cjs/api.d.ts +2 -2
- package/dist/cjs/api.d.ts.map +1 -1
- package/dist/cjs/api.js +1 -1
- package/dist/cjs/api.js.map +1 -1
- package/dist/cjs/{cloneRouter-C9Rth_8U.js → cloneRouter-7z-60z_f.js} +2 -2
- package/dist/cjs/{cloneRouter-C9Rth_8U.js.map → cloneRouter-7z-60z_f.js.map} +1 -1
- package/dist/cjs/{index-C-i6vx5Y.d.ts → index-BWUmnecT.d.ts} +1 -2
- package/dist/cjs/index-BWUmnecT.d.ts.map +1 -0
- package/dist/cjs/{RouterError-WhCzIWuc.d.ts → index-CYpAZCoc.d.ts} +19 -2
- package/dist/cjs/index-CYpAZCoc.d.ts.map +1 -0
- package/dist/cjs/{index-K1U_fqfJ.d.ts → index-D2WRiyWS.d.ts} +2 -2
- package/dist/cjs/index-D2WRiyWS.d.ts.map +1 -0
- package/dist/cjs/index.d.ts +5 -5
- package/dist/cjs/index.js +1 -1
- package/dist/cjs/{internals-CWMOL1B8.js → internals-DJjgSePy.js} +2 -2
- package/dist/cjs/internals-DJjgSePy.js.map +1 -0
- package/dist/cjs/utils.d.ts +1 -1
- package/dist/cjs/utils.js +1 -1
- package/dist/cjs/utils.js.map +1 -1
- package/dist/cjs/validation.d.ts +17 -5
- package/dist/cjs/validation.d.ts.map +1 -1
- package/dist/cjs/validation.js +1 -1
- package/dist/esm/Router-B7txWo9N.mjs +6 -0
- package/dist/esm/Router-B7txWo9N.mjs.map +1 -0
- package/dist/{cjs/Router-Dg-zk8AS.d.ts → esm/Router-hW6ivqrX.d.mts} +2 -2
- package/dist/esm/Router-hW6ivqrX.d.mts.map +1 -0
- package/dist/esm/api.d.mts +2 -2
- package/dist/esm/api.d.mts.map +1 -1
- package/dist/esm/api.mjs +1 -1
- package/dist/esm/api.mjs.map +1 -1
- package/dist/esm/{cloneRouter-BYNiwchg.mjs → cloneRouter-BNCQ7tIa.mjs} +2 -2
- package/dist/esm/{cloneRouter-BYNiwchg.mjs.map → cloneRouter-BNCQ7tIa.mjs.map} +1 -1
- package/dist/esm/{index-C-i6vx5Y.d.mts → index-BWUmnecT.d.mts} +1 -2
- package/dist/esm/index-BWUmnecT.d.mts.map +1 -0
- package/dist/esm/{RouterError-WhCzIWuc.d.mts → index-CYpAZCoc.d.mts} +19 -2
- package/dist/esm/index-CYpAZCoc.d.mts.map +1 -0
- package/dist/esm/{index-DKzxav48.d.mts → index-CjWKWPY6.d.mts} +2 -2
- package/dist/esm/index-CjWKWPY6.d.mts.map +1 -0
- package/dist/esm/index.d.mts +5 -5
- package/dist/esm/index.mjs +1 -1
- package/dist/esm/index.mjs.map +1 -1
- package/dist/esm/{internals-DT4mneSz.mjs → internals-C8mRvTxc.mjs} +2 -2
- package/dist/esm/internals-C8mRvTxc.mjs.map +1 -0
- package/dist/esm/utils.d.mts +1 -1
- package/dist/esm/utils.mjs +1 -1
- package/dist/esm/utils.mjs.map +1 -1
- package/dist/esm/validation.d.mts +17 -5
- package/dist/esm/validation.d.mts.map +1 -1
- package/dist/esm/validation.mjs +1 -1
- package/package.json +3 -4
- package/dist/cjs/Router-C7eE1kIK.js +0 -6
- package/dist/cjs/Router-C7eE1kIK.js.map +0 -1
- package/dist/cjs/Router-Dg-zk8AS.d.ts.map +0 -1
- package/dist/cjs/RouterError-WhCzIWuc.d.ts.map +0 -1
- package/dist/cjs/index-C-i6vx5Y.d.ts.map +0 -1
- package/dist/cjs/index-K1U_fqfJ.d.ts.map +0 -1
- package/dist/cjs/internals-CWMOL1B8.js.map +0 -1
- package/dist/esm/Router-Dg-zk8AS.d.mts.map +0 -1
- package/dist/esm/Router-DiZbYMLx.mjs +0 -6
- package/dist/esm/Router-DiZbYMLx.mjs.map +0 -1
- package/dist/esm/RouterError-WhCzIWuc.d.mts.map +0 -1
- package/dist/esm/index-C-i6vx5Y.d.mts.map +0 -1
- package/dist/esm/index-DKzxav48.d.mts.map +0 -1
- package/dist/esm/internals-DT4mneSz.mjs.map +0 -1
- package/src/Router.ts +0 -725
- package/src/RouterError.ts +0 -324
- package/src/api/cloneRouter.ts +0 -159
- package/src/api/getDependenciesApi.ts +0 -160
- package/src/api/getLifecycleApi.ts +0 -65
- package/src/api/getPluginApi.ts +0 -228
- package/src/api/getRoutesApi.ts +0 -546
- package/src/api/helpers.ts +0 -10
- package/src/api/index.ts +0 -16
- package/src/api/types.ts +0 -12
- package/src/constants.ts +0 -101
- package/src/createRouter.ts +0 -32
- package/src/fsm/index.ts +0 -5
- package/src/fsm/routerFSM.ts +0 -130
- package/src/getNavigator.ts +0 -30
- package/src/guards.ts +0 -46
- package/src/helpers.ts +0 -197
- package/src/index.ts +0 -50
- package/src/internals.ts +0 -200
- package/src/namespaces/DependenciesNamespace/dependenciesStore.ts +0 -30
- package/src/namespaces/DependenciesNamespace/index.ts +0 -5
- package/src/namespaces/EventBusNamespace/EventBusNamespace.ts +0 -485
- package/src/namespaces/EventBusNamespace/index.ts +0 -5
- package/src/namespaces/EventBusNamespace/types.ts +0 -11
- package/src/namespaces/NavigationNamespace/NavigationNamespace.ts +0 -552
- package/src/namespaces/NavigationNamespace/constants.ts +0 -55
- package/src/namespaces/NavigationNamespace/index.ts +0 -5
- package/src/namespaces/NavigationNamespace/transition/completeTransition.ts +0 -108
- package/src/namespaces/NavigationNamespace/transition/errorHandling.ts +0 -124
- package/src/namespaces/NavigationNamespace/transition/guardPhase.ts +0 -283
- package/src/namespaces/NavigationNamespace/types.ts +0 -110
- package/src/namespaces/OptionsNamespace/OptionsNamespace.ts +0 -28
- package/src/namespaces/OptionsNamespace/constants.ts +0 -19
- package/src/namespaces/OptionsNamespace/helpers.ts +0 -50
- package/src/namespaces/OptionsNamespace/index.ts +0 -7
- package/src/namespaces/OptionsNamespace/validators.ts +0 -13
- package/src/namespaces/PluginsNamespace/PluginsNamespace.ts +0 -291
- package/src/namespaces/PluginsNamespace/constants.ts +0 -34
- package/src/namespaces/PluginsNamespace/index.ts +0 -7
- package/src/namespaces/PluginsNamespace/types.ts +0 -22
- package/src/namespaces/PluginsNamespace/validators.ts +0 -28
- package/src/namespaces/RouteLifecycleNamespace/RouteLifecycleNamespace.ts +0 -558
- package/src/namespaces/RouteLifecycleNamespace/index.ts +0 -5
- package/src/namespaces/RouteLifecycleNamespace/types.ts +0 -10
- package/src/namespaces/RouterLifecycleNamespace/RouterLifecycleNamespace.ts +0 -81
- package/src/namespaces/RouterLifecycleNamespace/constants.ts +0 -25
- package/src/namespaces/RouterLifecycleNamespace/index.ts +0 -5
- package/src/namespaces/RouterLifecycleNamespace/types.ts +0 -30
- package/src/namespaces/RoutesNamespace/RoutesNamespace.ts +0 -582
- package/src/namespaces/RoutesNamespace/constants.ts +0 -6
- package/src/namespaces/RoutesNamespace/forwardChain.ts +0 -34
- package/src/namespaces/RoutesNamespace/helpers.ts +0 -204
- package/src/namespaces/RoutesNamespace/index.ts +0 -11
- package/src/namespaces/RoutesNamespace/routeGuards.ts +0 -62
- package/src/namespaces/RoutesNamespace/routesStore.ts +0 -566
- package/src/namespaces/RoutesNamespace/types.ts +0 -81
- package/src/namespaces/StateNamespace/StateNamespace.ts +0 -224
- package/src/namespaces/StateNamespace/helpers.ts +0 -24
- package/src/namespaces/StateNamespace/index.ts +0 -5
- package/src/namespaces/StateNamespace/types.ts +0 -15
- package/src/namespaces/index.ts +0 -35
- package/src/stateMetaStore.ts +0 -15
- package/src/transitionPath.ts +0 -436
- package/src/typeGuards.ts +0 -59
- package/src/types/RouterValidator.ts +0 -156
- package/src/types.ts +0 -69
- package/src/utils/createRequestScope.ts +0 -174
- package/src/utils/getStaticPaths.ts +0 -50
- package/src/utils/hydrateRouter.ts +0 -89
- package/src/utils/index.ts +0 -27
- package/src/utils/serializeRouterState.ts +0 -120
- package/src/utils/serializeState.ts +0 -63
- package/src/validation.ts +0 -12
- package/src/wiring/RouterWiringBuilder.ts +0 -275
- package/src/wiring/index.ts +0 -7
- package/src/wiring/types.ts +0 -47
- 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
|
-
}
|