@real-router/validation-plugin 0.6.1 → 0.7.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@real-router/validation-plugin",
3
- "version": "0.6.1",
3
+ "version": "0.7.1",
4
4
  "type": "commonjs",
5
5
  "description": "Route validation plugin with type guards and parameter validation",
6
6
  "main": "./dist/cjs/index.js",
@@ -44,15 +44,15 @@
44
44
  },
45
45
  "sideEffects": false,
46
46
  "dependencies": {
47
- "@real-router/core": "^0.50.0",
47
+ "@real-router/core": "^0.52.0",
48
48
  "@real-router/logger": "^0.3.0"
49
49
  },
50
50
  "peerDependencies": {
51
- "@real-router/core": "^0.50.0"
51
+ "@real-router/core": "^0.52.0"
52
52
  },
53
53
  "devDependencies": {
54
54
  "route-tree": "^0.3.4",
55
- "type-guards": "^0.4.8"
55
+ "type-guards": "^0.4.9"
56
56
  },
57
57
  "scripts": {
58
58
  "test": "vitest",
@@ -32,6 +32,7 @@ import {
32
32
  import {
33
33
  validateNavigateArgs,
34
34
  validateNavigateToDefaultArgs,
35
+ validateNavigateToStateArgs,
35
36
  validateNavigationOptions,
36
37
  validateNavigateParams,
37
38
  validateStartArgs,
@@ -253,6 +254,7 @@ function buildValidatorObject(ctx: RouterInternals): RouterValidator {
253
254
  navigation: {
254
255
  validateNavigateArgs,
255
256
  validateNavigateToDefaultArgs,
257
+ validateNavigateToStateArgs,
256
258
  validateNavigationOptions,
257
259
  validateParams: validateNavigateParams,
258
260
  validateStartArgs,
@@ -1,6 +1,11 @@
1
1
  // packages/validation-plugin/src/validators/navigation.ts
2
2
 
3
- import { getTypeDescription, isNavigationOptions, isParams } from "type-guards";
3
+ import {
4
+ getTypeDescription,
5
+ isNavigationOptions,
6
+ isParams,
7
+ isString,
8
+ } from "type-guards";
4
9
 
5
10
  import type { NavigationOptions } from "@real-router/core";
6
11
 
@@ -20,6 +25,32 @@ export function validateNavigateToDefaultArgs(opts: unknown): void {
20
25
  }
21
26
  }
22
27
 
28
+ export function validateNavigateToStateArgs(state: unknown): void {
29
+ if (typeof state !== "object" || state === null) {
30
+ throw new TypeError(
31
+ `[router.navigateToState] Invalid state: ${getTypeDescription(state)}. Expected State object.`,
32
+ );
33
+ }
34
+
35
+ const candidate = state as { name: unknown; params: unknown; path: unknown };
36
+
37
+ if (!isString(candidate.name)) {
38
+ throw new TypeError(
39
+ `[router.navigateToState] Invalid state.name: ${getTypeDescription(candidate.name)}. Expected string.`,
40
+ );
41
+ }
42
+ if (!isParams(candidate.params)) {
43
+ throw new TypeError(
44
+ `[router.navigateToState] Invalid state.params: ${getTypeDescription(candidate.params)}. Expected plain object.`,
45
+ );
46
+ }
47
+ if (!isString(candidate.path)) {
48
+ throw new TypeError(
49
+ `[router.navigateToState] Invalid state.path: ${getTypeDescription(candidate.path)}. Expected string.`,
50
+ );
51
+ }
52
+ }
53
+
23
54
  export function validateNavigationOptions(
24
55
  opts: unknown,
25
56
  methodName: string,