js-routes 2.3.5 → 2.3.6

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5340711dfd4078cf7c63d618dbd4957f58fd79d0e3f82ca6b1f6a0b6cd0381a5
4
- data.tar.gz: 00a7ae1424f6e61211f7bd0cc26f86542c3054c8d17ae062f026da2a44da7b32
3
+ metadata.gz: 3b618b5e9e78d0a6ed8878c737c26c84fdc00c9e26ede9bd01329a042818b816
4
+ data.tar.gz: e86d3fa9a429188ff3d6146ad981cae9ff01f3f2c7113a87dd2fcc601e674c85
5
5
  SHA512:
6
- metadata.gz: '00963c11a5f95f269924111950e8a3f9b9c9fc9347d3a52e745b191de8d6550d9d2d518d32088b3e98eec2e3fe8022f585523b99c71460be2d234f02c0f02cef'
7
- data.tar.gz: 452e998d9c85ce6a7061cf002cd8cac7e77538fd71353fb3ea359f500060628a521dbc3f2e36b0dfdf43d3a4252d59566872914901e5e931ce55c19dca45231a
6
+ metadata.gz: 67a230e2e6500fe55d6e7ed408ecf895d386d920383c34f8dd4fa384dad13bc5d7d96f98d960ac4df0aab3658d638f21d208c90cc547c3a042c9856a1ed1047a
7
+ data.tar.gz: b158b8a4cb4ffa635c63de49e8fd9cb4415938cb21af078f384e36aaf2d90ce5f51661499dbfe4372fd6051e9ebba301bff8c9fd550b354932c5234173429f3a
data/CHANGELOG.md CHANGED
@@ -1,5 +1,23 @@
1
1
  # Changelog
2
2
 
