@kitbag/router 0.20.8 → 0.20.10

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.
@@ -121,6 +121,11 @@ export type Router<TRoutes extends Routes = any, TOptions extends RouterOptions
121
121
  * Registers a hook to be called after a route is updated.
122
122
  */
123
123
  onAfterRouteUpdate: AddRouterAfterRouteHook<TRoutes | TPlugin['routes'], keyof TOptions['rejections'] | KeysOfUnion<TPlugin['rejections']>>;
124
+ /**
125
+ * Registers a hook to be called when an error occurs.
126
+ * If the hook returns true, the error is considered handled and the other hooks are not run. If all hooks return false the error is rethrown
127
+ */
128
+ onError: AddRouterErrorHook<TRoutes | TPlugin['routes'], keyof TOptions['rejections'] | KeysOfUnion<TPlugin['rejections']>>;
124
129
  /**
125
130
  * Given a URL, returns true if host does not match host stored on router instance
126
131
  */
@@ -168,6 +173,22 @@ export type RouterAfterRouteHook<TRoutes extends Routes, TRejections extends Pro
168
173
  export type AddRouterAfterRouteHook<TRoutes extends Routes, TRejections extends PropertyKey> = (hook: RouterAfterRouteHook<TRoutes, TRejections>) => RouteHookRemove;
169
174
  export type RouterRouteHookBeforeRunner<TRoutes extends Routes> = (context: HookContext<TRoutes>) => Promise<BeforeRouteHookResponse>;
170
175
  export type RouterRouteHookAfterRunner<TRoutes extends Routes> = (context: HookContext<TRoutes>) => Promise<AfterRouteHookResponse>;
176
+ export type RouterErrorHookContext<TRoutes extends Routes, TRejections extends PropertyKey> = {
177
+ to: RouterResolvedRouteUnion<TRoutes>;
178
+ from: RouterResolvedRouteUnion<TRoutes> | null;
179
+ source: 'props' | 'hook' | 'component';
180
+ reject: RouterReject<TRejections>;
181
+ push: RouterPush<TRoutes>;
182
+ replace: RouterReplace<TRoutes>;
183
+ };
184
+ export type RouterErrorHook<TRoutes extends Routes, TRejections extends PropertyKey> = (error: unknown, context: RouterErrorHookContext<TRoutes, TRejections>) => void;
185
+ export type AddRouterErrorHook<TRoutes extends Routes, TRejections extends PropertyKey> = (hook: RouterErrorHook<TRoutes, TRejections>) => RouteHookRemove;
186
+ export type RouterRouteHookErrorRunnerContext<TRoutes extends Routes> = {
187
+ to: RouterResolvedRouteUnion<TRoutes>;
188
+ from: RouterResolvedRouteUnion<TRoutes> | null;
189
+ source: 'props' | 'hook';
190
+ };
191
+ export type RouterRouteHookErrorRunner<TRoutes extends Routes> = (error: unknown, context: RouterRouteHookErrorRunnerContext<TRoutes>) => void;
171
192
  /**
172
193
  * This type is the same as `RouterRoute<ResolvedRoute<TRoutes[number]>>` while remaining distributive
173
194
  */
@@ -9,136 +9,152 @@ export declare function getError(callback: () => any): unknown;
9
9
  export declare const component: {
10
10
  template: string;
11
11
  };
