ruby_event_store-browser 3.2.0 → 3.3.0

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: 76e9c3cd6aa4cecec6df20a2e2a0ebb295134adb1f3f83dcf85d49a31dae8d1e
4
- data.tar.gz: 19f15eefc78180491385a727975edb8a3e3d92a53a0fceb8385fb9890120af02
3
+ metadata.gz: db6f09e74e225a99692afd10ae4d1e1687cad11009249ae162b592fdb251bfc3
4
+ data.tar.gz: 91f1943b8f68fcbf090841858da5841856a5ca0e73370df23342ee64c49f49f4
5
5
  SHA512:
6
- metadata.gz: 9b2ac619bc01532ca77d1aaa959e82cb9078d1edbdcf33a36a54a0d57a5e20649469f2bcbc3569c71af4ef3dbc35a8a84b831bb774a781ee696569bcb863c931
7
- data.tar.gz: 3e0ccc68600358b643d1b77d952a78ad19921953bd52831de3f9efefe11f8708c88ea541bd428deef794c00ab28085653d73c522e458a0adf125dca21240685d
6
+ metadata.gz: d04dfd57ddc9dc1046b9a9ed21695ae322ee7464c3effa26c1bc6d54a01f54afac4ba7a2aabeaadd8ff922ec1a4ab137426ea3dc7ea1fd2ee72c74dfa07afd12
7
+ data.tar.gz: 4fa662f027fc5f0b818d73aa485c2147d449901006567386149a76b727192e934cc78b49403e4106f876bdefffd9f757d4ded7f81104919f10ec4298e8292349
@@ -8,9 +8,30 @@ module RubyEventStore
8
8
  class Renderer
9
9
  VIEWS_ROOT = File.expand_path("views", __dir__).freeze
10
10
 
11
+ Html = Class.new(String)
12
+
13
+ class Compiler < ERB::Compiler
14
+ def add_insert_cmd(out, content)
15
+ out.push("#{@insert_cmd}(h((#{content})))")
16
+ end
17
+ end
18
+
19
+ class Template < ERB
20
+ def make_compiler(trim_mode)
21
+ Compiler.new(trim_mode)
22
+ end
23
+ end
24
+
11
25
  class Context
12
26
  include ERB::Util
13
- alias_method :h, :html_escape
27
+
28
+ def h(value)
29
+ value.instance_of?(Html) ? value : Html.new(html_escape(value))
30
+ end
31
+
32
+ def raw(value)
33
+ Html.new(value)
34
+ end
14
35
 
15
36
  def initialize(renderer, locals)
16
37
  @_renderer = renderer
@@ -39,9 +60,45 @@ module RubyEventStore
39
60
  end
40
61
  end
41
62
 
63
+ def json_tree(value)
64
+ Html.new(append_json_value(+"", value))
65
+ end
66
+
42
67
  def get_binding
43
68
  binding
44
69
  end
70
+
71
+ private
72
+
73
+ def append_json_value(html, value)
74
+ if value.is_a?(Hash) && !value.empty?
75
+ html << '{<ul class="list-none ml-[26px] pl-0">'
76
+ value.sort_by { |key, _| key.to_s }.each do |key, child|
77
+ html << '<li class="relative"><span class="font-bold whitespace-pre">' << h(key) << "</span>: "
78
+ append_json_value(html, child)
79
+ html << ",</li>"
80
+ end
81
+ html << "</ul>}"
82
+ elsif value.is_a?(Array) && !value.empty?
83
+ html << '[<ul class="list-none ml-[26px] pl-0">'
84
+ value.each do |child|
85
+ html << '<li class="relative">'
86
+ append_json_value(html, child)
87
+ html << ",</li>"
88
+ end
89
+ html << "</ul>]"
90
+ else
91
+ color =
92
+ case value
93
+ when String then "text-[green]"
94
+ when Numeric then "text-[blue]"
95
+ when true, false then "text-[firebrick]"
96
+ when nil then "text-[gray]"
97
+ else ""
98
+ end
99
+ html << '<span class="whitespace-pre ' << color << '">' << h(safe_json(value)) << "</span>"
100
+ end
101
+ end
45
102
  end
