@kitbag/router 0.22.2 → 0.22.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/compositions/useQueryValue.d.ts +1 -1
- package/dist/kitbag-router.js +1537 -1517
- package/dist/kitbag-router.umd.cjs +3 -3
- package/dist/services/combineHash.d.ts +4 -3
- package/dist/services/combinePath.d.ts +8 -12
- package/dist/services/combineQuery.d.ts +8 -12
- package/dist/services/combineUrl.d.ts +2 -1
- package/dist/services/createRouteHooks.d.ts +2 -1
- package/dist/services/createRouterCallbackContext.d.ts +2 -29
- package/dist/services/createRouterHistory.d.ts +1 -1
- package/dist/services/createRouterReject.d.ts +2 -2
- package/dist/services/createVueAppStore.d.ts +2 -1
- package/dist/services/getParamsForString.d.ts +2 -1
- package/dist/services/params.d.ts +5 -4
- package/dist/services/paramsFinder.d.ts +3 -3
- package/dist/services/routeRegex.d.ts +2 -5
- package/dist/services/urlParser.d.ts +3 -2
- package/dist/services/withParams.d.ts +65 -10
- package/dist/types/createRouteOptions.d.ts +5 -5
- package/dist/types/params.d.ts +2 -7
- package/dist/types/url.d.ts +11 -17
- package/dist/types/utilities.d.ts +0 -1
- package/dist/utilities/array.d.ts +0 -1
- package/dist/utilities/testHelpers.d.ts +246 -90
- package/package.json +2 -2
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { UrlPart } from './withParams';
|
|
2
2
|
import { CombinePath } from './combinePath';
|
|
3
|
-
|
|
4
|
-
export declare function combineHash<TParentHash extends
|
|
3
|
+
type CombineHash<TParent extends UrlPart, TChild extends UrlPart> = CombinePath<TParent, TChild>;
|
|
4
|
+
export declare function combineHash<TParentHash extends UrlPart, TChildHash extends UrlPart>(parentHash: TParentHash, childHash: TChildHash): CombineHash<TParentHash, TChildHash>;
|
|
5
|
+
export {};
|
|
@@ -1,12 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
type
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
params: infer
|
|
7
|
-
} ?
|
|
8
|
-
|
|
9
|
-
params: infer TChildParams extends Record<string, unknown>;
|
|
10
|
-
} ? TParentParams & TChildParams extends Record<string, Param | undefined> ? WithParams<CombinePathString<TParentPath, TChildPath>, TParentParams & TChildParams> : WithParams<CombinePathString<TParentPath, TChildPath>, {}> : WithParams<'', {}> : WithParams<'', {}>;
|
|
11
|
-
export declare function combinePath<TParentPath extends WithParams, TChildPath extends WithParams>(parentPath: TParentPath, childPath: TChildPath): CombinePath<TParentPath, TChildPath>;
|
|
12
|
-
export {};
|
|
1
|
+
import { ToUrlPart, UrlPart, UrlParams } from './withParams';
|
|
2
|
+
import { Identity } from '../types/utilities';
|
|
3
|
+
export type CombinePath<TParent extends UrlPart, TChild extends UrlPart> = ToUrlPart<TParent> extends {
|
|
4
|
+
params: infer TParentParams extends UrlParams;
|
|
5
|
+
} ? ToUrlPart<TChild> extends {
|
|
6
|
+
params: infer TChildParams extends UrlParams;
|
|
7
|
+
} ? TParentParams & TChildParams extends UrlParams ? UrlPart<Identity<TParentParams & TChildParams>> : UrlPart<{}> : UrlPart<{}> : UrlPart<{}>;
|
|
8
|
+
export declare function combinePath<TParentPath extends UrlPart, TChildPath extends UrlPart>(parentPath: TParentPath, childPath: TChildPath): CombinePath<TParentPath, TChildPath>;
|
|
@@ -1,13 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
value: infer TChildQuery extends string;
|
|
10
|
-
params: infer TChildParams extends Record<string, unknown>;
|
|
11
|
-
} ? TParentParams & TChildParams extends Record<string, Param | undefined> ? WithParams<CombineQueryString<TParentQuery, TChildQuery>, TParentParams & TChildParams> : WithParams<CombineQueryString<TParentQuery, TChildQuery>, {}> : WithParams<'', {}> : WithParams<'', {}>;
|
|
12
|
-
export declare function combineQuery<TParentQuery extends WithParams, TChildQuery extends WithParams>(parentQuery: TParentQuery, childQuery: TChildQuery): CombineQuery<TParentQuery, TChildQuery>;
|
|
1
|
+
import { ToUrlPart, UrlPart, UrlParams } from './withParams';
|
|
2
|
+
import { Identity } from '../types/utilities';
|
|
3
|
+
type CombineQuery<TParent extends UrlPart, TChild extends UrlPart> = ToUrlPart<TParent> extends {
|
|
4
|
+
params: infer TParentParams extends UrlParams;
|
|
5
|
+
} ? ToUrlPart<TChild> extends {
|
|
6
|
+
params: infer TChildParams extends UrlParams;
|
|
7
|
+
} ? TParentParams & TChildParams extends UrlParams ? UrlPart<Identity<TParentParams & TChildParams>> : UrlPart<{}> : UrlPart<{}> : UrlPart<{}>;
|
|
8
|
+
export declare function combineQuery<TParentQuery extends UrlPart, TChildQuery extends UrlPart>(parentQuery: TParentQuery, childQuery: TChildQuery): CombineQuery<TParentQuery, TChildQuery>;
|
|
13
9
|
export {};
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { CreateUrlOptions, ToUrl, Url } from '../types/url';
|
|
2
|
-
|
|
2
|
+
import { Identity } from '../types/utilities';
|
|
3
|
+
export type CombineUrl<TParent extends Url, TChild extends Url> = TParent extends Url<infer TParentParams> ? TChild extends Url<infer TChildParams> ? Url<Identity<TParentParams & TChildParams>> : never : never;
|
|
3
4
|
export declare function combineUrl<const TParent extends Url, const TChild extends Url>(parent: TParent, child: TChild): CombineUrl<TParent, TChild>;
|
|
4
5
|
export declare function combineUrl<const TParent extends Url, const TChild extends CreateUrlOptions>(parent: TParent, child: TChild): CombineUrl<TParent, ToUrl<TChild>>;
|
|
@@ -3,7 +3,7 @@ import { Routes } from '../types/route';
|
|
|
3
3
|
import { Hooks } from '../models/hooks';
|
|
4
4
|
import { Rejection } from '../types/rejection';
|
|
5
5
|
import { RouteRedirect } from '../types/redirects';
|
|
6
|
-
|
|
6
|
+
type RouteHooks<TRoutes extends Routes = Routes, TRejections extends Rejection[] = Rejection[]> = {
|
|
7
7
|
redirect: RouteRedirect;
|
|
8
8
|
onBeforeRouteEnter: AddBeforeEnterHook<TRoutes, TRejections>;
|
|
9
9
|
onBeforeRouteUpdate: AddBeforeUpdateHook<TRoutes, TRejections>;
|
|
@@ -15,3 +15,4 @@ export type RouteHooks<TRoutes extends Routes = Routes, TRejections extends Reje
|
|
|
15
15
|
store: Hooks;
|
|
16
16
|
};
|
|
17
17
|
export declare function createRouteHooks(): RouteHooks;
|
|
18
|
+
export {};
|
|
@@ -1,43 +1,15 @@
|
|
|
1
1
|
import { RouterPush } from '../types/routerPush';
|
|
2
2
|
import { RouterReject } from '../types/routerReject';
|
|
3
3
|
import { RouterReplace } from '../types/routerReplace';
|
|
4
|
-
import { BuiltInRejectionType } from './createRouterReject';
|
|
5
|
-
import { AsString } from '../types/utilities';
|
|
6
4
|
import { Routes } from '../types/route';
|
|
7
5
|
import { Rejections } from '../types/rejection';
|
|
8
6
|
import { RouteUpdate } from '../types/routeUpdate';
|
|
9
7
|
import { ResolvedRoute } from '../types/resolved';
|
|
10
|
-
/**
|
|
11
|
-
* Defines the structure of a successful callback response.
|
|
12
|
-
*/
|
|
13
|
-
export type RouterCallbackSuccessResponse = {
|
|
14
|
-
status: 'SUCCESS';
|
|
15
|
-
};
|
|
16
|
-
/**
|
|
17
|
-
* Defines the structure of an aborted callback response.
|
|
18
|
-
*/
|
|
19
|
-
export type RouterCallbackAbortResponse = {
|
|
20
|
-
status: 'ABORT';
|
|
21
|
-
};
|
|
22
|
-
/**
|
|
23
|
-
* Defines the structure of a callback response that results in a push to a new route.
|
|
24
|
-
*/
|
|
25
|
-
export type RouterCallbackPushResponse<TRoutes extends Routes> = {
|
|
26
|
-
status: 'PUSH';
|
|
27
|
-
to: Parameters<RouterPush<TRoutes>>;
|
|
28
|
-
};
|
|
29
|
-
/**
|
|
30
|
-
* Defines the structure of a callback response that results in the rejection of a route transition.
|
|
31
|
-
*/
|
|
32
|
-
export type RouterCallbackRejectResponse<TRejections extends string> = {
|
|
33
|
-
status: 'REJECT';
|
|
34
|
-
type: AsString<TRejections> | BuiltInRejectionType;
|
|
35
|
-
};
|
|
36
8
|
/**
|
|
37
9
|
* A function that can be called to abort a routing operation.
|
|
38
10
|
*/
|
|
39
11
|
export type CallbackContextAbort = () => void;
|
|
40
|
-
|
|
12
|
+
type RouterCallbackContext<TRoutes extends Routes = Routes, TRejections extends Rejections = Rejections> = {
|
|
41
13
|
reject: RouterReject<TRejections>;
|
|
42
14
|
push: RouterPush<TRoutes>;
|
|
43
15
|
replace: RouterReplace<TRoutes>;
|
|
@@ -47,3 +19,4 @@ export type RouterCallbackContext<TRoutes extends Routes = Routes, TRejections e
|
|
|
47
19
|
export declare function createRouterCallbackContext<TRoutes extends Routes, TRejections extends Rejections>({ to }: {
|
|
48
20
|
to: ResolvedRoute;
|
|
49
21
|
}): RouterCallbackContext<TRoutes, TRejections>;
|
|
22
|
+
export {};
|
|
@@ -5,7 +5,7 @@ type NavigationPushOptions = {
|
|
|
5
5
|
};
|
|
6
6
|
type NavigationUpdate = (url: string, options?: NavigationPushOptions) => void;
|
|
7
7
|
type NavigationRefresh = () => void;
|
|
8
|
-
|
|
8
|
+
type RouterHistory = History & {
|
|
9
9
|
update: NavigationUpdate;
|
|
10
10
|
refresh: NavigationRefresh;
|
|
11
11
|
startListening: () => void;
|
|
@@ -4,11 +4,11 @@ import { Rejection } from '../types/rejection';
|
|
|
4
4
|
import { Router } from '../types/router';
|
|
5
5
|
import { RouterReject } from '../types/routerReject';
|
|
6
6
|
export type BuiltInRejectionType = 'NotFound';
|
|
7
|
-
|
|
7
|
+
type RouterSetReject = (type: string | null) => void;
|
|
8
8
|
type GetRejectionRoute = (type: string) => ResolvedRoute;
|
|
9
9
|
export type RouterRejection<T extends Rejection = Rejection> = Ref<T | null>;
|
|
10
10
|
export type RouterRejections<TRouter extends Router> = TRouter['reject'] extends RouterReject<infer TRejections extends Rejection[]> ? TRejections[number] : never;
|
|
11
|
-
|
|
11
|
+
type CreateRouterReject = {
|
|
12
12
|
setRejection: RouterSetReject;
|
|
13
13
|
rejection: RouterRejection;
|
|
14
14
|
getRejectionRoute: GetRejectionRoute;
|
|
@@ -2,7 +2,8 @@ import { App } from 'vue';
|
|
|
2
2
|
export type HasVueAppStore = {
|
|
3
3
|
setVueApp: (app: App) => void;
|
|
4
4
|
};
|
|
5
|
-
|
|
5
|
+
type VueAppStore = HasVueAppStore & {
|
|
6
6
|
runWithContext: <T>(callback: () => T) => T;
|
|
7
7
|
};
|
|
8
8
|
export declare function createVueAppStore(): VueAppStore;
|
|
9
|
+
export {};
|
|
@@ -1,2 +1,3 @@
|
|
|
1
|
+
import { UrlParams } from './withParams';
|
|
1
2
|
import { Param } from '../types/paramTypes';
|
|
2
|
-
export declare function getParamsForString(string?: string, params?: Record<string, Param | undefined>):
|
|
3
|
+
export declare function getParamsForString(string?: string, params?: Record<string, Param | undefined>): UrlParams;
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
+
import { UrlParam } from './withParams';
|
|
1
2
|
import { ExtractParamType } from '../types/params';
|
|
2
3
|
import { Param } from '../types/paramTypes';
|
|
3
4
|
export declare function getParam(params: Record<string, Param | undefined>, paramName: string): Param;
|
|
4
|
-
export declare function getParamValue<T extends Param>(value: string | undefined, param: T
|
|
5
|
-
export declare function safeGetParamValue<T extends Param>(value: string | undefined, param: T
|
|
6
|
-
export declare function safeSetParamValue(value: unknown, param:
|
|
7
|
-
export declare function setParamValue(value: unknown, param
|
|
5
|
+
export declare function getParamValue<T extends Param>(value: string | undefined, param: Partial<UrlParam<T>>): ExtractParamType<T>;
|
|
6
|
+
export declare function safeGetParamValue<T extends Param>(value: string | undefined, param: Partial<UrlParam<T>>): ExtractParamType<T> | undefined;
|
|
7
|
+
export declare function safeSetParamValue(value: unknown, param: Partial<UrlParam>): string | undefined;
|
|
8
|
+
export declare function setParamValue(value: unknown, { param, isOptional }?: Partial<UrlParam>): string;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export declare function getParamValueFromUrl(url: string, path:
|
|
3
|
-
export declare function setParamValueOnUrl(url: string, path:
|
|
1
|
+
import { UrlPart } from './withParams';
|
|
2
|
+
export declare function getParamValueFromUrl(url: string, path: UrlPart, paramName: string): string | undefined;
|
|
3
|
+
export declare function setParamValueOnUrl(url: string, path: UrlPart, paramName: string, value: unknown): string;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { UrlPart } from './withParams';
|
|
1
2
|
export declare const paramRegex = "\\[\\??([\\w-_]+)\\*?\\]";
|
|
2
3
|
export declare const optionalParamRegex = "\\[\\?([\\w-_]+)\\*?\\]";
|
|
3
4
|
export declare const requiredParamRegex = "\\[([\\w-_]+)\\*?\\]";
|
|
@@ -6,17 +7,13 @@ export declare const regexCatchAll = "[^/]*";
|
|
|
6
7
|
export declare const regexGreedyCatchAll = ".*";
|
|
7
8
|
export declare const regexCaptureAll = "([^/]*)";
|
|
8
9
|
export declare const regexGreedyCaptureAll = "(.*)";
|
|
9
|
-
export declare function escapeRegExp(string: string): string;
|
|
10
10
|
export declare function splitByMatches(string: string, regexp: RegExp): string[];
|
|
11
11
|
export declare function generateRouteHostRegexPattern(host: string): RegExp;
|
|
12
12
|
export declare function generateRoutePathRegexPattern(path: string): RegExp;
|
|
13
13
|
export declare function generateRouteHashRegexPattern(hash: string): RegExp;
|
|
14
14
|
export declare function generateRouteQueryRegexPatterns(query: string): RegExp[];
|
|
15
|
-
export declare function replaceParamSyntaxWithCatchAllsAndEscapeRest(value: string): string;
|
|
16
15
|
export declare function replaceParamSyntaxWithCatchAlls(value: string): string;
|
|
17
|
-
export declare function replaceIndividualParamWithCaptureGroup(path:
|
|
18
|
-
export declare function paramIsOptional(path: string, paramName: string): boolean;
|
|
19
|
-
export declare function paramIsGreedy(path: string, paramName: string): boolean;
|
|
16
|
+
export declare function replaceIndividualParamWithCaptureGroup(path: UrlPart, paramName: string): string;
|
|
20
17
|
export declare function isOptionalParamSyntax(value: string): boolean;
|
|
21
18
|
export declare function isRequiredParamSyntax(value: string): boolean;
|
|
22
19
|
export declare function isGreedyParamSyntax(value: string): boolean;
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { QuerySource } from '../types/querySource';
|
|
2
2
|
import { UrlString } from '../types/urlString';
|
|
3
|
-
|
|
3
|
+
type UrlParts = {
|
|
4
4
|
host?: string;
|
|
5
5
|
path: string;
|
|
6
6
|
query: URLSearchParams;
|
|
7
7
|
hash: string;
|
|
8
8
|
};
|
|
9
|
-
|
|
9
|
+
type UrlPartsInput = {
|
|
10
10
|
host?: string;
|
|
11
11
|
path?: string;
|
|
12
12
|
query?: QuerySource;
|
|
@@ -16,3 +16,4 @@ export declare function stringifyUrl(parts: UrlPartsInput): UrlString;
|
|
|
16
16
|
export declare function parseUrl(value: string): UrlParts;
|
|
17
17
|
export declare function updateUrl(url: string, updates: UrlPartsInput): UrlString;
|
|
18
18
|
export declare function updateUrl(url: Partial<UrlParts>, updates: UrlPartsInput): UrlParts;
|
|
19
|
+
export {};
|
|
@@ -1,15 +1,70 @@
|
|
|
1
|
-
import { ExtractParamName, ParamEnd, ParamStart } from '../types/params';
|
|
1
|
+
import { ExtractParamName, ParamEnd, ParamIsGreedy, ParamIsOptional, ParamStart } from '../types/params';
|
|
2
2
|
import { Param } from '../types/paramTypes';
|
|
3
3
|
import { Identity } from '../types/utilities';
|
|
4
4
|
import { MakeOptional } from '../utilities/makeOptional';
|
|
5
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 ?
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
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 ? TParams[ExtractParamName<TParam>] extends Param ? Record<ExtractParamName<TParam>, {
|
|
7
|
+
param: TParams[ExtractParamName<TParam>];
|
|
8
|
+
isOptional: ParamIsOptional<TParam>;
|
|
9
|
+
isGreedy: ParamIsGreedy<TParam>;
|
|
10
|
+
}> & WithParamsParamsOutput<Rest, TParams> : Record<ExtractParamName<TParam>, {
|
|
11
|
+
param: StringConstructor;
|
|
12
|
+
isOptional: ParamIsOptional<TParam>;
|
|
13
|
+
isGreedy: ParamIsGreedy<TParam>;
|
|
14
|
+
}> & WithParamsParamsOutput<Rest, TParams> : Record<ExtractParamName<TParam>, {
|
|
15
|
+
param: StringConstructor;
|
|
16
|
+
isOptional: ParamIsOptional<TParam>;
|
|
17
|
+
isGreedy: ParamIsGreedy<TParam>;
|
|
18
|
+
}> & WithParamsParamsOutput<Rest, TParams> : {};
|
|
19
|
+
declare const UrlPartsWithParamsSymbol: unique symbol;
|
|
20
|
+
export type UrlParam<TParam extends Param = Param> = {
|
|
21
|
+
param: TParam;
|
|
22
|
+
isOptional: boolean;
|
|
23
|
+
isGreedy: boolean;
|
|
24
|
+
};
|
|
25
|
+
export type RequiredUrlParam<TParam extends Param = Param> = {
|
|
26
|
+
param: TParam;
|
|
27
|
+
isOptional: false;
|
|
28
|
+
isGreedy: false;
|
|
29
|
+
};
|
|
30
|
+
export type OptionalUrlParam<TParam extends Param = Param> = {
|
|
31
|
+
param: TParam;
|
|
32
|
+
isOptional: true;
|
|
33
|
+
isGreedy: false;
|
|
34
|
+
};
|
|
35
|
+
export type UrlParams = Record<string, UrlParam>;
|
|
36
|
+
export type UrlPart<TParams extends UrlParams = UrlParams> = {
|
|
37
|
+
value: string;
|
|
38
|
+
params: TParams;
|
|
39
|
+
[UrlPartsWithParamsSymbol]: true;
|
|
40
|
+
};
|
|
41
|
+
export type ToUrlPart<T extends string | UrlPart | undefined> = T extends string ? UrlPart<WithParamsParamsOutput<T>> : T extends undefined ? UrlPart<{}> : unknown extends T ? UrlPart<{}> : T;
|
|
42
|
+
export declare function toUrlPart<T extends string | UrlPart | undefined>(value: T): ToUrlPart<T>;
|
|
43
|
+
export declare function withParams<const TValue extends string, const TParams extends MakeOptional<WithParamsParamsInput<TValue>>>(value: TValue, params: TParams): UrlPart<WithParamsParamsOutput<TValue, TParams>>;
|
|
44
|
+
export declare function withParams(): UrlPart<{}>;
|
|
45
|
+
/**
|
|
46
|
+
* Type for query source that can be converted to a UrlPart object.
|
|
47
|
+
* Supports
|
|
48
|
+
* { query: 'foo=bar' }
|
|
49
|
+
* { query: 'foo=[bar]' }
|
|
50
|
+
* { query: { foo: 'bar' } }
|
|
51
|
+
* { query: [['foo', 'bar']] }
|
|
52
|
+
* { query: { foo: Param } }
|
|
53
|
+
* { query: [[ 'foo', Param ]] }
|
|
54
|
+
*/
|
|
55
|
+
export type UrlQueryPart = UrlPart | Record<string, Param> | [string, Param][];
|
|
56
|
+
export type ToUrlQueryPart<T extends UrlQueryPart | string | undefined> = T extends string ? UrlPart<WithParamsParamsOutput<T>> : T extends UrlPart ? T : T extends undefined ? UrlPart<{}> : T extends Record<string, string | Param> ? UrlPart<QueryRecordToUrlPart<T>> : T extends [string, string | Param][] ? UrlPart<QueryArrayToUrlPart<T>> : UrlPart<{}>;
|
|
57
|
+
type QueryRecordToUrlPart<T extends Record<string, Param>> = {
|
|
58
|
+
[K in keyof T as T[K] extends string ? never : ExtractParamName<K & string>]: {
|
|
59
|
+
param: T[K];
|
|
60
|
+
isOptional: ParamIsOptional<K & string>;
|
|
61
|
+
isGreedy: false;
|
|
62
|
+
};
|
|
63
|
+
};
|
|
64
|
+
type QueryArrayToUrlPart<T extends [string, string | Param][]> = T extends [infer First extends [string, string | Param], ...infer Rest extends [string, string | Param][]] ? First extends [string, string] ? {} : First extends [infer TKey extends string, infer TValue extends Param] ? Identity<Record<ExtractParamName<TKey>, {
|
|
65
|
+
param: TValue;
|
|
66
|
+
isOptional: ParamIsOptional<TKey>;
|
|
67
|
+
isGreedy: false;
|
|
68
|
+
}> & QueryArrayToUrlPart<Rest>> : never : {};
|
|
69
|
+
export declare function toUrlQueryPart<T extends UrlQueryPart | string | undefined>(querySource: T): ToUrlQueryPart<T>;
|
|
15
70
|
export {};
|
|
@@ -12,12 +12,12 @@ import { MaybePromise } from './utilities';
|
|
|
12
12
|
import { ToMeta } from './meta';
|
|
13
13
|
import { ToState } from './state';
|
|
14
14
|
import { ToName } from './name';
|
|
15
|
-
import {
|
|
15
|
+
import { UrlPart, UrlQueryPart } from '../services/withParams';
|
|
16
16
|
import { RouteContext, ToRouteContext } from './routeContext';
|
|
17
17
|
import { RouterViewProps } from '../components/routerView';
|
|
18
18
|
import { ToUrl } from './url';
|
|
19
19
|
import { CombineUrl } from '../services/combineUrl';
|
|
20
|
-
export type WithHost<THost extends string |
|
|
20
|
+
export type WithHost<THost extends string | UrlPart = string | UrlPart> = {
|
|
21
21
|
/**
|
|
22
22
|
* Host part of URL.
|
|
23
23
|
*/
|
|
@@ -53,15 +53,15 @@ export type CreateRouteOptions<TName extends string | undefined = string | undef
|
|
|
53
53
|
/**
|
|
54
54
|
* Path part of URL.
|
|
55
55
|
*/
|
|
56
|
-
path?: string |
|
|
56
|
+
path?: string | UrlPart | undefined;
|
|
57
57
|
/**
|
|
58
58
|
* Query (aka search) part of URL.
|
|
59
59
|
*/
|
|
60
|
-
query?: string |
|
|
60
|
+
query?: string | UrlQueryPart | undefined;
|
|
61
61
|
/**
|
|
62
62
|
* Hash part of URL.
|
|
63
63
|
*/
|
|
64
|
-
hash?: string |
|
|
64
|
+
hash?: string | UrlPart | undefined;
|
|
65
65
|
/**
|
|
66
66
|
* Represents additional metadata associated with a route, customizable via declaration merging.
|
|
67
67
|
*/
|
package/dist/types/params.d.ts
CHANGED
|
@@ -22,13 +22,6 @@ export declare function isParamGetSet(value: Param): value is ParamGetSet;
|
|
|
22
22
|
* @returns True if the value is a string, number, or boolean.
|
|
23
23
|
*/
|
|
24
24
|
export declare function isLiteralParam(value: Param): value is LiteralParam;
|
|
25
|
-
/**
|
|
26
|
-
* Determines if a given value is an optional parameter template.
|
|
27
|
-
* @template TKey - The key of the parameter.
|
|
28
|
-
* @template TValue - The value of the parameter.
|
|
29
|
-
* @returns True if the value is an optional parameter template.
|
|
30
|
-
*/
|
|
31
|
-
export type IsOptionalParamTemplate<TKey extends string, TValue extends string> = TValue extends `${string}${ParamStart}?${TKey}${ParamEnd}${string}` ? true : TValue extends `${string}${ParamStart}?${TKey}*${ParamEnd}${string}` ? true : false;
|
|
32
25
|
/**
|
|
33
26
|
* Extracts the parameter name from a string, handling optional parameters denoted by a leading '?'.
|
|
34
27
|
* @template TParam - The string from which to extract the parameter name.
|
|
@@ -41,3 +34,5 @@ export type ExtractParamName<TParam extends PropertyKey> = TParam extends string
|
|
|
41
34
|
* @returns The extracted type, or 'string' as a fallback.
|
|
42
35
|
*/
|
|
43
36
|
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;
|
|
37
|
+
export type ParamIsOptional<TParam extends string> = TParam extends `?${string}` ? true : false;
|
|
38
|
+
export type ParamIsGreedy<TParam extends string> = TParam extends `${string}*` ? true : false;
|
package/dist/types/url.d.ts
CHANGED
|
@@ -1,29 +1,23 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { ExtractParamType
|
|
1
|
+
import { OptionalUrlParam, UrlQueryPart, ToUrlQueryPart, RequiredUrlParam, ToUrlPart, UrlParams, UrlPart } from '../services/withParams';
|
|
2
|
+
import { ExtractParamType } from './params';
|
|
3
3
|
import { AllPropertiesAreOptional, Identity } from './utilities';
|
|
4
4
|
import { UrlString } from './urlString';
|
|
5
|
-
import {
|
|
5
|
+
import { ParamGetSet } from './paramTypes';
|
|
6
6
|
import { MakeOptional } from '../utilities/makeOptional';
|
|
7
7
|
export declare const IS_URL_SYMBOL: unique symbol;
|
|
8
8
|
export type CreateUrlOptions = {
|
|
9
|
-
host?: string |
|
|
10
|
-
path?: string |
|
|
11
|
-
query?: string |
|
|
12
|
-
hash?: string |
|
|
13
|
-
};
|
|
14
|
-
export type ToUrl<TOptions extends CreateUrlOptions> = Url<ToUrlParams<ToWithParams<TOptions['host']>> & ToUrlParams<ToWithParams<TOptions['path']>> & ToUrlParams<ToWithParams<TOptions['query']>> & ToUrlParams<ToWithParams<TOptions['hash']>>>;
|
|
15
|
-
type OptionalParam<TParam extends Param = Param> = [param: TParam, isOptional: true];
|
|
16
|
-
type RequiredParam<TParam extends Param = Param> = [param: TParam, isOptional: false];
|
|
17
|
-
type UrlParams = Record<string, OptionalParam | RequiredParam>;
|
|
18
|
-
type ToUrlParams<TWithParams extends WithParams> = {
|
|
19
|
-
[K in keyof TWithParams['params']]: [TWithParams['params'][K], IsOptionalParamTemplate<K & string, TWithParams['value']>];
|
|
9
|
+
host?: string | UrlPart | undefined;
|
|
10
|
+
path?: string | UrlPart | undefined;
|
|
11
|
+
query?: string | UrlQueryPart | undefined;
|
|
12
|
+
hash?: string | UrlPart | undefined;
|
|
20
13
|
};
|
|
14
|
+
export type ToUrl<TOptions extends CreateUrlOptions> = Url<Identity<ToUrlPart<TOptions['host']>['params'] & ToUrlPart<TOptions['path']>['params'] & ToUrlQueryPart<TOptions['query']>['params'] & ToUrlPart<TOptions['hash']>['params']>>;
|
|
21
15
|
/**
|
|
22
16
|
* Type guard to assert that a url has a schema.
|
|
23
17
|
* @internal
|
|
24
18
|
*/
|
|
25
19
|
export declare function isUrlWithSchema(url: unknown): url is Url & {
|
|
26
|
-
schema: Record<string,
|
|
20
|
+
schema: Record<string, UrlPart>;
|
|
27
21
|
};
|
|
28
22
|
/**
|
|
29
23
|
* Represents the structure of a url parts. Can be used to create a url with support for params.
|
|
@@ -71,7 +65,7 @@ type UrlParamsArgs<TParams extends UrlParams> = AllPropertiesAreOptional<ToUrlPa
|
|
|
71
65
|
*/
|
|
72
66
|
export type UrlParamsReading<TUrl extends Url> = ToUrlParamsReading<TUrl['params']>;
|
|
73
67
|
type ToUrlParamsReading<TParams extends UrlParams> = Identity<MakeOptional<{
|
|
74
|
-
[K in keyof TParams]: TParams[K] extends
|
|
68
|
+
[K in keyof TParams]: TParams[K] extends OptionalUrlParam<infer TParam> ? TParam extends Required<ParamGetSet> ? ExtractParamType<TParam> : ExtractParamType<TParam> | undefined : TParams[K] extends RequiredUrlParam<infer TParam> ? ExtractParamType<TParam> : unknown;
|
|
75
69
|
}>>;
|
|
76
70
|
/**
|
|
77
71
|
* Extracts combined types of path and query parameters for a given url, creating a unified parameter object.
|
|
@@ -81,6 +75,6 @@ type ToUrlParamsReading<TParams extends UrlParams> = Identity<MakeOptional<{
|
|
|
81
75
|
*/
|
|
82
76
|
export type UrlParamsWriting<TUrl extends Url> = ToUrlParamsWriting<TUrl['params']>;
|
|
83
77
|
type ToUrlParamsWriting<TParams extends UrlParams> = Identity<MakeOptional<{
|
|
84
|
-
[K in keyof TParams]: TParams[K] extends
|
|
78
|
+
[K in keyof TParams]: TParams[K] extends OptionalUrlParam<infer TParam> ? ExtractParamType<TParam> | undefined : TParams[K] extends RequiredUrlParam<infer TParam> ? ExtractParamType<TParam> : unknown;
|
|
85
79
|
}>>;
|
|
86
80
|
export {};
|
|
@@ -2,7 +2,6 @@ export type Identity<T> = T extends object ? {} & {
|
|
|
2
2
|
[P in keyof T as T[P] extends never ? never : P]: T[P];
|
|
3
3
|
} : T;
|
|
4
4
|
type IsEmptyObject<T> = T extends Record<string, never> ? (keyof T extends never ? true : false) : false;
|
|
5
|
-
export type MaybeArray<T> = T | T[];
|
|
6
5
|
export type LastInArray<T, TFallback = never> = T extends [...any[], infer Last] ? Last : TFallback;
|
|
7
6
|
export type MaybePromise<T> = T | Promise<T>;
|
|
8
7
|
type OnlyRequiredProperties<T> = {
|