nuxt-typed-router 3.0.0-beta.2 → 3.0.0-beta.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/module.json +1 -1
- package/dist/module.mjs +126 -50
- package/package.json +1 -1
package/dist/module.json
CHANGED
package/dist/module.mjs
CHANGED
|
@@ -584,6 +584,7 @@ function createIndexFile() {
|
|
|
584
584
|
export { useRouter } from './__useTypedRouter';
|
|
585
585
|
export { navigateTo } from './__navigateTo';
|
|
586
586
|
export { definePageMeta } from './__definePageMeta';
|
|
587
|
+
export { helpers } from './__helpers';
|
|
587
588
|
|
|
588
589
|
${returnIfTrue(
|
|
589
590
|
experimentalPathCheck,
|
|
@@ -591,20 +592,7 @@ function createIndexFile() {
|
|
|
591
592
|
)}
|
|
592
593
|
${returnIfTrue(i18n, `export {useLocalePath, useLocaleRoute} from './__i18n-router';`)}
|
|
593
594
|
|
|
594
|
-
|
|
595
|
-
route(
|
|
596
|
-
to: TypedRouteLocationRawFromName<T, P>,
|
|
597
|
-
): [T] extends [never] ? string : Required<
|
|
598
|
-
(Omit<Exclude<RouteLocationRaw, string>, 'name' | 'params'> & TypedLocationAsRelativeRaw<T>)
|
|
599
|
-
> {
|
|
600
|
-
return to;
|
|
601
|
-
},
|
|
602
|
-
path(
|
|
603
|
-
to: TypedPathParameter<T>,
|
|
604
|
-
) : [T] extends [never] ? string : Required<TypedRouteLocationRawFromName<RouteNameFromPath<T>, T>> {
|
|
605
|
-
return to;
|
|
606
|
-
}
|
|
607
|
-
}
|
|
595
|
+
|
|
608
596
|
`
|
|
609
597
|
);
|
|
610
598
|
}
|
|
@@ -1025,15 +1013,15 @@ function createDefinePageMetaFile() {
|
|
|
1025
1013
|
|
|
1026
1014
|
import { definePageMeta as defaultDefinePageMeta } from '#imports';
|
|
1027
1015
|
import type {PageMeta, NuxtError} from '#app'
|
|
1028
|
-
import type {TypedRouteFromName, TypedRoute, TypedRouteLocationRawFromName} from './__router';
|
|
1029
|
-
import type {RoutesNamesList
|
|
1016
|
+
import type {TypedRouteFromName, TypedRoute, TypedRouteLocationRawFromName, TypedRouteLocationRaw} from './__router';
|
|
1017
|
+
import type {RoutesNamesList} from './__routes';
|
|
1030
1018
|
${returnIfTrue(experimentalPathCheck, `import type {TypedPathParameter} from './__paths';`)}
|
|
1031
1019
|
|
|
1032
1020
|
type FilteredPageMeta = {
|
|
1033
1021
|
[T in keyof PageMeta as [unknown] extends [PageMeta[T]] ? never : T]: PageMeta[T];
|
|
1034
1022
|
}
|
|
1035
1023
|
|
|
1036
|
-
export type TypedPageMeta<T extends RoutesNamesList
|
|
1024
|
+
export type TypedPageMeta<T extends RoutesNamesList> = Omit<FilteredPageMeta, 'redirect' | 'validate' | 'key'> & {
|
|
1037
1025
|
/**
|
|
1038
1026
|
* Validate whether a given route can validly be rendered with this page.
|
|
1039
1027
|
*
|
|
@@ -1043,22 +1031,6 @@ function createDefinePageMetaFile() {
|
|
|
1043
1031
|
* will not be checked).
|
|
1044
1032
|
*/
|
|
1045
1033
|
validate?: (route: [T] extends [never] ? TypedRoute : TypedRouteFromName<T>) => boolean | Promise<boolean> | Partial<NuxtError> | Promise<Partial<NuxtError>>;
|
|
1046
|
-
/**
|
|
1047
|
-
* Where to redirect if the route is directly matched. The redirection happens
|
|
1048
|
-
* before any navigation guard and triggers a new navigation with the new
|
|
1049
|
-
* target location.
|
|
1050
|
-
*/
|
|
1051
|
-
redirect?:
|
|
1052
|
-
| TypedRouteLocationRawFromName<U, P>
|
|
1053
|
-
| ((to: [T] extends [never] ? TypedRoute : TypedRouteFromName<T>)
|
|
1054
|
-
=> TypedRouteLocationRawFromName<any, P> ${returnIfTrue(
|
|
1055
|
-
experimentalPathCheck && !strictOptions.router.strictToArgument,
|
|
1056
|
-
` | TypedPathParameter<P>`
|
|
1057
|
-
)})
|
|
1058
|
-
${returnIfTrue(
|
|
1059
|
-
experimentalPathCheck && !strictOptions.router.strictToArgument,
|
|
1060
|
-
` | TypedPathParameter<P>`
|
|
1061
|
-
)}
|
|
1062
1034
|
key?: false | string | ((route: [T] extends [never] ? TypedRoute : TypedRouteFromName<T>) => string);
|
|
1063
1035
|
}
|
|
1064
1036
|
|
|
@@ -1067,7 +1039,16 @@ function createDefinePageMetaFile() {
|
|
|
1067
1039
|
* Typed clone of \`definePageMeta\`
|
|
1068
1040
|
*
|
|
1069
1041
|
* \u26A0\uFE0F Types for the redirect function may be buggy or not display autocomplete
|
|
1070
|
-
*
|
|
1042
|
+
* Use \`helpers.route\` or \`helpers.path\` to provide autocomplete.
|
|
1043
|
+
*
|
|
1044
|
+
* \`\`\`ts
|
|
1045
|
+
* import {helpers} from '@typed-router';
|
|
1046
|
+
* definePageMeta({
|
|
1047
|
+
* redirect(route) {
|
|
1048
|
+
* return helpers.path('/foo')
|
|
1049
|
+
* }
|
|
1050
|
+
* });
|
|
1051
|
+
* \`\`\`
|
|
1071
1052
|
* @exemple
|
|
1072
1053
|
*
|
|
1073
1054
|
* \`\`\`ts
|
|
@@ -1080,22 +1061,113 @@ function createDefinePageMetaFile() {
|
|
|
1080
1061
|
* });
|
|
1081
1062
|
* \`\`\`
|
|
1082
1063
|
*/
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
}
|
|
1064
|
+
export function definePageMeta<P extends string, U extends RoutesNamesList>(
|
|
1065
|
+
meta: TypedPageMeta<never> & { redirect: TypedRouteLocationRawFromName<U, P> }
|
|
1066
|
+
): void;
|
|
1067
|
+
${returnIfTrue(
|
|
1068
|
+
experimentalPathCheck && !strictOptions.router.strictToArgument,
|
|
1069
|
+
`export function definePageMeta<P extends string>(
|
|
1070
|
+
meta: TypedPageMeta<never> & { redirect: TypedPathParameter<P> }
|
|
1071
|
+
): void;`
|
|
1072
|
+
)}
|
|
1073
|
+
export function definePageMeta<P extends string = string>(
|
|
1074
|
+
meta: TypedPageMeta<never> & {
|
|
1075
|
+
redirect?: (to: TypedRoute) => TypedRouteLocationRaw<P> ${returnIfTrue(
|
|
1076
|
+
experimentalPathCheck && !strictOptions.router.strictToArgument,
|
|
1077
|
+
` | TypedPathParameter<P>`
|
|
1078
|
+
)};
|
|
1079
|
+
}
|
|
1080
|
+
): void;
|
|
1081
|
+
export function definePageMeta<P extends string = string>(
|
|
1082
|
+
meta: TypedPageMeta<never> & {
|
|
1083
|
+
redirect?: () => TypedRouteLocationRaw<P> ${returnIfTrue(
|
|
1084
|
+
experimentalPathCheck && !strictOptions.router.strictToArgument,
|
|
1085
|
+
` | TypedPathParameter<P>`
|
|
1086
|
+
)};
|
|
1087
|
+
}
|
|
1088
|
+
): void;
|
|
1089
|
+
export function definePageMeta<
|
|
1090
|
+
T extends RoutesNamesList,
|
|
1091
|
+
P extends string,
|
|
1092
|
+
U extends RoutesNamesList
|
|
1093
|
+
>(routeName: T, meta: TypedPageMeta<T> & { redirect: TypedRouteLocationRawFromName<U, P> }): void;
|
|
1094
|
+
${returnIfTrue(
|
|
1095
|
+
experimentalPathCheck && !strictOptions.router.strictToArgument,
|
|
1096
|
+
`export function definePageMeta<T extends RoutesNamesList, P extends string>(
|
|
1097
|
+
routeName: T,
|
|
1098
|
+
meta: TypedPageMeta<T> & { redirect: TypedPathParameter<P> }
|
|
1099
|
+
): void;`
|
|
1100
|
+
)}
|
|
1101
|
+
export function definePageMeta<
|
|
1102
|
+
T extends RoutesNamesList,
|
|
1103
|
+
P extends string,
|
|
1104
|
+
U extends RoutesNamesList
|
|
1105
|
+
>(
|
|
1106
|
+
routeName: T,
|
|
1107
|
+
meta: TypedPageMeta<T> & {
|
|
1108
|
+
redirect?: (to: TypedRouteFromName<T>) => TypedRouteLocationRaw<P> ${returnIfTrue(
|
|
1109
|
+
experimentalPathCheck && !strictOptions.router.strictToArgument,
|
|
1110
|
+
` | TypedPathParameter<P>`
|
|
1111
|
+
)};
|
|
1098
1112
|
}
|
|
1113
|
+
): void;
|
|
1114
|
+
export function definePageMeta<T extends RoutesNamesList, P extends string>(
|
|
1115
|
+
routeName: T,
|
|
1116
|
+
meta: TypedPageMeta<T> & {
|
|
1117
|
+
redirect?: () => TypedRouteLocationRaw<P> ${returnIfTrue(
|
|
1118
|
+
experimentalPathCheck && !strictOptions.router.strictToArgument,
|
|
1119
|
+
` | TypedPathParameter<P>`
|
|
1120
|
+
)};
|
|
1121
|
+
}
|
|
1122
|
+
): void;
|
|
1123
|
+
export function definePageMeta(metaOrName: any, meta?: any): void {
|
|
1124
|
+
if (typeof metaOrName === 'string') {
|
|
1125
|
+
return defaultDefinePageMeta(meta as any);
|
|
1126
|
+
} else {
|
|
1127
|
+
return defaultDefinePageMeta(metaOrName as any);
|
|
1128
|
+
}
|
|
1129
|
+
}
|
|
1130
|
+
|
|
1131
|
+
|
|
1132
|
+
`
|
|
1133
|
+
);
|
|
1134
|
+
}
|
|
1135
|
+
|
|
1136
|
+
function createHelpersFile() {
|
|
1137
|
+
const { experimentalPathCheck } = moduleOptionStore;
|
|
1138
|
+
return (
|
|
1139
|
+
/* typescript */
|
|
1140
|
+
`
|
|
1141
|
+
|
|
1142
|
+
|
|
1143
|
+
|
|
1144
|
+
import type { RouteLocationRaw } from 'vue-router';
|
|
1145
|
+
import type { TypedRouteLocationRawFromName, TypedLocationAsRelativeRaw } from './__router';
|
|
1146
|
+
import type { RoutesNamesList } from './__routes';
|
|
1147
|
+
${returnIfTrue(
|
|
1148
|
+
experimentalPathCheck,
|
|
1149
|
+
`import type {TypedPathParameter, RouteNameFromPath} from './__paths';`
|
|
1150
|
+
)}
|
|
1151
|
+
|
|
1152
|
+
export const helpers = {
|
|
1153
|
+
route<T extends RoutesNamesList = never, P extends string = never>(
|
|
1154
|
+
to: TypedRouteLocationRawFromName<T, P>
|
|
1155
|
+
): [T] extends [never]
|
|
1156
|
+
? string
|
|
1157
|
+
: Required<
|
|
1158
|
+
Omit<Exclude<RouteLocationRaw, string>, 'name' | 'params'> & TypedLocationAsRelativeRaw<T>
|
|
1159
|
+
> {
|
|
1160
|
+
return to as any;
|
|
1161
|
+
},
|
|
1162
|
+
path<T extends string = never>(
|
|
1163
|
+
to: TypedPathParameter<T>
|
|
1164
|
+
): [T] extends [never]
|
|
1165
|
+
? string
|
|
1166
|
+
: Required<TypedRouteLocationRawFromName<RouteNameFromPath<T>, T>> {
|
|
1167
|
+
return to as any;
|
|
1168
|
+
},
|
|
1169
|
+
};
|
|
1170
|
+
|
|
1099
1171
|
|
|
1100
1172
|
`
|
|
1101
1173
|
);
|
|
@@ -1203,6 +1275,10 @@ async function saveGeneratedFiles({ outputData }) {
|
|
|
1203
1275
|
fileName: `__routes.ts`,
|
|
1204
1276
|
content: createRoutesTypesFile(outputData)
|
|
1205
1277
|
},
|
|
1278
|
+
{
|
|
1279
|
+
fileName: `__helpers.ts`,
|
|
1280
|
+
content: createHelpersFile()
|
|
1281
|
+
},
|
|
1206
1282
|
{
|
|
1207
1283
|
fileName: "__navigateTo.ts",
|
|
1208
1284
|
content: createNavigateToFile()
|
|
@@ -1490,7 +1566,7 @@ const module = defineNuxtModule({
|
|
|
1490
1566
|
"@typed-router": resolve(`${rootDir}/.nuxt/typed-router`)
|
|
1491
1567
|
};
|
|
1492
1568
|
nuxt.hook("prepare:types", (options) => {
|
|
1493
|
-
options.tsConfig.include?.
|
|
1569
|
+
options.tsConfig.include?.unshift("./typed-router/typed-router.d.ts");
|
|
1494
1570
|
if (moduleOptions.experimentalPathCheck) {
|
|
1495
1571
|
options.tsConfig.vueCompilerOptions = {
|
|
1496
1572
|
jsxTemplates: true,
|