46
103
 
47
104
  def initialize(views_roots = [VIEWS_ROOT])
@@ -50,7 +107,7 @@ module RubyEventStore
50
107
 
51
108
  def render(template, **locals)
52
109
  context = Context.new(self, locals)
53
- ERB.new(File.read(template_path(template)), trim_mode: "-").result(context.get_binding)
110
+ Html.new(Template.new(File.read(template_path(template)), trim_mode: "-").result(context.get_binding))
54
111
  end
55
112
 
56
113
  private
@@ -20,7 +20,7 @@ module RubyEventStore
20
20
 
21
21
  path_info = request.path_info
22
22
  match_data = regexp.match(path_info.start_with?("/") ? path_info : "/#{path_info}")
23
- match_data.named_captures.transform_values { |v| Rack::Utils.unescape(v) } if match_data
23
+ match_data.named_captures.transform_values { |v| Rack::Utils.unescape_path(v).force_encoding(Encoding::UTF_8) } if match_data
24
24
  end
25
25
 
26
26
  def call(params, urls)
@@ -24,11 +24,11 @@ module RubyEventStore
24
24
  end
25
25
 
26
26
  def stream_url(stream_name)
27
- "#{app_url}/streams/#{Rack::Utils.escape(stream_name)}"
27
+ "#{app_url}/streams/#{ERB::Util.url_encode(stream_name)}"
28
28
  end
29
29
 
30
30
  def event_url(event_id)
31
- "#{app_url}/events/#{event_id}"
31
+ app_url_for("events", event_id)
32
32
  end
33
33
 
34
34
  def stream_page_url(stream_name, cursor, count)
@@ -48,7 +48,7 @@ module RubyEventStore
48
48
  end
49
49
 
50
50
  def app_url_for(*segments, query: nil)
51
- path = segments.map { |segment| Rack::Utils.escape(segment) }.join("/")
51
+ path = segments.map { |segment| ERB::Util.url_encode(segment) }.join("/")
52
52
  query ? "#{app_url}/#{path}?#{URI.encode_www_form(query)}" : "#{app_url}/#{path}"
53
53
  end
54
54
 
@@ -2,6 +2,6 @@
2
2
 
3
3
  module RubyEventStore
4
4
  module Browser
5
- VERSION = "3.2.0"
5
+ VERSION = "3.3.0"
6
6
  end
7
7
  end
@@ -1 +1 @@
1
- <div class="font-[monospace] whitespace-pre">{<ul class="list-none ml-[26px] pl-0"><% hash.sort_by { |key, _| key.to_s }.each do |key, value| %><li class="relative"><span class="font-bold"><%= h(key) %></span>: <span class="<%= case value when String then "text-[green]" when Numeric then "text-[blue]" when true, false then "text-[firebrick]" when nil then "text-[gray]" else "text-gray-800" end %>"><%= h(safe_json(value)) %></span>,</li><% end %></ul>}</div>
1
+ <div class="font-[monospace] whitespace-nowrap"><%= json_tree(hash) %></div>
@@ -1,7 +1,7 @@
1
1
  <section class="space-y-4">
2
2
  <header class="flex justify-between border-gray-400 border-b text-xs pb-2">
3
3
  <h2 class="text-gray-500 uppercase font-bold"><%= title %></h2>
4
- <button data-controller="clipboard" data-clipboard-text-value="<%= h(safe_json(hash)) %>" data-action="clipboard#copy" class="text-red-700 no-underline"><%= render("_clipboard_icon", classes: "text-gray-400 hover:text-red-700", size: 16) %></button>
4
+ <button data-controller="clipboard" data-clipboard-text-value="<%= safe_json(hash) %>" data-action="clipboard#copy" class="text-red-700 no-underline"><%= render("_clipboard_icon", classes: "text-gray-400 hover:text-red-700", size: 16) %></button>
5
5
  </header>
