@kitbag/router 0.9.0 → 0.10.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.
@@ -131,21 +131,27 @@ declare const builtInRejections: ['NotFound'];
131
131
 
132
132
  declare type BuiltInRejectionType = typeof builtInRejections[number];
133
133
 
134
+ declare type CombineHash<TParent extends Hash, TChild extends Hash> = ToHash<TParent> extends {
135
+ value: infer TParentHash extends string;
136
+ } ? ToHash<TChild> extends {
137
+ value: infer ChildHash extends string;
138
+ } ? Hash<`${TParentHash}${ChildHash}`> : TParent : Hash;
139
+
134
140
  declare type CombineMeta<TParent extends Record<string, unknown>, TChild extends Record<string, unknown>> = TParent & TChild;
135
141
 
136
142
  declare type CombinePath<TParent extends Path, TChild extends Path> = ToPath<TParent> extends {
137
- path: infer TParentPath extends string;
143
+ value: infer TParentPath extends string;
138
144
  params: infer TParentParams extends Record<string, unknown>;
139
145
  } ? ToPath<TChild> extends {
140
- path: infer TChildPath extends string;
146
+ value: infer TChildPath extends string;
141
147
  params: infer TChildParams extends Record<string, unknown>;
142
148
  } ? RemoveLeadingQuestionMarkFromKeys<TParentParams> & RemoveLeadingQuestionMarkFromKeys<TChildParams> extends PathParamsWithParamNameExtracted<`${TParentPath}${TChildPath}`> ? Path<`${TParentPath}${TChildPath}`, RemoveLeadingQuestionMarkFromKeys<TParentParams> & RemoveLeadingQuestionMarkFromKeys<TChildParams>> : Path<'', {}> : Path<'', {}> : Path<'', {}>;
143
149
 
144
150
  declare type CombineQuery<TParent extends Query, TChild extends Query> = ToQuery<TParent> extends {
145
- query: infer TParentQuery extends string;
151
+ value: infer TParentQuery extends string;
146
152
  params: infer TParentParams extends Record<string, unknown>;
147
153
  } ? ToQuery<TChild> extends {
148
- query: infer TChildQuery extends string;
154
+ value: infer TChildQuery extends string;
149
155
  params: infer TChildParams extends Record<string, unknown>;
150
156
  } ? RemoveLeadingQuestionMarkFromKeys<TParentParams> & RemoveLeadingQuestionMarkFromKeys<TChildParams> extends QueryParamsWithParamNameExtracted<CombineQueryString<TParentQuery, TChildQuery>> ? Query<CombineQueryString<TParentQuery, TChildQuery>, RemoveLeadingQuestionMarkFromKeys<TParentParams> & RemoveLeadingQuestionMarkFromKeys<TChildParams>> : Query<'', {}> : Query<'', {}> : Query<'', {}>;
151
157
 
@@ -179,9 +185,9 @@ declare type ComponentPropsGetter<TComponent extends Component> = () => MaybePro
179
185
 
180
186
  declare type Constructor = new (...args: any) => any;
181
187
 
182
- export declare function createExternalRoute<const THost extends string | Host, const TName extends string | undefined = undefined, const TPath extends string | Path | undefined = undefined, const TQuery extends string | Query | undefined = undefined>(options: CreateRouteOptions<TName, TPath, TQuery> & WithHost<THost> & WithoutParent): Route<ToName<TName>, ToHost<THost>, ToPath<TPath>, ToQuery<TQuery>>;
188
+ export declare function createExternalRoute<const THost extends string | Host, const TName extends string | undefined = undefined, const TPath extends string | Path | undefined = undefined, const TQuery extends string | Query | undefined = undefined, const THash extends string | Hash | undefined = undefined, const TMeta extends RouteMeta = RouteMeta>(options: CreateRouteOptions<TName, TPath, TQuery> & WithHost<THost> & WithoutParent): Route<ToName<TName>, ToHost<THost>, ToPath<TPath>, ToQuery<TQuery>, ToHash<THash>, TMeta>;
183
189
 
