@kitbag/router 0.18.1 → 0.19.0
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 +31 -46
- package/dist/kitbag-router.js +1128 -1144
- package/dist/kitbag-router.umd.cjs +3 -3
- package/package.json +5 -5
package/dist/kitbag-router.d.ts
CHANGED
|
@@ -74,7 +74,6 @@ export declare type AddGlobalRouteHooks = (hooks: RouteHooks) => void;
|
|
|
74
74
|
export declare type AfterHookContext = {
|
|
75
75
|
to: ResolvedRoute;
|
|
76
76
|
from: ResolvedRoute | null;
|
|
77
|
-
app: App | null;
|
|
78
77
|
};
|
|
79
78
|
|
|
80
79
|
/**
|
|
@@ -109,7 +108,11 @@ export declare type AfterRouteHookResponse = CallbackSuccessResponse | CallbackP
|
|
|
109
108
|
|
|
110
109
|
declare type AllPropertiesAreOptional<T> = Record<string, unknown> extends T ? true : IsEmptyObject<OnlyRequiredProperties<T>>;
|
|
111
110
|
|
|
112
|
-
export declare function arrayOf<const T extends Param[]>(
|
|
111
|
+
export declare function arrayOf<const T extends Param[]>(params: T, options?: ArrayOfOptions): ParamGetSet<ExtractParamType<T[number]>[]>;
|
|
112
|
+
|
|
113
|
+
declare type ArrayOfOptions = {
|
|
114
|
+
separator?: string;
|
|
115
|
+
};
|
|
113
116
|
|
|
114
117
|
declare type AsNamedRoute<T extends Route> = IsRouteUnnamed<T> extends true ? never : T;
|
|
115
118
|
|
|
@@ -130,7 +133,6 @@ export declare function asUrl(value: string): Url;
|
|
|
130
133
|
export declare type BeforeHookContext = {
|
|
131
134
|
to: ResolvedRoute;
|
|
132
135
|
from: ResolvedRoute | null;
|
|
133
|
-
app: App | null;
|
|
134
136
|
};
|
|
135
137
|
|
|
136
138
|
/**
|
|
@@ -220,7 +222,7 @@ declare type CombinePath<TParent extends WithParams, TChild extends WithParams>
|
|
|
220
222
|
} ? ToWithParams<TChild> extends {
|
|
221
223
|
value: infer TChildPath extends string;
|
|
222
224
|
params: infer TChildParams extends Record<string, unknown>;
|
|
223
|
-
} ?
|
|
225
|
+
} ? TParentParams & TChildParams extends Record<string, Param | undefined> ? WithParams<CombinePathString<TParentPath, TChildPath>, TParentParams & TChildParams> : WithParams<CombinePathString<TParentPath, TChildPath>, {}> : WithParams<'', {}> : WithParams<'', {}>;
|
|
224
226
|
|
|
225
227
|
declare type CombinePathString<TParent extends string, TChild extends string> = `${TParent}${TChild}`;
|
|
226
228
|
|
|
@@ -230,7 +232,7 @@ declare type CombineQuery<TParent extends WithParams, TChild extends WithParams>
|
|
|
230
232
|
} ? ToWithParams<TChild> extends {
|
|
231
233
|
value: infer TChildQuery extends string;
|
|
232
234
|
params: infer TChildParams extends Record<string, unknown>;
|
|
233
|
-
} ?
|
|
235
|
+
} ? TParentParams & TChildParams extends Record<string, Param | undefined> ? WithParams<CombineQueryString<TParentQuery, TChildQuery>, TParentParams & TChildParams> : WithParams<CombineQueryString<TParentQuery, TChildQuery>, {}> : WithParams<'', {}> : WithParams<'', {}>;
|
|
234
236
|
|
|
235
237
|
declare type CombineQueryString<TParent extends string | undefined, TChild extends string | undefined> = StringHasValue<TParent> extends true ? StringHasValue<TChild> extends true ? `${TParent}&${TChild}` : TParent : TChild;
|
|
236
238
|
|
|
@@ -250,9 +252,9 @@ export declare type CreatedRouteOptions = Omit<CreateRouteOptions, 'props'> & Wi
|
|
|
250
252
|
props?: unknown;
|
|
251
253
|
};
|
|
252
254
|
|
|
253
|
-
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>;
|
|
255
|
+
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, THash, TMeta> & WithHost<THost> & WithoutParent): Route<ToName<TName>, ToWithParams<THost>, ToWithParams<TPath>, ToWithParams<TQuery>, ToWithParams<THash>, TMeta>;
|
|
254
256
|
|
|
255
|
-
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']>>;
|
|
257
|
+
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, THash, TMeta> & 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
258
|
|
|
257
259
|
export declare function createParam<TParam extends ParamWithDefault>(param: TParam): TParam;
|
|
258
260
|
|
|
@@ -370,7 +372,7 @@ declare type EmptyRouterPlugin = {
|
|
|
370
372
|
* @template TParam - The string from which to extract the parameter name.
|
|
371
373
|
* @returns The extracted parameter name, or never if the parameter string is empty.
|
|
372
374
|
*/
|
|
373
|
-
declare type ExtractParamName<TParam extends PropertyKey> = TParam extends `?${infer Param}` ? Param extends '' ? never : Param : TParam extends '' ? never : TParam;
|
|
375
|
+
declare type ExtractParamName<TParam extends PropertyKey> = TParam extends string ? TParam extends `?${infer Param}` ? Param extends '' ? never : Param : TParam extends '' ? never : TParam : never;
|
|
374
376
|
|
|
375
377
|
/**
|
|
376
378
|
* Extracts the actual type from a parameter type, handling getters and setters.
|
|
@@ -379,50 +381,43 @@ declare type ExtractParamName<TParam extends PropertyKey> = TParam extends `?${i
|
|
|
379
381
|
*/
|
|
380
382
|
declare type ExtractParamType<TParam extends Param> = TParam extends ParamGetSet<infer Type> ? Type : TParam extends ParamGetter ? ReturnType<TParam> : TParam extends ZodSchemaLike<infer Type> ? Type : TParam extends LiteralParam ? TParam : string;
|
|
381
383
|
|
|
382
|
-
/**
|
|
383
|
-
* Transforms a record of parameter types into a type with optional properties where the original type allows undefined.
|
|
384
|
-
* @template TParams - The record of parameter types, possibly including undefined.
|
|
385
|
-
* @returns A new type with the appropriate properties marked as optional.
|
|
386
|
-
*/
|
|
387
384
|
declare type ExtractParamTypes<TParams extends Record<string, Param>> = Identity<MakeOptional<{
|
|
388
385
|
[K in keyof TParams as ExtractParamName<K>]: ExtractParamType<TParams[K]>;
|
|
389
386
|
}>>;
|
|
390
387
|
|
|
391
388
|
/**
|
|
392
|
-
*
|
|
393
|
-
* Differs from ExtractParamTypes in that it also reads the string `value` from WithParams to determine what should be optional.
|
|
389
|
+
* Extracts combined types of path and query parameters for a given route, creating a unified parameter object.
|
|
394
390
|
* @template TParams - The record of parameter types, possibly including undefined.
|
|
395
391
|
* @returns A new type with the appropriate properties marked as optional.
|
|
396
392
|
*/
|
|
397
|
-
declare type
|
|
398
|
-
[K in keyof
|
|
393
|
+
declare type ExtractParamTypesReading<TWithParams extends WithParams> = {
|
|
394
|
+
[K in keyof TWithParams['params']]: TWithParams['value'] extends `${string}${ParamStart}?${K & string}${ParamEnd}${string}` ? TWithParams['params'][K] extends Required<ParamGetSet> ? ExtractParamType<TWithParams['params'][K]> : ExtractParamType<TWithParams['params'][K]> | undefined : ExtractParamType<TWithParams['params'][K]>;
|
|
399
395
|
};
|
|
400
396
|
|
|
401
397
|
/**
|
|
402
|
-
*
|
|
403
|
-
* Differs from
|
|
398
|
+
* Extracts combined types of path and query parameters for a given route, creating a unified parameter object.
|
|
399
|
+
* Differs from ExtractParamTypesReading in that optional params with defaults will remain optional.
|
|
404
400
|
* @template TParams - The record of parameter types, possibly including undefined.
|
|
405
401
|
* @returns A new type with the appropriate properties marked as optional.
|
|
406
402
|
*/
|
|
407
|
-
declare type
|
|
408
|
-
[K in keyof
|
|
403
|
+
declare type ExtractParamTypesWriting<TWithParams extends WithParams> = {
|
|
404
|
+
[K in keyof TWithParams['params']]: TWithParams['value'] extends `${string}${ParamStart}?${K & string}${ParamEnd}${string}` ? ExtractParamType<TWithParams['params'][K]> | undefined : ExtractParamType<TWithParams['params'][K]>;
|
|
409
405
|
};
|
|
410
406
|
|
|
411
407
|
/**
|
|
412
|
-
*
|
|
413
|
-
* Differs from ExtractRouteParamTypes in that it also reads the string `value` from WithParams to determine what should be optional.
|
|
408
|
+
* Extracts combined types of path and query parameters for a given route, creating a unified parameter object.
|
|
414
409
|
* @template TRoute - The route type from which to extract and merge parameter types.
|
|
415
410
|
* @returns A record of parameter names to their respective types, extracted and merged from both path and query parameters.
|
|
416
411
|
*/
|
|
417
|
-
declare type
|
|
412
|
+
declare type ExtractRouteParamTypesReading<TRoute extends Route> = Identity<MakeOptional<ExtractParamTypesReading<TRoute['host']> & ExtractParamTypesReading<TRoute['path']> & ExtractParamTypesReading<TRoute['query']> & ExtractParamTypesReading<TRoute['hash']>>>;
|
|
418
413
|
|
|
419
414
|
/**
|
|
420
|
-
*
|
|
421
|
-
* Differs from
|
|
415
|
+
* Extracts combined types of path and query parameters for a given route, creating a unified parameter object.
|
|
416
|
+
* Differs from ExtractRouteParamTypesReading in that optional params with defaults will remain optional.
|
|
422
417
|
* @template TRoute - The route type from which to extract and merge parameter types.
|
|
423
418
|
* @returns A record of parameter names to their respective types, extracted and merged from both path and query parameters.
|
|
424
419
|
*/
|
|
425
|
-
declare type
|
|
420
|
+
declare type ExtractRouteParamTypesWriting<TRoute extends Route> = Identity<MakeOptional<ExtractParamTypesWriting<TRoute['host']> & ExtractParamTypesWriting<TRoute['path']> & ExtractParamTypesWriting<TRoute['query']> & ExtractParamTypesWriting<TRoute['hash']>>>;
|
|
426
421
|
|
|
427
422
|
declare type ExtractRouteStateParamsAsOptional<TParams extends Record<string, Param>> = {
|
|
428
423
|
[K in keyof TParams]: ExtractParamType<TParams[K]> | undefined;
|
|
@@ -432,14 +427,6 @@ declare type ExtractStateParams<TRoute> = TRoute extends {
|
|
|
432
427
|
state: infer TState extends Record<string, Param>;
|
|
433
428
|
} ? ExtractParamTypes<TState> : Record<string, unknown>;
|
|
434
429
|
|
|
435
|
-
/**
|
|
436
|
-
* Determines the type of a path parameter from a record of parameter types, considering optional parameters.
|
|
437
|
-
* @template TParam - The parameter name string.
|
|
438
|
-
* @template TParams - The record object mapping parameter names to their types.
|
|
439
|
-
* @returns The type associated with the parameter, or StringConstructor if unspecified; may be undefined for optional parameters.
|
|
440
|
-
*/
|
|
441
|
-
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;
|
|
442
|
-
|
|
443
430
|
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> ? {
|
|
444
431
|
[K in keyof TParent['matched']['props']]: ReturnType<TParent['matched']['props'][K]>;
|
|
445
432
|
} : undefined : undefined;
|
|
@@ -753,12 +740,6 @@ export declare type RegisteredRoutes<T = Register> = T extends {
|
|
|
753
740
|
*/
|
|
754
741
|
export declare type RegisteredRoutesName = RoutesName<RegisteredRoutes>;
|
|
755
742
|
|
|
756
|
-
declare type RemoveLeadingQuestionMark<T extends PropertyKey> = T extends `?${infer TRest extends string}` ? TRest : T;
|
|
757
|
-
|
|
758
|
-
declare type RemoveLeadingQuestionMarkFromKeys<T extends Record<string, unknown>> = {
|
|
759
|
-
[K in keyof T as RemoveLeadingQuestionMark<K>]: T[K];
|
|
760
|
-
};
|
|
761
|
-
|
|
762
743
|
/**
|
|
763
744
|
* Represents a route that the router has matched to current browser location.
|
|
764
745
|
* @template TRoute - Underlying Route that has been resolved.
|
|
@@ -792,7 +773,7 @@ export declare type ResolvedRoute<TRoute extends Route = Route> = Readonly<{
|
|
|
792
773
|
/**
|
|
793
774
|
* Key value pair for route params, values will be the user provided value from current browser location.
|
|
794
775
|
*/
|
|
795
|
-
params:
|
|
776
|
+
params: ExtractRouteParamTypesReading<TRoute>;
|
|
796
777
|
/**
|
|
797
778
|
* Type for additional data intended to be stored in history state.
|
|
798
779
|
*/
|
|
@@ -913,7 +894,7 @@ export declare type RouteMeta<T = Register> = T extends {
|
|
|
913
894
|
routeMeta: infer RouteMeta extends Record<string, unknown>;
|
|
914
895
|
} ? RouteMeta : Record<string, unknown>;
|
|
915
896
|
|
|
916
|
-
declare type RouteParamsByKey<TRoutes extends Routes, TKey extends string> = RouteGetByKey<TRoutes, TKey> extends Route ?
|
|
897
|
+
declare type RouteParamsByKey<TRoutes extends Routes, TKey extends string> = RouteGetByKey<TRoutes, TKey> extends Route ? ExtractRouteParamTypesWriting<RouteGetByKey<TRoutes, TKey>> : Record<string, unknown>;
|
|
917
898
|
|
|
918
899
|
declare type RoutePropsRecord<TOptions extends CreateRouteOptions = CreateRouteOptions, TComponents extends Record<string, Component> = Record<string, Component>> = {
|
|
919
900
|
[K in keyof TComponents as ComponentPropsAreOptional<TComponents[K]> extends true ? K : never]?: PropsGetter<TOptions, TComponents[K]>;
|
|
@@ -1232,9 +1213,13 @@ declare type TupleOf<T extends Param[]> = {
|
|
|
1232
1213
|
[K in keyof T]: ExtractParamType<T[K]>;
|
|
1233
1214
|
};
|
|
1234
1215
|
|
|
1235
|
-
export declare function tupleOf<const T extends Param[]>(
|
|
1216
|
+
export declare function tupleOf<const T extends Param[]>(params: T, options?: TupleOfOptions): ParamGetSet<TupleOf<T>>;
|
|
1217
|
+
|
|
1218
|
+
declare type TupleOfOptions = {
|
|
1219
|
+
separator?: string;
|
|
1220
|
+
};
|
|
1236
1221
|
|
|
1237
|
-
export declare function unionOf<const T extends Param[]>(
|
|
1222
|
+
export declare function unionOf<const T extends Param[]>(params: T): ParamGetSet<ExtractParamType<T[number]>>;
|
|
1238
1223
|
|
|
1239
1224
|
export declare type Url = `http://${string}` | `https://${string}` | `/${string}`;
|
|
1240
1225
|
|
|
@@ -1402,7 +1387,7 @@ export declare function withParams(): WithParams<'', {}>;
|
|
|
1402
1387
|
|
|
1403
1388
|
declare type WithParamsParamsInput<TValue extends string> = TValue extends `${string}${ParamStart}${infer TParam}${ParamEnd}${infer Rest}` ? Record<ExtractParamName<TParam>, Param | undefined> & WithParamsParamsInput<Rest> : {};
|
|
1404
1389
|
|
|
1405
|
-
declare type WithParamsParamsOutput<TValue extends string, TParams extends Record<string, Param | undefined> = Record<never, never>> = TValue extends `${string}${ParamStart}${infer TParam}${ParamEnd}${infer Rest}` ? Record<TParam
|
|
1390
|
+
declare type WithParamsParamsOutput<TValue extends string, TParams extends Record<string, Param | undefined> = Record<never, never>> = TValue extends `${string}${ParamStart}${infer TParam}${ParamEnd}${infer Rest}` ? ExtractParamName<TParam> extends keyof TParams ? Record<ExtractParamName<TParam>, TParams[ExtractParamName<TParam>]> & WithParamsParamsOutput<Rest, TParams> : Record<ExtractParamName<TParam>, StringConstructor> & WithParamsParamsOutput<Rest, TParams> : {};
|
|
1406
1391
|
|
|
1407
1392
|
declare type WithParent<TParent extends Route = Route> = {
|
|
1408
1393
|
parent: TParent;
|