nuxt-typed-router 3.1.0-beta.0 → 3.1.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.
package/README.md CHANGED
@@ -66,7 +66,7 @@ npm install -D nuxt-typed-router
66
66
  pnpm install -D nuxt-typed-router
67
67
  ```
68
68
 
69
- ### Nuxt 2 legacy
69
+ ### Nuxt 2 legacy (not maintained)
70
70
 
71
71
  Nuxt 2 version is no longer maintained, but still available in [`nuxt2` branch](https://github.com/victorgarciaesgi/nuxt-typed-router/tree/nuxt2)
72
72
  It only has route name autocomplete functionnality
@@ -86,15 +86,6 @@ export default defineNuxtConfig({
86
86
  });
87
87
  ```
88
88
 
89
-
90
- # Roadmap
91
-
92
- - [x] Add `path` autocomplete with TS string templates
93
- - [x] Add support for `validate` and `redirect` in `definePageMeta`
94
- - [x] Add `strict` option to prevent path navigation
95
- - [ ] Enforce strong params typing depending of origin route
96
-
97
-
98
89
  ## Development
99
90
 
100
91
  1. Clone this repository
package/dist/module.json CHANGED
@@ -5,5 +5,5 @@
5
5
  "nuxt": "^3.0.0",
6
6
  "bridge": false
7
7
  },
8
- "version": "3.1.0-beta.0"
8
+ "version": "3.1.0"
9
9
  }
package/dist/module.mjs CHANGED
@@ -365,7 +365,7 @@ function createTypedRouterFile() {
365
365
  /**
366
366
  * Alternative version of {@link TypedRouteLocationRaw} but with a name generic
367
367
  */
368
- export type TypedRouteLocationRawFromName<T extends RoutesNamesList, P extends string = string> =
368
+ export type TypedRouteLocationRawFromName<T extends RoutesNamesList, P extends string = string, E extends boolean = false> =
369
369
  | (Omit<Exclude<RouteLocationRaw, string>, 'name' | 'params'> & TypedLocationAsRelativeRaw<T>)
370
370
  | Omit<RouteLocationPathRaw, 'path'>
371
371
  ${returnIfTrue(
@@ -373,6 +373,11 @@ function createTypedRouterFile() {
373
373
  `& {path?: TypedPathParameter<P>}`
374
374
  )}
375
375
  ${returnIfTrue(!pathCheck && !strictOptions.router.strictToArgument, ` | string`)}
376
+ ${returnIfTrue(
377
+ pathCheck && strictOptions.router.strictToArgument,
378
+ `| (E extends true ? string : void)`
379
+ )}
380
+
376
381
 
377
382
  /**
378
383
  * Generic providing inference and dynamic inclusion of \`params\` property
@@ -387,6 +392,27 @@ function createTypedRouterFile() {
387
392
  : { params: RoutesParamsRecord[T] });
388
393
 
389
394
 
395
+ /**
396
+ * Used for type assertion:
397
+ *
398
+ * @usage
399
+ *
400
+ * \`\`\`ts
401
+ * const myRoute = '/foo' as TypedRouteLocation;
402
+ * \`\`\`
403
+ * */
404
+ export type TypedRouteLocation<T extends string = '/'> =
405
+ | (Omit<Exclude<RouteLocationRaw, string>, 'name' | 'params'> & RoutesNamedLocations)
406
+ | Omit<RouteLocationPathRaw, 'path'>
407
+ ${returnIfTrue(
408
+ pathCheck && !strictOptions.router.strictRouteLocation,
409
+ `& {path?: TypedPathParameter<T>}`
410
+ )}
411
+ ${returnIfTrue(!pathCheck && !strictOptions.router.strictToArgument, ` | string`)}
412
+ ${returnIfTrue(pathCheck && !strictOptions.router.strictToArgument, `| TypedPathParameter<T>`)}
413
+ ;
414
+
415
+
390
416
  /** Augmented Router with typed methods
391
417
  * {@link Router}
392
418
  */
@@ -446,6 +472,8 @@ function createTypedRouterFile() {
446
472
  )}
447
473
  }
448
474
 
475
+
476
+
449
477
 
450
478
 
451
479
  // - Resolved normalized routes for current Location (ex: useRoute and currentRoute)