184
- export declare function createExternalRoute<const TParent extends Route, const TName extends string | undefined = undefined, const TPath extends string | Path | undefined = undefined, const TQuery extends string | Query | undefined = undefined>(options: CreateRouteOptions<TName, TPath, TQuery> & WithoutHost & WithParent<TParent>): Route<ToName<TName>, Host<'', {}>, CombinePath<TParent['path'], ToPath<TPath>>, CombineQuery<TParent['query'], ToQuery<TQuery>>>;
190
+ export declare function createExternalRoute<const TParent extends Route, const TName extends string | undefined = undefined, const TPath extends string | Path | undefined = undefined, const TQuery extends string | Query | undefined = undefined, const THash extends string | Hash | undefined = undefined, const TMeta extends RouteMeta = RouteMeta>(options: CreateRouteOptions<TName, TPath, TQuery> & WithoutHost & WithParent<TParent>): Route<ToName<TName>, Host<'', {}>, CombinePath<TParent['path'], ToPath<TPath>>, CombineQuery<TParent['query'], ToQuery<TQuery>>, CombineHash<TParent['hash'], ToHash<THash>>, CombineMeta<TMeta, TParent['meta']>>;
185
191
 
186
192
  export declare function createParam<TParam extends ParamWithDefault>(param: TParam): TParam;
187
193
 
@@ -189,19 +195,19 @@ export declare function createParam<TParam extends Param>(param: TParam): ParamG
189
195
 
190
196
  export declare function createParam<TParam extends Param>(param: TParam, defaultValue: ExtractParamType<TParam>): ParamWithDefault<TParam>;
191
197
 
192
- export declare function createRoute<const TName extends string | undefined = undefined, const TPath extends string | Path | undefined = undefined, const TQuery extends string | Query | undefined = undefined, const TMeta extends RouteMeta = RouteMeta, const TState extends Record<string, Param> = Record<string, Param>>(options: CreateRouteOptions<TName, TPath, TQuery, TMeta> & WithHooks & WithoutComponents & WithoutParent & (WithState<TState> | WithoutState)): Route<ToName<TName>, Host<'', {}>, ToPath<TPath>, ToQuery<TQuery>, TMeta, TState>;
198
+ export declare function createRoute<const TName extends string | undefined = undefined, const TPath extends string | Path | undefined = undefined, const TQuery extends string | Query | undefined = undefined, const THash extends string | Hash | undefined = undefined, const TMeta extends RouteMeta = RouteMeta, const TState extends Record<string, Param> = Record<string, Param>>(options: CreateRouteOptions<TName, TPath, TQuery, THash, TMeta> & WithHooks & WithoutComponents & WithoutParent & (WithState<TState> | WithoutState)): Route<ToName<TName>, Host<'', {}>, ToPath<TPath>, ToQuery<TQuery>, ToHash<THash>, TMeta, TState>;
193
199
 
194
- export declare function createRoute<const TParent extends Route, const TName extends string | undefined = undefined, const TPath extends string | Path | undefined = undefined, const TQuery extends string | Query | undefined = undefined, const TMeta extends RouteMeta = RouteMeta, const TState extends Record<string, Param> = Record<string, Param>>(options: CreateRouteOptions<TName, TPath, TQuery, TMeta> & WithHooks & WithoutComponents & WithParent<TParent> & (WithState<TState> | WithoutState)): Route<ToName<TName>, Host<'', {}>, CombinePath<TParent['path'], ToPath<TPath>>, CombineQuery<TParent['query'], ToQuery<TQuery>>, CombineMeta<TMeta, TParent['meta']>, CombineState<TState, TParent['state']>>;
200
+ export declare function createRoute<const TParent extends Route, const TName extends string | undefined = undefined, const TPath extends string | Path | undefined = undefined, const TQuery extends string | Query | undefined = undefined, const THash extends string | Hash | undefined = undefined, const TMeta extends RouteMeta = RouteMeta, const TState extends Record<string, Param> = Record<string, Param>>(options: CreateRouteOptions<TName, TPath, TQuery, THash, TMeta> & WithHooks & WithoutComponents & WithParent<TParent> & (WithState<TState> | WithoutState)): Route<ToName<TName>, Host<'', {}>, CombinePath<TParent['path'], ToPath<TPath>>, CombineQuery<TParent['query'], ToQuery<TQuery>>, CombineHash<TParent['hash'], ToHash<THash>>, CombineMeta<TMeta, TParent['meta']>, CombineState<TState, TParent['state']>>;
195
201
 