6
6
  <div class="overflow-auto w-full">
7
7
  <%= render("_json_tree", hash: hash) %>
@@ -1,7 +1,7 @@
1
1
  <div class="py-8 md:py-12 container mx-auto space-y-10">
2
2
  <header class="flex items-start justify-between gap-4 flex-wrap md:flex-nowrap">
3
3
  <div class="flex flex-col items-start">
4
- <h1 class="font-bold text-2xl break-words min-w-0 mb-2"><%= h(event.event_type) %></h1>
4
+ <h1 class="font-bold text-2xl break-words min-w-0 mb-2"><%= event.event_type %></h1>
5
5
  <p class="flex gap-2 md:items-center min-w-0 text-sm flex-wrap mb-4">
6
6
  <span class="whitespace-nowrap text-xs text-gray-500 uppercase font-bold">Event ID:</span>
7
7
  <button data-controller="clipboard" data-clipboard-text-value="<%= event.event_id %>" data-action="clipboard#copy" class="flex items-center text-left gap-2 group font-mono text-gray-800 font-bold text-sm">
@@ -12,7 +12,7 @@
12
12
  <% if extension_links.any? -%>
13
13
  <div class="flex gap-2">
14
14
  <% extension_links.each do |link| -%>
15
- <a class="inline-block text-center text-sm bg-red-700 text-gray-100 border border-red-700 rounded px-2 py-1" href="<%= h(link[:url]) %>"><%= h(link[:label]) %></a>
15
+ <a class="inline-block text-center text-sm bg-red-700 text-gray-100 border border-red-700 rounded px-2 py-1" href="<%= link[:url] %>"><%= link[:label] %></a>
16
16
  <% end -%>
17
17
  </div>
18
18
  <% end -%>
@@ -33,7 +33,7 @@
33
33
  <ul class="list-disc pl-4 space-y-2">
34
34
  <% streams.each do |stream| -%>
35
35
  <li>
36
- <a class="text-red-700 no-underline" href="<%= urls.stream_url(stream) %>"><%= h(stream) %></a>
36
+ <a class="text-red-700 no-underline" href="<%= urls.stream_url(stream) %>"><%= stream %></a>
37
37
  </li>
38
38
  <% end -%>
39
39
  </ul>
@@ -62,7 +62,7 @@
62
62
  <% caused_by.each do |child| -%>
63
63
  <tr class="border-gray-50 border-b hover:bg-gray-100">
64
64
  <td>
65
- <a class="text-red-700 no-underline min-h-11 w-full flex items-center px-4" href="<%= urls.event_url(child.event_id) %>"><%= h(child.event_type) %></a>
65
+ <a class="text-red-700 no-underline min-h-11 w-full flex items-center px-4" href="<%= urls.event_url(child.event_id) %>"><%= child.event_type %></a>
66
66
  </td>
67
67
  <td class="font-mono text-sm leading-none font-medium align-middle">
68
68
  <a class="no-underline h-full min-h-11 flex items-center" href="<%= urls.event_url(child.event_id) %>"><%= child.event_id %></a>
@@ -1,7 +1,7 @@
1
1
  <!DOCTYPE html>
2
2
  <html lang="en">
3
3
  <head>
4
- <title>RubyEventStore::Browser<% if defined?(title) && title %> - <%= h(title) %><% end %></title>
4
+ <title>RubyEventStore::Browser<% if defined?(title) && title %> - <%= title %><% end %></title>
5
5
  <link type="text/css" rel="stylesheet" href="<%= urls.browser_css_url %>">
6
6
  <% extension_stylesheets.each do |href| -%>
7
7
  <link type="text/css" rel="stylesheet" href="<%= href %>">
