grumlin 0.4.0 → 0.6.1
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 +0 -3
- data/.rubocop.yml +53 -12
- data/.tool-versions +1 -0
- data/Gemfile.lock +3 -3
- data/bin/console +1 -1
- data/lib/async/channel.rb +1 -1
- data/lib/grumlin/anonymous_step.rb +6 -6
- data/lib/grumlin/client.rb +5 -3
- data/lib/grumlin/edge.rb +1 -3
- data/lib/grumlin/order.rb +8 -13
- data/lib/grumlin/p.rb +1 -1
- data/lib/grumlin/pop.rb +8 -23
- data/lib/grumlin/request_dispatcher.rb +1 -1
- data/lib/grumlin/step.rb +1 -1
- data/lib/grumlin/sugar.rb +3 -17
- data/lib/grumlin/t.rb +8 -13
- data/lib/grumlin/test/rspec/gremlin_context.rb +7 -1
- data/lib/grumlin/translator.rb +4 -0
- data/lib/grumlin/transport.rb +2 -2
- data/lib/grumlin/traversal.rb +4 -5
- data/lib/grumlin/typed_value.rb +19 -0
- data/lib/grumlin/u.rb +4 -6
- data/lib/grumlin/version.rb +1 -1
- data/lib/grumlin.rb +1 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f6fc993f0e67d4bb4d7a97b3e2d64d692b334f862cb16c73349d222fdb21b95f
|
4
|
+
data.tar.gz: fb14fae220786a9f8b5654b271d344a24e09dcbaf565e998716e6465f6cc62f9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 14d22f47279dce78ccc70442ecaee502c8cf26547fa4a4ea679fb212699877e3bdda45af3fd957261bd4b77a2a410c5be20be9b80a6f239a3acb90d57e1daf40
|
7
|
+
data.tar.gz: 9b5fd78c4c8826e2459ed652b11bf611df64604086488a543687e8a8edb34913958df74dccd2bc0d08dc1eb2f1d0c608e0639c54aac956f5a164a66f8d1f2adb
|
data/.github/workflows/main.yml
CHANGED
data/.overcommit.yml
CHANGED
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
|
|
@@ -34,5 +54,26 @@ RSpec/NestedGroups:
|
|
34
54
|
RSpec/ExampleLength:
|
35
55
|
Enabled: false
|
36
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
|
+
|
37
78
|
Style/MultilineBlockChain:
|
38
|
-
Enabled: false
|
79
|
+
Enabled: false
|
data/.tool-versions
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
ruby 2.6.6
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
grumlin (0.
|
4
|
+
grumlin (0.6.1)
|
5
5
|
async-pool (~> 0.3)
|
6
6
|
async-websocket (~> 0.19)
|
7
7
|
|
@@ -70,7 +70,7 @@ GEM
|
|
70
70
|
ast (~> 2.4.1)
|
71
71
|
protocol-hpack (1.4.2)
|
72
72
|
protocol-http (0.22.5)
|
73
|
-
protocol-http1 (0.14.
|
73
|
+
protocol-http1 (0.14.2)
|
74
74
|
protocol-http (~> 0.22)
|
75
75
|
protocol-http2 (0.14.2)
|
76
76
|
protocol-hpack (~> 1.4)
|
@@ -166,4 +166,4 @@ DEPENDENCIES
|
|
166
166
|
solargraph
|
167
167
|
|
168
168
|
BUNDLED WITH
|
169
|
-
2.2.
|
169
|
+
2.2.26
|
data/bin/console
CHANGED
data/lib/async/channel.rb
CHANGED
@@ -4,23 +4,23 @@ module Grumlin
|
|
4
4
|
class AnonymousStep
|
5
5
|
attr_reader :name, :args
|
6
6
|
|
7
|
+
# TODO: add other steps
|
8
|
+
SUPPORTED_STEPS = %w[E V addE addV as by coalesce count dedup drop elementMap emit fold from group groupCount has
|
9
|
+
hasLabel hasNot in inV label limit not order out outE path project property repeat select to
|
10
|
+
unfold valueMap values where].freeze
|
11
|
+
|
7
12
|
def initialize(name, *args, previous_steps: [])
|
8
13
|
@name = name
|
9
14
|
@previous_steps = previous_steps
|
10
15
|
@args = args
|
11
16
|
end
|
12
17
|
|
13
|
-
|
14
|
-
not outE groupCount label group in out fold unfold inV path dedup project coalesce repeat emit
|
15
|
-
elementMap where].each do |step|
|
18
|
+
SUPPORTED_STEPS.each do |step|
|
16
19
|
define_method step do |*args|
|
17
20
|
add_step(step, args, previous_steps: steps)
|
18
21
|
end
|
19
22
|
end
|
20
23
|
|
21
|
-
alias addVertex addV
|
22
|
-
alias addEdge addE
|
23
|
-
|
24
24
|
def inspect
|
25
25
|
@inspect ||= to_bytecode.to_s
|
26
26
|
end
|
data/lib/grumlin/client.rb
CHANGED
@@ -49,8 +49,10 @@ module Grumlin
|
|
49
49
|
end
|
50
50
|
|
51
51
|
def close
|
52
|
-
@transport
|
53
|
-
|
52
|
+
@transport&.close
|
53
|
+
if @request_dispatcher&.requests&.any?
|
54
|
+
raise ResourceLeakError, "Request list is not empty: #{@request_dispatcher.requests}"
|
55
|
+
end
|
54
56
|
|
55
57
|
reset!
|
56
58
|
end
|
@@ -60,7 +62,7 @@ module Grumlin
|
|
60
62
|
end
|
61
63
|
|
62
64
|
# TODO: support yielding
|
63
|
-
def write(*args)
|
65
|
+
def write(*args)
|
64
66
|
raise NotConnectedError unless connected?
|
65
67
|
|
66
68
|
request_id = SecureRandom.uuid
|
data/lib/grumlin/edge.rb
CHANGED
@@ -1,11 +1,10 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
# rubocop:disable Naming/VariableName,Naming/MethodParameterName,Naming/MethodName
|
4
3
|
module Grumlin
|
5
4
|
class Edge
|
6
5
|
attr_reader :label, :id, :inVLabel, :outVLabel, :inV, :outV
|
7
6
|
|
8
|
-
def initialize(label:, id:, inVLabel:, outVLabel:, inV:, outV:)
|
7
|
+
def initialize(label:, id:, inVLabel:, outVLabel:, inV:, outV:)
|
9
8
|
@label = label
|
10
9
|
@id = Typing.cast(id)
|
11
10
|
@inVLabel = inVLabel
|
@@ -24,4 +23,3 @@ module Grumlin
|
|
24
23
|
alias to_s inspect
|
25
24
|
end
|
26
25
|
end
|
27
|
-
# rubocop:enable Naming/MethodParameterName,Naming/VariableName,Naming/MethodName
|
data/lib/grumlin/order.rb
CHANGED
@@ -2,21 +2,16 @@
|
|
2
2
|
|
3
3
|
module Grumlin
|
4
4
|
module Order
|
5
|
-
|
6
|
-
|
7
|
-
|
5
|
+
# TODO: share the code?
|
6
|
+
class << self
|
7
|
+
%i[asc desc].each do |step|
|
8
|
+
define_method step do
|
9
|
+
name = "@#{step}"
|
10
|
+
return instance_variable_get(name) if instance_variable_defined?(name)
|
8
11
|
|
9
|
-
|
10
|
-
|
11
|
-
def asc
|
12
|
-
ASC
|
13
|
-
end
|
14
|
-
|
15
|
-
def desc
|
16
|
-
DESC
|
12
|
+
instance_variable_set(name, TypedValue.new("Order", step))
|
13
|
+
end
|
17
14
|
end
|
18
15
|
end
|
19
|
-
|
20
|
-
extend Order
|
21
16
|
end
|
22
17
|
end
|
data/lib/grumlin/p.rb
CHANGED
data/lib/grumlin/pop.rb
CHANGED
@@ -2,31 +2,16 @@
|
|
2
2
|
|
3
3
|
module Grumlin
|
4
4
|
module Pop
|
5
|
-
|
6
|
-
|
5
|
+
# TODO: share the code?
|
6
|
+
class << self
|
7
|
+
%i[first last all mixed].each do |step|
|
8
|
+
define_method step do
|
9
|
+
name = "@#{step}"
|
10
|
+
return instance_variable_get(name) if instance_variable_defined?(name)
|
7
11
|
|
8
|
-
|
9
|
-
|
10
|
-
ALL = { "@type": "g:Pop", "@value": "all" }.freeze
|
11
|
-
MIXED = { "@type": "g:Pop", "@value": "mixed" }.freeze
|
12
|
-
|
13
|
-
def first
|
14
|
-
FIRST
|
15
|
-
end
|
16
|
-
|
17
|
-
def last
|
18
|
-
LAST
|
19
|
-
end
|
20
|
-
|
21
|
-
def all
|
22
|
-
ALL
|
23
|
-
end
|
24
|
-
|
25
|
-
def mixed
|
26
|
-
MIXED
|
12
|
+
instance_variable_set(name, TypedValue.new("Pop", step))
|
13
|
+
end
|
27
14
|
end
|
28
15
|
end
|
29
|
-
|
30
|
-
extend Pop
|
31
16
|
end
|
32
17
|
end
|
@@ -36,7 +36,7 @@ module Grumlin
|
|
36
36
|
|
37
37
|
# builds a response object, when it's ready sends it to the client via a channel
|
38
38
|
# TODO: sometimes response does not include requestID, no idea how to handle it so far.
|
39
|
-
def add_response(response) # rubocop:disable Metrics/AbcSize
|
39
|
+
def add_response(response) # rubocop:disable Metrics/AbcSize
|
40
40
|
request_id = response[:requestId]
|
41
41
|
raise "ERROR" unless ongoing_request?(request_id)
|
42
42
|
|
data/lib/grumlin/step.rb
CHANGED
data/lib/grumlin/sugar.rb
CHANGED
@@ -2,7 +2,6 @@
|
|
2
2
|
|
3
3
|
module Grumlin
|
4
4
|
module Sugar
|
5
|
-
# TODO: how to use it in specs?
|
6
5
|
HELPERS = [
|
7
6
|
Grumlin::U,
|
8
7
|
Grumlin::T,
|
@@ -12,25 +11,12 @@ module Grumlin
|
|
12
11
|
].freeze
|
13
12
|
|
14
13
|
def self.included(base)
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
module ClassMethods
|
19
|
-
def const_missing(name)
|
20
|
-
helper = HELPERS.find { |h| h.const_defined?(name) }
|
21
|
-
super if helper.nil?
|
22
|
-
|
23
|
-
const_set(name, helper)
|
14
|
+
HELPERS.each do |helper|
|
15
|
+
name = helper.name.split("::").last
|
16
|
+
base.const_set(name, helper)
|
24
17
|
end
|
25
18
|
end
|
26
19
|
|
27
|
-
def const_missing(name)
|
28
|
-
helper = HELPERS.find { |h| h.const_defined?(name) }
|
29
|
-
super if helper.nil?
|
30
|
-
|
31
|
-
const_set(name, helper)
|
32
|
-
end
|
33
|
-
|
34
20
|
def __
|
35
21
|
Grumlin::U
|
36
22
|
end
|
data/lib/grumlin/t.rb
CHANGED
@@ -2,21 +2,16 @@
|
|
2
2
|
|
3
3
|
module Grumlin
|
4
4
|
module T
|
5
|
-
|
6
|
-
|
7
|
-
|
5
|
+
# TODO: share the code?
|
6
|
+
class << self
|
7
|
+
%i[id label].each do |step|
|
8
|
+
define_method step do
|
9
|
+
name = "@#{step}"
|
10
|
+
return instance_variable_get(name) if instance_variable_defined?(name)
|
8
11
|
|
9
|
-
|
10
|
-
|
11
|
-
def id
|
12
|
-
T_ID
|
13
|
-
end
|
14
|
-
|
15
|
-
def label
|
16
|
-
T_LABEL
|
12
|
+
instance_variable_set(name, TypedValue.new("T", step))
|
13
|
+
end
|
17
14
|
end
|
18
15
|
end
|
19
|
-
|
20
|
-
extend T
|
21
16
|
end
|
22
17
|
end
|
@@ -8,8 +8,14 @@ module Grumlin
|
|
8
8
|
|
9
9
|
::RSpec.shared_context GremlinContext do
|
10
10
|
include GremlinContext
|
11
|
+
include Grumlin::Sugar
|
11
12
|
|
12
|
-
|
13
|
+
before do
|
14
|
+
Grumlin::Sugar::HELPERS.each do |helper|
|
15
|
+
name = helper.name.split("::").last
|
16
|
+
stub_const(name, helper)
|
17
|
+
end
|
18
|
+
end
|
13
19
|
|
14
20
|
after do
|
15
21
|
Grumlin.config.default_pool.close
|
data/lib/grumlin/translator.rb
CHANGED
@@ -20,6 +20,7 @@ module Grumlin
|
|
20
20
|
private
|
21
21
|
|
22
22
|
def arg_to_bytecode(arg)
|
23
|
+
return arg.to_bytecode if arg.is_a?(TypedValue)
|
23
24
|
return arg unless arg.is_a?(AnonymousStep)
|
24
25
|
|
25
26
|
args = arg.args.flatten.map do |a|
|
@@ -30,8 +31,11 @@ module Grumlin
|
|
30
31
|
|
31
32
|
def arg_to_query_bytecode(arg)
|
32
33
|
return ["none"] if arg.nil?
|
34
|
+
return arg.to_bytecode if arg.is_a?(TypedValue)
|
33
35
|
return arg unless arg.is_a?(AnonymousStep)
|
34
36
|
|
37
|
+
# return arg.to_bytecode if arg.is_a?(TypedValue)
|
38
|
+
|
35
39
|
args = arg.args.flatten.map do |a|
|
36
40
|
a.instance_of?(AnonymousStep) ? Typing.to_bytecode(to_bytecode(a.steps)) : arg_to_query_bytecode(a)
|
37
41
|
end
|
data/lib/grumlin/transport.rb
CHANGED
@@ -20,7 +20,7 @@ module Grumlin
|
|
20
20
|
@connected
|
21
21
|
end
|
22
22
|
|
23
|
-
def connect # rubocop:disable Metrics/
|
23
|
+
def connect # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
|
24
24
|
raise AlreadyConnectedError if connected?
|
25
25
|
|
26
26
|
@connection = Async::WebSocket::Client.connect(Async::HTTP::Endpoint.parse(@url), **@client_options)
|
@@ -56,7 +56,7 @@ module Grumlin
|
|
56
56
|
@request_channel << message
|
57
57
|
end
|
58
58
|
|
59
|
-
def close
|
59
|
+
def close
|
60
60
|
return unless connected?
|
61
61
|
|
62
62
|
@request_channel.close
|
data/lib/grumlin/traversal.rb
CHANGED
@@ -4,18 +4,17 @@ module Grumlin
|
|
4
4
|
class Traversal
|
5
5
|
attr_reader :connection
|
6
6
|
|
7
|
+
# TODO: add other start steps
|
8
|
+
SUPPORTED_START_STEPS = %w[E V addE addV].freeze
|
9
|
+
|
7
10
|
def initialize(pool = Grumlin.config.default_pool)
|
8
11
|
@pool = pool
|
9
12
|
end
|
10
13
|
|
11
|
-
|
12
|
-
%w[addV addE V E].each do |step|
|
14
|
+
SUPPORTED_START_STEPS.each do |step|
|
13
15
|
define_method step do |*args|
|
14
16
|
Step.new(@pool, step, *args)
|
15
17
|
end
|
16
18
|
end
|
17
|
-
|
18
|
-
alias addVertex addV
|
19
|
-
alias addEdge addE
|
20
19
|
end
|
21
20
|
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Grumlin
|
4
|
+
# TODO: find a better name
|
5
|
+
class TypedValue
|
6
|
+
def initialize(type, value)
|
7
|
+
@type = type
|
8
|
+
@value = value
|
9
|
+
end
|
10
|
+
|
11
|
+
def inspect(*)
|
12
|
+
"#{@type}.#{@value}"
|
13
|
+
end
|
14
|
+
|
15
|
+
def to_bytecode
|
16
|
+
@to_bytecode ||= { "@type": "g:#{@type}", "@value": @value }
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
data/lib/grumlin/u.rb
CHANGED
@@ -2,17 +2,15 @@
|
|
2
2
|
|
3
3
|
module Grumlin
|
4
4
|
module U
|
5
|
-
|
6
|
-
|
5
|
+
# TODO: add other start steps
|
6
|
+
SUPPORTED_START_STEPS = %w[V addV count has out unfold values].freeze
|
7
7
|
|
8
|
-
|
8
|
+
class << self
|
9
|
+
SUPPORTED_START_STEPS.each do |step|
|
9
10
|
define_method step do |*args|
|
10
11
|
AnonymousStep.new(step, *args)
|
11
12
|
end
|
12
13
|
end
|
13
14
|
end
|
14
|
-
|
15
|
-
# TODO: add alias __
|
16
|
-
extend U
|
17
15
|
end
|
18
16
|
end
|
data/lib/grumlin/version.rb
CHANGED
data/lib/grumlin.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: grumlin
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gleb Sinyavskiy
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-09-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: async-pool
|
@@ -50,6 +50,7 @@ files:
|
|
50
50
|
- ".overcommit.yml"
|
51
51
|
- ".rspec"
|
52
52
|
- ".rubocop.yml"
|
53
|
+
- ".tool-versions"
|
53
54
|
- CHANGELOG.md
|
54
55
|
- CODE_OF_CONDUCT.md
|
55
56
|
- Gemfile
|
@@ -82,6 +83,7 @@ files:
|
|
82
83
|
- lib/grumlin/translator.rb
|
83
84
|
- lib/grumlin/transport.rb
|
84
85
|
- lib/grumlin/traversal.rb
|
86
|
+
- lib/grumlin/typed_value.rb
|
85
87
|
- lib/grumlin/typing.rb
|
86
88
|
- lib/grumlin/u.rb
|
87
89
|
- lib/grumlin/version.rb
|