proc 0.5.0 → 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a3b65698431242010b57cb9897c5ddf826cbd9c81dea9a3947505062e8060aeb
4
- data.tar.gz: bf1d1caaa7fffda8b8eac8d65c50b29a4c95003d980b8c83962f65bed8e1749e
3
+ metadata.gz: 46f47f39b1b2b4f495b59575a14f1d8df1d837eada9048562ed5455a3d0fbc06
4
+ data.tar.gz: e93f11f26736d3504fc4e025be2fece6e9dafad9e66d6fac4c2d362470d3b207
5
5
  SHA512:
6
- metadata.gz: ba18a8388e58dfe25119b412274b13eaf7cf684fc33e2ca186c8527c85a6f8973ecf01d39c9f56b861456646262b0a0fbaf9272feaec44ce178f328e1c6349ca
7
- data.tar.gz: 77ecd00cf5f48da5e17e80da46b2f0145ec1c8ae87d710d0b423d3e1908f7fdbc13fe251b9efee67289b5f20e1711b81a2c186fc0a48a9042aaff02413a8cdc8
6
+ metadata.gz: c82d1cb2697caf43077d2e1a909602401cb7bf8a8518be6f21d5160a38889d49aceb93d1d578c124ca8077dec21aa7e6b5fdec31ebb5e4137e64ab278e58e124
7
+ data.tar.gz: ca6f582486efebd0817b30228e997da049c482e7c5b42f08b52128e76534d3da19080aa995e0124d15e011677f5af066c0310a7a67671788cf44cffc040e62d5
data/lib/proc.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require_relative "proc/client"
4
+ require_relative "proc/version"
4
5
 
5
6
  class Proc
6
7
  def self.connect(authorization, **options)
@@ -8,7 +9,7 @@ class Proc
8
9
  end
9
10
 
10
11
  def self.undefined
11
- @_undefined ||= Object.new
12
+ @_undefined ||= ::Object.new
12
13
  end
13
14
 
14
15
  def self.undefined?(value)
data/lib/proc/callable.rb CHANGED
@@ -16,7 +16,7 @@ class Proc
16
16
  @arguments = arguments.dup
17
17
  end
18
18
 
19
- def call(input = input_omitted = true, **arguments)
19
+ def call(input = input_omitted = true, **arguments, &block)
20
20
  callable = self.class.new(
21
21
  @proc,
22
22
  client: @client,
@@ -24,7 +24,7 @@ class Proc
24
24
  arguments: @arguments.merge(arguments)
25
25
  )
26
26
 
27
- @client.call(@proc, callable.input, **callable.arguments)
27
+ @client.call(@proc, callable.input, **callable.arguments, &block)
28
28
  end
29
29
 
30
30
  def with(input = input_omitted = true, **arguments)
@@ -43,7 +43,7 @@ class Proc
43
43
  composed
44
44
  end
45
45
 
46
- def serialize
46
+ def serialize(unwrapped: false)
47
47
  serialized = ["()", @proc]
48
48
 
49
49
  unless Proc.undefined?(@input)
@@ -52,7 +52,11 @@ class Proc
52
52
 
53
53
  serialized.concat(serialized_arguments)
54
54
 
55
- ["{}", serialized]
55
+ if unwrapped
56
+ serialized
57
+ else
58
+ ["{}", serialized]
59
+ end
56
60
  end
57
61
 
58
62
  def serialized_input
data/lib/proc/client.rb CHANGED
@@ -1,11 +1,16 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "async"
4
- require "oj"
4
+ require "msgpack"
5
+
6
+ require_relative "msgpack/types/decimal"
7
+ MessagePack::DefaultFactory.register_type(0x00, Proc::Msgpack::Types::Decimal)
8
+ MessagePack::DefaultFactory.register_type(-1, Time, packer: MessagePack::Time::Packer, unpacker: MessagePack::Time::Unpacker)
5
9
 
6
10
  require_relative "argument"
7
11
  require_relative "callable"
8
12
  require_relative "composition"
13
+ require_relative "enumerator"
9
14
 
10
15
  require_relative "http/client"
11
16
 
@@ -37,6 +42,8 @@ class Proc
37
42
  end
38
43
 
39
44
  class Client
45
+ attr_reader :authorization, :scheme, :host
46
+
40
47
  def initialize(authorization, scheme: "https", host: "proc.dev")
