ziggy-js 2.4.2 → 2.5.1

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
@@ -550,7 +550,7 @@ Route::get('ziggy', fn () => response()->json(new Ziggy));
550
550
 
551
551
  ### Re-generating the routes file when your app routes change
552
552
 
553
- If you are generating your Ziggy config as a file by running `php artisan ziggy:generate`, you may want to re-run that command when your app's route files change. The example below is a Laravel Mix plugin, but similar functionality could be achieved without Mix. Huge thanks to [Nuno Rodrigues](https://github.com/nacr) for [the idea and a sample implementation](https://github.com/tighten/ziggy/issues/321#issuecomment-689150082). See [#655 for a Vite example](https://github.com/tighten/ziggy/pull/655/files#diff-4aeb78f813e14842fcf95bdace9ced23b8a6eed60b23c165eaa52e8db2f97b61).
553
+ If you are generating your Ziggy config as a file by running `php artisan ziggy:generate`, you may want to re-run that command when your app's route files change. The example below is a Laravel Mix plugin, but similar functionality could be achieved without Mix. Huge thanks to [Nuno Rodrigues](https://github.com/nacr) for [the idea and a sample implementation](https://github.com/tighten/ziggy/issues/321#issuecomment-689150082). See [#655](https://github.com/tighten/ziggy/pull/655/files#diff-4aeb78f813e14842fcf95bdace9ced23b8a6eed60b23c165eaa52e8db2f97b61) or [vite-plugin-ziggy](https://github.com/aniftyco/vite-plugin-ziggy) for Vite examples.
554
554
 
555
555
  <details>
556
556
  <summary>Laravel Mix plugin example</summary>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ziggy-js",
3
- "version": "2.4.2",
3
+ "version": "2.5.1",
4
4
  "description": "Use your Laravel named routes in JavaScript.",
5
5
  "keywords": [
6
6
  "laravel",
package/src/js/index.d.ts CHANGED
@@ -1,5 +1,3 @@
1
- import { ParsedQs } from 'qs';
2
-
3
1
  /**
4
2
  * A list of routes and their parameters and bindings.
5
3
  *
@@ -20,13 +18,16 @@ type KnownRouteName = keyof RouteList;
20
18
  /**
21
19
  * A route name, or any string.
22
20
  */
23
- type RouteName = TypeConfig extends { strictRouteNames: true }
24
- ? KnownRouteName
25
- : KnownRouteName | (string & {});
21
+ type RouteName = KnownRouteName | (string & {});
26
22
  // `(string & {})` prevents TypeScript from reducing this type to just `string`,
27
23
  // which would prevent intellisense from autocompleting known route names.
28
24
  // See https://stackoverflow.com/a/61048124/6484459.
29
25
 
26
+ /**
27
+ * A valid route name to pass to `route()` to generate a URL.
28
+ */
29
+ type ValidRouteName = TypeConfig extends { strictRouteNames: true } ? KnownRouteName : RouteName;
30
+
30
31
  /**
31
32
  * Information about a single route parameter.
32
33
  */
@@ -160,16 +161,21 @@ interface Config {
160
161
  };
161
162
  }
162
163
 
164
+ // qs's parsed query params type, so we don't have to have qs as a dependency
165
+ interface ParsedQs {
166
+ [key: string]: undefined | string | string[] | ParsedQs | ParsedQs[];
167
+ }
168
+
163
169
  /**
164
170
  * Ziggy's Router class.
165
171
  */
166
172
  interface Router {
167
- current(): RouteName | undefined;
168
- current<T extends RouteName>(name: T, params?: ParameterValue | RouteParams<T>): boolean;
173
+ current(): ValidRouteName | undefined;
174
+ current<T extends ValidRouteName>(name: T, params?: ParameterValue | RouteParams<T>): boolean;
169
175
  get params(): Record<string, string>;
170
176
  get routeParams(): Record<string, string>;
171
177
  get queryParams(): ParsedQs;
172
- has<T extends RouteName>(name: T): boolean;
178
+ has<T extends ValidRouteName>(name: T): boolean;
173
179
  }
174
180
 
175
181
  /**
@@ -187,14 +193,14 @@ export function route(
187
193
  ): Router;
188
194
 
189
195
  // Called with a route name and optional additional arguments - returns a URL string
190
- export function route<T extends RouteName>(
196
+ export function route<T extends ValidRouteName>(
191
197
  name: T,
192
198
  params?: RouteParams<T> | undefined,
193
199
  absolute?: boolean,
194
200
  config?: Config,
195
201
  ): string;
196
202
 
197
- export function route<T extends RouteName>(
203
+ export function route<T extends ValidRouteName>(
198
204
  name: T,
199
205
  params?: ParameterValue | undefined,
200
206
  absolute?: boolean,