durable_streams-rails 0.6.2 → 0.7.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:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 3f4756bb48c61889c0f2ed552d9dfb96d37e15566a7b2c67d38ee3e48a3d2048
|
|
4
|
+
data.tar.gz: 12c21fd8ff0842f3d121898fe6fe52da2914aa45b25dd1feb9752e232e40f3ca
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: be4dfd3ea33bfc0a1f641d05ce0a05a725e6d2f57a1f88da6145d4dbb2632b874128da7a4aeb682ad422ad1869bff3d984ae6707d6f68e05d52f5778fe770ff6
|
|
7
|
+
data.tar.gz: 06a91cc06ff3b1d00314632e6f64e7db4ffbe505844ae31c12c75c644f142f703dbe833fec559279f4f6e05a286c4fbe2476121706320b7d55fc88920113e976
|
|
@@ -67,6 +67,11 @@ module DurableStreams::Rails::Broadcasts
|
|
|
67
67
|
private
|
|
68
68
|
# Single transport point for all broadcasts. Testing intercepts here.
|
|
69
69
|
#
|
|
70
|
+
# ==== Network cost
|
|
71
|
+
#
|
|
72
|
+
# PUT via <tt>ensure_stream_exists</tt> (cached after first call per stream per
|
|
73
|
+
# process — see <tt>StreamProvisioner</tt>), then one POST to append the message.
|
|
74
|
+
#
|
|
70
75
|
# Content type is hardcoded to <tt>application/json</tt> because every public method in this
|
|
71
76
|
# module produces JSON (State Protocol events via +broadcast_event_to+, free-form JSON via
|
|
72
77
|
# +broadcast_to+). This ensures the POST body is correctly wrapped in a JSON array for the
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# Provides the read actions for the <tt>DurableStreams</tt> module — the counterpart to
|
|
2
|
+
# <tt>DurableStreams::Rails::Broadcasts</tt> (write path).
|
|
3
|
+
#
|
|
4
|
+
# Broadcasts push data out to streams. Feeds pull data in from streams. Currently
|
|
5
|
+
# limited to stream metadata (offsets via HEAD); future additions may include event
|
|
6
|
+
# replay and catch-up reads.
|
|
7
|
+
module DurableStreams::Rails::Feeds
|
|
8
|
+
private
|
|
9
|
+
# Single read point for stream offsets. Testing intercepts here.
|
|
10
|
+
#
|
|
11
|
+
# Returns the tail offset from a HEAD request, or <tt>"0"</tt> during testing.
|
|
12
|
+
def feed_head_offset(stream_name)
|
|
13
|
+
return "0" if DurableStreams::Rails::Testing.recording?
|
|
14
|
+
|
|
15
|
+
DurableStreams::Stream.new(stream_name, context: DurableStreams.default_context)
|
|
16
|
+
.head.next_offset
|
|
17
|
+
end
|
|
18
|
+
end
|
|
@@ -3,6 +3,7 @@ require "durable_streams/rails/engine"
|
|
|
3
3
|
require "durable_streams/rails/stream_name"
|
|
4
4
|
require "durable_streams/rails/stream_provisioner"
|
|
5
5
|
require "durable_streams/rails/broadcasts"
|
|
6
|
+
require "durable_streams/rails/feeds"
|
|
6
7
|
require "durable_streams/rails/testing"
|
|
7
8
|
require "active_support/core_ext/module/attribute_accessors_per_thread"
|
|
8
9
|
|
|
@@ -11,6 +12,7 @@ module DurableStreams
|
|
|
11
12
|
extend DurableStreams::Rails::StreamName
|
|
12
13
|
extend DurableStreams::Rails::StreamProvisioner
|
|
13
14
|
extend DurableStreams::Rails::Broadcasts
|
|
15
|
+
extend DurableStreams::Rails::Feeds
|
|
14
16
|
|
|
15
17
|
mattr_accessor :client_url
|
|
16
18
|
mattr_accessor :server_url
|
|
@@ -32,6 +34,17 @@ module DurableStreams
|
|
|
32
34
|
@server_api_key or raise ArgumentError, "DurableStreams requires a server_api_key"
|
|
33
35
|
end
|
|
34
36
|
|
|
37
|
+
# Generates a signed URL that grants a client read (or read/write) access to a
|
|
38
|
+
# Durable Stream identified by the given +streamables+. The URL embeds a signed
|
|
39
|
+
# token with the stream name, permissions, and expiry.
|
|
40
|
+
#
|
|
41
|
+
# Calls <tt>ensure_stream_exists</tt> to guarantee the stream has been created on
|
|
42
|
+
# the server (PUT, cached after the first call per stream per process — see
|
|
43
|
+
# <tt>StreamProvisioner</tt>). No other network requests.
|
|
44
|
+
#
|
|
45
|
+
# DurableStreams.signed_stream_url(room, :messages)
|
|
46
|
+
# # => "http://localhost:4437/v1/streams/gid://app/Room/1/messages?token=..."
|
|
47
|
+
#
|
|
35
48
|
def signed_stream_url(*streamables, permissions: [ :read ], expires_in: DurableStreams.signed_stream_url_expires_in)
|
|
36
49
|
path = stream_name_from(streamables)
|
|
37
50
|
ensure_stream_exists(path)
|
|
@@ -42,6 +55,31 @@ module DurableStreams
|
|
|
42
55
|
"#{client_url}/#{path}?token=#{token}"
|
|
43
56
|
end
|
|
44
57
|
|
|
58
|
+
# Returns the current tail offset of the stream as an opaque string. The tail offset
|
|
59
|
+
# is the position where the next append will land — a client that connects from this
|
|
60
|
+
# offset will receive every event appended after it.
|
|
61
|
+
#
|
|
62
|
+
# Uses the same +*streamables+ argument convention as <tt>signed_stream_url</tt>.
|
|
63
|
+
#
|
|
64
|
+
# ==== Network cost
|
|
65
|
+
#
|
|
66
|
+
# Calls <tt>ensure_stream_exists</tt> (PUT, cached after first call per stream per
|
|
67
|
+
# process — see <tt>StreamProvisioner</tt>), then one HEAD request per call. HEAD is
|
|
68
|
+
# the cheapest HTTP request (no body, headers only). On the internal network between
|
|
69
|
+
# Rails and the stream server, this is sub-millisecond.
|
|
70
|
+
#
|
|
71
|
+
# The offset must be fresh — caching would risk serving a stale position that skips
|
|
72
|
+
# events. This is the correct price for knowing "where is the stream right now."
|
|
73
|
+
#
|
|
74
|
+
# DurableStreams.stream_offset(room, :messages)
|
|
75
|
+
# # => "0000000001-0000000000"
|
|
76
|
+
#
|
|
77
|
+
def stream_offset(*streamables)
|
|
78
|
+
path = stream_name_from(streamables)
|
|
79
|
+
ensure_stream_exists(path)
|
|
80
|
+
feed_head_offset(path)
|
|
81
|
+
end
|
|
82
|
+
|
|
45
83
|
# Verifies the signed token embedded in a stream URL. Used by the auth controller
|
|
46
84
|
# to validate forward_auth requests from the Durable Streams server.
|
|
47
85
|
#
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: durable_streams-rails
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.7.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- tokimonki
|
|
@@ -56,6 +56,7 @@ files:
|
|
|
56
56
|
- lib/durable_streams/rails/broadcastable/test_helper.rb
|
|
57
57
|
- lib/durable_streams/rails/broadcasts.rb
|
|
58
58
|
- lib/durable_streams/rails/engine.rb
|
|
59
|
+
- lib/durable_streams/rails/feeds.rb
|
|
59
60
|
- lib/durable_streams/rails/server_config.rb
|
|
60
61
|
- lib/durable_streams/rails/stream_name.rb
|
|
61
62
|
- lib/durable_streams/rails/stream_provisioner.rb
|
|
@@ -86,7 +87,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
86
87
|
- !ruby/object:Gem::Version
|
|
87
88
|
version: '0'
|
|
88
89
|
requirements: []
|
|
89
|
-
rubygems_version: 4.0.
|
|
90
|
+
rubygems_version: 4.0.9
|
|
90
91
|
specification_version: 4
|
|
91
92
|
summary: Durable Streams integration for Rails
|
|
92
93
|
test_files: []
|