@@ -21,12 +21,12 @@
21
21
  <div class="flex items-center gap-6">
22
22
  <a href="<%= urls.app_url %>" class="font-semibold text-gray-100">Ruby Event Store</a>
23
23
  <% extension_nav_links.each do |link| -%>
24
- <a href="<%= h(link[:url]) %>" class="text-sm text-red-100 hover:text-white"><%= h(link[:label]) %></a>
24
+ <a href="<%= link[:url] %>" class="text-sm text-red-100 hover:text-white"><%= link[:label] %></a>
25
25
  <% end -%>
26
26
  </div>
27
27
  <div class="flex items-center gap-2">
28
28
  <button class="flex items-center gap-2 px-3 text-sm text-red-100 bg-red-800 rounded outline-none hover:bg-red-900 h-9" data-action="search#open">
29
- <svg class="size-4" fill="none" height="24" width="24" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" viewBox="0 0 24 24"><circle cx="11" cy="11" r="8"></circle><line x1="21" y1="21" x2="16.65" y2="16.65"></line></svg>Go to stream&hellip;<span class="text-xs">&#x2318;K</span>
29
+ <svg class="size-4" fill="none" height="24" width="24" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" viewBox="0 0 24 24"><circle cx="11" cy="11" r="8"></circle><line x1="21" y1="21" x2="16.65" y2="16.65"></line></svg>Go to stream&hellip;<span class="text-xs" data-search-target="shortcut">&#x2318;K</span>
30
30
  </button>
31
31
  </div>
32
32
  </nav>
@@ -1,3 +1,3 @@
1
1
  <div class="py-12">
2
- <h1 class="font-bold px-8 text-2xl"><%= h(message) %></h1>
2
+ <h1 class="font-bold px-8 text-2xl"><%= message %></h1>
3
3
  </div>
@@ -1,6 +1,6 @@
1
1
  <div class="container py-8 mx-auto">
2
2
  <div class="flex justify-between">
3
- <h1 class="text-2xl font-bold">Events in <%= h(stream_name) %> </h1>
3
+ <h1 class="text-2xl font-bold">Events in <%= stream_name %> </h1>
4
4
  <div>
5
5
  <ul class="flex">
6
6
  <% [["first", pagination[:first]], ["previous", pagination[:prev]], ["next", pagination[:next]], ["last", pagination[:last]]].each do |label, url| -%>
@@ -16,7 +16,7 @@
16
16
  </div>
17
17
  </div>
18
18
  <% unless stream_name == SERIALIZED_GLOBAL_STREAM_NAME -%>
19
- <button class="inline-flex items-center gap-1 px-2 py-1 mt-3 text-sm text-center text-gray-100 bg-blue-800 border border-blue-800 rounded hover:bg-blue-900" data-stream-name="<%= h(stream_name) %>" data-action="swimlane#add">
19
+ <button class="inline-flex items-center gap-1 px-2 py-1 mt-3 text-sm text-center text-gray-100 bg-blue-800 border border-blue-800 rounded hover:bg-blue-900" data-stream-name="<%= stream_name %>" data-action="swimlane#add">
20
20
  <svg class="pointer-events-none size-4" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><line x1="12" y1="5" x2="12" y2="19"/><line x1="5" y1="12" x2="19" y2="12"/></svg>
21
21
  Add to swimlane
22
22
  </button>
@@ -26,7 +26,7 @@
26
26
  <% if links.any? -%>
27
27
  <div class="flex gap-2 pt-3">
28
28
  <% links.each do |link| -%>
29
- <a class="inline-block px-2 py-1 text-sm text-center text-gray-100 bg-red-700 border border-red-700 rounded" href="<%= h(link[:url]) %>"><%= h(link[:label]) %></a>
29
+ <a class="inline-block px-2 py-1 text-sm text-center text-gray-100 bg-red-700 border border-red-700 rounded" href="<%= link[:url] %>"><%= link[:label] %></a>
30
30
  <% end -%>
