ruby_event_store-browser 1.3.0 → 2.0.2

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: 0ee3b62119666fd63aa0b6090137e3ad086e1e68bebb89ff9ac253cfcc04d9bc
4
- data.tar.gz: 151a9dd67a12d59dda7674a77bee84042f22cc627f6bb105c24da2daba0ce079
3
+ metadata.gz: 7f2279e04f4c9e2c8e2463367f7e0592f1e3b740aea73976931dfc094b7d44e9
4
+ data.tar.gz: 8a94bbd29bd5de2fdc6413ea20ab6a2ffb793edf0040744e57bf8833a2940d12
5
5
  SHA512:
6
- metadata.gz: 8fdf001f6b443f8aea64889f048a5cf31e79ac691bb2bdb6d578c10fdc43a91c06357ef417642c1a30eeaee74eda3c3aefe6a861d8efc03145861e75031829e0
7
- data.tar.gz: 8fee6c1f5e9a9f657feaa008467a077027a68ac05c30eb85a821ffde6abf6e96ea4eff515ad2b1caaf4bba986cd93500550d343ccc6fde856fe80dfa2647c532
6
+ metadata.gz: 8b32f390429c2806e01f35b64654d7c806ca33f497a93b1a526aa3f4275a9cbdf0938ebf5ad4e3e80484a5bc82a93f1ae94400d9383feb78c6b2d7849913f71b
7
+ data.tar.gz: 17576122e04932e78836c4d6ff5f1cf8488746b06a9efee690834fe22dfa163775d25f35d62c2c99237e12756a4feab60c17c6d9591ef162daab78c87e8b5ae6
@@ -6,13 +6,14 @@ require 'sinatra/base'
6
6
  module RubyEventStore
7
7
  module Browser
8
8
  class App < Sinatra::Base
9
- def self.for(event_store_locator:, host: nil, path: nil, environment: :production, related_streams_query: DEFAULT_RELATED_STREAMS_QUERY)
9
+ def self.for(event_store_locator:, host: nil, path: nil, api_url: nil, environment: :production, related_streams_query: DEFAULT_RELATED_STREAMS_QUERY)
10
10
  self.tap do |app|
11
11
  app.settings.instance_exec do
12
12
  set :event_store_locator, event_store_locator
13
13
  set :related_streams_query, -> { related_streams_query }
14
14
  set :host, host
15
15
  set :root_path, path
16
+ set :api_url, api_url
16
17
  set :environment, environment
17
18
  set :public_folder, "#{__dir__}/../../../public"
18
19
  end
@@ -22,6 +23,7 @@ module RubyEventStore
22
23
  configure do
23
24
  set :host, nil
24
25
  set :root_path, nil
26
+ set :api_url, nil
25
27
  set :event_store_locator, -> {}
26
28
  set :related_streams_query, nil
27
29
  set :protection, except: :path_traversal
@@ -29,32 +31,7 @@ module RubyEventStore
29
31
  mime_type :json, 'application/vnd.api+json'
30
32
  end
31
33
 
32
- get '/' do
33
- erb %{
34
- <!DOCTYPE html>
35
- <html>
36
- <head>
37
- <title>RubyEventStore::Browser</title>
38
- <link type="text/css" rel="stylesheet" href="<%= path %>/ruby_event_store_browser.css">
39
- </head>
40
- <body>
41
- <script type="text/javascript" src="<%= path %>/ruby_event_store_browser.js"></script>
42
- <script type="text/javascript">
43
- RubyEventStore.Browser.Elm.Main.init({
44
- flags: {
45
- rootUrl: "<%= path %>",
46
- eventsUrl: "<%= path %>/events",
47
- streamsUrl: "<%= path %>/streams",
48
- resVersion: "<%= RubyEventStore::VERSION %>"
49
- }
50
- });
51
- </script>
52
- </body>
53
- </html>
54
- }, locals: { path: settings.root_path || request.script_name }
55
- end
56
-
57
- get '/events/:id' do
34
+ get '/api/events/:id' do
58
35
  begin
