js-routes 2.3.4 → 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: b8057000afc83b5ce111428c7aec30249f52ef15872db97527757c94fc7faf6d
4
- data.tar.gz: f7d4b47f6248278cb53b5cac80807d37aec7a51a1c47f1c4711e1e6bd0d2d3ea
3
+ metadata.gz: 3b618b5e9e78d0a6ed8878c737c26c84fdc00c9e26ede9bd01329a042818b816
4
+ data.tar.gz: e86d3fa9a429188ff3d6146ad981cae9ff01f3f2c7113a87dd2fcc601e674c85
5
5
  SHA512:
6
- metadata.gz: 40c3c12d7d4a37089268aebda4b82d2f5d8944d5c16048394c1e38eda270f82f867faed7b129e4c27295bcf8158e998e42b92b552c015303d965c0e2227b0780
7
- data.tar.gz: 0f075f81e3d5c0b3d6ed9315e3a34d34857c9c9bf34f136c6884e95b4ab6c6f37c0ebb4ee767eceba98bad7377bd1f4e0bc5e68019c9179fef32b4a7f57b96ea
6
+ metadata.gz: 67a230e2e6500fe55d6e7ed408ecf895d386d920383c34f8dd4fa384dad13bc5d7d96f98d960ac4df0aab3658d638f21d208c90cc547c3a042c9856a1ed1047a
7
+ data.tar.gz: b158b8a4cb4ffa635c63de49e8fd9cb4415938cb21af078f384e36aaf2d90ce5f51661499dbfe4372fd6051e9ebba301bff8c9fd550b354932c5234173429f3a
data/CHANGELOG.md CHANGED
@@ -1,5 +1,36 @@
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
+
21
+ ## [2.3.5]
22
+
23
+ * Support `bigint` route parameter
24
+
25
+ ``` typescript
26
+ import {nft_path} from "./routes"
27
+
28
+ nft_path(123456789012345678901234567890n)
29
+ // => /nfts/123456789012345678901234567890
30
+ ```
31
+
32
+ * Fix rake task for non-esm modules. [#316](https://github.com/railsware/js-routes/issues/316)
33
+
3
34
  ## [2.3.4]
4
35
 
5
36
  * Fix deprecator usage in `rake js:routes:typescript` [#327](https://github.com/railsware/js-routes/issues/327)
@@ -118,7 +149,7 @@ end
118
149
 
119
150
  ## [2.2.1]
120
151
 
121
- * Improve generator to update route files on `assets:precompile` and add them to `.gitignore by default` [#288](https://github.com/railsware/js-routes/issues/288#issuecomment-1012182815)
152
+ * Improve generator to update route files on `assets:precompile` and add them to `.gitignore` by default [#288](https://github.com/railsware/js-routes/issues/288#issuecomment-1012182815)
122
153
 
123
154
  ## [2.2.0]
124
155
 
data/Readme.md CHANGED
@@ -2,6 +2,8 @@
2
2
 
3
3
  [![CI](https://github.com/railsware/js-routes/actions/workflows/ci.yml/badge.svg)](https://github.com/railsware/js-routes/actions/workflows/ci.yml)
4
4
 
5
+ <img src="/logo.webp" alt="Logo" width="200" height="200">
6
+
5
7
  Generates javascript file that defines all Rails named routes as javascript helpers:
6
8
 
7
9
  ``` js
@@ -115,15 +117,13 @@ Create webpack ERB config `config/webpack/loaders/erb.js`:
115
117
 
116
118
  ``` javascript
117
119
  module.exports = {
118
- module: {
119
- rules: [
120
- {
121
- test: /\.erb$/,
122
- enforce: 'pre',
123
- loader: 'rails-erb-loader'
124
- },
125
- ]
126
- }
120
+ rules: [
121
+ {
122
+ test: /\.erb$/,
123
+ enforce: "pre",
124
+ loader: "rails-erb-loader",
125
+ },
126
+ ],
127
127
  };
128
128
  ```
129
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.4"
3
+ VERSION = "2.3.6"
4
4
  end
data/lib/js_routes.rb CHANGED
@@ -37,8 +37,11 @@ module JsRoutes
37
37
 
38
38
  sig { params(file_name: FileName, typed: T::Boolean, opts: T.untyped).void }
39
39
  def generate!(file_name = configuration.file, typed: false, **opts)
40
- Instance.new(file: file_name, **opts).generate!
41
- definitions!(file_name, **opts) if typed
40
+ instance = Instance.new(file: file_name, **opts)
41
+ instance.generate!
42
+ if typed && instance.configuration.modern?
43
+ definitions!(file_name, **opts)
44
+ end
42
45
  end
43
46
 
44
47
  sig { params(file_name: FileName, opts: T.untyped).void }
data/lib/routes.d.ts CHANGED
@@ -2,7 +2,7 @@ declare type Optional<T> = {
2
2
  [P in keyof T]?: T[P] | null;
3
3
  };
4
4
  declare type Collection<T> = Record<string, T>;
5
- declare type BaseRouteParameter = string | boolean | Date | number;
5
+ declare type BaseRouteParameter = string | boolean | Date | number | bigint;
6
6
  declare type MethodRouteParameter = BaseRouteParameter | (() => BaseRouteParameter);
7
7
  declare type ModelRouteParameter = {
8
8
  id: MethodRouteParameter;
@@ -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
@@ -1,7 +1,7 @@
1
1
  type Optional<T> = { [P in keyof T]?: T[P] | null };
2
2
  type Collection<T> = Record<string, T>;
3
3
 
4
- type BaseRouteParameter = string | boolean | Date | number;
4
+ type BaseRouteParameter = string | boolean | Date | number | bigint;
5
5
  type MethodRouteParameter = BaseRouteParameter | (() => BaseRouteParameter);
6
6
  type ModelRouteParameter =
7
7
  | { id: MethodRouteParameter }
@@ -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.4
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: 2024-12-17 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.4/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.4/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: