@real-router/core 0.56.0 → 0.57.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 (112) hide show
  1. package/dist/cjs/Router-Brp6_4FE.js +6 -0
  2. package/dist/cjs/Router-Brp6_4FE.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-CZx0T0RQ.js} +2 -2
  6. package/dist/cjs/{cloneRouter-DRieJvam.js.map → cloneRouter-CZx0T0RQ.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-CYpAZCoc.d.ts.map +1 -1
  10. package/dist/cjs/index.d.ts +1 -1
  11. package/dist/cjs/index.js +1 -1
  12. package/dist/cjs/utils.js +1 -1
  13. package/dist/cjs/utils.js.map +1 -1
  14. package/dist/cjs/validation.d.ts +1 -1
  15. package/dist/esm/Router-LT61erYH.mjs +6 -0
  16. package/dist/esm/Router-LT61erYH.mjs.map +1 -0
  17. package/dist/esm/api.d.mts +1 -1
  18. package/dist/esm/api.mjs +1 -1
  19. package/dist/esm/{cloneRouter-DHrH6D_z.mjs → cloneRouter-DAscsmmF.mjs} +2 -2
  20. package/dist/esm/{cloneRouter-DHrH6D_z.mjs.map → cloneRouter-DAscsmmF.mjs.map} +1 -1
  21. package/dist/esm/{index-C-i6vx5Y.d.mts → index-BWUmnecT.d.mts} +1 -2
  22. package/dist/esm/index-BWUmnecT.d.mts.map +1 -0
  23. package/dist/esm/index-CYpAZCoc.d.mts.map +1 -1
  24. package/dist/esm/index.d.mts +1 -1
  25. package/dist/esm/index.mjs +1 -1
  26. package/dist/esm/utils.mjs +1 -1
  27. package/dist/esm/utils.mjs.map +1 -1
  28. package/dist/esm/validation.d.mts +1 -1
  29. package/package.json +4 -5
  30. package/dist/cjs/Router-IEGavTKk.js +0 -6
  31. package/dist/cjs/Router-IEGavTKk.js.map +0 -1
  32. package/dist/cjs/index-C-i6vx5Y.d.ts.map +0 -1
  33. package/dist/esm/Router-B3aeavRb.mjs +0 -6
  34. package/dist/esm/Router-B3aeavRb.mjs.map +0 -1
  35. package/dist/esm/index-C-i6vx5Y.d.mts.map +0 -1
  36. package/src/Router.ts +0 -737
  37. package/src/RouterError.ts +0 -324
  38. package/src/api/cloneRouter.ts +0 -159
  39. package/src/api/getDependenciesApi.ts +0 -160
  40. package/src/api/getLifecycleApi.ts +0 -65
  41. package/src/api/getPluginApi.ts +0 -228
  42. package/src/api/getRoutesApi.ts +0 -831
  43. package/src/api/helpers.ts +0 -10
  44. package/src/api/index.ts +0 -16
  45. package/src/api/types.ts +0 -12
  46. package/src/constants.ts +0 -101
  47. package/src/createRouter.ts +0 -32
  48. package/src/fsm/index.ts +0 -5
  49. package/src/fsm/routerFSM.ts +0 -130
  50. package/src/getNavigator.ts +0 -30
  51. package/src/guards.ts +0 -46
  52. package/src/helpers.ts +0 -197
  53. package/src/index.ts +0 -66
  54. package/src/internals.ts +0 -228
  55. package/src/namespaces/DependenciesNamespace/dependenciesStore.ts +0 -30
  56. package/src/namespaces/DependenciesNamespace/index.ts +0 -5
  57. package/src/namespaces/EventBusNamespace/EventBusNamespace.ts +0 -522
  58. package/src/namespaces/EventBusNamespace/index.ts +0 -5
  59. package/src/namespaces/EventBusNamespace/types.ts +0 -11
  60. package/src/namespaces/NavigationNamespace/NavigationNamespace.ts +0 -552
  61. package/src/namespaces/NavigationNamespace/constants.ts +0 -55
  62. package/src/namespaces/NavigationNamespace/index.ts +0 -5
  63. package/src/namespaces/NavigationNamespace/transition/completeTransition.ts +0 -108
  64. package/src/namespaces/NavigationNamespace/transition/errorHandling.ts +0 -124
  65. package/src/namespaces/NavigationNamespace/transition/guardPhase.ts +0 -283
  66. package/src/namespaces/NavigationNamespace/types.ts +0 -110
  67. package/src/namespaces/OptionsNamespace/OptionsNamespace.ts +0 -28
  68. package/src/namespaces/OptionsNamespace/constants.ts +0 -19
  69. package/src/namespaces/OptionsNamespace/helpers.ts +0 -50
  70. package/src/namespaces/OptionsNamespace/index.ts +0 -7
  71. package/src/namespaces/OptionsNamespace/validators.ts +0 -13
  72. package/src/namespaces/PluginsNamespace/PluginsNamespace.ts +0 -291
  73. package/src/namespaces/PluginsNamespace/constants.ts +0 -34
  74. package/src/namespaces/PluginsNamespace/index.ts +0 -7
  75. package/src/namespaces/PluginsNamespace/types.ts +0 -22
  76. package/src/namespaces/PluginsNamespace/validators.ts +0 -28
  77. package/src/namespaces/RouteLifecycleNamespace/RouteLifecycleNamespace.ts +0 -558
  78. package/src/namespaces/RouteLifecycleNamespace/index.ts +0 -5
  79. package/src/namespaces/RouteLifecycleNamespace/types.ts +0 -10
  80. package/src/namespaces/RouterLifecycleNamespace/RouterLifecycleNamespace.ts +0 -81
  81. package/src/namespaces/RouterLifecycleNamespace/constants.ts +0 -25
  82. package/src/namespaces/RouterLifecycleNamespace/index.ts +0 -5
  83. package/src/namespaces/RouterLifecycleNamespace/types.ts +0 -30
  84. package/src/namespaces/RoutesNamespace/RoutesNamespace.ts +0 -582
  85. package/src/namespaces/RoutesNamespace/constants.ts +0 -6
  86. package/src/namespaces/RoutesNamespace/forwardChain.ts +0 -34
  87. package/src/namespaces/RoutesNamespace/helpers.ts +0 -204
  88. package/src/namespaces/RoutesNamespace/index.ts +0 -11
  89. package/src/namespaces/RoutesNamespace/routeGuards.ts +0 -62
  90. package/src/namespaces/RoutesNamespace/routesStore.ts +0 -566
  91. package/src/namespaces/RoutesNamespace/types.ts +0 -81
  92. package/src/namespaces/StateNamespace/StateNamespace.ts +0 -224
  93. package/src/namespaces/StateNamespace/helpers.ts +0 -24
  94. package/src/namespaces/StateNamespace/index.ts +0 -5
  95. package/src/namespaces/StateNamespace/types.ts +0 -15
  96. package/src/namespaces/index.ts +0 -35
  97. package/src/stateMetaStore.ts +0 -15
  98. package/src/transitionPath.ts +0 -440
  99. package/src/typeGuards.ts +0 -59
  100. package/src/types/RouterValidator.ts +0 -156
  101. package/src/types.ts +0 -77
  102. package/src/utils/createRequestScope.ts +0 -174
  103. package/src/utils/getStaticPaths.ts +0 -50
  104. package/src/utils/hydrateRouter.ts +0 -89
  105. package/src/utils/index.ts +0 -27
  106. package/src/utils/serializeRouterState.ts +0 -120
  107. package/src/utils/serializeState.ts +0 -63
  108. package/src/validation.ts +0 -12
  109. package/src/wiring/RouterWiringBuilder.ts +0 -275
  110. package/src/wiring/index.ts +0 -7
  111. package/src/wiring/types.ts +0 -47
  112. package/src/wiring/wireRouter.ts +0 -26
@@ -1,228 +0,0 @@
1
- import { throwIfDisposed } from "./helpers";
2
- import { errorCodes } from "../constants";
3
- import { getInternals } from "../internals";
4
- import { RouterError } from "../RouterError";
5
-
6
- import type { PluginApi } from "./types";
7
- import type {
8
- ContextNamespaceClaim,
9
- DefaultDependencies,
10
- Params,
11
- Router,
12
- State,
13
- } from "@real-router/types";
14
-
15
- // Cache the assembled PluginApi per router — mirrors getNavigator() (#525):
16
- // avoids re-allocating the closure-bag on each call (plugins call this once
17
- // at init, but tests + nested plugins poll it), and gives spy/stub helpers
18
- // a stable object identity to attach to (e.g. spying on
19
- // `getPluginApi(router).navigateToState` to inject errors in popstate
20
- // recovery tests).
21
- const cache = new WeakMap<object, PluginApi>();
22
-
23
- export function getPluginApi<
24
- Dependencies extends DefaultDependencies = DefaultDependencies,
25
- >(router: Router<Dependencies>): PluginApi {
26
- const cached = cache.get(router);
27
-
28
- if (cached) {
29
- return cached;
30
- }
31
-
32
- const ctx = getInternals(router);
33
- const api: PluginApi = {
34
- makeState: (name, params, path, meta) => {
35
- ctx.validator?.state.validateMakeStateArgs(name, params, path);
36
-
37
- return ctx.makeState(
38
- name,
39
- params,
40
- path,
41
- meta?.params as
42
- | Record<string, Record<string, "url" | "query">>
43
- | undefined,
44
- );
45
- },
46
- buildState: (routeName, routeParams) => {
47
- ctx.validator?.routes.validateStateBuilderArgs(
48
- routeName,
49
- routeParams,
50
- "buildState",
51
- );
52
-
53
- const { name, params } = ctx.forwardState(routeName, routeParams);
54
-
55
- return ctx.buildStateResolved(name, params);
56
- },
57
- forwardState: <P extends Params = Params>(
58
- routeName: string,
59
- routeParams: P,
60
- ) => {
61
- ctx.validator?.routes.validateStateBuilderArgs(
62
- routeName,
63
- routeParams,
64
- "forwardState",
65
- );
66
-
67
- return ctx.forwardState(routeName, routeParams);
68
- },
69
- matchPath: (path) => {
70
- ctx.validator?.routes.validateMatchPathArgs(path);
71
-
72
- return ctx.matchPath(path, ctx.getOptions());
73
- },
74
- navigateToState: (state, options) => {
75
- throwIfDisposed(ctx.isDisposed);
76
-
77
- ctx.validator?.navigation.validateNavigateToStateArgs(state);
78
-
79
- if (options !== undefined) {
80
- ctx.validator?.navigation.validateNavigationOptions(
81
- options,
82
- "navigateToState",
83
- );
84
- }
85
-
86
- return ctx.navigateToState(state, options);
87
- },
88
- setRootPath: (rootPath) => {
89
- throwIfDisposed(ctx.isDisposed);
90
-
91
- ctx.validator?.routes.validateSetRootPathArgs(rootPath);
92
-
93
- ctx.setRootPath(rootPath);
94
- },
95
- getRootPath: ctx.getRootPath,
96
- addEventListener: (eventName, cb) => {
97
- throwIfDisposed(ctx.isDisposed);
98
-
99
- ctx.validator?.eventBus.validateListenerArgs(eventName, cb);
100
-
101
- return ctx.addEventListener(eventName, cb);
102
- },
103
- buildNavigationState: (name, params = {}) => {
104
- ctx.validator?.routes.validateStateBuilderArgs(
105
- name,
106
- params,
107
- "buildNavigationState",
108
- );
109
-
110
- const { name: resolvedName, params: resolvedParams } = ctx.forwardState(
111
- name,
112
- params,
113
- );
114
- const routeInfo = ctx.buildStateResolved(resolvedName, resolvedParams);
115
-
116
- if (!routeInfo) {
117
- return;
118
- }
119
-
120
- return ctx.makeState(
121
- routeInfo.name,
122
- routeInfo.params,
123
- ctx.buildPath(routeInfo.name, routeInfo.params),
124
- routeInfo.meta,
125
- );
126
- },
127
- getOptions: ctx.getOptions,
128
- getTree: ctx.getTree,
129
- addInterceptor: (method, fn) => {
130
- throwIfDisposed(ctx.isDisposed);
131
- ctx.validator?.plugins.validateAddInterceptorArgs(method, fn);
132
- let list = ctx.interceptors.get(method);
133
-
134
- if (!list) {
135
- list = [];
136
- ctx.interceptors.set(method, list);
137
- }
138
-
139
- list.push(fn);
140
-
141
- return () => {
142
- const index = list.indexOf(fn);
143
-
144
- if (index !== -1) {
145
- list.splice(index, 1);
146
- }
147
- };
148
- },
149
- getRouteConfig: (name) => {
150
- const store = ctx.routeGetStore();
151
-
152
- if (!store.matcher.hasRoute(name)) {
153
- return;
154
- }
155
-
156
- return store.routeCustomFields[name];
157
- },
158
- extendRouter: (extensions: Record<string, unknown>) => {
159
- throwIfDisposed(ctx.isDisposed);
160
-
161
- const keys = Object.keys(extensions);
162
-
163
- for (const key of keys) {
164
- if (key in router) {
165
- throw new RouterError(errorCodes.PLUGIN_CONFLICT, {
166
- message: `Cannot extend router: property "${key}" already exists`,
167
- });
168
- }
169
- }
170
-
171
- for (const key of keys) {
172
- (router as Record<string, unknown>)[key] = extensions[key];
173
- }
174
-
175
- const extensionRecord = { keys };
176
-
177
- ctx.routerExtensions.push(extensionRecord);
178
-
179
- let removed = false;
180
-
181
- return () => {
182
- if (removed) {
183
- return;
184
- }
185
-
186
- removed = true;
187
-
188
- for (const key of extensionRecord.keys) {
189
- delete (router as Record<string, unknown>)[key];
190
- }
191
-
192
- const idx = ctx.routerExtensions.indexOf(extensionRecord);
193
-
194
- if (idx !== -1) {
195
- ctx.routerExtensions.splice(idx, 1);
196
- }
197
- };
198
- },
199
- emitTransitionError: (error) => {
200
- throwIfDisposed(ctx.isDisposed);
201
- ctx.emitTransitionError(error);
202
- },
203
- claimContextNamespace: (namespace: string) => {
204
- throwIfDisposed(ctx.isDisposed);
205
-
206
- if (ctx.contextClaimRecords.has(namespace)) {
207
- throw new RouterError(errorCodes.CONTEXT_NAMESPACE_ALREADY_CLAIMED, {
208
- message: `Cannot claim context namespace: "${namespace}" is already claimed by another plugin`,
209
- });
210
- }
211
-
212
- ctx.contextClaimRecords.add(namespace);
213
-
214
- return {
215
- write(state: State, value: unknown) {
216
- state.context[namespace] = value;
217
- },
218
- release() {
219
- ctx.contextClaimRecords.delete(namespace);
220
- },
221
- } satisfies ContextNamespaceClaim;
222
- },
223
- };
224
-
225
- cache.set(router, api);
226
-
227
- return api;
228
- }