@kitbag/router 0.20.5 → 0.20.7

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.
Files changed (203) hide show
  1. package/dist/components/echo.d.ts +6 -0
  2. package/dist/components/helloWorld.d.ts +2 -0
  3. package/dist/components/rejection.d.ts +2 -0
  4. package/dist/components/routerLink.browser.spec.d.ts +1 -0
  5. package/dist/components/routerLink.d.ts +36 -0
  6. package/dist/components/routerView.browser.spec.d.ts +1 -0
  7. package/dist/components/routerView.d.ts +20 -0
  8. package/dist/components/routerView.spec.d.ts +1 -0
  9. package/dist/compositions/useComponentsStore.d.ts +5 -0
  10. package/dist/compositions/useEventListener.d.ts +2 -0
  11. package/dist/compositions/useLink.d.ts +16 -0
  12. package/dist/compositions/usePrefetching.d.ts +14 -0
  13. package/dist/compositions/usePropStore.d.ts +7 -0
  14. package/dist/compositions/useQueryValue.browser.spec.d.ts +1 -0
  15. package/dist/compositions/useQueryValue.d.ts +15 -0
  16. package/dist/compositions/useRejection.d.ts +7 -0
  17. package/dist/compositions/useRoute.browser.spec.d.ts +1 -0
  18. package/dist/compositions/useRoute.d.ts +16 -0
  19. package/dist/compositions/useRouter.d.ts +3 -0
  20. package/dist/compositions/useRouterDepth.d.ts +8 -0
  21. package/dist/compositions/useRouterHooks.d.ts +4 -0
  22. package/dist/compositions/useVisibilityObserver.d.ts +8 -0
  23. package/dist/errors/callbackContextAbortError.d.ts +5 -0
  24. package/dist/errors/callbackContextPushError.d.ts +5 -0
  25. package/dist/errors/callbackContextRejectionError.d.ts +6 -0
  26. package/dist/errors/duplicateNamesError.d.ts +11 -0
  27. package/dist/errors/duplicateParamsError.d.ts +13 -0
  28. package/dist/errors/initialRouteMissingError.d.ts +3 -0
  29. package/dist/errors/invalidRouteParamValueError.d.ts +2 -0
  30. package/dist/errors/metaPropertyConflict.d.ts +8 -0
  31. package/dist/errors/routeNotFoundError.d.ts +6 -0
  32. package/dist/errors/routerNotInstalledError.d.ts +7 -0
  33. package/dist/errors/useRouteInvalidError.d.ts +13 -0
  34. package/dist/guards/routes.d.ts +46 -0
  35. package/dist/guards/routes.spec-d.d.ts +1 -0
  36. package/dist/keys.d.ts +3 -0
  37. package/dist/kitbag-router.d.ts +2 -1433
  38. package/dist/kitbag-router.js +1751 -1675
  39. package/dist/kitbag-router.umd.cjs +3 -3
  40. package/dist/main.d.ts +302 -0
  41. package/dist/models/RouteHooks.d.ts +9 -0
  42. package/dist/models/RouterRouteHooks.d.ts +10 -0
  43. package/dist/services/arrayOf.d.ts +7 -0
  44. package/dist/services/arrayOf.spec.d.ts +1 -0
  45. package/dist/services/combineHash.d.ts +4 -0
  46. package/dist/services/combineHash.spec.d.ts +1 -0
  47. package/dist/services/combineMeta.d.ts +2 -0
  48. package/dist/services/combineMeta.spec.d.ts +1 -0
  49. package/dist/services/combinePath.d.ts +12 -0
  50. package/dist/services/combinePath.spec-d.d.ts +1 -0
  51. package/dist/services/combinePath.spec.d.ts +1 -0
  52. package/dist/services/combineQuery.d.ts +13 -0
  53. package/dist/services/combineQuery.spec.d.ts +1 -0
  54. package/dist/services/combineState.d.ts +3 -0
  55. package/dist/services/combineState.spec.d.ts +1 -0
  56. package/dist/services/component.browser.spec.d.ts +1 -0
  57. package/dist/services/component.d.ts +12 -0
  58. package/dist/services/createCallbackContext.d.ts +38 -0
  59. package/dist/services/createComponentHooks.d.ts +11 -0
  60. package/dist/services/createComponentsStore.d.ts +7 -0
  61. package/dist/services/createCurrentRoute.d.ts +13 -0
  62. package/dist/services/createExternalRoute.d.ts +3 -0
  63. package/dist/services/createExternalRoute.spec.d.ts +1 -0
  64. package/dist/services/createIsExternal.d.ts +1 -0
  65. package/dist/services/createIsExternal.spec.d.ts +1 -0
  66. package/dist/services/createParam.d.ts +6 -0
  67. package/dist/services/createPropStore.d.ts +13 -0
  68. package/dist/services/createResolvedRoute.d.ts +4 -0
  69. package/dist/services/createResolvedRouteForUrl.browser.spec.d.ts +1 -0
  70. package/dist/services/createResolvedRouteForUrl.d.ts +3 -0
  71. package/dist/services/createResolvedRouteQuery.d.ts +5 -0
  72. package/dist/services/createRoute.d.ts +4 -0
  73. package/dist/services/createRoute.spec-d.d.ts +1 -0
  74. package/dist/services/createRoute.spec.d.ts +1 -0
  75. package/dist/services/createRouteId.d.ts +1 -0
  76. package/dist/services/createRouter.browser.spec.d.ts +1 -0
  77. package/dist/services/createRouter.d.ts +28 -0
  78. package/dist/services/createRouter.spec-d.d.ts +1 -0
  79. package/dist/services/createRouter.spec.d.ts +1 -0
  80. package/dist/services/createRouterAssets.d.ts +118 -0
  81. package/dist/services/createRouterHistory.browser.spec.d.ts +1 -0
  82. package/dist/services/createRouterHistory.d.ts +20 -0
  83. package/dist/services/createRouterHooks.d.ts +20 -0
  84. package/dist/services/createRouterKeyStore.d.ts +3 -0
  85. package/dist/services/createRouterPlugin.browser.spec.d.ts +1 -0
  86. package/dist/services/createRouterPlugin.d.ts +4 -0
  87. package/dist/services/createRouterReject.d.ts +16 -0
  88. package/dist/services/createRouterRoute.d.ts +7 -0
  89. package/dist/services/createRouterRoute.spec.d.ts +1 -0
  90. package/dist/services/createUniqueIdSequence.d.ts +2 -0
  91. package/dist/services/createVisibilityObserver.d.ts +7 -0
  92. package/dist/services/createVueAppStore.d.ts +8 -0
  93. package/dist/services/getGlobalHooksForRouter.d.ts +4 -0
  94. package/dist/services/getGlobalRouteHooks.d.ts +5 -0
  95. package/dist/services/getInitialUrl.browser.spec.d.ts +1 -0
  96. package/dist/services/getInitialUrl.d.ts +1 -0
  97. package/dist/services/getInitialUrl.spec.d.ts +1 -0
  98. package/dist/services/getMatchesForUrl.d.ts +2 -0
  99. package/dist/services/getMatchesForUrl.spec.d.ts +1 -0
  100. package/dist/services/getParamsForString.d.ts +2 -0
  101. package/dist/services/getRouteHooks.d.ts +4 -0
  102. package/dist/services/getRouteHooks.spec.d.ts +1 -0
  103. package/dist/services/getRoutesForRouter.d.ts +9 -0
  104. package/dist/services/getRoutesForRouter.spec.d.ts +1 -0
  105. package/dist/services/hooks.browser.spec.d.ts +1 -0
  106. package/dist/services/hooks.d.ts +8 -0
  107. package/dist/services/hooks.spec.d.ts +1 -0
  108. package/dist/services/insertBaseRoute.d.ts +2 -0
  109. package/dist/services/insertBaseRoute.spec.d.ts +1 -0
  110. package/dist/services/paramValidation.d.ts +4 -0
  111. package/dist/services/paramValidation.spec.d.ts +1 -0
  112. package/dist/services/params.d.ts +7 -0
  113. package/dist/services/params.spec.d.ts +1 -0
  114. package/dist/services/paramsFinder.d.ts +3 -0
  115. package/dist/services/paramsFinder.spec.d.ts +1 -0
  116. package/dist/services/routeMatchRules.d.ts +5 -0
  117. package/dist/services/routeMatchRules.spec.d.ts +1 -0
  118. package/dist/services/routeMatchScore.d.ts +7 -0
  119. package/dist/services/routeMatchScore.spec.d.ts +1 -0
  120. package/dist/services/routeRegex.d.ts +18 -0
  121. package/dist/services/routeRegex.spec.d.ts +1 -0
  122. package/dist/services/state.d.ts +9 -0
  123. package/dist/services/state.spec.d.ts +1 -0
  124. package/dist/services/tupleOf.d.ts +10 -0
  125. package/dist/services/tupleOf.spec.d.ts +1 -0
  126. package/dist/services/unionOf.d.ts +3 -0
  127. package/dist/services/unionOf.spec.d.ts +1 -0
  128. package/dist/services/urlAssembly.d.ts +10 -0
  129. package/dist/services/urlAssembly.spec.d.ts +1 -0
  130. package/dist/services/urlCombine.d.ts +2 -0
  131. package/dist/services/urlCombine.spec.d.ts +1 -0
  132. package/dist/services/urlCreator.d.ts +2 -0
  133. package/dist/services/urlCreator.spec.d.ts +1 -0
  134. package/dist/services/urlParser.d.ts +2 -0
  135. package/dist/services/urlParser.spec.d.ts +1 -0
  136. package/dist/services/valibot.d.ts +7 -0
  137. package/dist/services/valibot.spec-d.d.ts +1 -0
  138. package/dist/services/valibot.spec.d.ts +1 -0
  139. package/dist/services/withDefault.d.ts +5 -0
  140. package/dist/services/withParams.d.ts +15 -0
  141. package/dist/services/withParams.spec-d.d.ts +1 -0
  142. package/dist/services/withParams.spec.d.ts +1 -0
  143. package/dist/services/zod.d.ts +11 -0
  144. package/dist/services/zod.spec-d.d.ts +1 -0
  145. package/dist/services/zod.spec.d.ts +1 -0
  146. package/dist/tests/hooks.spec.d.ts +1 -0
  147. package/dist/tests/routeProps.browser.spec.d.ts +1 -0
  148. package/dist/tests/routeProps.spec.d.ts +1 -0
  149. package/dist/types/createRouteOptions.d.ts +120 -0
  150. package/dist/types/hooks.d.ts +111 -0
  151. package/dist/types/meta.d.ts +2 -0
  152. package/dist/types/name.d.ts +2 -0
  153. package/dist/types/paramTypes.d.ts +14 -0
  154. package/dist/types/params.d.ts +71 -0
  155. package/dist/types/prefetch.d.ts +27 -0
  156. package/dist/types/props.d.ts +23 -0
  157. package/dist/types/querySource.d.ts +1 -0
  158. package/dist/types/register.d.ts +57 -0
  159. package/dist/types/register.spec.d.ts +1 -0
  160. package/dist/types/resolved.d.ts +47 -0
  161. package/dist/types/resolved.spec-d.d.ts +1 -0
  162. package/dist/types/route.d.ts +76 -0
  163. package/dist/types/route.spec-d.d.ts +1 -0
  164. package/dist/types/routeMatchRule.d.ts +2 -0
  165. package/dist/types/routeUpdate.d.ts +9 -0
  166. package/dist/types/routeWithParams.d.ts +5 -0
  167. package/dist/types/routeWithParams.spec-d.d.ts +1 -0
  168. package/dist/types/router.d.ts +185 -0
  169. package/dist/types/routerLink.d.ts +16 -0
  170. package/dist/types/routerPlugin.d.ts +18 -0
  171. package/dist/types/routerPush.d.ts +33 -0
  172. package/dist/types/routerReject.d.ts +3 -0
  173. package/dist/types/routerReplace.d.ts +20 -0
  174. package/dist/types/routerResolve.d.ts +15 -0
  175. package/dist/types/routerRoute.d.ts +16 -0
  176. package/dist/types/routesMap.d.ts +9 -0
  177. package/dist/types/routesMap.spec-ts.d.ts +1 -0
  178. package/dist/types/state.d.ts +18 -0
  179. package/dist/types/url.d.ts +23 -0
  180. package/dist/types/useLink.d.ts +51 -0
  181. package/dist/types/utilities.d.ts +22 -0
  182. package/dist/utilities/array.d.ts +2 -0
  183. package/dist/utilities/checkDuplicateKeys.d.ts +1 -0
  184. package/dist/utilities/checkDuplicateKeys.spec.d.ts +1 -0
  185. package/dist/utilities/checkDuplicateNames.d.ts +2 -0
  186. package/dist/utilities/checkDuplicateNames.spec.d.ts +1 -0
  187. package/dist/utilities/components.d.ts +6 -0
  188. package/dist/utilities/components.spec.d.ts +1 -0
  189. package/dist/utilities/guards.d.ts +5 -0
  190. package/dist/utilities/guards.spec.d.ts +1 -0
  191. package/dist/utilities/index.d.ts +6 -0
  192. package/dist/utilities/isBrowser.browser.spec.d.ts +1 -0
  193. package/dist/utilities/isBrowser.d.ts +1 -0
  194. package/dist/utilities/isBrowser.spec.d.ts +1 -0
  195. package/dist/utilities/makeOptional.d.ts +9 -0
  196. package/dist/utilities/prefetch.d.ts +4 -0
  197. package/dist/utilities/prefetch.spec.d.ts +1 -0
  198. package/dist/utilities/promises.d.ts +1 -0
  199. package/dist/utilities/props.d.ts +6 -0
  200. package/dist/utilities/testHelpers.d.ts +144 -0
  201. package/dist/utilities/urlSearchParams.d.ts +2 -0
  202. package/dist/utilities/urlSearchParams.spec.d.ts +1 -0
  203. package/package.json +11 -11
