···15151616 class Firehose::CommitMessage < Firehose::Message
17171818+ #
1919+ # @private
2020+ # @param type_object [Hash] first decoded CBOR frame with metadata
2121+ # @param data_object [Hash] second decoded CBOR frame with payload
2222+ # @raise [DecodeError] if the message doesn't include required data
2323+ #
2424+ def initialize(type_object, data_object)
2525+ super
2626+ check_if_not_nil :seq, :repo, :commit, :blocks, :ops, :time
2727+ end
2828+1829 # @return [CID] CID (Content Identifier) of the commit
1930 def commit
2020- @commit ||= @data_object['commit'] && CID.from_cbor_tag(@data_object['commit'])
3131+ @commit ||= CID.from_cbor_tag(@data_object['commit'])
2132 end
22332334 # @return [Skyfall::CarArchive] commit data in the form of a parsed CAR archive
+14-3
lib/skyfall/firehose/identity_message.rb
···15151616 class Firehose::IdentityMessage < Firehose::Message
17171818- # @return [String, nil] current handle assigned to the DID
1919- def handle
2020- @data_object['handle']
1818+ #
1919+ # @private
2020+ # @param type_object [Hash] first decoded CBOR frame with metadata
2121+ # @param data_object [Hash] second decoded CBOR frame with payload
2222+ # @raise [DecodeError] if the message doesn't include required data
2323+ #
2424+ def initialize(type_object, data_object)
2525+ super
2626+ check_if_not_nil :seq, :did, :time
2727+2828+ @handle = @data_object['handle']
2129 end
3030+3131+ # @return [String, nil] current handle assigned to the DID
3232+ attr_reader :handle
2233 end
2334end
+2
lib/skyfall/firehose/info_message.rb
···3030 # @private
3131 # @param type_object [Hash] first decoded CBOR frame with metadata
3232 # @param data_object [Hash] second decoded CBOR frame with payload
3333+ # @raise [DecodeError] if the message doesn't include required data
3334 #
3435 def initialize(type_object, data_object)
3536 super
3737+ check_if_not_nil :name
36383739 @name = @data_object['name']
3840 @message = @data_object['message']
···145145 instance_variables - [:@type_object, :@data_object, :@blocks]
146146 end
147147148148+ # Checks if all required fields are set in the data object.
149149+ # @param fields [Array<Symbol, String>] list of fields to check
150150+ # @raise [DecodeError] if any of the fields is nil or not set
151151+ def check_if_not_nil(*fields)
152152+ missing = fields.select { |f| @data_object[f.to_s].nil? }
153153+154154+ raise DecodeError.new("Missing event details (#{missing.map(&:to_s).join(', ')})") if missing.length > 0
155155+ end
156156+148157149158 private
150159···163172 raise SubscriptionError.new(data['error'], data['message'])
164173 end
165174166166- raise DecodeError.new("Invalid object type: #{type}") unless type.is_a?(Hash)
167167- raise UnsupportedError.new("Unexpected CBOR object: #{type}") unless type['op'] == 1
168168- raise DecodeError.new("Missing data: #{type} #{objects.inspect}") unless type['op'] && type['t']
169169- raise DecodeError.new("Invalid message type: #{type['t']}") unless type['t'].start_with?('#')
170170- raise DecodeError.new("Invalid object type: #{data}") unless data.is_a?(Hash)
175175+ raise DecodeError.new("Invalid object type: #{type.inspect}") unless type.is_a?(Hash)
176176+ raise DecodeError.new("Missing data: #{type.inspect}") unless type['op'] && type['t']
177177+ raise DecodeError.new("Invalid object type: #{type['op'].inspect}") unless type['op'].is_a?(Integer)
178178+ raise DecodeError.new("Invalid object type: #{type['t'].inspect}") unless type['t'].is_a?(String)
179179+ raise DecodeError.new("Invalid message type: #{type['t'].inspect}") unless type['t'].start_with?('#')
180180+ raise UnsupportedError.new("Unsupported version: #{type['op']}") unless type['op'] == 1
181181+ raise DecodeError.new("Invalid object type: #{data.inspect}") unless data.is_a?(Hash)
171182172183 [type, data]
173184 end
+1-1
lib/skyfall/jetstream/account_message.rb
···1919 # @raise [DecodeError] if the message doesn't include required data
2020 #
2121 def initialize(json)
2222- raise DecodeError.new("Missing event details") if json['account'].nil?
2222+ raise DecodeError.new("Missing event details (account)") if json['account'].nil? || json['account']['active'].nil?
2323 super
2424 end
2525
+4-1
lib/skyfall/jetstream/commit_message.rb
···1717 # @raise [DecodeError] if the message doesn't include required data
1818 #
1919 def initialize(json)
2020- raise DecodeError.new("Missing event details") if json['commit'].nil?
2020+ raise DecodeError.new("Missing event details (commit)") if json['commit'].nil?
2121+2222+ %w(collection rkey operation).each { |f| raise DecodeError.new("Missing event details (#{f})") if json['commit'][f].nil? }
2323+2124 super
2225 end
2326
+1-1
lib/skyfall/jetstream/identity_message.rb
···2121 # @raise [DecodeError] if the message doesn't include required data
2222 #
2323 def initialize(json)
2424- raise DecodeError.new("Missing event details") if json['identity'].nil?
2424+ raise DecodeError.new("Missing event details (identity)") if json['identity'].nil?
2525 super
2626 end
2727
+4-1
lib/skyfall/jetstream/message.rb
···72727373 #
7474 # @param json [Hash] message JSON decoded from the websocket message
7575+ # @raise [DecodeError] if the message doesn't include required data
7576 #
7677 def initialize(json)
7878+ %w(kind did time_us).each { |f| raise DecodeError.new("Missing event details (#{f})") if json[f].nil? }
7979+7780 @json = json
7881 @type = @json['kind'].to_sym
7982 @did = @json['did']
···122125 # @return [Time]
123126 #
124127 def time
125125- @time ||= @json['time_us'] && Time.at(@json['time_us'] / 1_000_000.0)
128128+ @time ||= Time.at(@time_us / 1_000_000.0)
126129 end
127130 end
128131end