59
36
  json Event.new(
60
37
  event_store: settings.event_store_locator,
@@ -65,7 +42,7 @@ module RubyEventStore
65
42
  end
66
43
  end
67
44
 
68
- get '/streams/:id' do
45
+ get '/api/streams/:id' do
69
46
  json GetStream.new(
70
47
  stream_name: params[:id],
71
48
  routing: routing,
@@ -73,7 +50,7 @@ module RubyEventStore
73
50
  )
74
51
  end
75
52
 
76
- get '/streams/:id/relationships/events' do
53
+ get '/api/streams/:id/relationships/events' do
77
54
  json GetEventsFromStream.new(
78
55
  event_store: settings.event_store_locator,
79
56
  params: symbolized_params,
@@ -81,12 +58,28 @@ module RubyEventStore
81
58
  )
82
59
  end
83
60
 
84
- get '/streams/:id/relationships/events/:position/:direction/:count' do
85
- json GetEventsFromStream.new(
86
- event_store: settings.event_store_locator,
87
- params: symbolized_params,
88
- routing: routing,
89
- )
61
+ get %r{/(events/.*|streams/.*)?} do
62
+ erb %{
63
+ <!DOCTYPE html>
64
+ <html>
65
+ <head>
66
+ <title>RubyEventStore::Browser</title>
67
+ <link type="text/css" rel="stylesheet" href="<%= path %>/ruby_event_store_browser.css">
68
+ </head>
69
+ <body>
70
+ <script type="text/javascript" src="<%= path %>/ruby_event_store_browser.js"></script>
71
+ <script type="text/javascript">
72
+ RubyEventStore.Browser.Elm.Main.init({
73
+ flags: {
74
+ rootUrl: "<%= routing.root_url %>",
75
+ apiUrl: "<%= api_url %>",
76
+ resVersion: "<%= RubyEventStore::VERSION %>"
77
+ }
78
+ });
79
+ </script>
80
+ </body>
81
+ </html>
82
+ }, locals: { path: settings.root_path || request.script_name, api_url: settings.api_url || routing.api_url }
90
83
  end
91
84
 
92
85
  helpers do
@@ -84,11 +84,11 @@ module RubyEventStore
84
84
  end
85
85
 
86
86
  def count
87
- Integer(params.fetch(:count, PAGE_SIZE))
87
+ Integer(pagination_param[:count] || PAGE_SIZE)
88
88
  end
89
89
 
90
90
  def direction
91
- case params[:direction]
91
+ case pagination_param[:direction]
92
92
  when 'forward'
93
93
  :forward
94
94
  else
@@ -97,17 +97,21 @@ module RubyEventStore
97
97
  end
98
98
 
99
99
  def position
100
- case params[:position]
100
+ case pagination_param[:position]
101
101
  when 'head', nil
102
102
  HEAD
103
103
  else
104
- params.fetch(:position)
104
+ pagination_param.fetch(:position)
105
105
  end
106
106
  end
107
107
 
108
108
  def stream_name
109
109
  params.fetch(:id)
110
110
  end
111
+
112
+ def pagination_param
113
+ params[:page] || {}
114
+ end
111
115
  end
112
116
  end
113
117
  end
@@ -29,16 +29,8 @@ module RubyEventStore
29
29
 
30
30
  def metadata
31
31
  event.metadata.to_h.tap do |m|
32
- m[:timestamp] = as_time(m.fetch(:timestamp)).iso8601(3)
33
- end
34
- end
35
-
36
- def as_time(value)
37
- case value
38
- when String
39
- Time.parse(value)
40
- else
41
- value
32
+ m[:timestamp] = event.metadata.fetch(:timestamp).iso8601(TIMESTAMP_PRECISION)
33
+ m[:valid_at] = event.metadata.fetch(:valid_at).iso8601(TIMESTAMP_PRECISION)
42
34
  end
43
35
  end
44
36
 
@@ -6,20 +6,43 @@ module RubyEventStore
6
6
  @root_path = root_path
7
7
  end
8
8
 
9
+ def root_url
10
+ base_url
11
+ end
12
+
13
+ def events_url
14
+ "#{api_url}/events"
15
+ end
16
+
17
+ def api_url
18
+ "#{base_url}/api"
19
+ end
20
+
21
+ def streams_url
22
+ "#{api_url}/streams"
23
+ end
24
+
9
25
  def paginated_events_from_stream_url(id:, position: nil, direction: nil, count: nil)
10
- base = [host, root_path].join
11
- args = [position, direction, count].compact
12
26
  stream_name = Rack::Utils.escape(id)
27
+ query_string = URI.encode_www_form({
28
+ "page[position]" => position,
29
+ "page[direction]" => direction,
30
+ "page[count]" => count,
31
+ }.compact)
13
32
 
14
- if args.empty?
15
- "#{base}/streams/#{stream_name}/relationships/events"
33
+ if query_string.empty?
34
+ "#{api_url}/streams/#{stream_name}/relationships/events"
16
35
  else
17
- "#{base}/streams/#{stream_name}/relationships/events/#{args.join('/')}"
36
+ "#{api_url}/streams/#{stream_name}/relationships/events?#{query_string}"
18
37
  end
19
38
  end
20
39
 
21
40
  private
22
41
  attr_reader :host, :root_path
42
+
43
+ def base_url
44
+ [host, root_path].join
45
+ end
23
46
  end
24
47
  end
25
48
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module RubyEventStore
4
4
  module Browser
5
- VERSION = "1.3.0"
5
+ VERSION = "2.0.2"
6
6
  end
7
7
  end