@@ -544,6 +572,10 @@ function createTypedRouterDefinitionFile() {
544
572
  )}
545
573
  ${returnIfTrue(!pathCheck && !strictOptions.NuxtLink.strictToArgument, ` | string`)}
546
574
  ${returnIfTrue(
575
+ pathCheck && strictOptions.NuxtLink.strictToArgument,
576
+ ` | (E extends true ? string : void)`
577
+ )}
578
+ ${returnIfTrue(
547
579
  pathCheck && !strictOptions.NuxtLink.strictToArgument,
548
580
  ` | (E extends true ? string : TypedPathParameter<T>)`
549
581
  )},
@@ -588,7 +620,8 @@ function createTypedRouterDefinitionFile() {
588
620
  }
589
621
 
590
622
  function createIndexFile() {
591
- const { i18n, pathCheck } = moduleOptionStore;
623
+ const { i18n, i18nOptions, pathCheck } = moduleOptionStore;
624
+ const hasPrefixStrategy = i18n && i18nOptions?.strategy !== "no_prefix";
592
625
  return (
593
626
  /* typescript */
594
627
  `
@@ -598,6 +631,7 @@ function createIndexFile() {
598
631
  TypedResolvedMatcherLocation,
599
632
  TypedRoute,
600
633
  TypedRouteFromName,
634
+ TypedRouteLocation,
601
635
  TypedRouteLocationFromName,
602
636
  TypedRouteLocationRaw,
603
637
  TypedRouteLocationRawFromName,
@@ -621,9 +655,15 @@ function createIndexFile() {
621
655
 
622
656
  ${returnIfTrue(
623
657
  pathCheck,
624
- `export type { ValidatePath, RoutePathSchema, TypedPathParameter, RouteNameFromPath } from './__paths';`
658
+ `export type { ValidatePath, RoutePathSchema, TypedPathParameter, RouteNameFromPath, ${returnIfTrue(
659
+ hasPrefixStrategy,
660
+ `TypedLocalePathParameter`
661
+ )} } from './__paths';`
662
+ )}
663
+ ${returnIfTrue(
664
+ i18n,
665
+ `export {useLocalePath, useLocaleRoute, TypedToLocalePath, TypedLocaleRoute} from './__i18n-router';`
625
666
  )}
626
- ${returnIfTrue(i18n, `export {useLocalePath, useLocaleRoute} from './__i18n-router';`)}
627
667
 
628
668
 
629
669
  `
@@ -737,6 +777,10 @@ function createNavigateToFile() {
737
777
  `import type {TypedPathParameter, RouteNameFromPath} from './__paths';`
738
778
  )}
739
779
 
780
+ type TypedNavigateToOptions<E extends boolean> = Omit<NavigateToOptions, 'external'> & {
781
+ external?: E
782
+ }
783
+
740
784
  /**
741
785
  * Typed clone of \`navigateTo\`
742
786
  *
@@ -749,15 +793,15 @@ function createNavigateToFile() {
749
793
 
750
794
 
751
795
  interface NavigateToFunction {
752
- <T extends RoutesNamesList, P extends string>(
753
- to: TypedRouteLocationRawFromName<T, P>,
754
- options?: NavigateToOptions
796
+ <T extends RoutesNamesList, P extends string, E extends boolean = false>(
797
+ to: TypedRouteLocationRawFromName<T, P, E>,
798
+ options?: TypedNavigateToOptions<E>
755
799
  ) : Promise<void | NavigationFailure | TypedRouteFromName<T>>
756
800
  ${returnIfTrue(
757
801
  pathCheck && !router.strictToArgument,
758
- `<T extends string>(
759
- to: TypedPathParameter<T>,
760
- options?: NavigateToOptions
802
+ `<T extends string, E extends boolean = false>(
803
+ to: (E extends true ? string : TypedPathParameter<T>),
804
+ options?: TypedNavigateToOptions<E>
761
805
  ) : Promise<void | NavigationFailure | TypedRouteFromName<RouteNameFromPath<T>>>`
762
806
  )}
763
807
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nuxt-typed-router",
3
- "version": "3.1.0-beta.0",
3
+ "version": "3.1.0",
4
4
  "description": "Provide autocompletion for routes paths, names and params in Nuxt apps",
5
5
  "type": "module",
6
6
  "main": "./dist/module.cjs",