opal-vite 0.3.13 → 0.3.14

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: 67f79084fe35586cb8dc0f98103778f6fe8a87a14876dc94d974c5ab434be56d
4
- data.tar.gz: 4f4f7c07407bd93599f9230168992cd16af6f61a708fab7db12a3229300a1f55
3
+ metadata.gz: 70f625bc74c24b95f12fb5fbfddd5f5aee028c1f1953affb73d9bfab639deedf
4
+ data.tar.gz: 416c5805372e4ff28a55005ec0d0fc0cb23e2d2d76cfe81db04e1da5131ac4d5
5
5
  SHA512:
6
- metadata.gz: 2ef2c6d46990c04cc7b7d23267d255a384d4d6b263f7a1d83d47f2a7c82969796edd7d6e1ebcfa6cf209fd1eb53ff83cde108aced69e387b27e7ff9274a08a38
7
- data.tar.gz: 11497fc562b1fc9a1ca9836cbe218988e771576a3bb2258915ceb7440c91aabfeecea843cea34a9f861f2c30498084574ccf94c10a311301c2bdb7130025761c
6
+ metadata.gz: 97ecab260b4b8284f5a07a5bdbb9ede917e5708193348d40c77b2d953be852b3f6b97a5a7405082ce2aec62c3abae0561c9a04960f599d622af8ea1ce801edc0
7
+ data.tar.gz: d51d3a7602afbbc9e3d5cc3898f31f95a9f0c731635074e3d9fe88ae731aadf676f6a9d8e39f5ece06cedca44998fac708983311068fcb38c8c5f2f2a11dc679
@@ -1,5 +1,5 @@
1
1
  module Opal
2
2
  module Vite
3
- VERSION = "0.3.13"
3
+ VERSION = "0.3.14"
4
4
  end
5
5
  end
@@ -318,7 +318,7 @@ module OpalVite
318
318
  json_str = cable_data(data, key)
319
319
  return nil if json_str.nil?
320
320
  `JSON.parse(#{json_str})`
321
- rescue
321
+ rescue Exception
322
322
  nil
323
323
  end
324
324
 
@@ -29,7 +29,7 @@ module OpalVite
29
29
  # @return [String] Base64 encoded string
30
30
  def base64_encode(str)
31
31
  `btoa(#{str})`
32
- rescue
32
+ rescue Exception
33
33
  nil
34
34
  end
35
35
 
@@ -38,7 +38,7 @@ module OpalVite
38
38
  # @return [String] Decoded string
39
39
  def base64_decode(str)
40
40
  `atob(#{str})`
41
- rescue
41
+ rescue Exception
42
42
  nil
43
43
  end
44
44
 
@@ -81,7 +81,7 @@ module OpalVite
81
81
  def base64_encode_unicode(str)
82
82
  # Convert to UTF-8 bytes, then encode
83
83
  `btoa(unescape(encodeURIComponent(#{str})))`
84
- rescue
84
+ rescue Exception
85
85
  nil
86
86
  end
87
87
 
@@ -90,7 +90,7 @@ module OpalVite
90
90
  # @return [String] Decoded Unicode string
91
91
  def base64_decode_unicode(str)
92
92
  `decodeURIComponent(escape(atob(#{str})))`
93
- rescue
93
+ rescue Exception
94
94
  nil
95
95
  end
96
96
 
@@ -108,7 +108,7 @@ module OpalVite
108
108
  }
109
109
  return btoa(binary);
110
110
  `
111
- rescue
111
+ rescue Exception
112
112
  nil
113
113
  end
114
114
 
@@ -124,7 +124,7 @@ module OpalVite
124
124
  }
125
125
  return bytes;
126
126
  `
127
- rescue
127
+ rescue Exception
128
128
  nil
129
129
  end
130
130
 
@@ -202,7 +202,7 @@ module OpalVite
202
202
  return nil unless payload_json
203
203
 
204
204
  `JSON.parse(#{payload_json})`
205
- rescue
205
+ rescue Exception
206
206
  nil
