grumlin 0.1.0 → 0.3.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 +67 -12
- data/.gitignore +1 -0
- data/.overcommit.yml +8 -0
- data/.rubocop.yml +3 -0
- data/Gemfile +2 -2
- data/Gemfile.lock +30 -23
- data/bin/console +6 -3
- data/bin/setup +1 -0
- data/docker-compose.yml +6 -0
- data/gremlin_server/Dockerfile +3 -0
- data/gremlin_server/tinkergraph-empty.properties +3 -0
- data/grumlin.gemspec +4 -3
- data/lib/grumlin.rb +46 -3
- data/lib/grumlin/anonymous_step.rb +44 -0
- data/lib/grumlin/client.rb +61 -131
- data/lib/grumlin/edge.rb +2 -2
- data/lib/grumlin/exceptions.rb +22 -2
- data/lib/grumlin/order.rb +22 -0
- data/lib/grumlin/p.rb +18 -0
- data/lib/grumlin/path.rb +15 -0
- data/lib/grumlin/pop.rb +32 -0
- data/lib/grumlin/request_dispatcher.rb +84 -0
- data/lib/grumlin/step.rb +18 -29
- data/lib/grumlin/sugar.rb +42 -0
- data/lib/grumlin/t.rb +22 -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 +21 -0
- data/lib/grumlin/translator.rb +22 -21
- data/lib/grumlin/transport.rb +78 -0
- data/lib/grumlin/traversal.rb +4 -11
- data/lib/grumlin/typing.rb +25 -5
- data/lib/grumlin/u.rb +18 -0
- data/lib/grumlin/version.rb +1 -1
- data/lib/grumlin/vertex.rb +2 -2
- metadata +41 -13
- data/Rakefile +0 -12
- 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: e532964db5d5afd11d89978a132a5f4f7d1a4d98c740f639acadac260c93be89
|
4
|
+
data.tar.gz: 9015cb71bbab17895d8809dc7ff514b90e9d1ceb81ed6a9eec446a0db7ec0994
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a4295b9e6041726c36c05cc0aed94a645e8d7103c99351dfadef7077f14037b81daf87a4ffb1fd48105d8c1fa888e96ce173aa3be42c9b35ec58de3e289c01ed
|
7
|
+
data.tar.gz: 51824ca159be63be91fc798b40777a25d55f0ce423b07a9ce4ce9880002e94b4e4196bc0d92b4ca84bee86356f17fd90f3cc2dd9daa594f906fc2e93f11be422
|
data/.github/workflows/main.yml
CHANGED
@@ -1,18 +1,73 @@
|
|
1
1
|
name: Ruby
|
2
2
|
|
3
|
-
on: [push,pull_request]
|
3
|
+
on: [push, pull_request]
|
4
4
|
|
5
5
|
jobs:
|
6
|
-
|
6
|
+
lint:
|
7
7
|
runs-on: ubuntu-latest
|
8
8
|
steps:
|
9
|
-
|
10
|
-
|
11
|
-
uses: ruby/setup-ruby@v1
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
9
|
+
- uses: actions/checkout@v2
|
10
|
+
|
11
|
+
- uses: ruby/setup-ruby@v1
|
12
|
+
with:
|
13
|
+
ruby-version: 3.0
|
14
|
+
bundler-cache: true
|
15
|
+
|
16
|
+
- name: Run the default task
|
17
|
+
run: |
|
18
|
+
gem install bundler -v 2.2.15
|
19
|
+
bundle install
|
20
|
+
bundle exec rubocop
|
21
|
+
test:
|
22
|
+
runs-on: ubuntu-latest
|
23
|
+
strategy:
|
24
|
+
matrix:
|
25
|
+
ruby: [2.6, 2.7, 3.0]
|
26
|
+
steps:
|
27
|
+
- uses: actions/checkout@v2
|
28
|
+
|
29
|
+
- uses: ruby/setup-ruby@v1
|
30
|
+
with:
|
31
|
+
ruby-version: ${{ matrix.ruby }}
|
32
|
+
bundler-cache: true
|
33
|
+
|
34
|
+
- name: Start Gremlin server
|
35
|
+
run: |
|
36
|
+
docker-compose up -d --build
|
37
|
+
sleep 3
|
38
|
+
|
39
|
+
- name: Install deps
|
40
|
+
run: |
|
41
|
+
gem install bundler -v 2.2.15
|
42
|
+
bundle install
|
43
|
+
|
44
|
+
- name: Run tests
|
45
|
+
run: bundle exec rspec
|
46
|
+
publish:
|
47
|
+
runs-on: ubuntu-latest
|
48
|
+
needs:
|
49
|
+
- lint
|
50
|
+
- test
|
51
|
+
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v')
|
52
|
+
steps:
|
53
|
+
- uses: actions/checkout@v2
|
54
|
+
|
55
|
+
- uses: ruby/setup-ruby@v1
|
56
|
+
with:
|
57
|
+
ruby-version: 3.0
|
58
|
+
bundler-cache: true
|
59
|
+
|
60
|
+
- name: Build gem
|
61
|
+
run: gem build
|
62
|
+
|
63
|
+
- name: Create credentials
|
64
|
+
run: |
|
65
|
+
mkdir ~/.gem
|
66
|
+
cat << EOF > ~/.gem/credentials
|
67
|
+
---
|
68
|
+
:rubygems_api_key: ${{ secrets.rubygems_api_key }}
|
69
|
+
EOF
|
70
|
+
chmod 0600 /home/runner/.gem/credentials
|
71
|
+
|
72
|
+
- name: Push gem
|
73
|
+
run: gem push *gem
|
data/.gitignore
CHANGED
data/.overcommit.yml
ADDED
data/.rubocop.yml
CHANGED
data/Gemfile
CHANGED
@@ -4,8 +4,7 @@ source "https://rubygems.org"
|
|
4
4
|
|
5
5
|
gemspec
|
6
6
|
|
7
|
-
gem "
|
8
|
-
|
7
|
+
gem "nokogiri"
|
9
8
|
gem "rubocop"
|
10
9
|
gem "rubocop-performance"
|
11
10
|
gem "rubocop-rspec"
|
@@ -14,5 +13,6 @@ gem "solargraph"
|
|
14
13
|
|
15
14
|
gem "async-rspec"
|
16
15
|
gem "factory_bot"
|
16
|
+
gem "overcommit"
|
17
17
|
gem "rspec"
|
18
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.3.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,6 +52,7 @@ 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
|
@@ -57,13 +60,16 @@ GEM
|
|
57
60
|
kramdown (~> 2.0)
|
58
61
|
minitest (5.14.4)
|
59
62
|
nio4r (2.5.7)
|
60
|
-
nokogiri (1.11.
|
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)
|
@@ -74,7 +80,6 @@ GEM
|
|
74
80
|
protocol-http1 (~> 0.2)
|
75
81
|
racc (1.5.2)
|
76
82
|
rainbow (3.0.0)
|
77
|
-
rake (13.0.3)
|
78
83
|
regexp_parser (2.1.1)
|
79
84
|
reverse_markdown (2.0.0)
|
80
85
|
nokogiri
|
@@ -96,16 +101,16 @@ GEM
|
|
96
101
|
diff-lcs (>= 1.2.0, < 2.0)
|
97
102
|
rspec-support (~> 3.10.0)
|
98
103
|
rspec-support (3.10.2)
|
99
|
-
rubocop (1.
|
104
|
+
rubocop (1.16.1)
|
100
105
|
parallel (~> 1.10)
|
101
106
|
parser (>= 3.0.0.0)
|
102
107
|
rainbow (>= 2.2.2, < 4.0)
|
103
108
|
regexp_parser (>= 1.8, < 3.0)
|
104
109
|
rexml
|
105
|
-
rubocop-ast (>= 1.
|
110
|
+
rubocop-ast (>= 1.7.0, < 2.0)
|
106
111
|
ruby-progressbar (~> 1.7)
|
107
112
|
unicode-display_width (>= 1.4.0, < 3.0)
|
108
|
-
rubocop-ast (1.
|
113
|
+
rubocop-ast (1.7.0)
|
109
114
|
parser (>= 3.0.1.1)
|
110
115
|
rubocop-performance (1.11.3)
|
111
116
|
rubocop (>= 1.7.0, < 2.0)
|
@@ -120,10 +125,11 @@ GEM
|
|
120
125
|
simplecov_json_formatter (~> 0.1)
|
121
126
|
simplecov-html (0.12.3)
|
122
127
|
simplecov_json_formatter (0.1.3)
|
123
|
-
solargraph (0.
|
124
|
-
backport (~> 1.
|
128
|
+
solargraph (0.43.0)
|
129
|
+
backport (~> 1.2)
|
125
130
|
benchmark
|
126
131
|
bundler (>= 1.17.2)
|
132
|
+
diff-lcs (~> 1.4)
|
127
133
|
e2mmap
|
128
134
|
jaro_winkler (~> 1.5)
|
129
135
|
kramdown (~> 2.3)
|
@@ -150,7 +156,8 @@ DEPENDENCIES
|
|
150
156
|
async-rspec
|
151
157
|
factory_bot
|
152
158
|
grumlin!
|
153
|
-
|
159
|
+
nokogiri
|
160
|
+
overcommit
|
154
161
|
rspec
|
155
162
|
rubocop
|
156
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/docker-compose.yml
ADDED
data/grumlin.gemspec
CHANGED
@@ -8,8 +8,8 @@ Gem::Specification.new do |spec|
|
|
8
8
|
spec.authors = ["Gleb Sinyavskiy"]
|
9
9
|
spec.email = ["zhulik.gleb@gmail.com"]
|
10
10
|
|
11
|
-
spec.summary = "
|
12
|
-
spec.description = "
|
11
|
+
spec.summary = "Gremlin query language DSL for Ruby."
|
12
|
+
spec.description = "Gremlin query language DSL for Ruby."
|
13
13
|
spec.homepage = "https://github.com/zhulik/grumlin"
|
14
14
|
spec.license = "MIT"
|
15
15
|
spec.required_ruby_version = Gem::Requirement.new(">= 2.6.0")
|
@@ -23,5 +23,6 @@ Gem::Specification.new do |spec|
|
|
23
23
|
end
|
24
24
|
spec.require_paths = ["lib"]
|
25
25
|
|
26
|
-
spec.add_dependency "async-
|
26
|
+
spec.add_dependency "async-pool", "~> 0.3"
|
27
|
+
spec.add_dependency "async-websocket", "~> 0.19"
|
27
28
|
end
|
data/lib/grumlin.rb
CHANGED
@@ -4,21 +4,64 @@ 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
|
|
11
15
|
require_relative "grumlin/version"
|
12
16
|
require_relative "grumlin/exceptions"
|
13
17
|
|
18
|
+
require_relative "grumlin/transport"
|
19
|
+
require_relative "grumlin/client"
|
20
|
+
|
14
21
|
require_relative "grumlin/vertex"
|
15
22
|
require_relative "grumlin/edge"
|
23
|
+
require_relative "grumlin/path"
|
16
24
|
require_relative "grumlin/typing"
|
17
|
-
require_relative "grumlin/client"
|
18
25
|
require_relative "grumlin/traversal"
|
19
|
-
require_relative "grumlin/
|
26
|
+
require_relative "grumlin/request_dispatcher"
|
20
27
|
require_relative "grumlin/translator"
|
21
|
-
|
28
|
+
|
29
|
+
require_relative "grumlin/anonymous_step"
|
30
|
+
require_relative "grumlin/step"
|
31
|
+
|
32
|
+
require_relative "grumlin/t"
|
33
|
+
require_relative "grumlin/order"
|
34
|
+
require_relative "grumlin/u"
|
35
|
+
require_relative "grumlin/p"
|
36
|
+
require_relative "grumlin/pop"
|
37
|
+
require_relative "grumlin/sugar"
|
22
38
|
|
23
39
|
module Grumlin
|
40
|
+
class Config
|
41
|
+
attr_accessor :url, :pool_size, :client_concurrency
|
42
|
+
|
43
|
+
# For some reason, client_concurrency must be greather pool_size
|
44
|
+
def initialize
|
45
|
+
@pool_size = 10
|
46
|
+
@client_concurrency = 20
|
47
|
+
end
|
48
|
+
|
49
|
+
def default_pool
|
50
|
+
@default_pool ||= Async::Pool::Controller.new(Grumlin::Client::PoolResource, limit: pool_size)
|
51
|
+
end
|
52
|
+
|
53
|
+
def reset!
|
54
|
+
@default_pool = nil
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
class << self
|
59
|
+
def configure
|
60
|
+
yield config
|
61
|
+
end
|
62
|
+
|
63
|
+
def config
|
64
|
+
@config ||= Config.new
|
65
|
+
end
|
66
|
+
end
|
24
67
|
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
|