proc 0.6.0 → 0.9.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 +4 -4
- data/lib/proc.rb +2 -1
- data/lib/proc/callable.rb +8 -4
- data/lib/proc/client.rb +63 -24
- data/lib/proc/composition.rb +3 -15
- data/lib/proc/enumerator.rb +22 -0
- data/lib/proc/http/client.rb +5 -13
- data/lib/proc/msgpack/types/decimal.rb +34 -0
- data/lib/proc/version.rb +1 -1
- metadata +12 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cbe8ec8f147808e160d44b09da719dafb03e329b3b1fb78f345300af4c9ab798
|
4
|
+
data.tar.gz: f7d81cecd2d9c6cf88e3b4f59bae7681e962bd2dd7d95fd6a1c1593f8245639c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e31c9f0c03adc5b2b82f0a2205cfb990f7be7bf529cf287580f2253b70425b63be00f19583838b93e15642f5ea2d3a1289d88065d6658f247f25b875d5bd8e3f
|
7
|
+
data.tar.gz: 9f44c4c22a636faa3f3032420a48e8aa8e7b92b18d2023115736612ef1b03736d967b770a43cf28e3ef426057b2ffa31a0398e627b51e271b6612cfadd2d0fea
|
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
|
-
|
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,21 +1,21 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require "async"
|
4
|
-
require "
|
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
|
|
12
17
|
Console.logger.off!
|
13
18
|
|
14
|
-
Oj.default_options = {
|
15
|
-
mode: :custom,
|
16
|
-
bigdecimal_load: :auto
|
17
|
-
}.freeze
|
18
|
-
|
19
19
|
class Proc
|
20
20
|
class Error < StandardError
|
21
21
|
end
|
@@ -42,6 +42,8 @@ class Proc
|
|
42
42
|
end
|
43
43
|
|
44
44
|
class Client
|
45
|
+
attr_reader :authorization, :scheme, :host
|
46
|
+
|
45
47
|
def initialize(authorization, scheme: "https", host: "proc.dev")
|
46
48
|
@authorization = authorization
|
47
49
|
@scheme = scheme
|
@@ -53,28 +55,33 @@ class Proc
|
|
53
55
|
Callable.new(proc, client: self)
|
54
56
|
end
|
55
57
|
|
56
|
-
def
|
57
|
-
|
58
|
-
|
59
|
-
|
58
|
+
def rate_limit
|
59
|
+
refresh_rate_limit
|
60
|
+
@rate_limit
|
61
|
+
end
|
62
|
+
|
63
|
+
def rate_limit_window
|
64
|
+
refresh_rate_limit
|
65
|
+
@rate_limit_window
|
66
|
+
end
|
60
67
|
|
61
|
-
|
68
|
+
def rate_limit_reset
|
69
|
+
refresh_rate_limit
|
70
|
+
@rate_limit_reset
|
62
71
|
end
|
63
72
|
|
64
|
-
def
|
65
|
-
unless defined?(@
|
73
|
+
private def refresh_rate_limit
|
74
|
+
unless defined?(@rate_limit_reset)
|
66
75
|
self["ping"].call
|
67
76
|
end
|
68
|
-
|
69
|
-
@resets_at
|
70
77
|
end
|
71
78
|
|
72
79
|
DEFAULT_HEADERS = {
|
73
|
-
"accept" => "application/vnd.proc+
|
74
|
-
"content-type" => "application/vnd.proc+
|
80
|
+
"accept" => "application/vnd.proc+msgpack",
|
81
|
+
"content-type" => "application/vnd.proc+msgpack"
|
75
82
|
}.freeze
|
76
83
|
|
77
|
-
def call(proc = nil, input = Proc.undefined, **arguments)
|
84
|
+
def call(proc = nil, input = Proc.undefined, **arguments, &block)
|
78
85
|
body = []
|
79
86
|
|
80
87
|
unless Proc.undefined?(input)
|
@@ -89,11 +96,30 @@ class Proc
|
|
89
96
|
"authorization" => "bearer #{@authorization}"
|
90
97
|
}.merge(DEFAULT_HEADERS)
|
91
98
|
|
92
|
-
status, payload = get_payload(proc: proc, headers: headers, body: body)
|
99
|
+
status, headers, payload = get_payload(proc: proc, headers: headers, body: body)
|
93
100
|
|
94
101
|
case status
|
95
102
|
when 200
|
96
|
-
extract_output(payload)
|
103
|
+
result = extract_output(payload)
|
104
|
+
|
105
|
+
if (cursor = headers["x-cursor"])
|
106
|
+
enumerator = if cursor.empty?
|
107
|
+
Enumerator.new(result)
|
108
|
+
else
|
109
|
+
Enumerator.new(result) {
|
110
|
+
arguments[:cursor] = cursor.to_s
|
111
|
+
call(proc, input, **arguments)
|
112
|
+
}
|
113
|
+
end
|
114
|
+
|
115
|
+
if block
|
116
|
+
enumerator.each(&block)
|
117
|
+
else
|
118
|
+
enumerator
|
119
|
+
end
|
120
|
+
else
|
121
|
+
result
|
122
|
+
end
|
97
123
|
when 400
|
98
124
|
raise Proc::Invalid, extract_error_message(payload)
|
99
125
|
when 401
|
@@ -153,10 +179,23 @@ class Proc
|
|
153
179
|
end
|
154
180
|
|
155
181
|
private def get_payload(proc:, headers:, body:)
|
156
|
-
@internal.call(:post, build_uri(proc), headers: headers, body:
|
157
|
-
|
158
|
-
|
159
|
-
[
|
182
|
+
@internal.call(:post, build_uri(proc), headers: headers, body: MessagePack.pack(body)) do |response|
|
183
|
+
split_limit = response.headers["x-rate-limit"].to_s.split(";window=")
|
184
|
+
|
185
|
+
@rate_limit = split_limit[0].to_i
|
186
|
+
|
187
|
+
@rate_limit_window = case split_limit[1]
|
188
|
+
when "60"
|
189
|
+
:minute
|
190
|
+
when "1"
|
191
|
+
:second
|
192
|
+
end
|
193
|
+
|
194
|
+
@rate_limit_reset = if (reset = response.headers["x-rate-limit-reset"])
|
195
|
+
Time.at(reset.to_s.to_i)
|
196
|
+
end
|
197
|
+
|
198
|
+
[response.status, response.headers, MessagePack.unpack(response.read)]
|
160
199
|
end
|
161
200
|
rescue
|
162
201
|
raise Proc::Unavailable
|
data/lib/proc/composition.rb
CHANGED
@@ -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("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)
|
@@ -57,19 +57,7 @@ class Proc
|
|
57
57
|
serialized << [">>", serialized_input]
|
58
58
|
end
|
59
59
|
|
60
|
-
serialized + serialized_arguments +
|
61
|
-
end
|
62
|
-
|
63
|
-
def serialized_calls
|
64
|
-
@callables.map { |callable|
|
65
|
-
serialized = ["()", callable.proc]
|
66
|
-
|
67
|
-
unless Proc.undefined?(callable.input)
|
68
|
-
serialized << [">>", callable.serialized_input]
|
69
|
-
end
|
70
|
-
|
71
|
-
serialized.concat(callable.serialized_arguments)
|
72
|
-
}
|
60
|
+
serialized + serialized_arguments + @callables.map { |callable| callable.serialize(unwrapped: true) }
|
73
61
|
end
|
74
62
|
|
75
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
|
data/lib/proc/http/client.rb
CHANGED
@@ -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
|
37
|
-
|
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
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.
|
4
|
+
version: 0.9.1
|
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-
|
11
|
+
date: 2021-03-17 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.
|
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.
|
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.
|
33
|
+
version: 0.2.1
|
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.
|
40
|
+
version: 0.2.1
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
42
|
+
name: msgpack
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '
|
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: '
|
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.
|
93
|
+
rubygems_version: 3.2.4
|
92
94
|
signing_key:
|
93
95
|
specification_version: 4
|
94
96
|
summary: Proc client library.
|