ziggy-js 2.6.2 → 2.6.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 CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  # Ziggy – Use your Laravel routes in JavaScript
4
4
 
5
- [![GitHub Actions Status](https://img.shields.io/github/actions/workflow/status/tighten/ziggy/test.yml?branch=main&style=flat)](https://github.com/tighten/ziggy/actions?query=workflow:Test+branch:2.x)
5
+ [![GitHub Actions Status](https://img.shields.io/github/actions/workflow/status/tighten/ziggy/test.yml?style=flat)](https://github.com/tighten/ziggy/actions/workflows/test.yml)
6
6
  [![Latest Version on Packagist](https://img.shields.io/packagist/v/tightenco/ziggy.svg?style=flat)](https://packagist.org/packages/tightenco/ziggy)
7
7
  [![Downloads on Packagist](https://img.shields.io/packagist/dt/tightenco/ziggy.svg?style=flat)](https://packagist.org/packages/tightenco/ziggy)
8
8
  [![Latest Version on NPM](https://img.shields.io/npm/v/ziggy-js.svg?style=flat)](https://npmjs.com/package/ziggy-js)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ziggy-js",
3
- "version": "2.6.2",
3
+ "version": "2.6.3",
4
4
  "description": "Use your Laravel named routes in JavaScript.",
5
5
  "keywords": [
6
6
  "laravel",
package/src/js/index.d.ts CHANGED
@@ -24,9 +24,10 @@ type RouteName = KnownRouteName | (string & {});
24
24
  // See https://stackoverflow.com/a/61048124/6484459.
25
25
 
26
26
  /**
27
- * A generated route URL string.
27
+ * A generated route URL string, branded to distinguish it from a plain string.
28
28
  */
29
- export type RouteUrl = string;
29
+ declare const RouteUrlBrand: unique symbol;
30
+ export type RouteUrl = string & { readonly [RouteUrlBrand]: typeof RouteUrlBrand };
30
31
 
31
32
  /**
32
33
  * A valid route name to pass to `route()` to generate a URL.
@@ -114,16 +115,28 @@ type RouteParamsObject<N extends RouteName> = N extends KnownRouteName
114
115
  type GenericRouteParamsArray = unknown[];
115
116
  /**
116
117
  * An array of parameters for a specific named route.
118
+ *
119
+ * Required parameters come first as required tuple elements, then optional
120
+ * parameters become optional tuple elements, followed by arbitrary extras.
117
121
  */
118
122
  type KnownRouteParamsArray<I extends readonly ParameterInfo[]> = [
119
- ...{ [K in keyof I]: Routable<I[K]> },
120
- ...unknown[],
123
+ ...RequiredParamsTuple<I>,
124
+ ...OptionalParamsTuple<I>,
121
125
  ];
122
- // Because `K in keyof I` for a `readonly` array is always a number, even though this
123
- // looks like `{ 0: T, 1: U, 2: V }` TypeScript generates `[T, U, V]`. The nested
124
- // array destructing lets us type the first n items in the array, which are known
125
- // route parameters, and then allow arbitrary additional items.
126
- // See https://github.com/tighten/ziggy/pull/664#discussion_r1330002370.
126
+
127
+ type RequiredParamsTuple<I extends readonly ParameterInfo[]> =
128
+ I extends readonly [infer F extends ParameterInfo, ...infer R extends ParameterInfo[]]
129
+ ? F extends { required: true }
130
+ ? [Routable<F>, ...RequiredParamsTuple<R>]
131
+ : []
132
+ : [];
133
+
134
+ type OptionalParamsTuple<I extends readonly ParameterInfo[]> =
135
+ I extends readonly [infer F extends ParameterInfo, ...infer R extends ParameterInfo[]]
136
+ ? F extends { required: false }
137
+ ? [Routable<F>?, ...OptionalParamsTuple<R>]
138
+ : OptionalParamsTuple<R>
139
+ : [...unknown[]];
127
140
 
128
141
  // Uncomment to test:
129
142
  // type B = KnownRouteParamsArray<[{ name: 'post'; required: true; binding: 'uuid' }]>;