196
- export declare function createRoute<TComponent extends Component, const TName extends string | undefined = undefined, const TPath extends string | Path | undefined = undefined, const TQuery extends string | Query | undefined = undefined, const TMeta extends RouteMeta = RouteMeta, const TState extends Record<string, Param> = Record<string, Param>>(options: CreateRouteOptions<TName, TPath, TQuery, TMeta> & WithHooks & WithComponent<TComponent, RouteParams<TPath, TQuery>> & WithoutParent & (WithState<TState> | WithoutState)): Route<ToName<TName>, Host<'', {}>, ToPath<TPath>, ToQuery<TQuery>, TMeta, TState>;
202
+ export declare function createRoute<TComponent extends Component, const TName extends string | undefined = undefined, const TPath extends string | Path | undefined = undefined, const TQuery extends string | Query | undefined = undefined, const THash extends string | Hash | undefined = undefined, const TMeta extends RouteMeta = RouteMeta, const TState extends Record<string, Param> = Record<string, Param>>(options: CreateRouteOptions<TName, TPath, TQuery, THash, TMeta> & WithHooks & WithComponent<TComponent, RouteParams<TPath, TQuery>> & WithoutParent & (WithState<TState> | WithoutState)): Route<ToName<TName>, Host<'', {}>, ToPath<TPath>, ToQuery<TQuery>, ToHash<THash>, TMeta, TState>;
197
203
 
198
- export declare function createRoute<TComponent extends Component, const TParent extends Route, const TName extends string | undefined = undefined, const TPath extends string | Path | undefined = undefined, const TQuery extends string | Query | undefined = undefined, const TMeta extends RouteMeta = RouteMeta, const TState extends Record<string, Param> = Record<string, Param>>(options: CreateRouteOptions<TName, TPath, TQuery, TMeta> & WithHooks & WithComponent<TComponent, RouteParams<TPath, TQuery, TParent>> & WithParent<TParent> & (WithState<TState> | WithoutState)): Route<ToName<TName>, Host<'', {}>, CombinePath<TParent['path'], ToPath<TPath>>, CombineQuery<TParent['query'], ToQuery<TQuery>>, CombineMeta<TMeta, TParent['meta']>, CombineState<TState, TParent['state']>>;
204
+ export declare function createRoute<TComponent extends Component, const TParent extends Route, const TName extends string | undefined = undefined, const TPath extends string | Path | undefined = undefined, const TQuery extends string | Query | undefined = undefined, const THash extends string | Hash | undefined = undefined, const TMeta extends RouteMeta = RouteMeta, const TState extends Record<string, Param> = Record<string, Param>>(options: CreateRouteOptions<TName, TPath, TQuery, THash, TMeta> & WithHooks & WithComponent<TComponent, RouteParams<TPath, TQuery, TParent>> & WithParent<TParent> & (WithState<TState> | WithoutState)): Route<ToName<TName>, Host<'', {}>, CombinePath<TParent['path'], ToPath<TPath>>, CombineQuery<TParent['query'], ToQuery<TQuery>>, CombineHash<TParent['hash'], ToHash<THash>>, CombineMeta<TMeta, TParent['meta']>, CombineState<TState, TParent['state']>>;
199
205
 
200
- export declare function createRoute<TComponents extends Record<string, Component>, const TName extends string | undefined = undefined, const TPath extends string | Path | undefined = undefined, const TQuery extends string | Query | undefined = undefined, const TMeta extends RouteMeta = RouteMeta, const TState extends Record<string, Param> = Record<string, Param>>(options: CreateRouteOptions<TName, TPath, TQuery, TMeta> & WithHooks & WithComponents<TComponents, RouteParams<TPath, TQuery>> & WithoutParent & (WithState<TState> | WithoutState)): Route<ToName<TName>, Host<'', {}>, ToPath<TPath>, ToQuery<TQuery>, TMeta, TState>;
206
+ export declare function createRoute<TComponents extends Record<string, Component>, const TName extends string | undefined = undefined, const TPath extends string | Path | undefined = undefined, const TQuery extends string | Query | undefined = undefined, const THash extends string | Hash | undefined = undefined, const TMeta extends RouteMeta = RouteMeta, const TState extends Record<string, Param> = Record<string, Param>>(options: CreateRouteOptions<TName, TPath, TQuery, THash, TMeta> & WithHooks & WithComponents<TComponents, RouteParams<TPath, TQuery>> & WithoutParent & (WithState<TState> | WithoutState)): Route<ToName<TName>, Host<'', {}>, ToPath<TPath>, ToQuery<TQuery>, ToHash<THash>, TMeta, TState>;
201
207
 
