@real-router/core 0.23.1 → 0.25.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 (45) hide show
  1. package/README.md +0 -15
  2. package/dist/cjs/index.d.ts +12 -13
  3. package/dist/cjs/index.js +1 -1
  4. package/dist/cjs/index.js.map +1 -1
  5. package/dist/cjs/metafile-cjs.json +1 -1
  6. package/dist/esm/index.d.mts +12 -13
  7. package/dist/esm/index.mjs +1 -1
  8. package/dist/esm/index.mjs.map +1 -1
  9. package/dist/esm/metafile-esm.json +1 -1
  10. package/package.json +4 -4
  11. package/src/Router.ts +14 -57
  12. package/src/RouterError.ts +1 -1
  13. package/src/constants.ts +1 -3
  14. package/src/helpers.ts +1 -1
  15. package/src/index.ts +3 -3
  16. package/src/namespaces/CloneNamespace/CloneNamespace.ts +6 -6
  17. package/src/namespaces/CloneNamespace/types.ts +5 -9
  18. package/src/namespaces/DependenciesNamespace/DependenciesNamespace.ts +2 -4
  19. package/src/namespaces/NavigationNamespace/NavigationNamespace.ts +1 -0
  20. package/src/namespaces/NavigationNamespace/transition/{wrapSyncError.ts → errorHandling.ts} +23 -17
  21. package/src/namespaces/NavigationNamespace/transition/executeLifecycleHooks.ts +14 -55
  22. package/src/namespaces/NavigationNamespace/transition/index.ts +6 -24
  23. package/src/namespaces/NavigationNamespace/types.ts +2 -9
  24. package/src/namespaces/PluginsNamespace/PluginsNamespace.ts +2 -2
  25. package/src/namespaces/RouteLifecycleNamespace/RouteLifecycleNamespace.ts +28 -43
  26. package/src/namespaces/RouteLifecycleNamespace/validators.ts +3 -3
  27. package/src/namespaces/RoutesNamespace/RoutesNamespace.ts +53 -34
  28. package/src/namespaces/RoutesNamespace/stateBuilder.ts +1 -1
  29. package/src/namespaces/RoutesNamespace/types.ts +3 -3
  30. package/src/namespaces/index.ts +0 -2
  31. package/src/transitionPath.ts +4 -40
  32. package/src/typeGuards.ts +1 -2
  33. package/src/types.ts +8 -8
  34. package/src/wiring/RouterWiringBuilder.ts +1 -17
  35. package/src/wiring/types.ts +0 -3
  36. package/src/wiring/wireRouter.ts +0 -1
  37. package/src/namespaces/MiddlewareNamespace/MiddlewareNamespace.ts +0 -221
  38. package/src/namespaces/MiddlewareNamespace/constants.ts +0 -3
  39. package/src/namespaces/MiddlewareNamespace/index.ts +0 -5
  40. package/src/namespaces/MiddlewareNamespace/types.ts +0 -28
  41. package/src/namespaces/MiddlewareNamespace/validators.ts +0 -95
  42. package/src/namespaces/NavigationNamespace/transition/executeMiddleware.ts +0 -56
  43. package/src/namespaces/NavigationNamespace/transition/makeError.ts +0 -37
  44. package/src/namespaces/NavigationNamespace/transition/mergeStates.ts +0 -54
  45. package/src/namespaces/NavigationNamespace/transition/processLifecycleResult.ts +0 -81
@@ -1,81 +0,0 @@
1
- // packages/real-router/modules/transition/processLifecycleResult.ts
2
-
3
- import { isPromise, isState } from "type-guards";
4
-
5
- import { errorCodes } from "../../../constants";
6
- import { RouterError } from "../../../RouterError";
7
-
8
- import type { SyncErrorMetadata } from "./wrapSyncError";
9
- import type { State, ActivationFn } from "@real-router/types";
10
-
11
- /**
12
- * Builds error metadata from a caught promise rejection.
13
- * Extracts message, stack, and cause from Error instances.
14
- */
15
- function buildErrorMetadata(
16
- error_: unknown,
17
- errorData: SyncErrorMetadata,
18
- ): SyncErrorMetadata {
19
- if (error_ instanceof Error) {
20
- return {
21
- ...errorData,
22
- message: error_.message,
23
- stack: error_.stack,
24
- // Error.cause requires ES2022+ - safely access it if present
25
- ...("cause" in error_ &&
26
- error_.cause !== undefined && { cause: error_.cause }),
27
- };
28
- }
29
-
30
- if (error_ && typeof error_ === "object") {
31
- return { ...errorData, ...error_ };
32
- }
33
-
34
- return errorData;
35
- }
36
-
37
- // Helper: Lifecycle results Processing Function
38
- export const processLifecycleResult = async (
39
- result: ReturnType<ActivationFn>,
40
- currentState: State,
41
- segment?: string,
42
- ): Promise<State> => {
43
- const errorData = segment ? { segment } : {};
44
-
45
- if (result === undefined) {
46
- return currentState;
47
- }
48
-
49
- if (typeof result === "boolean") {
50
- if (result) {
51
- return currentState;
52
- } else {
53
- throw new RouterError(errorCodes.TRANSITION_ERR, errorData);
54
- }
55
- }
56
-
57
- if (isState(result)) {
58
- return result;
59
- }
60
-
61
- if (isPromise<State | boolean | undefined>(result)) {
62
- // Optimization: single try/catch instead of .then(onFulfill, onReject)
63
- try {
64
- const resVal = await result;
65
-
66
- return await processLifecycleResult(resVal, currentState, segment);
67
- } catch (error_: unknown) {
68
- throw new RouterError(
69
- errorCodes.TRANSITION_ERR,
70
- buildErrorMetadata(error_, errorData),
71
- );
72
- }
73
- }
74
-
75
- // This should never be reached - all valid ActivationFn return types are handled above
76
- // If we get here, it means the activation function returned an unexpected type
77
- throw new RouterError(errorCodes.TRANSITION_ERR, {
78
- ...errorData,
79
- message: `Invalid lifecycle result type: ${typeof result}`,
80
- });
81
- };