@kitbag/router 0.18.1 → 0.18.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.
@@ -220,7 +220,7 @@ declare type CombinePath<TParent extends WithParams, TChild extends WithParams>
220
220
  } ? ToWithParams<TChild> extends {
221
221
  value: infer TChildPath extends string;
222
222
  params: infer TChildParams extends Record<string, unknown>;
223
- } ? RemoveLeadingQuestionMarkFromKeys<TParentParams> & RemoveLeadingQuestionMarkFromKeys<TChildParams> extends Record<string, Param | undefined> ? WithParams<CombinePathString<TParentPath, TChildPath>, RemoveLeadingQuestionMarkFromKeys<TParentParams> & RemoveLeadingQuestionMarkFromKeys<TChildParams>> : WithParams<CombinePathString<TParentPath, TChildPath>, {}> : WithParams<'', {}> : WithParams<'', {}>;
223
+ } ? TParentParams & TChildParams extends Record<string, Param | undefined> ? WithParams<CombinePathString<TParentPath, TChildPath>, TParentParams & TChildParams> : WithParams<CombinePathString<TParentPath, TChildPath>, {}> : WithParams<'', {}> : WithParams<'', {}>;
224
224
 
225
225
  declare type CombinePathString<TParent extends string, TChild extends string> = `${TParent}${TChild}`;
226
226
 
@@ -230,7 +230,7 @@ declare type CombineQuery<TParent extends WithParams, TChild extends WithParams>
230
230
  } ? ToWithParams<TChild> extends {
231
231
  value: infer TChildQuery extends string;
232
232
  params: infer TChildParams extends Record<string, unknown>;
233
- } ? RemoveLeadingQuestionMarkFromKeys<TParentParams> & RemoveLeadingQuestionMarkFromKeys<TChildParams> extends Record<string, Param | undefined> ? WithParams<CombineQueryString<TParentQuery, TChildQuery>, RemoveLeadingQuestionMarkFromKeys<TParentParams> & RemoveLeadingQuestionMarkFromKeys<TChildParams>> : WithParams<CombineQueryString<TParentQuery, TChildQuery>, {}> : WithParams<'', {}> : WithParams<'', {}>;
233
+ } ? TParentParams & TChildParams extends Record<string, Param | undefined> ? WithParams<CombineQueryString<TParentQuery, TChildQuery>, TParentParams & TChildParams> : WithParams<CombineQueryString<TParentQuery, TChildQuery>, {}> : WithParams<'', {}> : WithParams<'', {}>;
234
234
 
235
235
  declare type CombineQueryString<TParent extends string | undefined, TChild extends string | undefined> = StringHasValue<TParent> extends true ? StringHasValue<TChild> extends true ? `${TParent}&${TChild}` : TParent : TChild;
236
236
 
@@ -250,9 +250,9 @@ export declare type CreatedRouteOptions = Omit<CreateRouteOptions, 'props'> & Wi
250
250
  props?: unknown;
251
251
  };
252
252
 
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>;
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, THash, TMeta> & WithHost<THost> & WithoutParent): Route<ToName<TName>, ToWithParams<THost>, ToWithParams<TPath>, ToWithParams<TQuery>, ToWithParams<THash>, TMeta>;
254
254
 
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']>>;
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, 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
256
 
257
257
  export declare function createParam<TParam extends ParamWithDefault>(param: TParam): TParam;
258
258
 