202
- export declare function createRoute<TComponents extends Record<string, Component>, const TParent extends Route, const TName extends string | undefined = undefined, const TPath extends string | Path | undefined = undefined, const TQuery extends string | Query | undefined = undefined, const TMeta extends RouteMeta = RouteMeta, const TState extends Record<string, Param> = Record<string, Param>>(options: CreateRouteOptions<TName, TPath, TQuery, TMeta> & WithHooks & WithComponents<TComponents, RouteParams<TPath, TQuery, TParent>> & WithParent<TParent> & (WithState<TState> | WithoutState)): Route<ToName<TName>, Host<'', {}>, CombinePath<TParent['path'], ToPath<TPath>>, CombineQuery<TParent['query'], ToQuery<TQuery>>, CombineMeta<TMeta, TParent['meta']>, CombineState<TState, TParent['state']>>;
208
+ export declare function createRoute<TComponents extends Record<string, Component>, const TParent extends Route, const TName extends string | undefined = undefined, const TPath extends string | Path | undefined = undefined, const TQuery extends string | Query | undefined = undefined, const THash extends string | Hash | undefined = undefined, const TMeta extends RouteMeta = RouteMeta, const TState extends Record<string, Param> = Record<string, Param>>(options: CreateRouteOptions<TName, TPath, TQuery, THash, TMeta> & WithHooks & WithComponents<TComponents, RouteParams<TPath, TQuery, TParent>> & WithParent<TParent> & (WithState<TState> | WithoutState)): Route<ToName<TName>, Host<'', {}>, CombinePath<TParent['path'], ToPath<TPath>>, CombineQuery<TParent['query'], ToQuery<TQuery>>, CombineHash<TParent['hash'], ToHash<THash>>, CombineMeta<TMeta, TParent['meta']>, CombineState<TState, TParent['state']>>;
203
209
 
204
- export declare type CreateRouteOptions<TName extends string | undefined = string | undefined, TPath extends string | Path | undefined = string | Path | undefined, TQuery extends string | Query | undefined = string | Query | undefined, TMeta extends RouteMeta = RouteMeta> = {
210
+ export declare type CreateRouteOptions<TName extends string | undefined = string | undefined, TPath extends string | Path | undefined = string | Path | undefined, TQuery extends string | Query | undefined = string | Query | undefined, THash extends string | Hash | undefined = string | Hash | undefined, TMeta extends RouteMeta = RouteMeta> = {
205
211
  /**
206
212
  * Name for route, used to create route keys and in navigation.
207
213
  */
@@ -214,6 +220,10 @@ export declare type CreateRouteOptions<TName extends string | undefined = string
214
220
  * Query (aka search) part of URL.
215
221
  */
216
222
  query?: TQuery;
223
+ /**
224
+ * Hash part of URL.
225
+ */
226
+ hash?: THash;
217
227
  /**
218
228
  * Represents additional metadata associated with a route, customizable via declaration merging.
219
229
  */
@@ -359,8 +369,14 @@ declare type ExtractStateParams<TRoute> = TRoute extends {
359
369
  state: infer TState extends Record<string, Param>;
360
370
  } ? ExtractParamTypes<TState> : Record<string, unknown>;
361
371
 
372
+ declare type Hash<THash extends string | undefined = string | undefined> = {
373
+ value: THash;
374
+ hasValue: () => boolean;
375
+ toString: () => string;
376
+ };
377
+
362
378
  declare type Host<THost extends string = string, TParams extends HostParamsWithParamNameExtracted<THost> = Record<string, Param | undefined>> = {
363
- host: THost;
379
+ value: THost;
364
380
  params: string extends THost ? Record<string, Param> : Identity<ExtractParamsFromHostString<THost, TParams>>;
365
381
  toString: () => string;
366
382
  };
@@ -497,7 +513,7 @@ declare type ParentPath<TParent extends Route | undefined> = TParent extends Rou
497
513
  declare type ParentQuery<TParent extends Route | undefined> = TParent extends Route ? TParent['query'] : Query<'', {}>;
498
514
 
499
515
  declare type Path<TPath extends string = string, TParams extends PathParamsWithParamNameExtracted<TPath> = Record<string, Param | undefined>> = {
500
- path: TPath;
516
+ value: TPath;
501
517
  params: string extends TPath ? Record<string, Param> : Identity<ExtractParamsFromPathString<TPath, TParams>>;
502
518
  toString: () => string;
503
519
  };
@@ -507,7 +523,7 @@ declare type Path<TPath extends string = string, TParams extends PathParamsWithP
507
523
  *
508
524
  * @template TPath - The string literal type that represents the path.
509
525
  * @template TParams - The type of the path parameters associated with the path.
510
- * @param path - The path string.
526
+ * @param value - The path string.
511
527
  * @param params - The parameters associated with the path, typically as key-value pairs.
512
528
  * @returns An object representing the path which includes the path string, its parameters,
513
529
  * and a toString method for getting the path as a string.
@@ -523,7 +539,7 @@ declare type Path<TPath extends string = string, TParams extends PathParamsWithP
523
539
  * })