41
48
  @authorization = authorization
42
49
  @scheme = scheme
@@ -65,11 +72,11 @@ class Proc
65
72
  end
66
73
 
67
74
  DEFAULT_HEADERS = {
68
- "accept" => "application/vnd.proc+json",
69
- "content-type" => "application/vnd.proc+json"
75
+ "accept" => "application/vnd.proc+msgpack",
76
+ "content-type" => "application/vnd.proc+msgpack"
70
77
  }.freeze
71
78
 
72
- def call(proc = nil, input = Proc.undefined, **arguments)
79
+ def call(proc = nil, input = Proc.undefined, **arguments, &block)
73
80
  body = []
74
81
 
75
82
  unless Proc.undefined?(input)
@@ -84,11 +91,30 @@ class Proc
84
91
  "authorization" => "bearer #{@authorization}"
85
92
  }.merge(DEFAULT_HEADERS)
86
93
 
87
- status, payload = get_payload(proc: proc, headers: headers, body: body)
94
+ status, headers, payload = get_payload(proc: proc, headers: headers, body: body)
88
95
 
89
96
  case status
90
97
  when 200
91
- extract_output(payload)
98
+ result = extract_output(payload)
99
+
100
+ if (cursor = headers["x-cursor"])
101
+ enumerator = if cursor.empty?
102
+ Enumerator.new(result)
103
+ else
104
+ Enumerator.new(result) {
105
+ arguments[:cursor] = cursor.to_s
106
+ call(proc, input, **arguments)
107
+ }
108
+ end
109
+
110
+ if block
111
+ enumerator.each(&block)
112
+ else
113
+ enumerator
114
+ end
115
+ else
116
+ result
117
+ end
92
118
  when 400
93
119
  raise Proc::Invalid, extract_error_message(payload)
94
120
  when 401
@@ -148,10 +174,10 @@ class Proc
148
174
  end
149
175
 
150
176
  private def get_payload(proc:, headers:, body:)
151
- @internal.call(:post, build_uri(proc), headers: headers, body: Oj.dump(body, mode: :custom)) do |response|
177
+ @internal.call(:post, build_uri(proc), headers: headers, body: MessagePack.pack(body)) do |response|
152
178
  @remaining = response.headers["x-rate-limit-remaining"].to_s.to_i
153
179
  @resets_at = Time.at(response.headers["x-rate-limit-reset"].to_s.to_i)
154
- [response.status, Oj.load(response.read, mode: :compat, compat_bigdecimal: true)]
180
+ [response.status, response.headers, MessagePack.unpack(response.read)]
155
181
  end
156
182
  rescue
157
183
  raise Proc::Unavailable
@@ -15,7 +15,7 @@ class Proc
15
15
  @callables = @callables.dup
16
16
  end
17
17
 
18
- def call(input = input_omitted = true, **arguments)
18
+ def call(input = input_omitted = true, **arguments, &block)
19
19
  callable = self.class.new(
20
20
  client: @client,
21
21
  input: input_omitted ? @input : input,
@@ -23,7 +23,7 @@ class Proc
23
23
  arguments: @arguments.merge(arguments)
24
24
  )
25
25
 
26
- @client.call("proc.exec", Proc.undefined, proc: callable)
26
+ @client.call("exec", Proc.undefined, proc: callable, &block)
27
27
  end
28
28
 
29
29
  def with(input = input_omitted = true, **arguments)
@@ -51,33 +51,13 @@ class Proc
51
51
  end
52
52
 
53
53
  def serialize
54
- # wrapped = {"[]" => serialized_calls}
55
-
56
- # unless Proc.undefined?(@input)
57
- # wrapped["<<"] = serialized_input
58
- # end
59
-
60
- # {"{}" => wrapped.merge(serialized_arguments)}
61
-
62
54
  serialized = ["{}"]
63
55
 
64
56
  unless Proc.undefined?(@input)
65
57
  serialized << [">>", serialized_input]
66
58
  end
67
59
 
68
- serialized + serialized_arguments + serialized_calls
69
- end
70
-
71
- def serialized_calls
72
- @callables.map { |callable|
73
- serialized = ["()", callable.proc]
74
-
75
- unless Proc.undefined?(callable.input)
76
- serialized << [">>", callable.serialized_input]
77
- end
78
-
79
- serialized.concat(callable.serialized_arguments)
80
- }
60
+ serialized + serialized_arguments + @callables.map { |callable| callable.serialize(unwrapped: true) }
81
61
  end