3
+ ## [2.3.6]
4
+
5
+ * Fixed serialization of empty `Array` and empty `Hash`. Fixes [#336](https://github.com/railsware/js-routes/issues/336).
6
+
7
+ ``` javascript
8
+ blog_path({filters: {}, columns: []}) // => /blog
9
+ ```
10
+
11
+ * Support new Rails 8.1 nil parameter serialization.
12
+ [Rails #53962](https://github.com/rails/rails/pull/53962)
13
+ JsRoutes consistently follows current rails version behavior:
14
+
15
+ ``` ruby
16
+ root_path(hello: nil)
17
+ # 8.0 => "/?hello="
18
+ # 8.1 => "/?hello"
19
+ ```
20
+
3
21
  ## [2.3.5]
4
22
 
5
23
  * Support `bigint` route parameter
data/Readme.md CHANGED
@@ -117,15 +117,13 @@ Create webpack ERB config `config/webpack/loaders/erb.js`:
117
117
 
118
118
  ``` javascript
119
119
  module.exports = {
120
- module: {
121
- rules: [
122
- {
123
- test: /\.erb$/,
124
- enforce: 'pre',
125
- loader: 'rails-erb-loader'
126
- },
127
- ]
128
- }
120
+ rules: [
121
+ {
122
+ test: /\.erb$/,
123
+ enforce: "pre",
124
+ loader: "rails-erb-loader",
125
+ },
126
+ ],
129
127
  };
130
128
  ```
131
129
 
@@ -94,6 +94,7 @@ module JsRoutes
94
94
  {
95
95
  'ROUTES_OBJECT' => routes_object,
96
96
  'DEPRECATED_FALSE_PARAMETER_BEHAVIOR' => Rails.version < '7.0.0',
97
+ 'DEPRECATED_NIL_QUERY_PARAMETER_BEHAVIOR' => Rails.version < '8.1.0',
97
98
  'DEFAULT_URL_OPTIONS' => json(@configuration.default_url_options),
98
99
  'PREFIX' => json(prefix),
99
100
  'SPECIAL_OPTIONS_KEY' => json(@configuration.special_options_key),
@@ -1,4 +1,4 @@
1
1
  # typed: strict
2
2
  module JsRoutes
3
- VERSION = "2.3.5"
3
+ VERSION = "2.3.6"
4
4
  end
data/lib/routes.d.ts CHANGED
@@ -62,6 +62,7 @@ declare type ModuleType = "CJS" | "AMD" | "UMD" | "ESM" | "DTS" | "NIL";
62
62
  declare const RubyVariables: {
63
63
  PREFIX: string;
64
64
  DEPRECATED_FALSE_PARAMETER_BEHAVIOR: boolean;
65
+ DEPRECATED_NIL_QUERY_PARAMETER_BEHAVIOR: boolean;
65
66
  SPECIAL_OPTIONS_KEY: string;
66
67
  DEFAULT_URL_OPTIONS: RouteParameters;
67
68
  SERIALIZER: Serializer;
data/lib/routes.js CHANGED
@@ -122,9 +122,6 @@ RubyVariables.WRAPPER(
122
122
  };
123
123
  }
124
124
  default_serializer(value, prefix) {
125
- if (this.is_nullable(value)) {
126
- return "";
127
- }
128
125
  if (!prefix && !this.is_object(value)) {
129
126
  throw new Error("Url parameters should be a javascript hash");
130
127
  }
@@ -140,21 +137,22 @@ RubyVariables.WRAPPER(
140
137
  if (!hasProp(value, key))
141
138
  continue;
142
139
  let prop = value[key];
143
- if (this.is_nullable(prop) && prefix) {
144
- prop = "";
140
+ if (prefix) {
141
+ key = prefix + "[" + key + "]";
145
142
  }
146
- if (this.is_not_nullable(prop)) {
147
- if (prefix) {
148
- key = prefix + "[" + key + "]";
149
- }
150
- result.push(this.default_serializer(prop, key));
143
+ const subvalue = this.default_serializer(prop, key);
144
+ if (subvalue.length) {
145
+ result.push(subvalue);
151
146
  }
152
147
  }
153
148
  }
154
149
  else {
155
- if (this.is_not_nullable(value)) {
156
- result.push(encodeURIComponent(prefix) + "=" + encodeURIComponent("" + value));
157
- }
150
+ result.push(this.is_not_nullable(value) ||
151
+ RubyVariables.DEPRECATED_NIL_QUERY_PARAMETER_BEHAVIOR
152
+ ? encodeURIComponent(prefix) +
153
+ "=" +
154
+ encodeURIComponent("" + (value !== null && value !== void 0 ? value : ""))
155
+ : encodeURIComponent(prefix));
158
156
  }
159
157
  return result.join("&");
160
158
  }
data/lib/routes.ts CHANGED
@@ -79,6 +79,7 @@ type ModuleType = "CJS" | "AMD" | "UMD" | "ESM" | "DTS" | "NIL";
79
79
  declare const RubyVariables: {
80
80
  PREFIX: string;
81
81
  DEPRECATED_FALSE_PARAMETER_BEHAVIOR: boolean;
82
+ DEPRECATED_NIL_QUERY_PARAMETER_BEHAVIOR: boolean;
82
83
  SPECIAL_OPTIONS_KEY: string;
83
84
  DEFAULT_URL_OPTIONS: RouteParameters;
84
85
  SERIALIZER: Serializer;
@@ -246,9 +247,6 @@ RubyVariables.WRAPPER(
246
247
  };
247
248
 
248
249
  default_serializer(value: unknown, prefix?: string | null): string {
249
- if (this.is_nullable(value)) {
250
- return "";
251
- }
252
250
  if (!prefix && !this.is_object(value)) {
253
251
  throw new Error("Url parameters should be a javascript hash");
254
252
  }
@@ -262,22 +260,23 @@ RubyVariables.WRAPPER(
262
260
  for (let key in value) {
263
261
  if (!hasProp(value, key)) continue;
264
262
  let prop = value[key];
265
- if (this.is_nullable(prop) && prefix) {
266
- prop = "";
263
+ if (prefix) {
264
+ key = prefix + "[" + key + "]";
267
265
  }
268
- if (this.is_not_nullable(prop)) {
269
- if (prefix) {
270
- key = prefix + "[" + key + "]";
271
- }
272
- result.push(this.default_serializer(prop, key));
266
+ const subvalue = this.default_serializer(prop, key);
267
+ if (subvalue.length) {
268
+ result.push(subvalue);
273
269
  }
274
270
  }
275
271
  } else {
276
- if (this.is_not_nullable(value)) {
277
- result.push(
278
- encodeURIComponent(prefix) + "=" + encodeURIComponent("" + value)
279
- );
280
- }
272
+ result.push(
273
+ this.is_not_nullable(value) ||
274
+ RubyVariables.DEPRECATED_NIL_QUERY_PARAMETER_BEHAVIOR
275
+ ? encodeURIComponent(prefix) +
276
+ "=" +
277
+ encodeURIComponent("" + (value ?? ""))
278
+ : encodeURIComponent(prefix)
279
+ );
281
280
  }
282
281
  return result.join("&");
283
282
  }
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: js-routes
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.3.5
4
+ version: 2.3.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bogdan Gusiev
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2025-02-13 00:00:00.000000000 Z
11
+ date: 2025-12-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: railties
@@ -144,9 +144,9 @@ licenses:
144
144
  - MIT
145
145
  metadata:
146
146
  bug_tracker_uri: https://github.com/railsware/js-routes/issues
147
- changelog_uri: https://github.com/railsware/js-routes/blob/v2.3.5/CHANGELOG.md
147
+ changelog_uri: https://github.com/railsware/js-routes/blob/v2.3.6/CHANGELOG.md
148
148
  documentation_uri: https://github.com/railsware/js-routes
149
- source_code_uri: https://github.com/railsware/js-routes/tree/v2.3.5/activerecord
149
+ source_code_uri: https://github.com/railsware/js-routes/tree/v2.3.6
150
150
  rubygems_mfa_required: 'true'
151
151
  github_repo: ssh://github.com/railsware/js-routes
152
152
  post_install_message: