@kitbag/router 0.5.0 → 0.5.2
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/dist/kitbag-router.d.ts +22 -29
- package/dist/kitbag-router.js +185 -198
- package/dist/kitbag-router.umd.cjs +1 -1
- package/package.json +1 -1
package/dist/kitbag-router.d.ts
CHANGED
|
@@ -88,17 +88,6 @@ export declare type AfterRouteHookResponse<TRoutes extends Routes> = RouteHookSu
|
|
|
88
88
|
|
|
89
89
|
declare type AllPropertiesAreOptional<T> = Record<string, unknown> extends T ? true : IsEmptyObject<OnlyRequiredProperties<T>>;
|
|
90
90
|
|
|
91
|
-
declare type BaseRoute = {
|
|
92
|
-
key: string;
|
|
93
|
-
disabled: false;
|
|
94
|
-
path: {
|
|
95
|
-
params: Record<string, unknown>;
|
|
96
|
-
};
|
|
97
|
-
query: {
|
|
98
|
-
params: Record<string, unknown>;
|
|
99
|
-
};
|
|
100
|
-
};
|
|
101
|
-
|
|
102
91
|
/**
|
|
103
92
|
* Represents a function called before a route change, potentially altering the routing operation.
|
|
104
93
|
* @param to - {@link ResolvedRoute} The resolved route the router is navigating to.
|
|
@@ -156,7 +145,7 @@ export declare type ChildRouteProps = (WithComponent | WithComponents) & WithHoo
|
|
|
156
145
|
meta?: RouteMeta;
|
|
157
146
|
};
|
|
158
147
|
|
|
159
|
-
declare type CombineName<TParentName extends string | undefined, TChildName extends string | undefined> = TParentName extends
|
|
148
|
+
declare type CombineName<TParentName extends string | undefined, TChildName extends string | undefined> = StringHasValue<TParentName> extends true ? StringHasValue<TChildName> extends true ? `${TParentName}.${TChildName}` : TParentName : StringHasValue<TChildName> extends true ? TChildName : '';
|
|
160
149
|
|
|
161
150
|
declare type CombinePath<TParent extends Path, TChild extends Path> = ToPath<TParent> extends {
|
|
162
151
|
path: infer TParentPath extends string;
|
|
@@ -164,7 +153,7 @@ declare type CombinePath<TParent extends Path, TChild extends Path> = ToPath<TPa
|
|
|
164
153
|
} ? ToPath<TChild> extends {
|
|
165
154
|
path: infer TChildPath extends string;
|
|
166
155
|
params: infer TChildParams extends Record<string, unknown>;
|
|
167
|
-
} ? MergeParams<TParentParams
|
|
156
|
+
} ? MergeParams<RemoveLeadingQuestionMarkFromKeys<TParentParams>, RemoveLeadingQuestionMarkFromKeys<TChildParams>> extends PathParamsWithParamNameExtracted<`${TParentPath}${TChildPath}`> ? Path<`${TParentPath}${TChildPath}`, MergeParams<RemoveLeadingQuestionMarkFromKeys<TParentParams>, RemoveLeadingQuestionMarkFromKeys<TChildParams>>> : Path<'', {}> : Path<'', {}> : Path<'', {}>;
|
|
168
157
|
|
|
169
158
|
declare type CombineQuery<TParent extends Query | undefined, TChild extends Query | undefined> = ToQuery<TParent> extends {
|
|
170
159
|
query: infer TParentQuery extends string;
|
|
@@ -172,7 +161,7 @@ declare type CombineQuery<TParent extends Query | undefined, TChild extends Quer
|
|
|
172
161
|
} ? ToQuery<TChild> extends {
|
|
173
162
|
query: infer TChildQuery extends string;
|
|
174
163
|
params: infer TChildParams extends Record<string, unknown>;
|
|
175
|
-
} ? MergeParams<TParentParams
|
|
164
|
+
} ? MergeParams<RemoveLeadingQuestionMarkFromKeys<TParentParams>, RemoveLeadingQuestionMarkFromKeys<TChildParams>> extends QueryParamsWithParamNameExtracted<CombineQueryString<TParentQuery, TChildQuery>> ? Query<CombineQueryString<TParentQuery, TChildQuery>, MergeParams<RemoveLeadingQuestionMarkFromKeys<TParentParams>, RemoveLeadingQuestionMarkFromKeys<TChildParams>>> : Query<'', {}> : Query<'', {}> : Query<'', {}>;
|
|
176
165
|
|
|
177
166
|
declare type CombineQueryString<TParent extends string | undefined, TChild extends string | undefined> = StringHasValue<TParent> extends true ? StringHasValue<TChild> extends true ? `${TParent}&${TChild}` : TParent : TChild;
|
|
178
167
|
|
|
@@ -389,7 +378,9 @@ declare type ExtractRouteParamTypesWithoutLosingOptional<TRoute> = TRoute extend
|
|
|
389
378
|
|
|
390
379
|
declare type Flatten<T extends any[]> = T extends [infer First, ...infer Rest] ? First extends unknown[] ? Flatten<[...First, ...Flatten<Rest>]> : [First, ...Flatten<Rest>] : [];
|
|
391
380
|
|
|
392
|
-
declare type FlattenRoute<TRoute extends RouteProps | ExternalRouteProps, TKey extends string =
|
|
381
|
+
declare type FlattenRoute<TRoute extends RouteProps | ExternalRouteProps, TKey extends string = TRoute extends {
|
|
382
|
+
name: infer T extends string;
|
|
383
|
+
} ? T : '', THost extends string = TRoute extends {
|
|
393
384
|
host: infer T extends string;
|
|
394
385
|
} ? T : '', TPath extends Path = ToPath<TRoute['path']>, TQuery extends Query = ToQuery<TRoute['query']>, TDisabled extends boolean = TRoute['disabled'] extends boolean ? TRoute['disabled'] : false, TChildren extends Route[] = ExtractRouteChildren<TRoute>> = [
|
|
395
386
|
Route<TKey, THost, TPath, TQuery, TDisabled>,
|
|
@@ -459,10 +450,16 @@ export declare function isRoute<TRouteKey extends RegisteredRoutesKey>(route: un
|
|
|
459
450
|
|
|
460
451
|
export declare function isRoute(route: unknown, routeKey?: string, options?: IsRouteOptions): boolean;
|
|
461
452
|
|
|
453
|
+
declare type IsRouteDisabled<T extends Route> = T extends {
|
|
454
|
+
disabled: true;
|
|
455
|
+
} ? true : false;
|
|
456
|
+
|
|
462
457
|
declare type IsRouteOptions = {
|
|
463
458
|
exact?: boolean;
|
|
464
459
|
};
|
|
465
460
|
|
|
461
|
+
declare type IsRouteUnnamed<T extends Route> = StringHasValue<T['key']> extends true ? false : true;
|
|
462
|
+
|
|
466
463
|
export declare function isRouteWithComponent(value: RouteProps): value is RouteProps & WithComponent;
|
|
467
464
|
|
|
468
465
|
export declare function isRouteWithComponent(value: Readonly<RouteProps>): value is Readonly<RouteProps & WithComponent>;
|
|
@@ -491,8 +488,6 @@ export declare type MergeParams<TAlpha extends Record<string, unknown>, TBeta ex
|
|
|
491
488
|
[K in keyof TAlpha | keyof TBeta]: K extends keyof TAlpha & keyof TBeta ? never : K extends keyof TAlpha ? TAlpha[K] : K extends keyof TBeta ? TBeta[K] : never;
|
|
492
489
|
};
|
|
493
490
|
|
|
494
|
-
declare type NamedNotDisabled<T> = T extends BaseRoute ? T : never;
|
|
495
|
-
|
|
496
491
|
/**
|
|
497
492
|
* Registers a hook that is called after a route has been entered. Must be called during setup.
|
|
498
493
|
* This allows performing actions right after the component becomes active, such as fetching data or setting up event listeners.
|
|
@@ -629,10 +624,6 @@ declare type Path<TPath extends string = string, TParams extends PathParamsWithP
|
|
|
629
624
|
*/
|
|
630
625
|
export declare function path<TPath extends string, TParams extends PathParamsWithParamNameExtracted<TPath>>(path: TPath, params: Identity<TParams>): Path<TPath, TParams>;
|
|
631
626
|
|
|
632
|
-
declare type PathParams<TPath extends string> = {
|
|
633
|
-
[K in keyof ExtractParamsFromPathString<TPath>]?: Param;
|
|
634
|
-
};
|
|
635
|
-
|
|
636
627
|
declare type PathParamsWithParamNameExtracted<TPath extends string> = {
|
|
637
628
|
[K in keyof ExtractParamsFromPathString<TPath> as ExtractParamName<K>]?: Param;
|
|
638
629
|
};
|
|
@@ -672,10 +663,6 @@ declare type Query<TQuery extends string = string, TQueryParams extends QueryPar
|
|
|
672
663
|
*/
|
|
673
664
|
export declare function query<TQuery extends string, TParams extends QueryParamsWithParamNameExtracted<TQuery>>(query: TQuery, params: Identity<TParams>): Query<TQuery, TParams>;
|
|
674
665
|
|
|
675
|
-
declare type QueryParams<T extends string> = {
|
|
676
|
-
[K in keyof ExtractQueryParamsFromQueryString<T>]?: Param;
|
|
677
|
-
};
|
|
678
|
-
|
|
679
666
|
declare type QueryParamsWithParamNameExtracted<T extends string> = {
|
|
680
667
|
[K in keyof ExtractQueryParamsFromQueryString<T> as ExtractParamName<K>]?: Param;
|
|
681
668
|
};
|
|
@@ -749,6 +736,12 @@ export declare type RegisteredRoutes = Register extends {
|
|
|
749
736
|
*/
|
|
750
737
|
export declare type RegisteredRoutesKey = RoutesKey<RegisteredRoutes>;
|
|
751
738
|
|
|
739
|
+
declare type RemoveLeadingQuestionMark<T extends PropertyKey> = T extends `?${infer TRest extends string}` ? TRest : T;
|
|
740
|
+
|
|
741
|
+
declare type RemoveLeadingQuestionMarkFromKeys<T extends Record<string, unknown>> = {
|
|
742
|
+
[K in keyof T as RemoveLeadingQuestionMark<K>]: T[K];
|
|
743
|
+
};
|
|
744
|
+
|
|
752
745
|
/**
|
|
753
746
|
* Represents a route that the router has matched to current browser location.
|
|
754
747
|
* @template TRoute - Underlying Route that has been resolved.
|
|
@@ -891,6 +884,8 @@ declare type RouteHookSuccessResponse = {
|
|
|
891
884
|
status: 'SUCCESS';
|
|
892
885
|
};
|
|
893
886
|
|
|
887
|
+
declare type RouteIsNamedAndNotDisabled<T extends Route> = IsRouteDisabled<T> extends true ? never : IsRouteUnnamed<T> extends true ? never : T;
|
|
888
|
+
|
|
894
889
|
/**
|
|
895
890
|
* Represents additional metadata associated with a route, customizable via declaration merging.
|
|
896
891
|
* @example
|
|
@@ -1167,9 +1162,7 @@ export declare type Routes = Readonly<Route[]>;
|
|
|
1167
1162
|
declare type RoutesKey<TRoutes extends Routes> = string & keyof RoutesMap<TRoutes>;
|
|
1168
1163
|
|
|
1169
1164
|
declare type RoutesMap<TRoutes extends Routes = []> = {
|
|
1170
|
-
[K in TRoutes[number] as
|
|
1171
|
-
key: string;
|
|
1172
|
-
} ? NamedNotDisabled<K>['key'] : never]: NamedNotDisabled<K>;
|
|
1165
|
+
[K in TRoutes[number] as RouteIsNamedAndNotDisabled<K>['key']]: RouteIsNamedAndNotDisabled<K>;
|
|
1173
1166
|
};
|
|
1174
1167
|
|
|
1175
1168
|
declare type RouteUpdate<TRoute extends ResolvedRoute = ResolvedRoute> = ResolvedRoute extends TRoute ? {
|
|
@@ -1180,7 +1173,7 @@ declare type RouteUpdate<TRoute extends ResolvedRoute = ResolvedRoute> = Resolve
|
|
|
1180
1173
|
(params: Partial<TRoute['params']>, options?: RouterPushOptions): Promise<void>;
|
|
1181
1174
|
};
|
|
1182
1175
|
|
|
1183
|
-
declare type StringHasValue<T
|
|
1176
|
+
declare type StringHasValue<T> = string extends T ? true : '' extends T ? false : T extends string ? true : false;
|
|
1184
1177
|
|
|
1185
1178
|
export declare function throwIfDuplicateParamsAreFound(routes: Route[]): void;
|
|
1186
1179
|
|