proc 0.5.0 → 0.9.0
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 +34 -8
- data/lib/proc/composition.rb +3 -23
- 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: 46f47f39b1b2b4f495b59575a14f1d8df1d837eada9048562ed5455a3d0fbc06
|
4
|
+
data.tar.gz: e93f11f26736d3504fc4e025be2fece6e9dafad9e66d6fac4c2d362470d3b207
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
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 "
|
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+
|
69
|
-
"content-type" => "application/vnd.proc+
|
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:
|
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,
|
180
|
+
[response.status, response.headers, MessagePack.unpack(response.read)]
|
155
181
|
end
|
156
182
|
rescue
|
157
183
|
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("
|
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 +
|
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
|
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.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-
|
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.
|
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.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.
|
40
|
+
version: 0.1.0
|
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.
|