31
31
  </div>
32
32
  <% end -%>
@@ -41,11 +41,14 @@
41
41
  </tr>
42
42
  </thead>
43
43
  <tbody class="align-top">
44
+ <% if events.empty? -%>
45
+ <tr><td colspan="3" class="p-4 text-center text-gray-500">No items</td></tr>
46
+ <% end -%>
44
47
  <% events.each do |event| -%>
45
48
  <% href = urls.event_url(event.event_id) -%>
46
49
  <tr class="border-b border-gray-50 hover:bg-gray-100">
47
50
  <td>
48
- <a class="flex items-center w-full px-4 text-red-700 no-underline min-h-11" href="<%= href %>"><span class="min-w-0 break-words"><%= h(event.event_type) %></span></a>
51
+ <a class="flex items-center w-full px-4 text-red-700 no-underline min-h-11" href="<%= href %>"><span class="min-w-0 break-words"><%= event.event_type %></span></a>
49
52
  </td>
50
53
  <td class="font-mono text-sm font-medium leading-none align-middle">
51
54
  <a class="flex items-center h-full no-underline min-h-11" href="<%= href %>"><%= event.event_id %></a>
@@ -65,7 +68,7 @@
65
68
  <h2 class="text-xl font-bold">Related streams:</h2>
66
69
  <ul class="pl-8 list-disc">
67
70
  <% related_streams.each do |stream| -%>
68
- <li><a class="text-red-700 no-underline" href="<%= urls.stream_url(stream) %>"><%= h(stream) %></a></li>
71
+ <li><a class="text-red-700 no-underline" href="<%= urls.stream_url(stream) %>"><%= stream %></a></li>
69
72
  <% end -%>
70
73
  </ul>
71
74
  </div>
@@ -12,7 +12,7 @@
12
12
  <% stream_names.each_with_index do |stream_name, column| -%>
13
13
  <td class="<%= cell %><%= " border-l border-gray-200" if column.positive? %><%= " hover:bg-gray-100" if names.include?(stream_name) %>">
14
14
  <% if names.include?(stream_name) -%>
15
- <a href="<%= urls.event_url(event.event_id) %>" class="no-underline text-red-700 text-sm break-words"><%= h(event.event_type) %></a>
15
+ <a href="<%= urls.event_url(event.event_id) %>" class="no-underline text-red-700 text-sm break-words"><%= event.event_type %></a>
16
16
  <% end -%>
17
17
  </td>
18
18
  <% end -%>
@@ -1,12 +1,12 @@
1
1
  <div class="w-full shrink-0" data-controller="swimlane-view swimlane-add" data-swimlane-view-more-url-value="<%= more_url %>" data-swimlane-add-base-url-value="<%= urls.swimlane_url(stream_names, sort) %>">
2
2
  <div class="container py-8 mx-auto">
3
3
  <div class="flex items-center justify-between">
4
- <h1 class="text-2xl font-bold">Comparing <%= h(stream_names.join(", ")) %></h1>
4
+ <h1 class="text-2xl font-bold">Comparing <%= stream_names.join(", ") %></h1>
5
5
  <button class="px-2 py-1 text-sm text-center text-red-700 border border-red-700 rounded" data-action="swimlane-add#open">Add stream</button>
6
6
  </div>
7
7
  <% missing_stream_names.each do |stream_name| -%>
8
8
  <p class="px-4 py-3 mt-4 text-sm text-yellow-800 border border-yellow-300 rounded bg-yellow-50">
9
- Stream <span class="font-bold"><%= h(stream_name) %></span> does not exist.
9
+ Stream <span class="font-bold"><%= stream_name %></span> does not exist.
10
10
  </p>
11
11
  <% end -%>
12
12
  <% if stream_names.any? -%>
@@ -28,7 +28,7 @@
28
28
  <% stream_names.each_with_index do |stream_name, column| -%>