207
207
  end
208
208
 
@@ -264,7 +264,9 @@ module OpalVite
264
264
 
265
265
  len = str.length
266
266
  padding = str.end_with?('==') ? 2 : (str.end_with?('=') ? 1 : 0)
267
- (len * 3 / 4) - padding
267
+ # Use integer division: in Opal `len * 3 / 4` is JS float division, so
268
+ # unpadded/URL-safe input (len % 4 == 2 or 3) would yield e.g. 16.5.
269
+ ((len * 3) / 4).floor - padding
268
270
  end
269
271
  end
270
272
  end
@@ -275,7 +275,10 @@ module OpalVite
275
275
 
276
276
  # Stringify to JSON
277
277
  def to_json(object)
278
- `JSON.stringify(#{object})`
278
+ # Convert Ruby Hash/Array to a native JS value first; passing a raw
279
+ # Opal Hash to JSON.stringify serializes to "{}" (silent data loss).
280
+ native = object.respond_to?(:to_n) ? object.to_n : object
281
+ `JSON.stringify(#{native})`
279
282
  end
280
283
 
281
284
  # ===================
@@ -11,7 +11,7 @@ module OpalVite
11
11
 
12
12
  begin
13
13
  `JSON.parse(stored)`
14
- rescue
14
+ rescue Exception
15
15
  nil
16
16
  end
17
17
  end
@@ -356,7 +356,13 @@ module OpalVite
356
356
  # source = turbo_stream_from("/notifications/stream")
357
357
  # # Turbo will automatically process incoming streams
358
358
  def turbo_stream_from(url)
359
- `window.Turbo.connectStreamSource(new EventSource(#{url}))`
359
+ # Keep a reference to the EventSource and return it: connectStreamSource
360
+ # returns undefined, so returning its result would make the documented
361
+ # `turbo_stream_disconnect(source)` call `undefined.close()` and leak
362
+ # the SSE connection.
363
+ source = `new EventSource(#{url})`
364
+ `window.Turbo.connectStreamSource(#{source})`
365
+ source
360
366
  end
361
367
 
362
368
  # Disconnect a Turbo Stream SSE source
@@ -27,7 +27,7 @@ module OpalVite
27
27
  # @return [Native] JavaScript URL object
28
28
  def parse_url(url_string)
29
29
  `new URL(#{url_string})`
30
- rescue
30
+ rescue Exception
31
31
  nil
32
32
  end
33
33
 
@@ -37,7 +37,7 @@ module OpalVite
37
37
  # @return [Native] JavaScript URL object
38
38
  def parse_url_with_base(url_string, base)
39
39
  `new URL(#{url_string}, #{base})`
40
- rescue
40
+ rescue Exception
41
41
  nil
42
42
  end
43
43
 
@@ -225,7 +225,7 @@ module OpalVite
225
225
  # @return [String] Decoded string
226
226
  def decode_uri_component(str)
227
227
  `decodeURIComponent(#{str})`
228
- rescue
228
+ rescue Exception
229
229
  str
230
230
  end
231
231
 
@@ -241,7 +241,7 @@ module OpalVite
241
241
  # @return [String] Decoded URI
242
242
  def decode_uri(str)
243
243
  `decodeURI(#{str})`
244
- rescue
244
+ rescue Exception
245
245
  str
246
246
  end
247
247
 
@@ -315,7 +315,10 @@ module OpalVite
315
315
 
316
316
  # Stringify to JSON
317
317
  def to_json_string(object)
318
- `JSON.stringify(#{object})`
318
+ # Convert Ruby Hash/Array to a native JS value first; passing a raw
319
+ # Opal Hash to JSON.stringify serializes to "{}" (silent data loss).
320
+ native = object.respond_to?(:to_n) ? object.to_n : object
321
+ `JSON.stringify(#{native})`
319
322
  end
320
323
 
321
324
  # ===================
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: opal-vite
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.13
4
+ version: 0.3.14
5
5
  platform: ruby
6
6
  authors:
7
7
  - stofu1234