12
- export declare const routes: readonly [import('../main').Route<"parentA", import('../services/withParams').WithParams<"", {}>, import('../services/withParams').WithParams<"/parentA/[paramA]", {}>, import('../services/withParams').WithParams<"", {}>, import('../services/withParams').WithParams<"", {}>, {}, {}, [Omit<{
12
+ export declare const routes: readonly [import('../main').Route<"parentA", import('../services/withParams').WithParams<"", {}>, import('../services/withParams').WithParams<"/parentA/[paramA]", {}>, import('../services/withParams').WithParams<"", {}>, import('../services/withParams').WithParams<"", {}>, Readonly<{}>, {}, [Omit<{
13
13
  readonly name: "parentA";
14
14
  readonly path: "/parentA/[paramA]";
15
- }, "props"> & {
15
+ }, "meta" | "props"> & {
16
16
  id: string;
17
17
  props: undefined;
18
+ meta: Readonly<{}>;
18
19
  }]>, import('../main').Route<"parentA.childA", import('../services/withParams').WithParams<"", {}>, import('../services/withParams').WithParams<"/parentA/[paramA]/childA/[?paramB]", {
19
20
  paramA: StringConstructor;
20
21
  } & {
21
22
  paramB: StringConstructor;
22
- }>, import('../services/withParams').WithParams<"", {}>, import('../services/withParams').WithParams<"", {}>, {}, {}, [Omit<{
23
+ }>, import('../services/withParams').WithParams<"", {}>, import('../services/withParams').WithParams<"", {}>, Readonly<{}>, {}, [Omit<{
23
24
  readonly name: "parentA";
24
25
  readonly path: "/parentA/[paramA]";
25
- }, "props"> & {
26
+ }, "meta" | "props"> & {
26
27
  id: string;
27
28
  props: undefined;
29
+ meta: Readonly<{}>;
28
30
  }, Omit<{
29
- readonly parent: import('../main').Route<"parentA", import('../services/withParams').WithParams<"", {}>, import('../services/withParams').WithParams<"/parentA/[paramA]", {}>, import('../services/withParams').WithParams<"", {}>, import('../services/withParams').WithParams<"", {}>, {}, {}, [Omit<{
31
+ readonly parent: import('../main').Route<"parentA", import('../services/withParams').WithParams<"", {}>, import('../services/withParams').WithParams<"/parentA/[paramA]", {}>, import('../services/withParams').WithParams<"", {}>, import('../services/withParams').WithParams<"", {}>, Readonly<{}>, {}, [Omit<{
30
32
  readonly name: "parentA";
31
33
  readonly path: "/parentA/[paramA]";
32
- }, "props"> & {
34
+ }, "meta" | "props"> & {
33
35
  id: string;
34
36
  props: undefined;
37
+ meta: Readonly<{}>;
35
38
  }]>;
36
39
  readonly name: "parentA.childA";
37
40
  readonly path: "/childA/[?paramB]";
38
- }, "props"> & {
41
+ }, "meta" | "props"> & {
39
42
  id: string;
40
43
  props: undefined;
44
+ meta: Readonly<{}>;
41
45
  }]>, import('../main').Route<"parentA.childB", import('../services/withParams').WithParams<"", {}>, import('../services/withParams').WithParams<"/parentA/[paramA]/childB/[paramD]", {
42
46
  paramA: StringConstructor;
43
47
  } & {
44
48
  paramD: StringConstructor;
45
- }>, import('../services/withParams').WithParams<"", {}>, import('../services/withParams').WithParams<"", {}>, {}, {}, [Omit<{
49
+ }>, import('../services/withParams').WithParams<"", {}>, import('../services/withParams').WithParams<"", {}>, Readonly<{}>, {}, [Omit<{
46
50
  readonly name: "parentA";
47
51
  readonly path: "/parentA/[paramA]";
48
- }, "props"> & {
52
+ }, "meta" | "props"> & {
49
53
  id: string;
50
54
  props: undefined;
55
+ meta: Readonly<{}>;
51
56
  }, Omit<{
52
- readonly parent: import('../main').Route<"parentA", import('../services/withParams').WithParams<"", {}>, import('../services/withParams').WithParams<"/parentA/[paramA]", {}>, import('../services/withParams').WithParams<"", {}>, import('../services/withParams').WithParams<"", {}>, {}, {}, [Omit<{
57
+ readonly parent: import('../main').Route<"parentA", import('../services/withParams').WithParams<"", {}>, import('../services/withParams').WithParams<"/parentA/[paramA]", {}>, import('../services/withParams').WithParams<"", {}>, import('../services/withParams').WithParams<"", {}>, Readonly<{}>, {}, [Omit<{
53
58
  readonly name: "parentA";
54
59
  readonly path: "/parentA/[paramA]";
55
- }, "props"> & {
60
+ }, "meta" | "props"> & {
56
61
  id: string;
57
62
  props: undefined;
63
+ meta: Readonly<{}>;
58
64
  }]>;
59
65
  readonly name: "parentA.childB";
60
66
  readonly path: "/childB/[paramD]";
61
67
  readonly component: {
62
68
  template: string;
63
69
  };
64
- }, "props"> & {
70
+ }, "meta" | "props"> & {
65
71
  id: string;
66
72
  props: undefined;
73
+ meta: Readonly<{}>;
67
74
  }]>, import('../main').Route<"parentA.childA.grandChildA", import('../services/withParams').WithParams<"", {}>, import('../services/withParams').WithParams<"/parentA/[paramA]/childA/[?paramB]/[paramC]", {
68
75
  paramA: StringConstructor;
69
76
  paramB: StringConstructor;
70
77
  } & {
71
78
  paramC: StringConstructor;
72
- }>, import('../services/withParams').WithParams<"", {}>, import('../services/withParams').WithParams<"", {}>, {}, {}, [Omit<{
79
+ }>, import('../services/withParams').WithParams<"", {}>, import('../services/withParams').WithParams<"", {}>, Readonly<{}>, {}, [Omit<{
73
80
  readonly name: "parentA";
74
81
  readonly path: "/parentA/[paramA]";
75
- }, "props"> & {
82
+ }, "meta" | "props"> & {
76
83
  id: string;
77
84
  props: undefined;
85
+ meta: Readonly<{}>;
78
86
  }, Omit<{
79
- readonly parent: import('../main').Route<"parentA", import('../services/withParams').WithParams<"", {}>, import('../services/withParams').WithParams<"/parentA/[paramA]", {}>, import('../services/withParams').WithParams<"", {}>, import('../services/withParams').WithParams<"", {}>, {}, {}, [Omit<{
87
+ readonly parent: import('../main').Route<"parentA", import('../services/withParams').WithParams<"", {}>, import('../services/withParams').WithParams<"/parentA/[paramA]", {}>, import('../services/withParams').WithParams<"", {}>, import('../services/withParams').WithParams<"", {}>, Readonly<{}>, {}, [Omit<{
80
88
  readonly name: "parentA";
81
89
  readonly path: "/parentA/[paramA]";
82
- }, "props"> & {
90
+ }, "meta" | "props"> & {
83
91
  id: string;
84
92
  props: undefined;
93
+ meta: Readonly<{}>;
85
94
  }]>;
86
95
  readonly name: "parentA.childA";
87
96
  readonly path: "/childA/[?paramB]";
88
- }, "props"> & {
97
+ }, "meta" | "props"> & {
89
98
  id: string;
90
99
  props: undefined;
100
+ meta: Readonly<{}>;
91
101
  }, Omit<{
92
102
  readonly parent: import('../main').Route<"parentA.childA", import('../services/withParams').WithParams<"", {}>, import('../services/withParams').WithParams<"/parentA/[paramA]/childA/[?paramB]", {
93
103
  paramA: StringConstructor;
94
104
  } & {
95
105
  paramB: StringConstructor;
96
- }>, import('../services/withParams').WithParams<"", {}>, import('../services/withParams').WithParams<"", {}>, {}, {}, [Omit<{
106
+ }>, import('../services/withParams').WithParams<"", {}>, import('../services/withParams').WithParams<"", {}>, Readonly<{}>, {}, [Omit<{
97
107
  readonly name: "parentA";
98
108
  readonly path: "/parentA/[paramA]";
99
- }, "props"> & {
109
+ }, "meta" | "props"> & {
100
110
  id: string;
101
111
  props: undefined;
112
+ meta: Readonly<{}>;
102
113
  }, Omit<{
103
- readonly parent: import('../main').Route<"parentA", import('../services/withParams').WithParams<"", {}>, import('../services/withParams').WithParams<"/parentA/[paramA]", {}>, import('../services/withParams').WithParams<"", {}>, import('../services/withParams').WithParams<"", {}>, {}, {}, [Omit<{
114
+ readonly parent: import('../main').Route<"parentA", import('../services/withParams').WithParams<"", {}>, import('../services/withParams').WithParams<"/parentA/[paramA]", {}>, import('../services/withParams').WithParams<"", {}>, import('../services/withParams').WithParams<"", {}>, Readonly<{}>, {}, [Omit<{
104
115
  readonly name: "parentA";
105
116
  readonly path: "/parentA/[paramA]";
106
- }, "props"> & {
117
+ }, "meta" | "props"> & {
107
118
  id: string;
108
119
  props: undefined;
120
+ meta: Readonly<{}>;
109
121
  }]>;
110
122
  readonly name: "parentA.childA";
111
123
  readonly path: "/childA/[?paramB]";
112
- }, "props"> & {
124
+ }, "meta" | "props"> & {
113
125
  id: string;
114
126
  props: undefined;
127
+ meta: Readonly<{}>;
115
128
  }]>;
116
129
  readonly name: "parentA.childA.grandChildA";
117
130
  readonly path: "/[paramC]";
118
131
  readonly component: {
119
132
  template: string;
120
133
  };
121
- }, "props"> & {
134
+ }, "meta" | "props"> & {
122
135
  id: string;
123
136
  props: undefined;
124
- }]>, import('../main').Route<"parentB", import('../services/withParams').WithParams<"", {}>, import('../services/withParams').WithParams<"/parentB", {}>, import('../services/withParams').WithParams<"", {}>, import('../services/withParams').WithParams<"", {}>, {}, {}, [Omit<{
137
+ meta: Readonly<{}>;
138
+ }]>, import('../main').Route<"parentB", import('../services/withParams').WithParams<"", {}>, import('../services/withParams').WithParams<"/parentB", {}>, import('../services/withParams').WithParams<"", {}>, import('../services/withParams').WithParams<"", {}>, Readonly<{}>, {}, [Omit<{
125
139
  readonly name: "parentB";
126
140
  readonly path: "/parentB";
127
141
  readonly component: {
128
142
  template: string;
129
143
  };
130
- }, "props"> & {
144
+ }, "meta" | "props"> & {
131
145
  id: string;
132
146
  props: undefined;
133
- }]>, import('../main').Route<"parentC", import('../services/withParams').WithParams<"", {}>, import('../services/withParams').WithParams<"/", {}>, import('../services/withParams').WithParams<"", {}>, import('../services/withParams').WithParams<"", {}>, {}, {}, [Omit<{
147
+ meta: Readonly<{}>;
148
+ }]>, import('../main').Route<"parentC", import('../services/withParams').WithParams<"", {}>, import('../services/withParams').WithParams<"/", {}>, import('../services/withParams').WithParams<"", {}>, import('../services/withParams').WithParams<"", {}>, Readonly<{}>, {}, [Omit<{
134
149
  readonly name: "parentC";
135
150
  readonly path: "/";
136
151
  readonly component: {
137
152
  template: string;
138
153
  };
139
- }, "props"> & {
154
+ }, "meta" | "props"> & {
140
155
  id: string;
141
156
  props: undefined;
157
+ meta: Readonly<{}>;
142
158
  }]>];
143
159
  export declare function mockRoute(name: string): ResolvedRoute['matched'];
144
160
  export declare function mockResolvedRoute(matched: ResolvedRoute['matched'], matches: ResolvedRoute['matched'][]): ResolvedRoute;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@kitbag/router",
3
3
  "private": false,
4
- "version": "0.20.8",
4
+ "version": "0.20.10",
5
5
  "bugs": {
6
6
  "url": "https://github.com/kitbagjs/router/issues"
7
7
  },
@@ -17,7 +17,7 @@
17
17
  "scripts": {
18
18
  "build": "vite build",
19
19
  "build:watch": "vite build --watch --minify=false",
20
- "test": "vitest --typecheck",
20
+ "test": "vitest",
21
21
  "lint": "eslint ./src",
22
22
  "lint:fix": "eslint ./src --fix",
23
23
  "types": "vue-tsc --noEmit",
@@ -41,21 +41,22 @@
41
41
  },
42
42
  "devDependencies": {
43
43
  "@kitbag/eslint-config": "1.0.2",
44
- "@vitejs/plugin-vue": "^6.0.1",
44
+ "@vitejs/plugin-vue": "^6.0.2",
45
45
  "@vue/test-utils": "^2.4.6",
46
46
  "eslint": "^9.39.1",
47
47
  "globals": "^16.5.0",
48
- "happy-dom": "^20.0.8",
49
- "typedoc": "^0.28.14",
48
+ "happy-dom": "^20.0.11",
49
+ "typedoc": "^0.28.15",
50
50
  "typedoc-plugin-markdown": "^4.9.0",
51
51
  "typedoc-vitepress-theme": "^1.1.2",
52
52
  "typescript": "^5.9.3",
53
53
  "valibot": "^1.0.0",
54
- "vite": "^7.1.12",
54
+ "vite": "^7.2.4",
55
55
  "vite-plugin-dts": "^4.5.4",
56
56
  "vitepress": "^1.6.4",
57
- "vitest": "^4.0.4",
58
- "vue-tsc": "^3.1.2"
57
+ "vitest": "^4.0.15",
58
+ "vue-tsc": "^3.1.5",
59
+ "zod": "^3.24.1"
59
60
  },
60
61
  "peerDependencies": {
61
62
  "vue": "^3.5.0",