29
29
  <th class="font-bold border-b border-gray-400 pb-2 px-2 normal-case text-base text-gray-800<%= " border-l" if column.positive? %>">
30
30
  <div class="flex items-center justify-between gap-2">
31
- <span class="break-words"><%= h(stream_name) %></span>
31
+ <span class="break-words"><%= stream_name %></span>
32
32
  <% if stream_names.size > 1 -%>
33
33
  <a class="text-xl leading-none text-gray-400 no-underline hover:text-red-700" href="<%= urls.swimlane_url(stream_names - [stream_name], sort) %>" title="Remove from comparison">&times;</a>
34
34
  <% end -%>
@@ -5,9 +5,17 @@ const application = Application.start()
5
5
  application.register(
6
6
  "search",
7
7
  class extends Controller {
8
- static targets = ["dialog", "input"]
8
+ static targets = ["dialog", "input", "shortcut"]
9
9
  static values = { base: String }
10
10
 
11
+ connect() {
12
+ if (!this.isMac() && this.hasShortcutTarget) this.shortcutTarget.textContent = "Ctrl K"
13
+ }
14
+
15
+ isMac() {
16
+ return /Mac|iPhone|iPad|iPod/.test(navigator.platform)
17
+ }
18
+
11
19
  open(event) {
12
20
  event?.preventDefault()
13
21
  this.dialogTarget.showModal()
@@ -155,7 +163,7 @@ application.register(
155
163
  item.className = "flex items-center justify-between gap-2 py-1.5"
156
164
 
157
165
  const link = document.createElement("a")
158
- link.href = `/streams/${encodeURIComponent(stream)}`
166
+ link.href = `${this.baseUrlValue}/streams/${encodeURIComponent(stream)}`
159
167
  link.title = stream
160
168
  link.className = "text-sm text-red-700 no-underline break-all hover:underline"
161
169
  link.textContent = stream
@@ -213,17 +221,24 @@ application.register(
213
221
 
214
222
  loadMore() {
215
223
  const url = this.moreUrlValue
216
- if (!url) return
217
- this.moreUrlValue = ""
224
+ if (!url || this.loading) return
225
+ this.loading = true
218
226
 
219
227
  fetch(url, { headers: { Accept: "application/json" } })
220
- .then((response) => response.json())
228
+ .then((response) => {
229
+ if (!response.ok) throw new Error(`HTTP ${response.status}`)
230
+ return response.json()
231
+ })
221
232
  .then(({ html, more_url }) => {
233
+ this.loading = false
222
234
  this.tbodyTarget.insertAdjacentHTML("beforeend", html)
223
235
  this.moreUrlValue = more_url || ""
224
236
  this.renderTimes(this.zone())
225
237
  this.catchUp()
226
238
  })
239
+ .catch(() => {
240
+ this.loading = false
241
+ })
227
242
  }
228
243
 
229
244
  zone() {
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby_event_store-browser
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.2.0
4
+ version: 3.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Arkency
@@ -15,14 +15,14 @@ dependencies:
15
15
  requirements:
16
16
  - - '='
17
17
  - !ruby/object:Gem::Version
18
- version: 3.2.0
18
+ version: 3.3.0
19
19
  type: :runtime
20
20
  prerelease: false
21
21
  version_requirements: !ruby/object:Gem::Requirement
22
22
  requirements:
23
23
  - - '='
24
24
  - !ruby/object:Gem::Version
25
- version: 3.2.0
25
+ version: 3.3.0
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: rack
28
28
  requirement: !ruby/object:Gem::Requirement
@@ -105,7 +105,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
105
105
  - !ruby/object:Gem::Version
106
106
  version: '0'
107
107
  requirements: []
108
- rubygems_version: 4.0.16
108
+ rubygems_version: 4.0.20
109
109
  specification_version: 4
110
110
  summary: Event browser companion application for RubyEventStore
111
111
  test_files: []