lib/workato/connector/sdk/stream.rb in workato-connector-sdk-1.3.0 vs lib/workato/connector/sdk/stream.rb in workato-connector-sdk-1.3.1
- old
+ new
@@ -77,10 +77,26 @@
data = data.nil? ? chunk : data + chunk
end
data
end
+ class << self
+ extend T::Sig
+
+ sig do
+ params(
+ stream: T.any(Proxy, T::Hash[T.untyped, T.untyped], String),
+ from: T.nilable(Integer),
+ frame_size: T.nilable(Integer),
+ blk: SorbetTypes::StreamInProc
+ ).void
+ end
+ def each_chunk(stream:, from:, frame_size: nil, &blk)
+ Reader.new(stream: stream, from: from, frame_size: frame_size).each_chunk(&blk)
+ end
+ end
+
class Reader
extend T::Sig
ProxyReadProc = T.type_alias do
T.proc.params(
@@ -151,10 +167,13 @@
raise 'Mock streams with Proc or Hash. Read spec/examples/stream/connector_spec.rb for examples'
end
end
end
+ private_constant :Reader
+
+ # @api private
class Proxy
extend T::Sig
sig { params(name: String, input: SorbetTypes::StreamInputHash, stream: Stream).void }
def initialize(name:, input:, stream:)
@@ -210,12 +229,12 @@
end
class Mock
extend T::Sig
- sig { params(chunks: T.untyped).void }
+ sig { params(chunks: T::Hash[T.any(Integer, String), T.untyped]).void }
def initialize(chunks:)
- @chunks = chunks
+ @chunks = T.let(chunks.transform_keys(&:to_i), T::Hash[Integer, T.untyped])
end
sig { params(from: Integer, frame_size: Integer, _blk: Reader::ProxyReadProc).void }
def read(from:, frame_size:, &_blk)
last_from = chunks.keys.last