chrono_cable 0.0.1
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 +7 -0
- data/MIT-LICENSE +20 -0
- data/README.md +69 -0
- data/Rakefile +6 -0
- data/app/assets/javascripts/chronocable.js +607 -0
- data/app/assets/javascripts/chronocable_turbo.js +5970 -0
- data/app/assets/javascripts/chronocable_turbo.min.js +29 -0
- data/app/javascript/action_cable/adapters.js +4 -0
- data/app/javascript/action_cable/connection.js +183 -0
- data/app/javascript/action_cable/connection_monitor.js +124 -0
- data/app/javascript/action_cable/consumer.js +80 -0
- data/app/javascript/action_cable/index.js +33 -0
- data/app/javascript/action_cable/internal.js +21 -0
- data/app/javascript/action_cable/logger.js +22 -0
- data/app/javascript/action_cable/stream.js +73 -0
- data/app/javascript/action_cable/subscription.js +103 -0
- data/app/javascript/action_cable/subscription_guarantor.js +50 -0
- data/app/javascript/action_cable/subscriptions.js +141 -0
- data/app/javascript/turbo/cable.js +19 -0
- data/app/javascript/turbo/cable_stream_source_element.js +53 -0
- data/app/javascript/turbo/fetch_requests.js +59 -0
- data/app/javascript/turbo/index.js +13 -0
- data/app/javascript/turbo/snakeize.js +31 -0
- data/app/models/chrono_cable/application_record.rb +5 -0
- data/app/models/solid_cable/channel.rb +12 -0
- data/db/migrate/20260628205427_create_solid_cable_channels.rb +12 -0
- data/db/migrate/20260629194211_add_channel_id_to_solid_cable_messages.rb +7 -0
- data/lib/action_cable/subscription_adapter/message.rb +12 -0
- data/lib/chrono_cable/channel_base.rb +30 -0
- data/lib/chrono_cable/channel_streams.rb +121 -0
- data/lib/chrono_cable/connection_subscriptions.rb +16 -0
- data/lib/chrono_cable/engine.rb +11 -0
- data/lib/chrono_cable/solid_cable_adapter.rb +26 -0
- data/lib/chrono_cable/solid_cable_adapter_listener.rb +28 -0
- data/lib/chrono_cable/solid_cable_broadcasting.rb +19 -0
- data/lib/chrono_cable/solid_cable_message_class_methods.rb +9 -0
- data/lib/chrono_cable/subscription_adapter_base_extensions.rb +5 -0
- data/lib/chrono_cable/turbo_streams_channel.rb +5 -0
- data/lib/chrono_cable/version.rb +3 -0
- data/lib/chrono_cable.rb +38 -0
- data/lib/generators/chrono_cable/install/USAGE +9 -0
- data/lib/generators/chrono_cable/install/install_generator.rb +32 -0
- data/lib/generators/chrono_cable/install/templates/add_channel_id_to_solid_cable_messages.rb +7 -0
- data/lib/generators/chrono_cable/install/templates/create_solid_cable_channels.rb +12 -0
- data/lib/tasks/chrono_cable_tasks.rake +6 -0
- metadata +116 -0
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
// Based on https://github.com/nathan7/snakeize
|
|
2
|
+
//
|
|
3
|
+
// This software is released under the MIT license:
|
|
4
|
+
// Permission is hereby granted, free of charge, to any person obtaining a copy of
|
|
5
|
+
// this software and associated documentation files (the "Software"), to deal in
|
|
6
|
+
// the Software without restriction, including without limitation the rights to
|
|
7
|
+
// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
|
8
|
+
// the Software, and to permit persons to whom the Software is furnished to do so,
|
|
9
|
+
// subject to the following conditions:
|
|
10
|
+
|
|
11
|
+
// The above copyright notice and this permission notice shall be included in all
|
|
12
|
+
// copies or substantial portions of the Software.
|
|
13
|
+
|
|
14
|
+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
15
|
+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
|
16
|
+
// FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
|
17
|
+
// COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
|
18
|
+
// IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
19
|
+
// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
20
|
+
export default function walk (obj) {
|
|
21
|
+
if (!obj || typeof obj !== 'object') return obj;
|
|
22
|
+
if (obj instanceof Date || obj instanceof RegExp) return obj;
|
|
23
|
+
if (Array.isArray(obj)) return obj.map(walk);
|
|
24
|
+
return Object.keys(obj).reduce(function (acc, key) {
|
|
25
|
+
var camel = key[0].toLowerCase() + key.slice(1).replace(/([A-Z]+)/g, function (m, x) {
|
|
26
|
+
return '_' + x.toLowerCase();
|
|
27
|
+
});
|
|
28
|
+
acc[camel] = walk(obj[key]);
|
|
29
|
+
return acc;
|
|
30
|
+
}, {});
|
|
31
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "solid_cable"
|
|
4
|
+
|
|
5
|
+
module SolidCable
|
|
6
|
+
class Channel < ::SolidCable::Record
|
|
7
|
+
def self.lookup(channel)
|
|
8
|
+
channel_hash = ::SolidCable::Message.channel_hash_for(channel)
|
|
9
|
+
find_by(channel_hash:) || create_or_find_by!(channel_hash:)
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
end
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
class CreateSolidCableChannels < ActiveRecord::Migration[8.1]
|
|
2
|
+
def change
|
|
3
|
+
create_table :solid_cable_channels do |t|
|
|
4
|
+
t.integer :channel_hash, limit: 8, null: false
|
|
5
|
+
t.bigint :current_id, default: 0, null: false
|
|
6
|
+
t.index :channel_hash, unique: true
|
|
7
|
+
t.boolean :deliver_in_order, default: false, null: false
|
|
8
|
+
|
|
9
|
+
t.timestamps
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
end
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
class AddChannelIdToSolidCableMessages < ActiveRecord::Migration[8.1]
|
|
2
|
+
def change
|
|
3
|
+
add_column :solid_cable_messages, :channel_id, :bigint, if_not_exists: true
|
|
4
|
+
add_index :solid_cable_messages, [ :channel_hash, :channel_id ], unique: true,
|
|
5
|
+
if_not_exists: true
|
|
6
|
+
end
|
|
7
|
+
end
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
module ChronoCable::ChannelBase
|
|
2
|
+
private
|
|
3
|
+
def transmit(data, via: nil, id: nil, broadcasting: nil) # :doc:
|
|
4
|
+
logger.debug do
|
|
5
|
+
status = "#{self.class.name} transmitting #{data.inspect.truncate(300)}"
|
|
6
|
+
status += " (via #{via})" if via
|
|
7
|
+
status
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
payload = { channel_class: self.class.name, data: data, via: via }
|
|
11
|
+
ActiveSupport::Notifications.instrument("transmit.action_cable", payload) do
|
|
12
|
+
broadcasting = ChronoCable.signed_stream_verifier.generate(broadcasting) if broadcasting
|
|
13
|
+
connection.transmit **{ identifier: @identifier, message: data, broadcasting:, id: }.compact
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def transmit_subscription_confirmation
|
|
18
|
+
unless subscription_confirmation_sent?
|
|
19
|
+
logger.debug "#{self.class.name} is transmitting the subscription confirmation"
|
|
20
|
+
|
|
21
|
+
ActiveSupport::Notifications.instrument("transmit_subscription_confirmation.action_cable", channel_class: self.class.name, identifier: @identifier) do
|
|
22
|
+
connection.transmit **{ identifier: @identifier,
|
|
23
|
+
type: ActionCable::INTERNAL[:message_types][:confirmation],
|
|
24
|
+
ids: @subscription_confirmation_ids
|
|
25
|
+
}.compact
|
|
26
|
+
@subscription_confirmation_sent = true
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
module ChronoCable::ChannelStreams
|
|
2
|
+
def stream_from(broadcasting, callback = nil, coder: nil, deliver_in_order: false, &block)
|
|
3
|
+
return if unsubscribed?
|
|
4
|
+
|
|
5
|
+
broadcasting = String(broadcasting)
|
|
6
|
+
ordered = deliver_in_order && pubsub.supports_history?
|
|
7
|
+
|
|
8
|
+
ordered_streams.delete broadcasting
|
|
9
|
+
pubsub.enable_ordered_delivery(broadcasting) if ordered
|
|
10
|
+
|
|
11
|
+
# Don't send the confirmation until pubsub#subscribe is successful
|
|
12
|
+
defer_subscription_confirmation!
|
|
13
|
+
|
|
14
|
+
# Build a stream handler by wrapping the user-provided callback with a decoder
|
|
15
|
+
# or defaulting to a JSON-decoding retransmitter.
|
|
16
|
+
user_handler = callback || block
|
|
17
|
+
handler = worker_pool_stream_handler(broadcasting, user_handler, coder: coder)
|
|
18
|
+
streams[broadcasting] = handler
|
|
19
|
+
|
|
20
|
+
if ordered
|
|
21
|
+
ordered_streams[broadcasting] = user_handler && stream_handler(broadcasting, user_handler, coder:)
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
pubsub.subscribe(broadcasting, handler, lambda do |last_id = nil|
|
|
25
|
+
confirmation_was_sent = subscription_confirmation_sent?
|
|
26
|
+
|
|
27
|
+
record_subscription_confirmation_id broadcasting, last_id if ordered_stream?(broadcasting)
|
|
28
|
+
ensure_confirmation_sent
|
|
29
|
+
transmit_subscription_id broadcasting, last_id if confirmation_was_sent
|
|
30
|
+
|
|
31
|
+
logger.info "#{self.class.name} is streaming from #{broadcasting}"
|
|
32
|
+
end)
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def stop_all_streams
|
|
36
|
+
super
|
|
37
|
+
ordered_streams.clear
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def stop_stream_from(broadcasting)
|
|
41
|
+
broadcasting = String(broadcasting)
|
|
42
|
+
super
|
|
43
|
+
ordered_streams.delete broadcasting
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
private
|
|
47
|
+
def stream_decoder(handler = nil, coder:)
|
|
48
|
+
->(message) do
|
|
49
|
+
payload = message.try(:payload) || message
|
|
50
|
+
payload = coder.decode(payload) if coder
|
|
51
|
+
|
|
52
|
+
handler ? handler.(payload) : payload
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
def stream_transmitter(handler = nil, broadcasting:)
|
|
57
|
+
via = "streamed from #{broadcasting}"
|
|
58
|
+
|
|
59
|
+
->(message) do
|
|
60
|
+
data =
|
|
61
|
+
if handler
|
|
62
|
+
handler.(message)
|
|
63
|
+
else
|
|
64
|
+
message
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
params = { via: via }
|
|
68
|
+
params.merge!(id: message.try(:id), broadcasting:) if ordered_stream?(broadcasting)
|
|
69
|
+
transmit data, **params
|
|
70
|
+
end
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
def ordered_streams
|
|
74
|
+
@ordered_streams ||= {}
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
def ordered_stream?(broadcasting)
|
|
78
|
+
ordered_streams.key? broadcasting
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
def record_subscription_confirmation_id(broadcasting, id)
|
|
82
|
+
return if id.nil?
|
|
83
|
+
|
|
84
|
+
@subscription_confirmation_ids ||= {}
|
|
85
|
+
@subscription_confirmation_ids[ChronoCable.signed_stream_verifier.generate(broadcasting)] = id
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
def __history(data = nil)
|
|
89
|
+
signed_broadcasting = data.to_h["broadcasting"]
|
|
90
|
+
return unless signed_broadcasting.is_a?(String)
|
|
91
|
+
|
|
92
|
+
broadcasting = ChronoCable.signed_stream_verifier.verified(signed_broadcasting)
|
|
93
|
+
return unless ordered_stream?(broadcasting)
|
|
94
|
+
|
|
95
|
+
messages = pubsub.history(broadcasting, after_id: data["id"])
|
|
96
|
+
if handler = ordered_streams[broadcasting]
|
|
97
|
+
messages.each do |message|
|
|
98
|
+
handler.call ActionCable::SubscriptionAdapter::Message.new(
|
|
99
|
+
id: message[:id], payload: message[:payload]
|
|
100
|
+
)
|
|
101
|
+
end
|
|
102
|
+
transmit_history [], broadcasting:
|
|
103
|
+
else
|
|
104
|
+
transmit_history messages, broadcasting:
|
|
105
|
+
end
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
def transmit_subscription_id(broadcasting, id)
|
|
109
|
+
return unless ordered_stream?(broadcasting) && id
|
|
110
|
+
|
|
111
|
+
transmit_history [], broadcasting:, id:
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
def transmit_history(messages, broadcasting:, id: nil)
|
|
115
|
+
message = { messages:, id: }.compact
|
|
116
|
+
broadcasting = ChronoCable.signed_stream_verifier.generate(broadcasting)
|
|
117
|
+
|
|
118
|
+
connection.transmit identifier: @identifier, broadcasting:,
|
|
119
|
+
type: ActionCable::INTERNAL[:message_types][:history], message: message
|
|
120
|
+
end
|
|
121
|
+
end
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
module ChronoCable::ConnectionSubscriptions
|
|
2
|
+
def execute_command(data)
|
|
3
|
+
if data["command"] == "history"
|
|
4
|
+
fetch_history data
|
|
5
|
+
else
|
|
6
|
+
super
|
|
7
|
+
end
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def fetch_history(data)
|
|
11
|
+
subscription = find(data)
|
|
12
|
+
raise ActionCable::Connection::Subscriptions::UnknownSubscription.new(data["identifier"]) unless subscription
|
|
13
|
+
|
|
14
|
+
subscription.__send__(:__history, data)
|
|
15
|
+
end
|
|
16
|
+
end
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
module ChronoCable::SolidCableAdapter
|
|
2
|
+
def supports_history?
|
|
3
|
+
true
|
|
4
|
+
end
|
|
5
|
+
|
|
6
|
+
def history(channel, after_id: nil)
|
|
7
|
+
messages = ::SolidCable::Message.
|
|
8
|
+
where(channel_hash: channel_hash_for(channel)).
|
|
9
|
+
where.not(channel_id: nil)
|
|
10
|
+
messages = messages.where(channel_id: (after_id.to_i + 1)..) if after_id
|
|
11
|
+
messages.order(:channel_id).pluck(:channel_id, :payload).map do |id, payload|
|
|
12
|
+
{ id:, payload: }
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def enable_ordered_delivery(channel)
|
|
17
|
+
channel = ::SolidCable::Channel.lookup(channel_with_prefix(channel))
|
|
18
|
+
|
|
19
|
+
channel.update_columns(deliver_in_order: true) unless channel.deliver_in_order?
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
private
|
|
23
|
+
def channel_hash_for(channel)
|
|
24
|
+
::SolidCable::Message.channel_hash_for channel_with_prefix(channel)
|
|
25
|
+
end
|
|
26
|
+
end
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
module ChronoCable::SolidCableAdapterListener
|
|
2
|
+
Broadcast = Data.define(:channel, :payload)
|
|
3
|
+
|
|
4
|
+
def add_subscriber(channel, subscriber, on_success)
|
|
5
|
+
if on_success
|
|
6
|
+
callback = on_success
|
|
7
|
+
on_success = -> { callback.call current_channel_id(channel) }
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
super
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
private
|
|
14
|
+
def current_channel_id(channel)
|
|
15
|
+
SolidCable::Message.
|
|
16
|
+
where(channel_hash: SolidCable::Message.channel_hash_for(channel)).
|
|
17
|
+
maximum(:channel_id).to_i
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def broadcast(message)
|
|
21
|
+
payload = ::ActionCable::SubscriptionAdapter::Message.new(
|
|
22
|
+
payload: message.payload,
|
|
23
|
+
id: message.channel_id
|
|
24
|
+
)
|
|
25
|
+
|
|
26
|
+
super Broadcast.new(message.channel, payload)
|
|
27
|
+
end
|
|
28
|
+
end
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
module ChronoCable::SolidCableBroadcasting
|
|
2
|
+
Message = Struct.new(:channel, :payload, :channel_id, keyword_init: true)
|
|
3
|
+
|
|
4
|
+
def broadcast(channel, payload)
|
|
5
|
+
message = Message.new(channel:, payload:)
|
|
6
|
+
channel_record = SolidCable::Channel.lookup(channel)
|
|
7
|
+
|
|
8
|
+
if channel_record.deliver_in_order?
|
|
9
|
+
channel_record.with_lock do
|
|
10
|
+
channel_record.increment!(:current_id)
|
|
11
|
+
message.channel_id = channel_record.current_id
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
queue.enq message
|
|
16
|
+
rescue ClosedQueueError
|
|
17
|
+
raise SolidCable::BatchedBroadcaster::Stopped, "Solid Cable writer has stopped"
|
|
18
|
+
end
|
|
19
|
+
end
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
module ChronoCable::SolidCableMessageClassMethods
|
|
2
|
+
def broadcast_batch(broadcasts)
|
|
3
|
+
created_at = Time.current
|
|
4
|
+
insert_all broadcasts.map { |message|
|
|
5
|
+
{ created_at:, channel: message.channel, channel_id: message.channel_id,
|
|
6
|
+
payload: message.payload, channel_hash: channel_hash_for(message.channel) }
|
|
7
|
+
}
|
|
8
|
+
end
|
|
9
|
+
end
|
data/lib/chrono_cable.rb
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
require "chrono_cable/version"
|
|
2
|
+
require "chrono_cable/engine"
|
|
3
|
+
|
|
4
|
+
require "action_cable/subscription_adapter/message"
|
|
5
|
+
|
|
6
|
+
require "chrono_cable/subscription_adapter_base_extensions"
|
|
7
|
+
require "chrono_cable/connection_subscriptions"
|
|
8
|
+
require "chrono_cable/channel_base"
|
|
9
|
+
require "chrono_cable/channel_streams"
|
|
10
|
+
require "chrono_cable/turbo_streams_channel"
|
|
11
|
+
|
|
12
|
+
require "chrono_cable/solid_cable_message_class_methods"
|
|
13
|
+
require "chrono_cable/solid_cable_adapter_listener"
|
|
14
|
+
require "chrono_cable/solid_cable_adapter"
|
|
15
|
+
require "chrono_cable/solid_cable_broadcasting"
|
|
16
|
+
|
|
17
|
+
module ChronoCable
|
|
18
|
+
def self.signed_stream_verifier
|
|
19
|
+
Rails.application.message_verifier("chrono_cable/stream_name")
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def self.install!
|
|
23
|
+
::ActionCable::INTERNAL[:message_types][:history] = "history"
|
|
24
|
+
|
|
25
|
+
::ActionCable::SubscriptionAdapter::Base.include ::ChronoCable::SubscriptionAdapterBaseExtensions
|
|
26
|
+
|
|
27
|
+
::ActionCable::Connection::Subscriptions.prepend ChronoCable::ConnectionSubscriptions
|
|
28
|
+
::ActionCable::Channel::Base.prepend ChronoCable::ChannelBase
|
|
29
|
+
::ActionCable::Channel::Streams.prepend ChronoCable::ChannelStreams
|
|
30
|
+
::Turbo::StreamsChannel.prepend ChronoCable::TurboStreamsChannel if defined?(::Turbo::StreamsChannel)
|
|
31
|
+
|
|
32
|
+
::ActionCable::SubscriptionAdapter::SolidCable::Listener.prepend ::ChronoCable::SolidCableAdapterListener
|
|
33
|
+
::ActionCable::SubscriptionAdapter::SolidCable.include ChronoCable::SolidCableAdapter
|
|
34
|
+
|
|
35
|
+
SolidCable::BatchedBroadcaster.prepend ::ChronoCable::SolidCableBroadcasting
|
|
36
|
+
SolidCable::Message.singleton_class.prepend ::ChronoCable::SolidCableMessageClassMethods
|
|
37
|
+
end
|
|
38
|
+
end
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
Description:
|
|
2
|
+
Copies the Chrono Cable database migrations into the application.
|
|
3
|
+
|
|
4
|
+
Example:
|
|
5
|
+
bin/rails generate chrono_cable:install
|
|
6
|
+
|
|
7
|
+
This will create:
|
|
8
|
+
db/cable_migrate/*_create_solid_cable_channels.rb
|
|
9
|
+
db/cable_migrate/*_add_channel_id_to_solid_cable_messages.rb
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
require "rails/generators"
|
|
2
|
+
require "rails/generators/active_record"
|
|
3
|
+
|
|
4
|
+
class ChronoCable::InstallGenerator < Rails::Generators::Base
|
|
5
|
+
include Rails::Generators::Migration
|
|
6
|
+
|
|
7
|
+
source_root File.expand_path("templates", __dir__)
|
|
8
|
+
|
|
9
|
+
def self.next_migration_number(dirname)
|
|
10
|
+
ActiveRecord::Generators::Base.next_migration_number(dirname)
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def copy_migrations
|
|
14
|
+
migration_template "create_solid_cable_channels.rb",
|
|
15
|
+
"db/cable_migrate/create_solid_cable_channels.rb"
|
|
16
|
+
|
|
17
|
+
migration_template "add_channel_id_to_solid_cable_messages.rb",
|
|
18
|
+
"db/cable_migrate/add_channel_id_to_solid_cable_messages.rb"
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def update_importmap
|
|
22
|
+
return unless File.exist?(File.join(destination_root, "config/importmap.rb"))
|
|
23
|
+
|
|
24
|
+
gsub_file "config/importmap.rb",
|
|
25
|
+
/pin\s+["']@rails\/actioncable["'],\s+to:\s+["']actioncable\.esm\.js["']/,
|
|
26
|
+
'pin "@rails/actioncable", to: "chronocable.js"'
|
|
27
|
+
|
|
28
|
+
gsub_file "config/importmap.rb",
|
|
29
|
+
/pin\s+["']@hotwired\/turbo-rails["'],\s+to:\s+["']turbo\.min\.js["']/,
|
|
30
|
+
'pin "@hotwired/turbo-rails", to: "chronocable_turbo.min.js"'
|
|
31
|
+
end
|
|
32
|
+
end
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
class AddChannelIdToSolidCableMessages < ActiveRecord::Migration[8.1]
|
|
2
|
+
def change
|
|
3
|
+
add_column :solid_cable_messages, :channel_id, :bigint, if_not_exists: true
|
|
4
|
+
add_index :solid_cable_messages, [ :channel_hash, :channel_id ], unique: true,
|
|
5
|
+
if_not_exists: true
|
|
6
|
+
end
|
|
7
|
+
end
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
class CreateSolidCableChannels < ActiveRecord::Migration[8.1]
|
|
2
|
+
def change
|
|
3
|
+
create_table :solid_cable_channels, if_not_exists: true do |t|
|
|
4
|
+
t.integer :channel_hash, limit: 8, null: false
|
|
5
|
+
t.bigint :current_id, default: 0, null: false
|
|
6
|
+
t.index :channel_hash, unique: true
|
|
7
|
+
t.boolean :deliver_in_order, default: false, null: false
|
|
8
|
+
|
|
9
|
+
t.timestamps
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: chrono_cable
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.0.1
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Nick Pezza
|
|
8
|
+
bindir: bin
|
|
9
|
+
cert_chain: []
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
11
|
+
dependencies:
|
|
12
|
+
- !ruby/object:Gem::Dependency
|
|
13
|
+
name: rails
|
|
14
|
+
requirement: !ruby/object:Gem::Requirement
|
|
15
|
+
requirements:
|
|
16
|
+
- - ">"
|
|
17
|
+
- !ruby/object:Gem::Version
|
|
18
|
+
version: '8.1'
|
|
19
|
+
type: :runtime
|
|
20
|
+
prerelease: false
|
|
21
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
22
|
+
requirements:
|
|
23
|
+
- - ">"
|
|
24
|
+
- !ruby/object:Gem::Version
|
|
25
|
+
version: '8.1'
|
|
26
|
+
- !ruby/object:Gem::Dependency
|
|
27
|
+
name: solid_cable
|
|
28
|
+
requirement: !ruby/object:Gem::Requirement
|
|
29
|
+
requirements:
|
|
30
|
+
- - ">"
|
|
31
|
+
- !ruby/object:Gem::Version
|
|
32
|
+
version: '4.0'
|
|
33
|
+
type: :runtime
|
|
34
|
+
prerelease: false
|
|
35
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
36
|
+
requirements:
|
|
37
|
+
- - ">"
|
|
38
|
+
- !ruby/object:Gem::Version
|
|
39
|
+
version: '4.0'
|
|
40
|
+
description: Adds per-stream sequence numbers and history replay to Action Cable broadcasts
|
|
41
|
+
stored by Solid Cable.
|
|
42
|
+
email:
|
|
43
|
+
- pezza@hey.com
|
|
44
|
+
executables: []
|
|
45
|
+
extensions: []
|
|
46
|
+
extra_rdoc_files: []
|
|
47
|
+
files:
|
|
48
|
+
- MIT-LICENSE
|
|
49
|
+
- README.md
|
|
50
|
+
- Rakefile
|
|
51
|
+
- app/assets/javascripts/chronocable.js
|
|
52
|
+
- app/assets/javascripts/chronocable_turbo.js
|
|
53
|
+
- app/assets/javascripts/chronocable_turbo.min.js
|
|
54
|
+
- app/javascript/action_cable/adapters.js
|
|
55
|
+
- app/javascript/action_cable/connection.js
|
|
56
|
+
- app/javascript/action_cable/connection_monitor.js
|
|
57
|
+
- app/javascript/action_cable/consumer.js
|
|
58
|
+
- app/javascript/action_cable/index.js
|
|
59
|
+
- app/javascript/action_cable/internal.js
|
|
60
|
+
- app/javascript/action_cable/logger.js
|
|
61
|
+
- app/javascript/action_cable/stream.js
|
|
62
|
+
- app/javascript/action_cable/subscription.js
|
|
63
|
+
- app/javascript/action_cable/subscription_guarantor.js
|
|
64
|
+
- app/javascript/action_cable/subscriptions.js
|
|
65
|
+
- app/javascript/turbo/cable.js
|
|
66
|
+
- app/javascript/turbo/cable_stream_source_element.js
|
|
67
|
+
- app/javascript/turbo/fetch_requests.js
|
|
68
|
+
- app/javascript/turbo/index.js
|
|
69
|
+
- app/javascript/turbo/snakeize.js
|
|
70
|
+
- app/models/chrono_cable/application_record.rb
|
|
71
|
+
- app/models/solid_cable/channel.rb
|
|
72
|
+
- db/migrate/20260628205427_create_solid_cable_channels.rb
|
|
73
|
+
- db/migrate/20260629194211_add_channel_id_to_solid_cable_messages.rb
|
|
74
|
+
- lib/action_cable/subscription_adapter/message.rb
|
|
75
|
+
- lib/chrono_cable.rb
|
|
76
|
+
- lib/chrono_cable/channel_base.rb
|
|
77
|
+
- lib/chrono_cable/channel_streams.rb
|
|
78
|
+
- lib/chrono_cable/connection_subscriptions.rb
|
|
79
|
+
- lib/chrono_cable/engine.rb
|
|
80
|
+
- lib/chrono_cable/solid_cable_adapter.rb
|
|
81
|
+
- lib/chrono_cable/solid_cable_adapter_listener.rb
|
|
82
|
+
- lib/chrono_cable/solid_cable_broadcasting.rb
|
|
83
|
+
- lib/chrono_cable/solid_cable_message_class_methods.rb
|
|
84
|
+
- lib/chrono_cable/subscription_adapter_base_extensions.rb
|
|
85
|
+
- lib/chrono_cable/turbo_streams_channel.rb
|
|
86
|
+
- lib/chrono_cable/version.rb
|
|
87
|
+
- lib/generators/chrono_cable/install/USAGE
|
|
88
|
+
- lib/generators/chrono_cable/install/install_generator.rb
|
|
89
|
+
- lib/generators/chrono_cable/install/templates/add_channel_id_to_solid_cable_messages.rb
|
|
90
|
+
- lib/generators/chrono_cable/install/templates/create_solid_cable_channels.rb
|
|
91
|
+
- lib/tasks/chrono_cable_tasks.rake
|
|
92
|
+
homepage: https://github.com/npezza93/chrono_cable
|
|
93
|
+
licenses:
|
|
94
|
+
- MIT
|
|
95
|
+
metadata:
|
|
96
|
+
homepage_uri: https://github.com/npezza93/chrono_cable
|
|
97
|
+
source_code_uri: https://github.com/npezza93/chrono_cable
|
|
98
|
+
rubygems_mfa_required: 'true'
|
|
99
|
+
rdoc_options: []
|
|
100
|
+
require_paths:
|
|
101
|
+
- lib
|
|
102
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
103
|
+
requirements:
|
|
104
|
+
- - ">="
|
|
105
|
+
- !ruby/object:Gem::Version
|
|
106
|
+
version: '0'
|
|
107
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
108
|
+
requirements:
|
|
109
|
+
- - ">="
|
|
110
|
+
- !ruby/object:Gem::Version
|
|
111
|
+
version: '0'
|
|
112
|
+
requirements: []
|
|
113
|
+
rubygems_version: 4.0.20
|
|
114
|
+
specification_version: 4
|
|
115
|
+
summary: Ordered, recoverable Action Cable streams backed by Solid Cable.
|
|
116
|
+
test_files: []
|