524
540
  * ```
525
541
  */
526
- export declare function path<TPath extends string, TParams extends PathParamsWithParamNameExtracted<TPath>>(path: TPath, params: Identity<TParams>): Path<TPath, TParams>;
542
+ export declare function path<TPath extends string, TParams extends PathParamsWithParamNameExtracted<TPath>>(value: TPath, params: Identity<TParams>): Path<TPath, TParams>;
527
543
 
528
544
  declare type PathParamsWithParamNameExtracted<TPath extends string> = {
529
545
  [K in keyof ExtractParamsFromPathString<TPath> as ExtractParamName<K>]?: Param;
@@ -543,7 +559,7 @@ declare type PrefetchConfigOptions = {
543
559
  };
544
560
 
545
561
  declare type Query<TQuery extends string = string, TQueryParams extends QueryParamsWithParamNameExtracted<TQuery> = Record<string, Param | undefined>> = {
546
- query: TQuery;
562
+ value: TQuery;
547
563
  params: string extends TQuery ? Record<string, Param> : Identity<ExtractQueryParamsFromQueryString<TQuery, TQueryParams>>;
548
564
  toString: () => string;
549
565
  };
@@ -553,7 +569,7 @@ declare type Query<TQuery extends string = string, TQueryParams extends QueryPar
553
569
  *
554
570
  * @template TQuery - The string literal type that represents the query.
555
571
  * @template TParams - The type of the query parameters associated with the query.
556
- * @param query - The query string.
572
+ * @param value - The query string.
557
573
  * @param params - The parameters associated with the query, typically as key-value pairs.
558
574
  * @returns An object representing the query which includes the query string, its parameters,
559
575
  * and a toString method for getting the query as a string.
@@ -569,7 +585,7 @@ declare type Query<TQuery extends string = string, TQueryParams extends QueryPar
569
585
  * })
570
586
  * ```
571
587
  */
572
- export declare function query<TQuery extends string, TParams extends QueryParamsWithParamNameExtracted<TQuery>>(query: TQuery, params: Identity<TParams>): Query<TQuery, TParams>;
588
+ export declare function query<TQuery extends string, TParams extends QueryParamsWithParamNameExtracted<TQuery>>(value: TQuery, params: Identity<TParams>): Query<TQuery, TParams>;
573
589
 
574
590
  declare type QueryParamsWithParamNameExtracted<T extends string> = {
575
591
  [K in keyof ExtractQueryParamsFromQueryString<T> as ExtractParamName<K>]?: Param;
@@ -691,7 +707,7 @@ declare type ResolvedRouteQuery = {
691
707
  * @template TPath - The type or structure of the route's path.
692
708
  * @template TQuery - The type or structure of the query parameters associated with the route.
693
709
  */
694
- export declare type Route<TName extends string = string, THost extends Host = Host, TPath extends Path = Path, TQuery extends Query = Query, TMeta extends RouteMeta = RouteMeta, TState extends Record<string, Param> = Record<string, Param>> = {
710
+ export declare type Route<TName extends string = string, THost extends Host = Host, TPath extends Path = Path, TQuery extends Query = Query, THash extends Hash = Hash, TMeta extends RouteMeta = RouteMeta, TState extends Record<string, Param> = Record<string, Param>> = {
695
711
  /**
696
712
  * The specific route properties that were matched in the current route.
697
713
  */
@@ -717,6 +733,10 @@ export declare type Route<TName extends string = string, THost extends Host = Ho
717
733
  * Represents the structured query of the route, including query params.
718
734
  */
719
735
  query: TQuery;
736
+ /**
737
+ * Represents the hash of the route.
738
+ */
739
+ hash: THash;
720
740
  /**
721
741
  * Represents additional metadata associated with a route, combined with any parents.
722
742
  */
@@ -1142,6 +1162,8 @@ declare type StringHasValue<T> = string extends T ? true : '' extends T ? false
1142
1162
 
1143
1163
  declare type ToCallback = (resolve: RegisteredRouter['resolve']) => string;
1144
1164
 
1165
+ declare type ToHash<T extends string | Hash | undefined> = T extends string ? Hash<T> : T extends undefined ? Hash<''> : unknown extends T ? Hash<''> : T;
1166
+
1145
1167
  declare type ToHost<T extends string | Host | undefined> = T extends string ? Host<T, {}> : T extends undefined ? Host<'', {}> : unknown extends T ? Host<'', {}> : T;
1146
1168
 
1147
1169
  declare type ToName<T extends string | undefined> = T extends string ? T : '';