@@ -0,0 +1,7 @@
1
+ import { Route } from '../types/route';
2
+ import { QuerySource } from '../types/querySource';
3
+ type RouteSortMethod = (aRoute: Route, bRoute: Route) => number;
4
+ export declare function getRouteScoreSortMethod(url: string): RouteSortMethod;
5
+ export declare function countExpectedPathParams(route: Route, actualPath: string): number;
6
+ export declare function countExpectedQueryParams(route: Route, actual: QuerySource): number;
7
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,18 @@
1
+ import { Route } from '../types/route';
2
+ import { WithParams } from './withParams';
3
+ export declare function splitByMatches(string: string, regexp: RegExp): string[];
4
+ export declare function generateRoutePathRegexPattern(route: Route): RegExp;
5
+ export declare function generateRouteQueryRegexPatterns(route: Route): RegExp[];
6
+ export declare function replaceParamSyntaxWithCatchAlls(value: string): string;
7
+ export declare function replaceIndividualParamWithCaptureGroup(path: string, paramName: string): string;
8
+ export declare function paramIsOptional(path: WithParams, paramName: string): boolean;
9
+ export declare function isOptionalParamSyntax(value: string): boolean;
10
+ export declare function isRequiredParamSyntax(value: string): boolean;
11
+ export declare const paramRegex = "\\[\\??([\\w-_]+)\\]";
12
+ export declare const optionalParamRegex = "\\[\\?([\\w-_]+)\\]";
13
+ export declare const requiredParamRegex = "\\[([\\w-_]+)\\]";
14
+ export declare const regexCatchAll = ".*";
15
+ export declare const regexCaptureAll = "(.*)";
16
+ export declare function getParamName(value: string): string | undefined;
17
+ export declare function getParamRegexPattern(paramName: string): RegExp;
18
+ export declare function getCaptureGroups(value: string, pattern: RegExp): (string | undefined)[];
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,9 @@
1
+ import { Param } from '../types/paramTypes';
2
+ /**
3
+ * This function is used to get the values inside the state converted from string values into the correct type.
4
+ */
5
+ export declare function getStateValues(params: Record<string, Param>, state: unknown): Record<string, unknown>;
6
+ /**
7
+ * This function is used to set the values inside the state to have string values, stored in history.
8
+ */
9
+ export declare const setStateValues: (params: Record<string, Param>, state: unknown) => Record<string, string | undefined>;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,10 @@
1
+ import { Param, ParamGetSet } from '../types/paramTypes';
2
+ import { ExtractParamType } from '../types/params';
3
+ type TupleOfOptions = {
4
+ separator?: string;
5
+ };
6
+ type TupleOf<T extends Param[]> = {
7
+ [K in keyof T]: ExtractParamType<T[K]>;
8
+ };
9
+ export declare function tupleOf<const T extends Param[]>(params: T, options?: TupleOfOptions): ParamGetSet<TupleOf<T>>;
10
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,3 @@
1
+ import { Param, ParamGetSet } from '../types/paramTypes';
2
+ import { ExtractParamType } from '../types/params';
3
+ export declare function unionOf<const T extends Param[]>(params: T): ParamGetSet<ExtractParamType<T[number]>>;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,10 @@
1
+ import { Route } from '../types/route';
2
+ import { Url } from '../types/url';
3
+ import { QuerySource } from '../types/querySource';
4
+ type AssembleUrlOptions = {
5
+ params?: Record<string, unknown>;
6
+ query?: QuerySource;
7
+ hash?: string;
8
+ };
9
+ export declare function assembleUrl(route: Route, options?: AssembleUrlOptions): Url;
10
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,2 @@
1
+ import { Url, UrlParts } from '../types/url';
2
+ export declare function combineUrl(previous: Url | Partial<UrlParts>, updated: Url | Partial<UrlParts>): Url;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,2 @@
1
+ import { Url, UrlParts } from '../types/url';
2
+ export declare function createUrl({ protocol, host, pathname, search, searchParams, hash }: Partial<UrlParts>): Url;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,2 @@
1
+ import { UrlParts } from '../types/url';
2
+ export declare function parseUrl(value: string): UrlParts;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,7 @@
1
+ import { Param, ParamGetSet } from '../types/paramTypes';
2
+ import { StandardSchemaV1 } from '@standard-schema/spec';
3
+ export interface ValibotSchemaLike extends StandardSchemaV1<any> {
4
+ type: string;
5
+ }
6
+ export declare function isValibotParam(value: Param): value is ValibotSchemaLike;
7
+ export declare function createValibotParam<T>(schema: ValibotSchemaLike): ParamGetSet<T>;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,5 @@
1
+ import { ExtractParamType } from '../types/params';
2
+ import { Param, ParamGetSet } from '../types/paramTypes';
3
+ export type ParamWithDefault<TParam extends Param = Param> = Required<ParamGetSet<ExtractParamType<TParam>>>;
4
+ export declare function isParamWithDefault(param: Param): param is ParamWithDefault;
5
+ export declare function withDefault<TParam extends Param>(param: TParam, defaultValue: ExtractParamType<TParam>): ParamWithDefault<TParam>;
@@ -0,0 +1,15 @@
1
+ import { ExtractParamName, ParamEnd, ParamStart } from '../types/params';
2
+ import { Param } from '../types/paramTypes';
3
+ import { Identity } from '../types/utilities';
4
+ import { MakeOptional } from '../utilities/makeOptional';
5
+ type WithParamsParamsInput<TValue extends string> = TValue extends `${string}${ParamStart}${infer TParam}${ParamEnd}${infer Rest}` ? Record<ExtractParamName<TParam>, Param | undefined> & WithParamsParamsInput<Rest> : {};
6
+ 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> : {};
7
+ export type WithParams<TValue extends string = string, TParams extends Record<string, Param | undefined> = Record<string, Param | undefined>> = {
8
+ value: TValue;
9
+ params: string extends TValue ? Record<string, Param> : Identity<WithParamsParamsOutput<TValue, TParams>>;
10
+ };
11
+ export type ToWithParams<T extends string | WithParams | undefined> = T extends string ? WithParams<T, {}> : T extends undefined ? WithParams<'', {}> : unknown extends T ? WithParams<'', {}> : T;
12
+ export declare function toWithParams<T extends string | WithParams | undefined>(value: T): ToWithParams<T>;
13
+ export declare function withParams<const TValue extends string, const TParams extends MakeOptional<WithParamsParamsInput<TValue>>>(value: TValue, params: TParams): WithParams<TValue, TParams>;
14
+ export declare function withParams(): WithParams<'', {}>;
15
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,11 @@
1
+ import { ParamGetSet } from '../types/paramTypes';
2
+ import { Routes } from '../types/route';
3
+ import { StandardSchemaV1 } from '@standard-schema/spec';
4
+ import { ZodSchema } from 'zod';
5
+ export interface ZodSchemaLike extends StandardSchemaV1<any> {
6
+ parse: (input: any) => any;
7
+ }
8
+ export declare function zotParamsDetected(routes: Routes): boolean;
9
+ export declare function initZod(): Promise<void>;
10
+ export declare function isZodParam(value: unknown): value is ZodSchema;
11
+ export declare function createZodParam<T>(schema: ZodSchema<T>): ParamGetSet<T>;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,120 @@
1
+ import { Component } from 'vue';
2
+ import { CombineHash } from '../services/combineHash';
3
+ import { CombineMeta } from '../services/combineMeta';
4
+ import { CombinePath } from '../services/combinePath';
5
+ import { CombineQuery } from '../services/combineQuery';
6
+ import { CombineState } from '../services/combineState';
7
+ import { Param } from './paramTypes';
8
+ import { PrefetchConfig } from './prefetch';
9
+ import { RouteMeta } from './register';
10
+ import { Route } from './route';
11
+ import { ResolvedRoute } from './resolved';
12
+ import { ComponentProps } from '../services/component';
13
+ import { PropsCallbackContext } from './props';
14
+ import { MaybePromise } from './utilities';
15
+ import { RouterView } from '../main';
16
+ import { ToMeta } from './meta';
17
+ import { ToState } from './state';
18
+ import { ToName } from './name';
19
+ import { WithHooks } from './hooks';
20
+ import { ToWithParams, WithParams } from '../services/withParams';
21
+ export type WithHost<THost extends string | WithParams = string | WithParams> = {
22
+ /**
23
+ * Host part of URL.
24
+ */
25
+ host: THost;
26
+ };
27
+ export type WithoutHost = {
28
+ host?: never;
29
+ };
30
+ export type WithParent<TParent extends Route = Route> = {
31
+ parent: TParent;
32
+ };
33
+ export declare function isWithParent<T extends Record<string, unknown>>(options: T): options is T & WithParent;
34
+ export type WithoutParent = {
35
+ parent?: never;
36
+ };
37
+ export declare function isWithComponent<T extends Record<string, unknown>>(options: T): options is T & {
38
+ component: Component;
39
+ };
40
+ export declare function isWithComponentProps<T extends Record<string, unknown>>(options: T): options is T & {
41
+ props: PropsGetter;
42
+ };
43
+ export declare function isWithComponents<T extends Record<string, unknown>>(options: T): options is T & {
44
+ components: Record<string, Component>;
45
+ };
46
+ export declare function isWithComponentPropsRecord<T extends Record<string, unknown>>(options: T): options is T & {
47
+ props: RoutePropsRecord;
48
+ };
49
+ export 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 & {
50
+ /**
51
+ * Name for route, used to create route keys and in navigation.
52
+ */
53
+ name?: TName;
54
+ /**
55
+ * Path part of URL.
56
+ */
57
+ path?: TPath;
58
+ /**
59
+ * Query (aka search) part of URL.
60
+ */
61
+ query?: TQuery;
62
+ /**
63
+ * Hash part of URL.
64
+ */
65
+ hash?: THash;
66
+ /**
67
+ * Represents additional metadata associated with a route, customizable via declaration merging.
68
+ */
69
+ meta?: TMeta;
70
+ /**
71
+ * Determines what assets are prefetched when router-link is rendered for this route. Overrides router level prefetch.
72
+ */
73
+ prefetch?: PrefetchConfig;
74
+ /**
75
+ * Type params for additional data intended to be stored in history state, all keys will be optional unless a default is provided.
76
+ */
77
+ state?: Record<string, Param>;
78
+ /**
79
+ * An optional parent route to nest this route under.
80
+ */
81
+ parent?: Route;
82
+ /**
83
+ * An optional component to render when this route is matched.
84
+ *
85
+ * @default RouterView
86
+ */
87
+ component?: Component;
88
+ /**
89
+ * An object of named components to render using named views
90
+ */
91
+ components?: Record<string, Component>;
92
+ /**
93
+ * Props have been moved to the second argument of `createRoute`. This property can no longer be used.
94
+ *
95
+ * @deprecated
96
+ */
97
+ props?: never;
98
+ };
99
+ export type PropsGetter<TOptions extends CreateRouteOptions = CreateRouteOptions, TComponent extends Component = Component> = (route: ResolvedRoute<ToRoute<TOptions, undefined>>, context: PropsCallbackContext<TOptions['parent']>) => MaybePromise<ComponentProps<TComponent>>;
100
+ type ComponentPropsAreOptional<TComponent extends Component> = Partial<ComponentProps<TComponent>> extends ComponentProps<TComponent> ? true : false;
101
+ type RoutePropsRecord<TOptions extends CreateRouteOptions = CreateRouteOptions, TComponents extends Record<string, Component> = Record<string, Component>> = {
102
+ [K in keyof TComponents as ComponentPropsAreOptional<TComponents[K]> extends true ? K : never]?: PropsGetter<TOptions, TComponents[K]>;
103
+ } & {
104
+ [K in keyof TComponents as ComponentPropsAreOptional<TComponents[K]> extends false ? K : never]: PropsGetter<TOptions, TComponents[K]>;
105
+ };
106
+ export type CreateRouteProps<TOptions extends CreateRouteOptions = CreateRouteOptions> = TOptions['component'] extends Component ? PropsGetter<TOptions, TOptions['component']> : TOptions['components'] extends Record<string, Component> ? RoutePropsRecord<TOptions, TOptions['components']> : PropsGetter<TOptions, typeof RouterView>;
107
+ type ToMatch<TOptions extends CreateRouteOptions, TProps extends CreateRouteProps<TOptions> | undefined> = Omit<TOptions, 'props'> & {
108
+ id: string;
109
+ props: TProps;
110
+ };
111
+ type ToMatches<TOptions extends CreateRouteOptions, TProps extends CreateRouteProps<TOptions> | undefined> = TOptions extends {
112
+ parent: infer TParent extends Route;
113
+ } ? [...TParent['matches'], ToMatch<TOptions, TProps>] : [ToMatch<TOptions, TProps>];
114
+ export type ToRoute<TOptions extends CreateRouteOptions, TProps extends CreateRouteProps<TOptions> | undefined> = CreateRouteOptions extends TOptions ? Route : TOptions extends {
115
+ parent: infer TParent extends Route;
116
+ } ? Route<ToName<TOptions['name']>, ToWithParams<TParent['host']>, 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']>, TOptions extends {
117
+ host: string | WithParams;
118
+ } ? ToWithParams<TOptions['host']> : WithParams<'', {}>, ToWithParams<TOptions['path']>, ToWithParams<TOptions['query']>, ToWithParams<TOptions['hash']>, ToMeta<TOptions['meta']>, ToState<TOptions['state']>, ToMatches<TOptions, TProps>>;
119
+ export declare function combineRoutes(parent: Route, child: Route): Route;
120
+ export {};
@@ -0,0 +1,111 @@
1
+ import { RouterRouteHooks } from '../models/RouterRouteHooks';
2
+ import { CallbackAbortResponse, CallbackContext, CallbackContextAbort, CallbackPushResponse, CallbackRejectResponse, CallbackSuccessResponse } from '../services/createCallbackContext';
3
+ import { ResolvedRoute } from './resolved';
4
+ import { MaybeArray, MaybePromise } from './utilities';
5
+ import { Routes } from './route';
6
+ import { RouterAfterRouteHook, RouterBeforeRouteHook } from './router';
7
+ /**
8
+ * Defines route hooks that can be applied before entering, updating, or leaving a route, as well as after these events.
9
+ */
10
+ export type WithHooks = {
11
+ onBeforeRouteEnter?: MaybeArray<BeforeRouteHook>;
12
+ onBeforeRouteUpdate?: MaybeArray<BeforeRouteHook>;
13
+ onBeforeRouteLeave?: MaybeArray<BeforeRouteHook>;
14
+ onAfterRouteEnter?: MaybeArray<AfterRouteHook>;
15
+ onAfterRouteUpdate?: MaybeArray<AfterRouteHook>;
16
+ onAfterRouteLeave?: MaybeArray<AfterRouteHook>;
17
+ };
18
+ export type BeforeHookContext = {
19
+ to: ResolvedRoute;
20
+ from: ResolvedRoute | null;
21
+ };
22
+ export type RouteHookBeforeRunner = (context: BeforeHookContext) => Promise<BeforeRouteHookResponse>;
23
+ export type AfterHookContext = {
24
+ to: ResolvedRoute;
25
+ from: ResolvedRoute | null;
26
+ };
27
+ export type RouteHookAfterRunner = (context: AfterHookContext) => Promise<AfterRouteHookResponse>;
28
+ export type RouteHookTiming = 'global' | 'component';
29
+ export type BeforeRouteHookRegistration<TRoutes extends Routes> = {
30
+ lifecycle: 'onBeforeRouteEnter' | 'onBeforeRouteUpdate' | 'onBeforeRouteLeave';
31
+ hook: RouterBeforeRouteHook<TRoutes>;
32
+ depth: number;
33
+ };
34
+ export type AddComponentBeforeRouteHook<TRoutes extends Routes> = (hook: BeforeRouteHookRegistration<TRoutes>) => RouteHookRemove;
35
+ export type AfterRouteHookRegistration<TRoutes extends Routes> = {
36
+ lifecycle: 'onAfterRouteEnter' | 'onAfterRouteUpdate' | 'onAfterRouteLeave';
37
+ hook: RouterAfterRouteHook<TRoutes>;
38
+ depth: number;
39
+ };
40
+ export type AddComponentAfterRouteHook<TRoutes extends Routes> = (hook: AfterRouteHookRegistration<TRoutes>) => RouteHookRemove;
41
+ export type AddGlobalRouteHooks<TRoutes extends Routes> = (hooks: RouterRouteHooks<TRoutes>) => void;
42
+ /**
43
+ * Context provided to route hooks, containing context of previous route and functions for triggering rejections and push/replace to another route.
44
+ */
45
+ type RouteHookContext = {
46
+ from: ResolvedRoute | null;
47
+ reject: CallbackContext['reject'];
48
+ push: CallbackContext['push'];
49
+ replace: CallbackContext['replace'];
50
+ };
51
+ /**
52
+ * Context provided to route hooks, containing context of previous route and functions for triggering rejections, push/replace to another route,
53
+ * as well as aborting current route change.
54
+ */
55
+ export type BeforeRouteHookContext = RouteHookContext & {
56
+ abort: CallbackContextAbort;
57
+ };
58
+ /**
59
+ * Context provided to route hooks, containing context of previous route and functions for triggering rejections and push/replace to another route.
60
+ */
61
+ export type AfterRouteHookContext = RouteHookContext;
62
+ /**
63
+ * Represents a function called before a route change, potentially altering the routing operation.
64
+ * @param to - {@link ResolvedRoute} The resolved route the router is navigating to.
65
+ * @param context - {@link BeforeRouteHookContext} The context providing functions and state for the routing operation.
66
+ * @returns Possibly a promise that resolves when the hook's logic has completed.
67
+ */
68
+ export type BeforeRouteHook = (to: ResolvedRoute, context: BeforeRouteHookContext) => MaybePromise<void>;
69
+ /**
70
+ * Represents a function called after a route change has occurred.
71
+ * @param to - {@link ResolvedRoute} The resolved route the router has navigated to.
72
+ * @param context - {@link AfterRouteHookContext} The context providing functions and state for the routing operation.
73
+ * @returns Possibly a promise that resolves when the hook's logic has completed.
74
+ */
75
+ export type AfterRouteHook = (to: ResolvedRoute, context: AfterRouteHookContext) => MaybePromise<void>;
76
+ /**
77
+ * Generic type representing a route hook, which can be either before or after a route change.
78
+ */
79
+ export type RouteHook = BeforeRouteHook | AfterRouteHook;
80
+ /**
81
+ * A function to remove a previously registered route hook.
82
+ */
83
+ export type RouteHookRemove = () => void;
84
+ /**
85
+ * Enumerates the lifecycle events for before route hooks.
86
+ */
87
+ export type BeforeRouteHookLifecycle = 'onBeforeRouteEnter' | 'onBeforeRouteUpdate' | 'onBeforeRouteLeave';
88
+ /**
89
+ * Enumerates the lifecycle events for after route hooks.
90
+ */
91
+ export type AfterRouteHookLifecycle = 'onAfterRouteEnter' | 'onAfterRouteUpdate' | 'onAfterRouteLeave';
92
+ /**
93
+ * Union type for all route hook lifecycle events.
94
+ */
95
+ export type RouteHookLifecycle = BeforeRouteHookLifecycle | AfterRouteHookLifecycle;
96
+ /**
97
+ * Type for responses from a before route hook, which may indicate different outcomes such as success, push, reject, or abort.
98
+ * @template TRoutes - The type of the routes configuration.
99
+ */
100
+ export type BeforeRouteHookResponse = CallbackSuccessResponse | CallbackPushResponse | CallbackRejectResponse | CallbackAbortResponse;
101
+ /**
102
+ * Type for responses from an after route hook, which may indicate different outcomes such as success, push, or reject.
103
+ * @template TRoutes - The type of the routes configuration.
104
+ */
105
+ export type AfterRouteHookResponse = CallbackSuccessResponse | CallbackPushResponse | CallbackRejectResponse;
106
+ /**
107
+ * Union type for all possible route hook responses, covering both before and after scenarios.
108
+ * @template TRoutes - The type of the routes configuration.
109
+ */
110
+ export type RouteHookResponse = BeforeRouteHookResponse | AfterRouteHookResponse;
111
+ export {};
@@ -0,0 +1,2 @@
1
+ import { RouteMeta } from './register';
2
+ export type ToMeta<TMeta extends RouteMeta | undefined> = TMeta extends undefined ? {} : unknown extends TMeta ? {} : TMeta;
@@ -0,0 +1,2 @@
1
+ export type ToName<T extends string | undefined> = T extends string ? T : '';
2
+ export declare function toName<T extends string | undefined>(value: T): ToName<T>;
@@ -0,0 +1,14 @@
1
+ import { ValibotSchemaLike } from '../services/valibot';
2
+ import { ZodSchemaLike } from '../services/zod';
3
+ export type ParamExtras = {
4
+ invalid: (message?: string) => never;
5
+ };
6
+ export type ParamGetter<T = any> = (value: string, extras: ParamExtras) => T;
7
+ export type ParamSetter<T = any> = (value: T, extras: ParamExtras) => string;
8
+ export type ParamGetSet<T = any> = {
9
+ get: ParamGetter<T>;
10
+ set: ParamSetter<T>;
11
+ defaultValue?: T;
12
+ };
13
+ export type LiteralParam = string | number | boolean;
14
+ export type Param = ParamGetter | ParamGetSet | RegExp | BooleanConstructor | NumberConstructor | StringConstructor | DateConstructor | JSON | ZodSchemaLike | ValibotSchemaLike | LiteralParam;
@@ -0,0 +1,71 @@
1
+ import { LiteralParam, Param, ParamGetSet, ParamGetter } from './paramTypes';
2
+ import { Identity } from './utilities';
3
+ import { MakeOptional } from '../utilities/makeOptional';
4
+ import { Route } from './route';
5
+ import { WithParams } from '../services/withParams';
6
+ import { StandardSchemaV1 } from '@standard-schema/spec';
7
+ export declare const paramStart = "[";
8
+ export type ParamStart = typeof paramStart;
9
+ export declare const paramEnd = "]";
10
+ export type ParamEnd = typeof paramEnd;
11
+ /**
12
+ * Type guard to check if a value conforms to the ParamGetter type.
13
+ * @param value - The value to check.
14
+ * @returns True if the value is a function that is not a constructor.
15
+ */
16
+ export declare function isParamGetter(value: Param): value is ParamGetter;
17
+ /**
18
+ * Type guard to check if a value conforms to the ParamGetSet type.
19
+ * @param value - The value to check.
20
+ * @returns True if the value is an object with both 'get' and 'set' functions defined.
21
+ */
22
+ export declare function isParamGetSet(value: Param): value is ParamGetSet;
23
+ /**
24
+ * Type guard to check if a value conforms to the LiteralParam type.
25
+ * @param value - The value to check.
26
+ * @returns True if the value is a string, number, or boolean.
27
+ */
28
+ export declare function isLiteralParam(value: Param): value is LiteralParam;
29
+ /**
30
+ * Extracts the parameter name from a string, handling optional parameters denoted by a leading '?'.
31
+ * @template TParam - The string from which to extract the parameter name.
32
+ * @returns The extracted parameter name, or never if the parameter string is empty.
33
+ */
34
+ export type ExtractParamName<TParam extends PropertyKey> = TParam extends string ? TParam extends `?${infer Param}` ? Param extends '' ? never : Param : TParam extends '' ? never : TParam : never;
35
+ /**
36
+ * Extracts combined types of path and query parameters for a given route, creating a unified parameter object.
37
+ * @template TRoute - The route type from which to extract and merge parameter types.
38
+ * @returns A record of parameter names to their respective types, extracted and merged from both path and query parameters.
39
+ */
40
+ export type ExtractRouteParamTypesReading<TRoute extends Route> = Identity<MakeOptional<ExtractParamTypesReading<TRoute['host']> & ExtractParamTypesReading<TRoute['path']> & ExtractParamTypesReading<TRoute['query']> & ExtractParamTypesReading<TRoute['hash']>>>;
41
+ /**
42
+ * Extracts combined types of path and query parameters for a given route, creating a unified parameter object.
43
+ * Differs from ExtractRouteParamTypesReading in that optional params with defaults will remain optional.
44
+ * @template TRoute - The route type from which to extract and merge parameter types.
45
+ * @returns A record of parameter names to their respective types, extracted and merged from both path and query parameters.
46
+ */
47
+ export type ExtractRouteParamTypesWriting<TRoute extends Route> = Identity<MakeOptional<ExtractParamTypesWriting<TRoute['host']> & ExtractParamTypesWriting<TRoute['path']> & ExtractParamTypesWriting<TRoute['query']> & ExtractParamTypesWriting<TRoute['hash']>>>;
48
+ /**
49
+ * Extracts combined types of path and query parameters for a given route, creating a unified parameter object.
50
+ * @template TParams - The record of parameter types, possibly including undefined.
51
+ * @returns A new type with the appropriate properties marked as optional.
52
+ */
53
+ type ExtractParamTypesReading<TWithParams extends WithParams> = {
54
+ [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]>;
55
+ };
56
+ /**
57
+ * Extracts combined types of path and query parameters for a given route, creating a unified parameter object.
58
+ * Differs from ExtractParamTypesReading in that optional params with defaults will remain optional.
59
+ * @template TParams - The record of parameter types, possibly including undefined.
60
+ * @returns A new type with the appropriate properties marked as optional.
61
+ */
62
+ type ExtractParamTypesWriting<TWithParams extends WithParams> = {
63
+ [K in keyof TWithParams['params']]: TWithParams['value'] extends `${string}${ParamStart}?${K & string}${ParamEnd}${string}` ? ExtractParamType<TWithParams['params'][K]> | undefined : ExtractParamType<TWithParams['params'][K]>;
64
+ };
65
+ /**
66
+ * Extracts the actual type from a parameter type, handling getters and setters.
67
+ * @template TParam - The parameter type.
68
+ * @returns The extracted type, or 'string' as a fallback.
69
+ */
70
+ export type ExtractParamType<TParam extends Param> = Param extends TParam ? unknown : TParam extends ParamGetSet<infer Type> ? Type : TParam extends ParamGetter ? ReturnType<TParam> : TParam extends StandardSchemaV1 ? StandardSchemaV1.InferOutput<TParam> : TParam extends LiteralParam ? TParam : string;
71
+ export {};
@@ -0,0 +1,27 @@
1
+ /**
2
+ * Determines when assets are prefetched.
3
+ * eager: Fetched immediately
4
+ * lazy: Fetched when visible
5
+ */
6
+ export type PrefetchStrategy = 'eager' | 'lazy' | 'intent';
7
+ export type PrefetchConfigOptions = {
8
+ /**
9
+ * When true any component that is wrapped in vue's defineAsyncComponent will be prefetched
10
+ * @default 'eager'
11
+ */
12
+ components?: boolean | PrefetchStrategy;
13
+ /**
14
+ * When true any props for routes will be prefetched
15
+ * @default false
16
+ */
17
+ props?: boolean | PrefetchStrategy;
18
+ };
19
+ /**
20
+ * Determines what assets are prefetched. A boolean enables or disables all prefetching.
21
+ */
22
+ export type PrefetchConfig = boolean | PrefetchStrategy | PrefetchConfigOptions;
23
+ export type PrefetchConfigs = {
24
+ routerPrefetch?: PrefetchConfig;
25
+ routePrefetch?: PrefetchConfig;
26
+ linkPrefetch?: PrefetchConfig;
27
+ };
@@ -0,0 +1,23 @@
1
+ import { CallbackContext } from '../services/createCallbackContext';
2
+ import { PropsGetter } from './createRouteOptions';
3
+ import { Route } from './route';
4
+ /**
5
+ * Context provided to props callback functions
6
+ */
7
+ export type PropsCallbackContext<TParent extends Route | undefined = Route | undefined> = {
8
+ push: CallbackContext['push'];
9
+ replace: CallbackContext['replace'];
10
+ reject: CallbackContext['reject'];
11
+ parent: PropsCallbackParent<TParent>;
12
+ };
13
+ export type PropsCallbackParent<TParent extends Route | undefined = Route | undefined> = Route | undefined extends TParent ? undefined | {
14
+ name: string;
15
+ props: unknown;
16
+ } : TParent extends Route ? {
17
+ name: TParent['name'];
18
+ props: GetParentPropsReturnType<TParent>;
19
+ } : undefined;
20
+ 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> ? {
21
+ [K in keyof TParent['matched']['props']]: ReturnType<TParent['matched']['props'][K]>;
22
+ } : undefined : undefined;
23
+ export {};
@@ -0,0 +1 @@
1
+ export type QuerySource = ConstructorParameters<typeof URLSearchParams>[0];
@@ -0,0 +1,57 @@
1
+ import { BuiltInRejectionType } from '../services/createRouterReject';
2
+ import { Route, Routes } from './route';
3
+ import { Router, RouterOptions } from './router';
4
+ import { RouterPush } from './routerPush';
5
+ import { RouterReplace } from './routerReplace';
6
+ /**
7
+ * Represents the state of currently registered router, and route meta. Used to provide correct type context for
8
+ * components like `RouterLink`, as well as for composables like `useRouter`, `useRoute`, and hooks.
9
+ *
10
+ * @example
11
+ * ```ts
12
+ * declare module '@kitbag/router' {
13
+ * interface Register {
14
+ * router: typeof router
15
+ * routeMeta: { public?: boolean }
16
+ * }
17
+ * }
18
+ * ```
19
+ */
20
+ export interface Register {
21
+ }
22
+ /**
23
+ * Represents the Router property within {@link Register}
24
+ */
25
+ export type RegisteredRouter<T = Register> = T extends {
26
+ router: infer TRouter;
27
+ } ? TRouter : Router;
28
+ /**
29
+ * Represents the Router routes property within {@link Register}
30
+ */
31
+ export type RegisteredRoutes<T = Register> = T extends {
32
+ router: Router<infer TRoutes extends Routes>;
33
+ } ? TRoutes : Route[];
34
+ /**
35
+ * Represents the possible Rejections registered within {@link Register}
36
+ */
37
+ export type RegisteredRejectionType<T = Register> = T extends {
38
+ router: Router<any, infer TOptions extends RouterOptions>;
39
+ } ? keyof TOptions['rejections'] | BuiltInRejectionType : BuiltInRejectionType;
40
+ /**
41
+ * Represents additional metadata associated with a route, customizable via declaration merging.
42
+ */
43
+ export type RouteMeta<T = Register> = T extends {
44
+ routeMeta: infer RouteMeta extends Record<string, unknown>;
45
+ } ? RouteMeta : Record<string, unknown>;
46
+ /**
47
+ * Represents the type for router `push`, with types for routes registered within {@link Register}
48
+ */
49
+ export type RegisteredRouterPush = RouterPush<RegisteredRoutes>;
50
+ /**
51
+ * Represents the type for router `replace`, with types for routes registered within {@link Register}
52
+ */
53
+ export type RegisteredRouterReplace = RouterReplace<RegisteredRoutes>;
54
+ /**
55
+ * Type for Router Reject method. Triggers rejections registered within {@link Register}
56
+ */
57
+ export type RegisteredRouterReject = (type: RegisteredRejectionType) => void;
@@ -0,0 +1 @@
1
+ export {};