@kitbag/router 0.0.2 → 0.0.3
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 +1 -2
- package/dist/kitbag-router.d.ts +37 -28
- package/dist/kitbag-router.js +475 -450
- package/dist/kitbag-router.umd.cjs +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -3,8 +3,7 @@
|
|
|
3
3
|
A simple and versatile mapping utility for Typescript.
|
|
4
4
|
|
|
5
5
|
[](https://www.npmjs.org/package/kitbag/router)
|
|
6
|
-
[](https://app.netlify.com/sites/kitbag-router/deploys)
|
|
6
|
+
[](https://app.netlify.com/sites/kitbag-router/deploys)
|
|
8
7
|
|
|
9
8
|
Get started with the [documentation](https://kitbag-router.netlify.app/)
|
|
10
9
|
|
package/dist/kitbag-router.d.ts
CHANGED
|
@@ -74,15 +74,23 @@ export declare type AfterRouteHookResponse<TRoutes extends Routes> = RouteHookSu
|
|
|
74
74
|
declare type AllPropertiesAreOptional<T> = Record<string, unknown> extends T ? true : IsEmptyObject<OnlyRequiredProperties<T>>;
|
|
75
75
|
|
|
76
76
|
declare type BaseResolvedRoute = Route & {
|
|
77
|
-
|
|
78
|
-
|
|
77
|
+
path: {
|
|
78
|
+
params: Record<string, unknown>;
|
|
79
|
+
};
|
|
80
|
+
query: {
|
|
81
|
+
params: Record<string, unknown>;
|
|
82
|
+
};
|
|
79
83
|
};
|
|
80
84
|
|
|
81
85
|
declare type BaseRoute = {
|
|
82
86
|
key: string;
|
|
83
87
|
disabled: false;
|
|
84
|
-
|
|
85
|
-
|
|
88
|
+
path: {
|
|
89
|
+
params: Record<string, unknown>;
|
|
90
|
+
};
|
|
91
|
+
query: {
|
|
92
|
+
params: Record<string, unknown>;
|
|
93
|
+
};
|
|
86
94
|
};
|
|
87
95
|
|
|
88
96
|
/**
|
|
@@ -144,7 +152,9 @@ declare type CombineQuery<TParent extends Query | undefined, TChild extends Quer
|
|
|
144
152
|
} ? ToQuery<TChild> extends {
|
|
145
153
|
query: infer TChildQuery extends string;
|
|
146
154
|
params: infer TChildParams extends Record<string, unknown>;
|
|
147
|
-
} ? MergeParams<TParentParams, TChildParams> extends QueryParams
|
|
155
|
+
} ? MergeParams<TParentParams, TChildParams> extends QueryParams<CombineQueryString<TParentQuery, TChildQuery>> ? Query<CombineQueryString<TParentQuery, TChildQuery>, MergeParams<TParentParams, TChildParams>> : Query<'', {}> : Query<'', {}> : Query<'', {}>;
|
|
156
|
+
|
|
157
|
+
declare type CombineQueryString<TParent extends string | undefined, TChild extends string | undefined> = StringHasValue<TParent> extends true ? StringHasValue<TChild> extends true ? `${TParent}&${TChild}` : TParent : TChild;
|
|
148
158
|
|
|
149
159
|
/**
|
|
150
160
|
* Creates a router instance for a Vue application, equipped with methods for route handling, lifecycle hooks, and state management.
|
|
@@ -172,7 +182,7 @@ declare type CombineQuery<TParent extends Query | undefined, TChild extends Quer
|
|
|
172
182
|
export declare function createRouter<const T extends Routes>(routes: T, options?: RouterOptions): Router<T>;
|
|
173
183
|
|
|
174
184
|
/**
|
|
175
|
-
* Creates an array of
|
|
185
|
+
* Creates an array of routes from a defined set of route properties, handling hierarchical route combinations.
|
|
176
186
|
* This function also validates for duplicate parameter keys across the combined routes.
|
|
177
187
|
*
|
|
178
188
|
* @param routesProps - An array of route properties used to configure and create routes.
|
|
@@ -244,11 +254,19 @@ declare type ExtractRouteChildren<TRoute extends RouteProps> = TRoute extends Pa
|
|
|
244
254
|
* @returns A record of parameter names to their respective types, extracted and merged from both path and query parameters.
|
|
245
255
|
*/
|
|
246
256
|
export declare type ExtractRouteParamTypes<TRoute extends {
|
|
247
|
-
|
|
248
|
-
|
|
257
|
+
path: {
|
|
258
|
+
params: Record<string, unknown>;
|
|
259
|
+
};
|
|
260
|
+
query: {
|
|
261
|
+
params: Record<string, unknown>;
|
|
262
|
+
};
|
|
249
263
|
}> = TRoute extends {
|
|
250
|
-
|
|
251
|
-
|
|
264
|
+
path: {
|
|
265
|
+
params: infer PathParams extends Record<string, Param | undefined>;
|
|
266
|
+
};
|
|
267
|
+
query: {
|
|
268
|
+
params: infer QueryParams extends Record<string, Param | undefined>;
|
|
269
|
+
};
|
|
252
270
|
} ? ExtractParamTypes<MergeParams<PathParams, QueryParams>> : Record<string, unknown>;
|
|
253
271
|
|
|
254
272
|
declare type Flatten<T extends any[]> = T extends [infer First, ...infer Rest] ? First extends unknown[] ? Flatten<[...First, ...Flatten<Rest>]> : [First, ...Flatten<Rest>] : [];
|
|
@@ -357,22 +375,22 @@ declare type OnlyRequiredProperties<T> = {
|
|
|
357
375
|
[K in keyof T as Extract<T[K], undefined> extends never ? K : never]: T[K];
|
|
358
376
|
};
|
|
359
377
|
|
|
360
|
-
declare type Param = ParamGetter | ParamGetSet | RegExp | BooleanConstructor | NumberConstructor | StringConstructor;
|
|
378
|
+
export declare type Param = ParamGetter | ParamGetSet | RegExp | BooleanConstructor | NumberConstructor | StringConstructor;
|
|
361
379
|
|
|
362
380
|
declare type ParamEnd = '/';
|
|
363
381
|
|
|
364
|
-
declare type ParamExtras = {
|
|
382
|
+
export declare type ParamExtras = {
|
|
365
383
|
invalid: (message?: string) => never;
|
|
366
384
|
};
|
|
367
385
|
|
|
368
|
-
declare type ParamGetSet<T = any> = {
|
|
386
|
+
export declare type ParamGetSet<T = any> = {
|
|
369
387
|
get: ParamGetter<T>;
|
|
370
388
|
set: ParamSetter<T>;
|
|
371
389
|
};
|
|
372
390
|
|
|
373
|
-
declare type ParamGetter<T = any> = (value: string, extras: ParamExtras) => T;
|
|
391
|
+
export declare type ParamGetter<T = any> = (value: string, extras: ParamExtras) => T;
|
|
374
392
|
|
|
375
|
-
declare type ParamSetter<T = any> = (value: T, extras: ParamExtras) => string;
|
|
393
|
+
export declare type ParamSetter<T = any> = (value: T, extras: ParamExtras) => string;
|
|
376
394
|
|
|
377
395
|
/**
|
|
378
396
|
* Represents properties common to parent routes in a route configuration, including hooks, path, and optional query parameters.
|
|
@@ -563,17 +581,6 @@ export declare type Route<TKey extends string | undefined = any, TPath extends s
|
|
|
563
581
|
* Represents the structured query of the route, including query params.
|
|
564
582
|
*/
|
|
565
583
|
query: ToQuery<TQuery>;
|
|
566
|
-
/**
|
|
567
|
-
* Extracted path params based on the route's path type.
|
|
568
|
-
*/
|
|
569
|
-
pathParams: ToPath<TPath>['params'];
|
|
570
|
-
/**
|
|
571
|
-
* Extracted query params based on the route's query type.
|
|
572
|
-
*/
|
|
573
|
-
queryParams: ToQuery<TQuery>['params'];
|
|
574
|
-
/**
|
|
575
|
-
* Represents the depth of the route in the route hierarchy.
|
|
576
|
-
*/
|
|
577
584
|
depth: number;
|
|
578
585
|
/**
|
|
579
586
|
* Indicates if the route is disabled.
|
|
@@ -786,7 +793,7 @@ to: Url | ToCallback;
|
|
|
786
793
|
}>;
|
|
787
794
|
|
|
788
795
|
/**
|
|
789
|
-
*
|
|
796
|
+
* An error thrown when an attempt is made to use routing functionality before the router has been installed.
|
|
790
797
|
*/
|
|
791
798
|
export declare class RouterNotInstalledError extends Error {
|
|
792
799
|
constructor();
|
|
@@ -890,6 +897,8 @@ declare type RouteUpdate<TRoute extends ResolvedRoute = ResolvedRoute> = {
|
|
|
890
897
|
(params: Partial<TRoute['params']>, options?: RouterPushOptions): Promise<void>;
|
|
891
898
|
};
|
|
892
899
|
|
|
900
|
+
declare type StringHasValue<T extends string | undefined> = T extends undefined ? false : '' extends T ? false : true;
|
|
901
|
+
|
|
893
902
|
declare type ToCallback = (resolve: RegisteredRouter['resolve']) => string;
|
|
894
903
|
|
|
895
904
|
declare type ToPath<T extends string | Path> = T extends string ? Path<T, {}> : T;
|
|
@@ -927,7 +936,7 @@ export declare function useRoute<TRouteKey extends string & keyof RegisteredRout
|
|
|
927
936
|
export declare function useRoute(): RouterRoute;
|
|
928
937
|
|
|
929
938
|
/**
|
|
930
|
-
*
|
|
939
|
+
* An error thrown when there is a mismatch between an expected route and the one actually used.
|
|
931
940
|
*/
|
|
932
941
|
export declare class UseRouteInvalidError extends Error {
|
|
933
942
|
/**
|