@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.
- package/README.md +0 -15
- package/dist/cjs/index.d.ts +12 -13
- package/dist/cjs/index.js +1 -1
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/metafile-cjs.json +1 -1
- package/dist/esm/index.d.mts +12 -13
- package/dist/esm/index.mjs +1 -1
- package/dist/esm/index.mjs.map +1 -1
- package/dist/esm/metafile-esm.json +1 -1
- package/package.json +4 -4
- package/src/Router.ts +14 -57
- package/src/RouterError.ts +1 -1
- package/src/constants.ts +1 -3
- package/src/helpers.ts +1 -1
- package/src/index.ts +3 -3
- package/src/namespaces/CloneNamespace/CloneNamespace.ts +6 -6
- package/src/namespaces/CloneNamespace/types.ts +5 -9
- package/src/namespaces/DependenciesNamespace/DependenciesNamespace.ts +2 -4
- package/src/namespaces/NavigationNamespace/NavigationNamespace.ts +1 -0
- package/src/namespaces/NavigationNamespace/transition/{wrapSyncError.ts → errorHandling.ts} +23 -17
- package/src/namespaces/NavigationNamespace/transition/executeLifecycleHooks.ts +14 -55
- package/src/namespaces/NavigationNamespace/transition/index.ts +6 -24
- package/src/namespaces/NavigationNamespace/types.ts +2 -9
- package/src/namespaces/PluginsNamespace/PluginsNamespace.ts +2 -2
- package/src/namespaces/RouteLifecycleNamespace/RouteLifecycleNamespace.ts +28 -43
- package/src/namespaces/RouteLifecycleNamespace/validators.ts +3 -3
- package/src/namespaces/RoutesNamespace/RoutesNamespace.ts +53 -34
- package/src/namespaces/RoutesNamespace/stateBuilder.ts +1 -1
- package/src/namespaces/RoutesNamespace/types.ts +3 -3
- package/src/namespaces/index.ts +0 -2
- package/src/transitionPath.ts +4 -40
- package/src/typeGuards.ts +1 -2
- package/src/types.ts +8 -8
- package/src/wiring/RouterWiringBuilder.ts +1 -17
- package/src/wiring/types.ts +0 -3
- package/src/wiring/wireRouter.ts +0 -1
- package/src/namespaces/MiddlewareNamespace/MiddlewareNamespace.ts +0 -221
- package/src/namespaces/MiddlewareNamespace/constants.ts +0 -3
- package/src/namespaces/MiddlewareNamespace/index.ts +0 -5
- package/src/namespaces/MiddlewareNamespace/types.ts +0 -28
- package/src/namespaces/MiddlewareNamespace/validators.ts +0 -95
- package/src/namespaces/NavigationNamespace/transition/executeMiddleware.ts +0 -56
- package/src/namespaces/NavigationNamespace/transition/makeError.ts +0 -37
- package/src/namespaces/NavigationNamespace/transition/mergeStates.ts +0 -54
- 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
|
-
};
|