grumlin 0.1.3 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/main.yml +1 -1
- data/.overcommit.yml +8 -0
- data/.rubocop.yml +55 -11
- data/Gemfile +2 -0
- data/Gemfile.lock +31 -22
- data/bin/console +6 -3
- data/bin/setup +1 -0
- data/grumlin.gemspec +2 -1
- data/lib/async/channel.rb +64 -0
- data/lib/grumlin.rb +49 -3
- data/lib/grumlin/anonymous_step.rb +44 -0
- data/lib/grumlin/client.rb +68 -132
- data/lib/grumlin/edge.rb +3 -5
- data/lib/grumlin/exceptions.rb +22 -2
- data/lib/grumlin/order.rb +18 -0
- data/lib/grumlin/p.rb +18 -0
- data/lib/grumlin/path.rb +15 -0
- data/lib/grumlin/pop.rb +28 -0
- data/lib/grumlin/request_dispatcher.rb +84 -0
- data/lib/grumlin/step.rb +19 -30
- data/lib/grumlin/sugar.rb +28 -0
- data/lib/grumlin/t.rb +18 -0
- data/lib/grumlin/test/rspec.rb +11 -0
- data/lib/grumlin/test/rspec/db_cleaner_context.rb +18 -0
- data/lib/grumlin/test/rspec/gremlin_context.rb +27 -0
- data/lib/grumlin/translator.rb +22 -21
- data/lib/grumlin/transport.rb +86 -0
- data/lib/grumlin/traversal.rb +4 -11
- data/lib/grumlin/typing.rb +25 -5
- data/lib/grumlin/u.rb +13 -0
- data/lib/grumlin/version.rb +1 -1
- data/lib/grumlin/vertex.rb +2 -2
- metadata +34 -7
- data/bin/stress +0 -51
- data/lib/grumlin/traversing_context.rb +0 -17
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ea9263ebc4f6303d3dc02ccd39c8dd04f2b46b434456edad4466a19ebe7dede2
|
4
|
+
data.tar.gz: 84205bc8a2568987933d6cce5c576cbbf298700659b31d7435ecac1fde030029
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1fc512adc3e110cc6a6ed2f348a24b888b5f5443d566eb1f57bb3b56dad60529390f1c4c52b1391296f75a1ea4cd79dc70eb427c3f57b4bf4f4c6417e54bbe95
|
7
|
+
data.tar.gz: 36029a741e2d89654cbb5a9ecd28213c7122e3ecc35cd030baa320af71bd238560d1e671a8b9d2aa1f4b40938d1787679b2166733b0ebc429d5a5a113142d3b2
|
data/.github/workflows/main.yml
CHANGED
data/.overcommit.yml
ADDED
data/.rubocop.yml
CHANGED
@@ -7,24 +7,44 @@ require:
|
|
7
7
|
- rubocop-performance
|
8
8
|
- rubocop-rspec
|
9
9
|
|
10
|
-
Style/StringLiterals:
|
11
|
-
Enabled: true
|
12
|
-
EnforcedStyle: double_quotes
|
13
|
-
|
14
|
-
Style/StringLiteralsInInterpolation:
|
15
|
-
Enabled: true
|
16
|
-
EnforcedStyle: double_quotes
|
17
|
-
|
18
|
-
Style/Documentation:
|
19
|
-
Enabled: false
|
20
|
-
|
21
10
|
Layout/LineLength:
|
22
11
|
Max: 120
|
12
|
+
Exclude:
|
13
|
+
- spec/**/*_spec.rb
|
23
14
|
|
24
15
|
Metrics/BlockLength:
|
25
16
|
Exclude:
|
26
17
|
- spec/**/*_spec.rb
|
27
18
|
|
19
|
+
Metrics/MethodLength:
|
20
|
+
Max: 20
|
21
|
+
|
22
|
+
Metrics/ParameterLists:
|
23
|
+
Max: 6
|
24
|
+
|
25
|
+
Naming/MethodName:
|
26
|
+
IgnoredPatterns:
|
27
|
+
- toList
|
28
|
+
- inVLabel
|
29
|
+
- outVLabel
|
30
|
+
- inV
|
31
|
+
- outV
|
32
|
+
|
33
|
+
Naming/VariableName:
|
34
|
+
AllowedIdentifiers:
|
35
|
+
- inV
|
36
|
+
- outV
|
37
|
+
- inVLabel
|
38
|
+
- outVLabel
|
39
|
+
|
40
|
+
Naming/MethodParameterName:
|
41
|
+
AllowedNames:
|
42
|
+
- id
|
43
|
+
- inV
|
44
|
+
- outV
|
45
|
+
- inVLabel
|
46
|
+
- outVLabel
|
47
|
+
|
28
48
|
RSpec/NamedSubject:
|
29
49
|
Enabled: false
|
30
50
|
|
@@ -33,3 +53,27 @@ RSpec/NestedGroups:
|
|
33
53
|
|
34
54
|
RSpec/ExampleLength:
|
35
55
|
Enabled: false
|
56
|
+
|
57
|
+
RSpec/MultipleExpectations:
|
58
|
+
Enabled: false
|
59
|
+
|
60
|
+
RSpec/DescribeClass:
|
61
|
+
Enabled: false
|
62
|
+
|
63
|
+
Style/WordArray:
|
64
|
+
Exclude:
|
65
|
+
- spec/**/*_spec.rb
|
66
|
+
|
67
|
+
Style/StringLiterals:
|
68
|
+
Enabled: true
|
69
|
+
EnforcedStyle: double_quotes
|
70
|
+
|
71
|
+
Style/StringLiteralsInInterpolation:
|
72
|
+
Enabled: true
|
73
|
+
EnforcedStyle: double_quotes
|
74
|
+
|
75
|
+
Style/Documentation:
|
76
|
+
Enabled: false
|
77
|
+
|
78
|
+
Style/MultilineBlockChain:
|
79
|
+
Enabled: false
|
data/Gemfile
CHANGED
@@ -4,6 +4,7 @@ source "https://rubygems.org"
|
|
4
4
|
|
5
5
|
gemspec
|
6
6
|
|
7
|
+
gem "nokogiri"
|
7
8
|
gem "rubocop"
|
8
9
|
gem "rubocop-performance"
|
9
10
|
gem "rubocop-rspec"
|
@@ -12,5 +13,6 @@ gem "solargraph"
|
|
12
13
|
|
13
14
|
gem "async-rspec"
|
14
15
|
gem "factory_bot"
|
16
|
+
gem "overcommit"
|
15
17
|
gem "rspec"
|
16
18
|
gem "simplecov"
|
data/Gemfile.lock
CHANGED
@@ -1,8 +1,9 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
grumlin (0.
|
5
|
-
async-
|
4
|
+
grumlin (0.5.0)
|
5
|
+
async-pool (~> 0.3)
|
6
|
+
async-websocket (~> 0.19)
|
6
7
|
|
7
8
|
GEM
|
8
9
|
remote: https://rubygems.org/
|
@@ -14,33 +15,34 @@ GEM
|
|
14
15
|
tzinfo (~> 2.0)
|
15
16
|
zeitwerk (~> 2.3)
|
16
17
|
ast (2.4.2)
|
17
|
-
async (1.
|
18
|
+
async (1.30.1)
|
18
19
|
console (~> 1.10)
|
19
20
|
nio4r (~> 2.3)
|
20
21
|
timers (~> 4.1)
|
21
|
-
async-http (0.56.
|
22
|
-
async (
|
23
|
-
async-io (
|
24
|
-
async-pool (
|
22
|
+
async-http (0.56.5)
|
23
|
+
async (>= 1.25)
|
24
|
+
async-io (>= 1.28)
|
25
|
+
async-pool (>= 0.2)
|
25
26
|
protocol-http (~> 0.22.0)
|
26
27
|
protocol-http1 (~> 0.14.0)
|
27
28
|
protocol-http2 (~> 0.14.0)
|
28
|
-
async-io (1.
|
29
|
-
async
|
30
|
-
async-pool (0.3.
|
31
|
-
async (
|
29
|
+
async-io (1.32.2)
|
30
|
+
async
|
31
|
+
async-pool (0.3.8)
|
32
|
+
async (>= 1.25)
|
32
33
|
async-rspec (1.16.0)
|
33
34
|
rspec (~> 3.0)
|
34
35
|
rspec-files (~> 1.0)
|
35
36
|
rspec-memory (~> 1.0)
|
36
|
-
async-websocket (0.
|
37
|
+
async-websocket (0.19.0)
|
37
38
|
async-http (~> 0.54)
|
38
39
|
async-io (~> 1.23)
|
39
40
|
protocol-websocket (~> 0.7.0)
|
40
|
-
backport (1.
|
41
|
+
backport (1.2.0)
|
41
42
|
benchmark (0.1.1)
|
43
|
+
childprocess (4.0.0)
|
42
44
|
concurrent-ruby (1.1.8)
|
43
|
-
console (1.
|
45
|
+
console (1.13.1)
|
44
46
|
fiber-local
|
45
47
|
diff-lcs (1.4.4)
|
46
48
|
docile (1.4.0)
|
@@ -50,20 +52,24 @@ GEM
|
|
50
52
|
fiber-local (1.0.0)
|
51
53
|
i18n (1.8.10)
|
52
54
|
concurrent-ruby (~> 1.0)
|
55
|
+
iniparse (1.5.0)
|
53
56
|
jaro_winkler (1.5.4)
|
54
57
|
kramdown (2.3.1)
|
55
58
|
rexml
|
56
59
|
kramdown-parser-gfm (1.1.0)
|
57
60
|
kramdown (~> 2.0)
|
58
61
|
minitest (5.14.4)
|
59
|
-
nio4r (2.5.
|
60
|
-
nokogiri (1.11.
|
62
|
+
nio4r (2.5.8)
|
63
|
+
nokogiri (1.11.7-x86_64-linux)
|
61
64
|
racc (~> 1.4)
|
65
|
+
overcommit (0.57.0)
|
66
|
+
childprocess (>= 0.6.3, < 5)
|
67
|
+
iniparse (~> 1.4)
|
62
68
|
parallel (1.20.1)
|
63
69
|
parser (3.0.1.1)
|
64
70
|
ast (~> 2.4.1)
|
65
71
|
protocol-hpack (1.4.2)
|
66
|
-
protocol-http (0.22.
|
72
|
+
protocol-http (0.22.5)
|
67
73
|
protocol-http1 (0.14.1)
|
68
74
|
protocol-http (~> 0.22)
|
69
75
|
protocol-http2 (0.14.2)
|
@@ -95,16 +101,16 @@ GEM
|
|
95
101
|
diff-lcs (>= 1.2.0, < 2.0)
|
96
102
|
rspec-support (~> 3.10.0)
|
97
103
|
rspec-support (3.10.2)
|
98
|
-
rubocop (1.
|
104
|
+
rubocop (1.16.1)
|
99
105
|
parallel (~> 1.10)
|
100
106
|
parser (>= 3.0.0.0)
|
101
107
|
rainbow (>= 2.2.2, < 4.0)
|
102
108
|
regexp_parser (>= 1.8, < 3.0)
|
103
109
|
rexml
|
104
|
-
rubocop-ast (>= 1.
|
110
|
+
rubocop-ast (>= 1.7.0, < 2.0)
|
105
111
|
ruby-progressbar (~> 1.7)
|
106
112
|
unicode-display_width (>= 1.4.0, < 3.0)
|
107
|
-
rubocop-ast (1.
|
113
|
+
rubocop-ast (1.7.0)
|
108
114
|
parser (>= 3.0.1.1)
|
109
115
|
rubocop-performance (1.11.3)
|
110
116
|
rubocop (>= 1.7.0, < 2.0)
|
@@ -119,10 +125,11 @@ GEM
|
|
119
125
|
simplecov_json_formatter (~> 0.1)
|
120
126
|
simplecov-html (0.12.3)
|
121
127
|
simplecov_json_formatter (0.1.3)
|
122
|
-
solargraph (0.
|
123
|
-
backport (~> 1.
|
128
|
+
solargraph (0.43.0)
|
129
|
+
backport (~> 1.2)
|
124
130
|
benchmark
|
125
131
|
bundler (>= 1.17.2)
|
132
|
+
diff-lcs (~> 1.4)
|
126
133
|
e2mmap
|
127
134
|
jaro_winkler (~> 1.5)
|
128
135
|
kramdown (~> 2.3)
|
@@ -149,6 +156,8 @@ DEPENDENCIES
|
|
149
156
|
async-rspec
|
150
157
|
factory_bot
|
151
158
|
grumlin!
|
159
|
+
nokogiri
|
160
|
+
overcommit
|
152
161
|
rspec
|
153
162
|
rubocop
|
154
163
|
rubocop-performance
|
data/bin/console
CHANGED
@@ -5,9 +5,12 @@ require "bundler/setup"
|
|
5
5
|
require "grumlin"
|
6
6
|
require "irb"
|
7
7
|
|
8
|
+
Grumlin.configure do |config|
|
9
|
+
config.url = ENV["GREMLIN_URL"] || "ws://localhost:8182/gremlin"
|
10
|
+
end
|
11
|
+
|
8
12
|
Async do
|
9
|
-
|
10
|
-
g = Grumlin::Traversal.new(client)
|
13
|
+
g = Grumlin::Traversal.new
|
11
14
|
|
12
15
|
IRB.setup(nil)
|
13
16
|
workspace = IRB::WorkSpace.new(binding)
|
@@ -16,5 +19,5 @@ Async do
|
|
16
19
|
rescue StandardError
|
17
20
|
raise
|
18
21
|
ensure
|
19
|
-
|
22
|
+
Grumlin.config.default_pool.close
|
20
23
|
end
|
data/bin/setup
CHANGED
data/grumlin.gemspec
CHANGED
@@ -0,0 +1,64 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Async
|
4
|
+
# Channel is a wrapper around Async::Queue that provides
|
5
|
+
# a protocol and handy tools for passing data, exceptions and closing.
|
6
|
+
# It is designed to be used with only one publisher and one subscriber
|
7
|
+
class Channel
|
8
|
+
class ChannelError < StandardError; end
|
9
|
+
|
10
|
+
class ChannelClosedError < ChannelError; end
|
11
|
+
|
12
|
+
def initialize
|
13
|
+
@queue = Async::Queue.new
|
14
|
+
@closed = false
|
15
|
+
end
|
16
|
+
|
17
|
+
def closed?
|
18
|
+
@closed
|
19
|
+
end
|
20
|
+
|
21
|
+
# Methods for a publisher
|
22
|
+
def <<(payload)
|
23
|
+
raise(ChannelClosedError, "Cannot send to a closed channel") if @closed
|
24
|
+
|
25
|
+
@queue << [:payload, payload]
|
26
|
+
end
|
27
|
+
|
28
|
+
def exception(exception)
|
29
|
+
raise(ChannelClosedError, "Cannot send to a closed channel") if closed?
|
30
|
+
|
31
|
+
@queue << [:exception, exception]
|
32
|
+
end
|
33
|
+
|
34
|
+
def close
|
35
|
+
raise(ChannelClosedError, "Cannot close a closed channel") if closed?
|
36
|
+
|
37
|
+
@queue << [:close]
|
38
|
+
@closed = true
|
39
|
+
end
|
40
|
+
|
41
|
+
# Methods for a subscriber
|
42
|
+
def dequeue
|
43
|
+
each do |payload| # rubocop:disable Lint/UnreachableLoop this is intended
|
44
|
+
return payload
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def each
|
49
|
+
raise(ChannelClosedError, "Cannot receive from a closed channel") if closed?
|
50
|
+
|
51
|
+
@queue.each do |type, payload|
|
52
|
+
case type
|
53
|
+
when :exception
|
54
|
+
payload.set_backtrace(caller + (payload.backtrace || [])) # A hack to preserve full backtrace
|
55
|
+
raise payload
|
56
|
+
when :payload
|
57
|
+
yield payload
|
58
|
+
when :close
|
59
|
+
break
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
data/lib/grumlin.rb
CHANGED
@@ -4,21 +4,67 @@ require "securerandom"
|
|
4
4
|
require "json"
|
5
5
|
|
6
6
|
require "async"
|
7
|
+
require "async/pool"
|
8
|
+
require "async/pool/resource"
|
9
|
+
require "async/pool/controller"
|
7
10
|
require "async/queue"
|
11
|
+
require "async/barrier"
|
8
12
|
require "async/http/endpoint"
|
9
13
|
require "async/websocket/client"
|
10
14
|
|
15
|
+
require_relative "async/channel"
|
16
|
+
|
11
17
|
require_relative "grumlin/version"
|
12
18
|
require_relative "grumlin/exceptions"
|
13
19
|
|
20
|
+
require_relative "grumlin/transport"
|
21
|
+
require_relative "grumlin/client"
|
22
|
+
|
14
23
|
require_relative "grumlin/vertex"
|
15
24
|
require_relative "grumlin/edge"
|
25
|
+
require_relative "grumlin/path"
|
16
26
|
require_relative "grumlin/typing"
|
17
|
-
require_relative "grumlin/client"
|
18
27
|
require_relative "grumlin/traversal"
|
19
|
-
require_relative "grumlin/
|
28
|
+
require_relative "grumlin/request_dispatcher"
|
20
29
|
require_relative "grumlin/translator"
|
21
|
-
|
30
|
+
|
31
|
+
require_relative "grumlin/anonymous_step"
|
32
|
+
require_relative "grumlin/step"
|
33
|
+
|
34
|
+
require_relative "grumlin/t"
|
35
|
+
require_relative "grumlin/order"
|
36
|
+
require_relative "grumlin/u"
|
37
|
+
require_relative "grumlin/p"
|
38
|
+
require_relative "grumlin/pop"
|
39
|
+
require_relative "grumlin/sugar"
|
22
40
|
|
23
41
|
module Grumlin
|
42
|
+
class Config
|
43
|
+
attr_accessor :url, :pool_size, :client_concurrency, :client_factory
|
44
|
+
|
45
|
+
# For some reason, client_concurrency must be greater than pool_size
|
46
|
+
def initialize
|
47
|
+
@pool_size = 10
|
48
|
+
@client_concurrency = 20
|
49
|
+
@client_factory = ->(url, parent) { Grumlin::Client.new(url, parent: parent) }
|
50
|
+
end
|
51
|
+
|
52
|
+
def default_pool
|
53
|
+
@default_pool ||= Async::Pool::Controller.new(Grumlin::Client::PoolResource, limit: pool_size)
|
54
|
+
end
|
55
|
+
|
56
|
+
def reset!
|
57
|
+
@default_pool = nil
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
class << self
|
62
|
+
def configure
|
63
|
+
yield config
|
64
|
+
end
|
65
|
+
|
66
|
+
def config
|
67
|
+
@config ||= Config.new
|
68
|
+
end
|
69
|
+
end
|
24
70
|
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Grumlin
|
4
|
+
class AnonymousStep
|
5
|
+
attr_reader :name, :args
|
6
|
+
|
7
|
+
def initialize(name, *args, previous_steps: [])
|
8
|
+
@name = name
|
9
|
+
@previous_steps = previous_steps
|
10
|
+
@args = args
|
11
|
+
end
|
12
|
+
|
13
|
+
%w[addV addE V E limit count drop property valueMap select from to as order by has hasLabel values hasNot
|
14
|
+
not outE groupCount label group in out fold unfold inV path dedup project coalesce repeat emit
|
15
|
+
elementMap where].each do |step|
|
16
|
+
define_method step do |*args|
|
17
|
+
add_step(step, args, previous_steps: steps)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
alias addVertex addV
|
22
|
+
alias addEdge addE
|
23
|
+
|
24
|
+
def inspect
|
25
|
+
@inspect ||= to_bytecode.to_s
|
26
|
+
end
|
27
|
+
|
28
|
+
alias to_s inspect
|
29
|
+
|
30
|
+
def to_bytecode
|
31
|
+
@to_bytecode ||= (@previous_steps.last&.to_bytecode || []) + [Translator.to_bytecode(self)]
|
32
|
+
end
|
33
|
+
|
34
|
+
def steps
|
35
|
+
(@previous_steps + [self])
|
36
|
+
end
|
37
|
+
|
38
|
+
private
|
39
|
+
|
40
|
+
def add_step(step_name, args, previous_steps:)
|
41
|
+
self.class.new(step_name, *args, previous_steps: previous_steps)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|