82
62
 
83
63
  def serialized_input
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Proc
4
+ class Enumerator
5
+ include Enumerable
6
+
7
+ def initialize(values, &next_block)
8
+ @values = values
9
+ @next_block = next_block
10
+ end
11
+
12
+ def each(&block)
13
+ return to_enum(:each) unless block
14
+
15
+ @values.each(&block)
16
+
17
+ if @next_block
18
+ @next_block.call.each(&block)
19
+ end
20
+ end
21
+ end
22
+ end
@@ -3,8 +3,6 @@
3
3
  require "async"
4
4
  require "async/http/internet"
5
5
 
6
- require "protocol/http/body/streamable"
7
-
8
6
  require "core/async"
9
7
 
10
8
  require_relative "request"
@@ -15,30 +13,24 @@ class Proc
15
13
  class Client
16
14
  include Is::Async
17
15
 
18
- def initialize
19
- @internet = Async::HTTP::Internet.new
20
- end
21
-
22
16
  def call(method, uri, params: {}, headers: {}, body: nil)
17
+ internet = Async::HTTP::Internet.new
23
18
  request = Request.new(method: method, uri: uri, params: params, headers: headers, body: body)
24
19
 
25
20
  await {
26
21
  begin
27
- response = make_request(request)
22
+ response = make_request(internet, request)
28
23
 
29
24
  yield response
30
25
  ensure
31
26
  response&.close
27
+ internet&.close
32
28
  end
33
29
  }
34
30
  end
35
31
 
36
- def close
37
- @internet.close
38
- end
39
-
40
- private def make_request(request)
41
- async_response = @internet.call(*request.callable)
32
+ private def make_request(internet, request)
33
+ async_response = internet.call(*request.callable)
42
34
  wrap_async_response_for_request(async_response, request)
43
35
  end
44
36
 
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ class BigDecimal
4
+ def to_msgpack(packer)
5
+ if precision > 16
6
+ packer.write(Proc::Msgpack::Types::Decimal.new(self))
7
+ packer
8
+ else
9
+ to_f.to_msgpack(packer)
10
+ end
11
+ end
12
+ end
13
+
14
+ class Proc
15
+ module Msgpack
16
+ module Types
17
+ class Decimal
18
+ class << self
19
+ def from_msgpack_ext(data)
20
+ BigDecimal(data)
21
+ end
22
+ end
23
+
24
+ def initialize(value)
25
+ @value = value
26
+ end
27
+
28
+ def to_msgpack_ext
29
+ @value.to_s
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
data/lib/proc/version.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class Proc
4
- VERSION = "0.5.0"
4
+ VERSION = "0.9.0"
5
5
 
6
6
  def self.version
7
7
  VERSION
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: proc
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bryan Powell
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-02-09 00:00:00.000000000 Z
11
+ date: 2021-03-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: async-http
@@ -16,42 +16,42 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 0.52.5
19
+ version: 0.54.1
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 0.52.5
26
+ version: 0.54.1
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: core-async
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: 0.0.0
33
+ version: 0.1.0
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: 0.0.0
40
+ version: 0.1.0
41
41
  - !ruby/object:Gem::Dependency
42
- name: oj
42
+ name: msgpack
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '3.10'
47
+ version: '1.4'
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '3.10'
54
+ version: '1.4'
55
55
  description: Proc client library.
56
56
  email: bryan@metabahn.com
57
57
  executables: []
@@ -65,9 +65,11 @@ files:
65
65
  - lib/proc/callable.rb
66
66
  - lib/proc/client.rb
67
67
  - lib/proc/composition.rb
68
+ - lib/proc/enumerator.rb
68
69
  - lib/proc/http/client.rb
69
70
  - lib/proc/http/request.rb
70
71
  - lib/proc/http/response.rb
72
+ - lib/proc/msgpack/types/decimal.rb
71
73
  - lib/proc/version.rb
72
74
  homepage: https://proc.dev/
73
75
  licenses:
@@ -88,7 +90,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
88
90
  - !ruby/object:Gem::Version
89
91
  version: '0'
90
92
  requirements: []
91
- rubygems_version: 3.1.4
93
+ rubygems_version: 3.2.4
92
94
  signing_key:
93
95
  specification_version: 4
94
96
  summary: Proc client library.