@kitbag/router 0.17.1 → 0.17.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/dist/kitbag-router.d.ts +58 -112
- package/dist/kitbag-router.js +1773 -1622
- package/dist/kitbag-router.umd.cjs +3 -3
- package/package.json +12 -6
package/dist/kitbag-router.d.ts
CHANGED
|
@@ -11,6 +11,7 @@ import { PublicProps } from 'vue';
|
|
|
11
11
|
import { Ref } from 'vue';
|
|
12
12
|
import { UnwrapRef } from 'vue';
|
|
13
13
|
import { VNode } from 'vue';
|
|
14
|
+
import { ZodSchema } from 'zod';
|
|
14
15
|
|
|
15
16
|
declare const __VLS_component: DefineComponent<__VLS_Props, {}, {}, {}, {}, ComponentOptionsMixin, ComponentOptionsMixin, {}, string, PublicProps, Readonly<__VLS_Props> & Readonly<{}>, {}, {}, {}, {}, string, ComponentProvideOptions, false, {}, any>;
|
|
16
17
|
|
|
@@ -208,29 +209,27 @@ declare type CallbackSuccessResponse = {
|
|
|
208
209
|
status: 'SUCCESS';
|
|
209
210
|
};
|
|
210
211
|
|
|
211
|
-
declare type CombineHash<TParent extends
|
|
212
|
-
value: infer TParentHash extends string;
|
|
213
|
-
} ? ToHash<TChild> extends {
|
|
214
|
-
value: infer ChildHash extends string;
|
|
215
|
-
} ? Hash<`${TParentHash}${ChildHash}`> : TParent : Hash;
|
|
212
|
+
declare type CombineHash<TParent extends WithParams, TChild extends WithParams> = CombinePath<TParent, TChild>;
|
|
216
213
|
|
|
217
214
|
declare type CombineMeta<TParent extends Record<string, unknown>, TChild extends Record<string, unknown>> = TParent & TChild;
|
|
218
215
|
|
|
219
|
-
declare type CombinePath<TParent extends
|
|
216
|
+
declare type CombinePath<TParent extends WithParams, TChild extends WithParams> = ToWithParams<TParent> extends {
|
|
220
217
|
value: infer TParentPath extends string;
|
|
221
218
|
params: infer TParentParams extends Record<string, unknown>;
|
|
222
|
-
} ?
|
|
219
|
+
} ? ToWithParams<TChild> extends {
|
|
223
220
|
value: infer TChildPath extends string;
|
|
224
221
|
params: infer TChildParams extends Record<string, unknown>;
|
|
225
|
-
} ? RemoveLeadingQuestionMarkFromKeys<TParentParams> & RemoveLeadingQuestionMarkFromKeys<TChildParams> extends
|
|
222
|
+
} ? RemoveLeadingQuestionMarkFromKeys<TParentParams> & RemoveLeadingQuestionMarkFromKeys<TChildParams> extends ParamsWithParamNameExtracted<CombinePathString<TParentPath, TChildPath>> ? WithParams<CombinePathString<TParentPath, TChildPath>, RemoveLeadingQuestionMarkFromKeys<TParentParams> & RemoveLeadingQuestionMarkFromKeys<TChildParams>> : WithParams<'', {}> : WithParams<'', {}> : WithParams<'', {}>;
|
|
226
223
|
|
|
227
|
-
declare type
|
|
224
|
+
declare type CombinePathString<TParent extends string, TChild extends string> = `${TParent}${TChild}`;
|
|
225
|
+
|
|
226
|
+
declare type CombineQuery<TParent extends WithParams, TChild extends WithParams> = ToWithParams<TParent> extends {
|
|
228
227
|
value: infer TParentQuery extends string;
|
|
229
228
|
params: infer TParentParams extends Record<string, unknown>;
|
|
230
|
-
} ?
|
|
229
|
+
} ? ToWithParams<TChild> extends {
|
|
231
230
|
value: infer TChildQuery extends string;
|
|
232
231
|
params: infer TChildParams extends Record<string, unknown>;
|
|
233
|
-
} ? RemoveLeadingQuestionMarkFromKeys<TParentParams> & RemoveLeadingQuestionMarkFromKeys<TChildParams> extends
|
|
232
|
+
} ? RemoveLeadingQuestionMarkFromKeys<TParentParams> & RemoveLeadingQuestionMarkFromKeys<TChildParams> extends ParamsWithParamNameExtracted<CombineQueryString<TParentQuery, TChildQuery>> ? WithParams<CombineQueryString<TParentQuery, TChildQuery>, RemoveLeadingQuestionMarkFromKeys<TParentParams> & RemoveLeadingQuestionMarkFromKeys<TChildParams>> : WithParams<'', {}> : WithParams<'', {}> : WithParams<'', {}>;
|
|
234
233
|
|
|
235
234
|
declare type CombineQueryString<TParent extends string | undefined, TChild extends string | undefined> = StringHasValue<TParent> extends true ? StringHasValue<TChild> extends true ? `${TParent}&${TChild}` : TParent : TChild;
|
|
236
235
|
|
|
@@ -250,9 +249,9 @@ export declare type CreatedRouteOptions = Omit<CreateRouteOptions, 'props'> & Wi
|
|
|
250
249
|
props?: unknown;
|
|
251
250
|
};
|
|
252
251
|
|
|
253
|
-
export declare function createExternalRoute<const THost extends string |
|
|
252
|
+
export declare function createExternalRoute<const THost extends string | WithParams, const TName extends string | undefined = undefined, const TPath extends string | WithParams | undefined = undefined, const TQuery extends string | WithParams | undefined = undefined, const THash extends string | WithParams | undefined = undefined, const TMeta extends RouteMeta = RouteMeta>(options: CreateRouteOptions<TName, TPath, TQuery> & WithHost<THost> & WithoutParent): Route<ToName<TName>, ToWithParams<THost>, ToWithParams<TPath>, ToWithParams<TQuery>, ToWithParams<THash>, TMeta>;
|
|
254
253
|
|
|
255
|
-
export declare function createExternalRoute<const TParent extends Route, const TName extends string | undefined = undefined, const TPath extends string |
|
|
254
|
+
export declare function createExternalRoute<const TParent extends Route, const TName extends string | undefined = undefined, const TPath extends string | WithParams | undefined = undefined, const TQuery extends string | WithParams | undefined = undefined, const THash extends string | WithParams | undefined = undefined, const TMeta extends RouteMeta = RouteMeta>(options: CreateRouteOptions<TName, TPath, TQuery> & WithoutHost & WithParent<TParent>): Route<ToName<TName>, WithParams<'', {}>, CombinePath<TParent['path'], ToWithParams<TPath>>, CombineQuery<TParent['query'], ToWithParams<TQuery>>, CombineHash<TParent['hash'], ToWithParams<THash>>, CombineMeta<TMeta, TParent['meta']>>;
|
|
256
255
|
|
|
257
256
|
export declare function createParam<TParam extends ParamWithDefault>(param: TParam): TParam;
|
|
258
257
|
|
|
@@ -262,7 +261,7 @@ export declare function createParam<TParam extends Param>(param: TParam, default
|
|
|
262
261
|
|
|
263
262
|
export declare function createRoute<const TOptions extends CreateRouteOptions, const TProps extends CreateRouteProps<TOptions>>(options: TOptions, ...args: CreateRouteWithProps<TOptions, TProps>): ToRoute<TOptions, CreateRouteProps<TOptions> extends TProps ? undefined : TProps>;
|
|
264
263
|
|
|
265
|
-
export declare type CreateRouteOptions<TName extends string | undefined = string | undefined, TPath extends string |
|
|
264
|
+
export declare type CreateRouteOptions<TName extends string | undefined = string | undefined, TPath extends string | WithParams | undefined = string | WithParams | undefined, TQuery extends string | WithParams | undefined = string | WithParams | undefined, THash extends string | WithParams | undefined = string | WithParams | undefined, TMeta extends RouteMeta = RouteMeta> = WithHooks & {
|
|
266
265
|
/**
|
|
267
266
|
* Name for route, used to create route keys and in navigation.
|
|
268
267
|
*/
|
|
@@ -372,9 +371,7 @@ declare type EmptyRouterPlugin = {
|
|
|
372
371
|
*/
|
|
373
372
|
declare type ExtractParamName<TParam extends PropertyKey> = TParam extends `?${infer Param}` ? Param extends '' ? never : Param : TParam extends '' ? never : TParam;
|
|
374
373
|
|
|
375
|
-
declare type
|
|
376
|
-
|
|
377
|
-
declare type ExtractParamsFromPathString<TPath extends string, TParams extends Record<string, Param | undefined> = Record<never, never>> = TPath extends `${string}${ParamStart}${infer Param}${ParamEnd}${infer Rest}` ? Record<Param, ExtractPathParamType<Param, TParams>> & ExtractParamsFromPathString<Rest, TParams> : Record<never, never>;
|
|
374
|
+
declare type ExtractParamsFromString<TValue extends string, TParams extends Record<string, Param | undefined> = Record<never, never>> = TValue extends `${string}${ParamStart}${infer Param}${ParamEnd}${infer Rest}` ? Record<Param, ExtractWithParamsParamType<Param, TParams>> & ExtractParamsFromString<Rest, TParams> : Record<never, never>;
|
|
378
375
|
|
|
379
376
|
/**
|
|
380
377
|
* Extracts the actual type from a parameter type, handling getters, setters, and potential undefined values.
|
|
@@ -397,17 +394,7 @@ declare type ExtractParamTypesWithoutLosingOptional<TParams extends Record<strin
|
|
|
397
394
|
[K in keyof TParams as ExtractParamName<K>]: ExtractParamTypeWithoutLosingOptional<TParams[K], K>;
|
|
398
395
|
}>>;
|
|
399
396
|
|
|
400
|
-
declare type ExtractParamTypeWithoutLosingOptional<TParam extends Param, TParamKey extends PropertyKey> = TParam extends ParamGetSet<infer Type> ? TParamKey extends `?${string}` ? Type | undefined : Type : TParam extends ParamGetter ? TParamKey extends `?${string}` ? ReturnType<TParam> | undefined : ReturnType<TParam> : TParam extends LiteralParam ? TParamKey extends `?${string}` ? TParam | undefined : TParam : TParamKey extends `?${string}` ? string | undefined : string;
|
|
401
|
-
|
|
402
|
-
/**
|
|
403
|
-
* Determines the type of a path parameter from a record of parameter types, considering optional parameters.
|
|
404
|
-
* @template TParam - The parameter name string.
|
|
405
|
-
* @template TParams - The record object mapping parameter names to their types.
|
|
406
|
-
* @returns The type associated with the parameter, or StringConstructor if unspecified; may be undefined for optional parameters.
|
|
407
|
-
*/
|
|
408
|
-
declare type ExtractPathParamType<TParam extends string, TParams extends Record<string, Param | undefined>> = TParam extends `?${infer OptionalParam}` ? OptionalParam extends keyof TParams ? TParams[OptionalParam] : StringConstructor : TParam extends keyof TParams ? TParams[TParam] : StringConstructor;
|
|
409
|
-
|
|
410
|
-
declare type ExtractQueryParamsFromQueryString<TQuery extends string, TParams extends Record<string, Param | undefined> = Record<never, never>> = TQuery extends `${string}=${ParamStart}${infer Param}${ParamEnd}${infer Rest}` ? Record<Param, ExtractPathParamType<Param, TParams>> & ExtractQueryParamsFromQueryString<Rest, TParams> : Record<never, never>;
|
|
397
|
+
declare type ExtractParamTypeWithoutLosingOptional<TParam extends Param, TParamKey extends PropertyKey> = TParam extends ParamGetSet<infer Type> ? TParamKey extends `?${string}` ? Type | undefined : Type : TParam extends ParamGetter ? TParamKey extends `?${string}` ? ReturnType<TParam> | undefined : ReturnType<TParam> : TParam extends ZodSchema<infer Type> ? TParamKey extends `?${string}` ? Type | undefined : Type : TParam extends LiteralParam ? TParamKey extends `?${string}` ? TParam | undefined : TParam : TParamKey extends `?${string}` ? string | undefined : string;
|
|
411
398
|
|
|
412
399
|
/**
|
|
413
400
|
* Extracts combined types of path and query parameters for a given route, creating a unified parameter object.
|
|
@@ -425,7 +412,10 @@ declare type ExtractRouteParamTypes<TRoute> = TRoute extends {
|
|
|
425
412
|
host: {
|
|
426
413
|
params: infer HostParams extends Record<string, Param>;
|
|
427
414
|
};
|
|
428
|
-
|
|
415
|
+
hash: {
|
|
416
|
+
params: infer HashParams extends Record<string, Param>;
|
|
417
|
+
};
|
|
418
|
+
} ? ExtractParamTypes<HostParams & PathParams & QueryParams & HashParams> : {};
|
|
429
419
|
|
|
430
420
|
declare type ExtractRouteParamTypesWithoutLosingOptional<TRoute> = TRoute extends {
|
|
431
421
|
host: {
|
|
@@ -437,7 +427,10 @@ declare type ExtractRouteParamTypesWithoutLosingOptional<TRoute> = TRoute extend
|
|
|
437
427
|
query: {
|
|
438
428
|
params: infer QueryParams extends Record<string, Param>;
|
|
439
429
|
};
|
|
440
|
-
|
|
430
|
+
hash: {
|
|
431
|
+
params: infer HashParams extends Record<string, Param>;
|
|
432
|
+
};
|
|
433
|
+
} ? ExtractParamTypesWithoutLosingOptional<HostParams & PathParams & QueryParams & HashParams> : Record<string, unknown>;
|
|
441
434
|
|
|
442
435
|
declare type ExtractRouteStateParamsAsOptional<T extends Record<string, Param>> = ExtractParamTypes<{
|
|
443
436
|
[K in keyof T as K extends string ? `?${K}` : never]: T[K];
|
|
@@ -447,22 +440,22 @@ declare type ExtractStateParams<TRoute> = TRoute extends {
|
|
|
447
440
|
state: infer TState extends Record<string, Param>;
|
|
448
441
|
} ? ExtractParamTypes<TState> : Record<string, unknown>;
|
|
449
442
|
|
|
443
|
+
/**
|
|
444
|
+
* Determines the type of a path parameter from a record of parameter types, considering optional parameters.
|
|
445
|
+
* @template TParam - The parameter name string.
|
|
446
|
+
* @template TParams - The record object mapping parameter names to their types.
|
|
447
|
+
* @returns The type associated with the parameter, or StringConstructor if unspecified; may be undefined for optional parameters.
|
|
448
|
+
*/
|
|
449
|
+
declare type ExtractWithParamsParamType<TParam extends string, TParams extends Record<string, Param | undefined>> = TParam extends `?${infer OptionalParam}` ? OptionalParam extends keyof TParams ? TParams[OptionalParam] : StringConstructor : TParam extends keyof TParams ? TParams[TParam] : StringConstructor;
|
|
450
|
+
|
|
450
451
|
declare type GetParentPropsReturnType<TParent extends Route | undefined = Route | undefined> = TParent extends Route ? TParent['matched']['props'] extends PropsGetter ? ReturnType<TParent['matched']['props']> : TParent['matched']['props'] extends Record<string, PropsGetter> ? {
|
|
451
452
|
[K in keyof TParent['matched']['props']]: ReturnType<TParent['matched']['props'][K]>;
|
|
452
453
|
} : undefined : undefined;
|
|
453
454
|
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
declare type Host<THost extends string = string, TParams extends HostParamsWithParamNameExtracted<THost> = Record<string, Param | undefined>> = {
|
|
459
|
-
value: THost;
|
|
460
|
-
params: string extends THost ? Record<string, Param> : Identity<ExtractParamsFromHostString<THost, TParams>>;
|
|
461
|
-
};
|
|
462
|
-
|
|
463
|
-
declare type HostParamsWithParamNameExtracted<THost extends string> = {
|
|
464
|
-
[K in keyof ExtractParamsFromHostString<THost> as ExtractParamName<K>]?: Param;
|
|
465
|
-
};
|
|
455
|
+
/**
|
|
456
|
+
* @deprecated use `withParams` instead
|
|
457
|
+
*/
|
|
458
|
+
export declare const host: typeof withParams;
|
|
466
459
|
|
|
467
460
|
declare type Identity<T> = T extends object ? {} & {
|
|
468
461
|
[P in keyof T as T[P] extends never ? never : P]: T[P];
|
|
@@ -617,7 +610,7 @@ declare type OnlyRequiredProperties<T> = {
|
|
|
617
610
|
[K in keyof T as Extract<T[K], undefined> extends never ? K : never]: T[K];
|
|
618
611
|
};
|
|
619
612
|
|
|
620
|
-
export declare type Param = ParamGetter | ParamGetSet | RegExp | BooleanConstructor | NumberConstructor | StringConstructor | DateConstructor | JSON | LiteralParam;
|
|
613
|
+
export declare type Param = ParamGetter | ParamGetSet | RegExp | BooleanConstructor | NumberConstructor | StringConstructor | DateConstructor | JSON | ZodSchema | LiteralParam;
|
|
621
614
|
|
|
622
615
|
declare type ParamEnd = typeof paramEnd;
|
|
623
616
|
|
|
@@ -641,39 +634,16 @@ declare type ParamStart = typeof paramStart;
|
|
|
641
634
|
|
|
642
635
|
declare const paramStart = "[";
|
|
643
636
|
|
|
644
|
-
declare type
|
|
645
|
-
|
|
646
|
-
declare type Path<TPath extends string = string, TParams extends PathParamsWithParamNameExtracted<TPath> = Record<string, Param | undefined>> = {
|
|
647
|
-
value: TPath;
|
|
648
|
-
params: string extends TPath ? Record<string, Param> : Identity<ExtractParamsFromPathString<TPath, TParams>>;
|
|
637
|
+
declare type ParamsWithParamNameExtracted<TValue extends string> = {
|
|
638
|
+
[K in keyof ExtractParamsFromString<TValue> as ExtractParamName<K>]?: Param;
|
|
649
639
|
};
|
|
650
640
|
|
|
641
|
+
declare type ParamWithDefault<TParam extends Param = Param> = Required<ParamGetSet<ExtractParamType<TParam>>>;
|
|
642
|
+
|
|
651
643
|
/**
|
|
652
|
-
*
|
|
653
|
-
*
|
|
654
|
-
* @template TPath - The string literal type that represents the path.
|
|
655
|
-
* @template TParams - The type of the path parameters associated with the path.
|
|
656
|
-
* @param value - The path string.
|
|
657
|
-
* @param params - The parameters associated with the path, typically as key-value pairs.
|
|
658
|
-
* @returns An object representing the path which includes the path string, its parameters,
|
|
659
|
-
* and a toString method for getting the path as a string.
|
|
660
|
-
*
|
|
661
|
-
* @example
|
|
662
|
-
* ```ts
|
|
663
|
-
* import { createRoute, path } from '@kitbag/router'
|
|
664
|
-
*
|
|
665
|
-
* export const routes = createRoute({
|
|
666
|
-
* name: 'home',
|
|
667
|
-
* path: path('/[foo]', { foo: Number }),
|
|
668
|
-
* component: Home
|
|
669
|
-
* })
|
|
670
|
-
* ```
|
|
644
|
+
* @deprecated use `withParams` instead
|
|
671
645
|
*/
|
|
672
|
-
export declare
|
|
673
|
-
|
|
674
|
-
declare type PathParamsWithParamNameExtracted<TPath extends string> = {
|
|
675
|
-
[K in keyof ExtractParamsFromPathString<TPath> as ExtractParamName<K>]?: Param;
|
|
676
|
-
};
|
|
646
|
+
export declare const path: typeof withParams;
|
|
677
647
|
|
|
678
648
|
/**
|
|
679
649
|
* Determines what assets are prefetched. A boolean enables or disables all prefetching.
|
|
@@ -720,37 +690,10 @@ declare type PropsCallbackParent<TParent extends Route | undefined = Route | und
|
|
|
720
690
|
|
|
721
691
|
declare type PropsGetter<TOptions extends CreateRouteOptions = CreateRouteOptions, TComponent extends Component = Component> = (route: ResolvedRoute<ToRoute<TOptions, undefined>>, context: PropsCallbackContext<TOptions['parent']>) => MaybePromise<ComponentProps<TComponent>>;
|
|
722
692
|
|
|
723
|
-
declare type Query<TQuery extends string = string, TQueryParams extends QueryParamsWithParamNameExtracted<TQuery> = Record<string, Param | undefined>> = {
|
|
724
|
-
value: TQuery;
|
|
725
|
-
params: string extends TQuery ? Record<string, Param> : Identity<ExtractQueryParamsFromQueryString<TQuery, TQueryParams>>;
|
|
726
|
-
};
|
|
727
|
-
|
|
728
693
|
/**
|
|
729
|
-
*
|
|
730
|
-
*
|
|
731
|
-
* @template TQuery - The string literal type that represents the query.
|
|
732
|
-
* @template TParams - The type of the query parameters associated with the query.
|
|
733
|
-
* @param value - The query string.
|
|
734
|
-
* @param params - The parameters associated with the query, typically as key-value pairs.
|
|
735
|
-
* @returns An object representing the query which includes the query string, its parameters,
|
|
736
|
-
* and a toString method for getting the query as a string.
|
|
737
|
-
*
|
|
738
|
-
* @example
|
|
739
|
-
* ```ts
|
|
740
|
-
* import { createRoute, query } from '@kitbag/router'
|
|
741
|
-
*
|
|
742
|
-
* export const routes = createRoute({
|
|
743
|
-
* name: 'home',
|
|
744
|
-
* query: query('bar=[bar]', { bar: Boolean }),
|
|
745
|
-
* component: Home
|
|
746
|
-
* })
|
|
747
|
-
* ```
|
|
694
|
+
* @deprecated use `withParams` instead
|
|
748
695
|
*/
|
|
749
|
-
export declare
|
|
750
|
-
|
|
751
|
-
declare type QueryParamsWithParamNameExtracted<T extends string> = {
|
|
752
|
-
[K in keyof ExtractQueryParamsFromQueryString<T> as ExtractParamName<K>]?: Param;
|
|
753
|
-
};
|
|
696
|
+
export declare const query: typeof withParams;
|
|
754
697
|
|
|
755
698
|
export declare type QuerySource = ConstructorParameters<typeof URLSearchParams>[0];
|
|
756
699
|
|
|
@@ -878,7 +821,7 @@ export declare type ResolvedRoute<TRoute extends Route = Route> = Readonly<{
|
|
|
878
821
|
* @template TPath - The type or structure of the route's path.
|
|
879
822
|
* @template TQuery - The type or structure of the query parameters associated with the route.
|
|
880
823
|
*/
|
|
881
|
-
export declare type Route<TName extends string = string, THost extends
|
|
824
|
+
export declare type Route<TName extends string = string, THost extends WithParams = WithParams, TPath extends WithParams = WithParams, TQuery extends WithParams = WithParams, THash extends WithParams = WithParams, TMeta extends RouteMeta = RouteMeta, TState extends Record<string, Param> = Record<string, Param>, TMatches extends CreatedRouteOptions[] = CreatedRouteOptions[]> = {
|
|
882
825
|
/**
|
|
883
826
|
* Unique identifier for the route, generated by router.
|
|
884
827
|
*/
|
|
@@ -1276,10 +1219,6 @@ declare type StringHasValue<T> = string extends T ? true : '' extends T ? false
|
|
|
1276
1219
|
|
|
1277
1220
|
export declare type ToCallback = (resolve: RegisteredRouter['resolve']) => ResolvedRoute | Url | undefined;
|
|
1278
1221
|
|
|
1279
|
-
declare type ToHash<T extends string | Hash | undefined> = T extends string ? Hash<T> : T extends undefined ? Hash<''> : unknown extends T ? Hash<''> : T;
|
|
1280
|
-
|
|
1281
|
-
declare type ToHost<T extends string | Host | undefined> = T extends string ? Host<T, {}> : T extends undefined ? Host<'', {}> : unknown extends T ? Host<'', {}> : T;
|
|
1282
|
-
|
|
1283
1222
|
declare type ToMatch<TOptions extends CreateRouteOptions, TProps extends CreateRouteProps<TOptions> | undefined> = Omit<TOptions, 'props'> & {
|
|
1284
1223
|
id: string;
|
|
1285
1224
|
props: TProps;
|
|
@@ -1293,16 +1232,14 @@ declare type ToMeta<TMeta extends RouteMeta | undefined> = TMeta extends undefin
|
|
|
1293
1232
|
|
|
1294
1233
|
declare type ToName<T extends string | undefined> = T extends string ? T : '';
|
|
1295
1234
|
|
|
1296
|
-
declare type ToPath<T extends string | Path | undefined> = T extends string ? Path<T, {}> : T extends undefined ? Path<'', {}> : unknown extends T ? Path<'', {}> : T;
|
|
1297
|
-
|
|
1298
|
-
declare type ToQuery<T extends string | Query | undefined> = T extends string ? Query<T, {}> : T extends undefined ? Query<'', {}> : unknown extends T ? Query<'', {}> : T;
|
|
1299
|
-
|
|
1300
1235
|
declare type ToRoute<TOptions extends CreateRouteOptions, TProps extends CreateRouteProps<TOptions> | undefined> = CreateRouteOptions extends TOptions ? Route : TOptions extends {
|
|
1301
1236
|
parent: infer TParent extends Route;
|
|
1302
|
-
} ? Route<ToName<TOptions['name']>,
|
|
1237
|
+
} ? Route<ToName<TOptions['name']>, WithParams<'', {}>, CombinePath<ToWithParams<TParent['path']>, ToWithParams<TOptions['path']>>, CombineQuery<ToWithParams<TParent['query']>, ToWithParams<TOptions['query']>>, CombineHash<ToWithParams<TParent['hash']>, ToWithParams<TOptions['hash']>>, CombineMeta<ToMeta<TParent['meta']>, ToMeta<TOptions['meta']>>, CombineState<ToState<TParent['state']>, ToState<TOptions['state']>>, ToMatches<TOptions, TProps>> : Route<ToName<TOptions['name']>, WithParams<'', {}>, ToWithParams<TOptions['path']>, ToWithParams<TOptions['query']>, ToWithParams<TOptions['hash']>, ToMeta<TOptions['meta']>, ToState<TOptions['state']>, ToMatches<TOptions, TProps>>;
|
|
1303
1238
|
|
|
1304
1239
|
declare type ToState<TState extends Record<string, Param> | undefined> = TState extends undefined ? Record<string, Param> : unknown extends TState ? {} : TState;
|
|
1305
1240
|
|
|
1241
|
+
declare type ToWithParams<T extends string | WithParams | undefined> = T extends string ? WithParams<T, {}> : T extends undefined ? WithParams<'', {}> : unknown extends T ? WithParams<'', {}> : T;
|
|
1242
|
+
|
|
1306
1243
|
declare type TupleOf<T extends Param[]> = {
|
|
1307
1244
|
[K in keyof T]: ExtractParamType<T[K]>;
|
|
1308
1245
|
};
|
|
@@ -1447,7 +1384,7 @@ export declare type WithHooks = {
|
|
|
1447
1384
|
onAfterRouteLeave?: MaybeArray<AfterRouteHook>;
|
|
1448
1385
|
};
|
|
1449
1386
|
|
|
1450
|
-
declare type WithHost<THost extends string |
|
|
1387
|
+
declare type WithHost<THost extends string | WithParams = string | WithParams> = {
|
|
1451
1388
|
/**
|
|
1452
1389
|
* Host part of URL.
|
|
1453
1390
|
*/
|
|
@@ -1466,6 +1403,15 @@ declare type WithoutParent = {
|
|
|
1466
1403
|
parent?: never;
|
|
1467
1404
|
};
|
|
1468
1405
|
|
|
1406
|
+
declare type WithParams<TValue extends string = string, TParams extends ParamsWithParamNameExtracted<TValue> = Record<string, Param | undefined>> = {
|
|
1407
|
+
value: TValue;
|
|
1408
|
+
params: string extends TValue ? Record<string, Param> : Identity<ExtractParamsFromString<TValue, TParams>>;
|
|
1409
|
+
};
|
|
1410
|
+
|
|
1411
|
+
export declare function withParams<const TValue extends string, const TParams extends ParamsWithParamNameExtracted<TValue>>(value: TValue, params: TParams): WithParams<TValue, TParams>;
|
|
1412
|
+
|
|
1413
|
+
export declare function withParams(): WithParams<'', {}>;
|
|
1414
|
+
|
|
1469
1415
|
declare type WithParent<TParent extends Route = Route> = {
|
|
1470
1416
|
parent: TParent;
|
|
1471
1417
|
};
|