@@ -370,7 +370,7 @@ declare type EmptyRouterPlugin = {
370
370
  * @template TParam - The string from which to extract the parameter name.
371
371
  * @returns The extracted parameter name, or never if the parameter string is empty.
372
372
  */
373
- declare type ExtractParamName<TParam extends PropertyKey> = TParam extends `?${infer Param}` ? Param extends '' ? never : Param : TParam extends '' ? never : TParam;
373
+ declare type ExtractParamName<TParam extends PropertyKey> = TParam extends string ? TParam extends `?${infer Param}` ? Param extends '' ? never : Param : TParam extends '' ? never : TParam : never;
374
374
 
375
375
  /**
376
376
  * Extracts the actual type from a parameter type, handling getters and setters.
@@ -379,50 +379,43 @@ declare type ExtractParamName<TParam extends PropertyKey> = TParam extends `?${i
379
379
  */
380
380
  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
381
 
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
382
  declare type ExtractParamTypes<TParams extends Record<string, Param>> = Identity<MakeOptional<{
388
383
  [K in keyof TParams as ExtractParamName<K>]: ExtractParamType<TParams[K]>;
389
384
  }>>;
390
385
 
391
386
  /**
392
- * Does everything that ExtractParamTypes does, but takes into consideration optional properties.
393
- * Differs from ExtractParamTypes in that it also reads the string `value` from WithParams to determine what should be optional.
387
+ * Extracts combined types of path and query parameters for a given route, creating a unified parameter object.
394
388
  * @template TParams - The record of parameter types, possibly including undefined.
395
389
  * @returns A new type with the appropriate properties marked as optional.
396
390
  */
397
- declare type ExtractParamTypesOptionalReading<TParams extends Record<string, Param>> = {
398
- [K in keyof TParams as ExtractParamName<K>]: K extends `?${string}` ? TParams[K] extends Required<ParamGetSet> ? ExtractParamType<TParams[K]> : ExtractParamType<TParams[K]> | undefined : ExtractParamType<TParams[K]>;
391
+ declare type ExtractParamTypesReading<TWithParams extends WithParams> = {
392
+ [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
393
  };
400
394
 
401
395
  /**
402
- * Does everything that ExtractParamTypes does, but takes into consideration optional properties.
403
- * Differs from ExtractParamTypesOptionalReading in that optional params with defaults will remain optional.
396
+ * Extracts combined types of path and query parameters for a given route, creating a unified parameter object.
397
+ * Differs from ExtractParamTypesReading in that optional params with defaults will remain optional.
404
398
  * @template TParams - The record of parameter types, possibly including undefined.
405
399
  * @returns A new type with the appropriate properties marked as optional.
406
400
  */
407
- declare type ExtractParamTypesOptionalWriting<TParams extends Record<string, Param>> = {
408
- [K in keyof TParams as ExtractParamName<K>]: K extends `?${string}` ? ExtractParamType<TParams[K]> | undefined : ExtractParamType<TParams[K]>;
401
+ declare type ExtractParamTypesWriting<TWithParams extends WithParams> = {
402
+ [K in keyof TWithParams['params']]: TWithParams['value'] extends `${string}${ParamStart}?${K & string}${ParamEnd}${string}` ? ExtractParamType<TWithParams['params'][K]> | undefined : ExtractParamType<TWithParams['params'][K]>;
409
403
  };
410
404
 
411
405
  /**
412
- * Does everything that ExtractRouteParamTypes does, but takes into consideration optional properties.
413
- * Differs from ExtractRouteParamTypes in that it also reads the string `value` from WithParams to determine what should be optional.
406
+ * Extracts combined types of path and query parameters for a given route, creating a unified parameter object.
414
407
  * @template TRoute - The route type from which to extract and merge parameter types.
415
408
  * @returns A record of parameter names to their respective types, extracted and merged from both path and query parameters.
416
409
  */
417
- declare type ExtractRouteParamTypesOptionalReading<TRoute extends Route> = Identity<MakeOptional<ExtractParamTypesOptionalReading<TRoute['host']['params']> & ExtractParamTypesOptionalReading<TRoute['path']['params']> & ExtractParamTypesOptionalReading<TRoute['query']['params']> & ExtractParamTypesOptionalReading<TRoute['hash']['params']>>>;
410
+ declare type ExtractRouteParamTypesReading<TRoute extends Route> = Identity<MakeOptional<ExtractParamTypesReading<TRoute['host']> & ExtractParamTypesReading<TRoute['path']> & ExtractParamTypesReading<TRoute['query']> & ExtractParamTypesReading<TRoute['hash']>>>;
418
411
 
419
412
  /**
420
- * Does everything that ExtractRouteParamTypes does, but takes into consideration optional properties.
421
- * Differs from ExtractRouteParamTypesOptionalReading in that optional params with defaults will remain optional.
413
+ * Extracts combined types of path and query parameters for a given route, creating a unified parameter object.
414
+ * Differs from ExtractRouteParamTypesReading in that optional params with defaults will remain optional.
422
415
  * @template TRoute - The route type from which to extract and merge parameter types.
423
416
  * @returns A record of parameter names to their respective types, extracted and merged from both path and query parameters.
424
417
  */
425
- declare type ExtractRouteParamTypesOptionalWriting<TRoute extends Route> = Identity<MakeOptional<ExtractParamTypesOptionalWriting<TRoute['host']['params']> & ExtractParamTypesOptionalWriting<TRoute['path']['params']> & ExtractParamTypesOptionalWriting<TRoute['query']['params']> & ExtractParamTypesOptionalWriting<TRoute['hash']['params']>>>;
418
+ declare type ExtractRouteParamTypesWriting<TRoute extends Route> = Identity<MakeOptional<ExtractParamTypesWriting<TRoute['host']> & ExtractParamTypesWriting<TRoute['path']> & ExtractParamTypesWriting<TRoute['query']> & ExtractParamTypesWriting<TRoute['hash']>>>;
426
419
 
427
420
  declare type ExtractRouteStateParamsAsOptional<TParams extends Record<string, Param>> = {
428
421
  [K in keyof TParams]: ExtractParamType<TParams[K]> | undefined;
@@ -432,14 +425,6 @@ declare type ExtractStateParams<TRoute> = TRoute extends {
432
425
  state: infer TState extends Record<string, Param>;
433
426
  } ? ExtractParamTypes<TState> : Record<string, unknown>;
434
427
 
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
428
  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
429
  [K in keyof TParent['matched']['props']]: ReturnType<TParent['matched']['props'][K]>;
445
430
  } : undefined : undefined;
@@ -753,12 +738,6 @@ export declare type RegisteredRoutes<T = Register> = T extends {
753
738
  */
754
739
  export declare type RegisteredRoutesName = RoutesName<RegisteredRoutes>;
755
740
 
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
741
  /**
763
742
  * Represents a route that the router has matched to current browser location.
764
743
  * @template TRoute - Underlying Route that has been resolved.
@@ -792,7 +771,7 @@ export declare type ResolvedRoute<TRoute extends Route = Route> = Readonly<{
792
771
  /**
793
772
  * Key value pair for route params, values will be the user provided value from current browser location.
794
773
  */
795
- params: ExtractRouteParamTypesOptionalReading<TRoute>;
774
+ params: ExtractRouteParamTypesReading<TRoute>;
796
775
  /**
797
776
  * Type for additional data intended to be stored in history state.
798
777
  */
@@ -913,7 +892,7 @@ export declare type RouteMeta<T = Register> = T extends {
913
892
  routeMeta: infer RouteMeta extends Record<string, unknown>;
914
893
  } ? RouteMeta : Record<string, unknown>;
915
894
 
916
- declare type RouteParamsByKey<TRoutes extends Routes, TKey extends string> = RouteGetByKey<TRoutes, TKey> extends Route ? ExtractRouteParamTypesOptionalWriting<RouteGetByKey<TRoutes, TKey>> : Record<string, unknown>;
895
+ declare type RouteParamsByKey<TRoutes extends Routes, TKey extends string> = RouteGetByKey<TRoutes, TKey> extends Route ? ExtractRouteParamTypesWriting<RouteGetByKey<TRoutes, TKey>> : Record<string, unknown>;
917
896
 
918
897
  declare type RoutePropsRecord<TOptions extends CreateRouteOptions = CreateRouteOptions, TComponents extends Record<string, Component> = Record<string, Component>> = {
919
898
  [K in keyof TComponents as ComponentPropsAreOptional<TComponents[K]> extends true ? K : never]?: PropsGetter<TOptions, TComponents[K]>;
@@ -1402,7 +1381,7 @@ export declare function withParams(): WithParams<'', {}>;
1402
1381
 
1403
1382
  declare type WithParamsParamsInput<TValue extends string> = TValue extends `${string}${ParamStart}${infer TParam}${ParamEnd}${infer Rest}` ? Record<ExtractParamName<TParam>, Param | undefined> & WithParamsParamsInput<Rest> : {};
1404
1383
 
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, ExtractWithParamsParamType<TParam, TParams>> & WithParamsParamsOutput<Rest, TParams> : {};
1384
+ 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
1385
 
1407
1386
  declare type WithParent<TParent extends Route = Route> = {
1408
1387
  parent: TParent;