rbs_protobuf 0.1.0 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,3 @@
1
1
  module RBSProtobuf
2
- VERSION = "0.1.0"
2
+ VERSION = "1.0.0"
3
3
  end
data/lib/rbs_protobuf.rb CHANGED
@@ -3,7 +3,7 @@ require "rbs_protobuf/version"
3
3
  require "logger"
4
4
 
5
5
  require "protobuf/descriptors"
6
- require "active_support/inflector"
6
+ require "active_support"
7
7
  require "rbs"
8
8
 
9
9
  module RBSProtobuf
@@ -14,6 +14,7 @@ module RBSProtobuf
14
14
  @logger = Logger.new(STDERR)
15
15
  end
16
16
 
17
+ require "rbs_protobuf/name"
17
18
  require "rbs_protobuf/rbs_factory"
18
19
  require "rbs_protobuf/translator/base"
19
20
  require "rbs_protobuf/translator/protobuf_gem"
@@ -0,0 +1,108 @@
1
+ ---
2
+ sources:
3
+ - name: ruby/gem_rbs_collection
4
+ remote: https://github.com/ruby/gem_rbs_collection.git
5
+ revision: main
6
+ repo_dir: gems
7
+ path: ".gem_rbs_collection"
8
+ gems:
9
+ - name: rbs
10
+ version: 2.3.2
11
+ source:
12
+ type: rubygems
13
+ - name: activesupport
14
+ version: '6.0'
15
+ source:
16
+ type: git
17
+ name: ruby/gem_rbs_collection
18
+ revision: c7b9329222debd0b8a4a85c0ccdae6588fedd57a
19
+ remote: https://github.com/ruby/gem_rbs_collection.git
20
+ repo_dir: gems
21
+ - name: ast
22
+ version: '2.4'
23
+ source:
24
+ type: git
25
+ name: ruby/gem_rbs_collection
26
+ revision: c7b9329222debd0b8a4a85c0ccdae6588fedd57a
27
+ remote: https://github.com/ruby/gem_rbs_collection.git
28
+ repo_dir: gems
29
+ - name: i18n
30
+ version: '1.10'
31
+ source:
32
+ type: git
33
+ name: ruby/gem_rbs_collection
34
+ revision: c7b9329222debd0b8a4a85c0ccdae6588fedd57a
35
+ remote: https://github.com/ruby/gem_rbs_collection.git
36
+ repo_dir: gems
37
+ - name: listen
38
+ version: '3.2'
39
+ source:
40
+ type: git
41
+ name: ruby/gem_rbs_collection
42
+ revision: c7b9329222debd0b8a4a85c0ccdae6588fedd57a
43
+ remote: https://github.com/ruby/gem_rbs_collection.git
44
+ repo_dir: gems
45
+ - name: parallel
46
+ version: '1.20'
47
+ source:
48
+ type: git
49
+ name: ruby/gem_rbs_collection
50
+ revision: c7b9329222debd0b8a4a85c0ccdae6588fedd57a
51
+ remote: https://github.com/ruby/gem_rbs_collection.git
52
+ repo_dir: gems
53
+ - name: rainbow
54
+ version: '3.0'
55
+ source:
56
+ type: git
57
+ name: ruby/gem_rbs_collection
58
+ revision: c7b9329222debd0b8a4a85c0ccdae6588fedd57a
59
+ remote: https://github.com/ruby/gem_rbs_collection.git
60
+ repo_dir: gems
61
+ - name: logger
62
+ version: '0'
63
+ source:
64
+ type: stdlib
65
+ - name: set
66
+ version: '0'
67
+ source:
68
+ type: stdlib
69
+ - name: pathname
70
+ version: '0'
71
+ source:
72
+ type: stdlib
73
+ - name: json
74
+ version: '0'
75
+ source:
76
+ type: stdlib
77
+ - name: optparse
78
+ version: '0'
79
+ source:
80
+ type: stdlib
81
+ - name: rubygems
82
+ version: '0'
83
+ source:
84
+ type: stdlib
85
+ - name: tsort
86
+ version: '0'
87
+ source:
88
+ type: stdlib
89
+ - name: monitor
90
+ version: '0'
91
+ source:
92
+ type: stdlib
93
+ - name: date
94
+ version: '0'
95
+ source:
96
+ type: stdlib
97
+ - name: singleton
98
+ version: '0'
99
+ source:
100
+ type: stdlib
101
+ - name: mutex_m
102
+ version: '0'
103
+ source:
104
+ type: stdlib
105
+ - name: time
106
+ version: '0'
107
+ source:
108
+ type: stdlib
@@ -0,0 +1,19 @@
1
+ # Download sources
2
+ sources:
3
+ - name: ruby/gem_rbs_collection
4
+ remote: https://github.com/ruby/gem_rbs_collection.git
5
+ revision: main
6
+ repo_dir: gems
7
+
8
+ # A directory to install the downloaded RBSs
9
+ path: .gem_rbs_collection
10
+
11
+ gems:
12
+ # Skip loading rbs gem's RBS.
13
+ # It's unnecessary if you don't use rbs as a library.
14
+ - name: rbs
15
+ - name: activesupport
16
+ - name: protobuf
17
+ ignore: true
18
+ - name: rbs_protobuf
19
+ ignore: true
data/rbs_protobuf.gemspec CHANGED
@@ -10,7 +10,7 @@ Gem::Specification.new do |spec|
10
10
  spec.description = "Generate RBS files from .proto files"
11
11
  spec.homepage = "https://github.com/square/rbs_protobuf"
12
12
  spec.license = "MIT"
13
- spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
13
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.7.0")
14
14
 
15
15
  spec.metadata["homepage_uri"] = spec.homepage
16
16
  spec.metadata["source_code_uri"] = "https://github.com/square/rbs_protobuf"
@@ -25,6 +25,6 @@ Gem::Specification.new do |spec|
25
25
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
26
26
  spec.require_paths = ["lib"]
27
27
 
28
- spec.add_runtime_dependency "rbs", ">=1.0.4"
28
+ spec.add_runtime_dependency "rbs", ">=2.2.0"
29
29
  spec.add_runtime_dependency "activesupport", ">=4.0"
30
30
  end
@@ -0,0 +1,45 @@
1
+ module RBSProtobuf
2
+ module Name
3
+ class Class
4
+ attr_reader name: RBS::TypeName
5
+
6
+ def initialize: (RBS::TypeName) -> void
7
+
8
+ def instance_type: (*RBS::Types::t args) -> RBS::Types::ClassInstance
9
+
10
+ def singleton_type: () -> RBS::Types::ClassSingleton
11
+
12
+ def instance_type?: (RBS::Types::t) -> bool
13
+
14
+ def singleton_type?: (RBS::Types::t) -> bool
15
+
16
+ alias [] instance_type
17
+
18
+ def super_class: (*RBS::Types::t args) -> RBS::AST::Declarations::Class::Super
19
+ end
20
+
21
+ class Alias
22
+ attr_reader name: RBS::TypeName
23
+
24
+ def initialize: (RBS::TypeName) -> void
25
+
26
+ def []: (*RBS::Types::t args) -> RBS::Types::Alias
27
+
28
+ def type?: (RBS::Types::t) -> bool
29
+
30
+ alias === type?
31
+ end
32
+
33
+ class Interface
34
+ attr_reader name: RBS::TypeName
35
+
36
+ def initialize: (RBS::TypeName) -> void
37
+
38
+ def []: (*RBS::Types::t args) -> RBS::Types::Interface
39
+
40
+ def type?: (RBS::Types::t) -> bool
41
+
42
+ alias === type?
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,41 @@
1
+ module RBSProtobuf
2
+ class RBSFactory
3
+ include RBS
4
+
5
+ def type_name: (String) -> RBS::TypeName
6
+
7
+ def namespace: (String) -> RBS::Namespace
8
+
9
+ def instance_type: (String | RBS::TypeName name, *RBS::Types::t args) -> RBS::Types::ClassInstance
10
+
11
+ def singleton_type: (String | RBS::TypeName name) -> RBS::Types::ClassSingleton
12
+
13
+ def union_type: (RBS::Types::t `type`, *RBS::Types::t types) -> RBS::Types::t
14
+
15
+ def nil_type: (?location: RBS::Location[untyped, untyped]?) -> RBS::Types::Bases::Nil
16
+
17
+ def bool_type: (?location: RBS::Location[untyped, untyped]?) -> RBS::Types::Bases::Bool
18
+
19
+ def alias_type: (String | RBS::TypeName name, ?location: RBS::Location[untyped, untyped]?) -> RBS::Types::Alias
20
+
21
+ def function: (?RBS::Types::t return_type) -> RBS::Types::Function
22
+
23
+ def param: (RBS::Types::t type, ?name: Symbol?) -> RBS::Types::Function::Param
24
+
25
+ def block: (RBS::Types::Function function, ?required: bool) -> RBS::Types::Block
26
+
27
+ def untyped: (?location: RBS::Location[untyped, untyped]?) -> RBS::Types::Bases::Any
28
+
29
+ def method_type: (?params: Array[Symbol], type: RBS::Types::Function, ?block: RBS::Types::Block?, ?location: RBS::Location[untyped, untyped]?) -> RBS::MethodType
30
+
31
+ def literal_type: (RBS::Types::Literal::literal) -> RBS::Types::Literal
32
+
33
+ def optional_type: (RBS::Types::t, ?location: RBS::Location[untyped, untyped]?) -> RBS::Types::Optional
34
+
35
+ def type_var: (Symbol name, ?location: RBS::Location[untyped, untyped]?) -> RBS::Types::Variable
36
+
37
+ def module_type_params: (*Symbol params) -> Array[RBS::AST::TypeParam]
38
+
39
+ def unwrap_optional: (RBS::Types::t) -> RBS::Types::t
40
+ end
41
+ end
@@ -0,0 +1,35 @@
1
+ module RBSProtobuf
2
+ module Translator
3
+ class Base
4
+ FieldDescriptorProto: untyped
5
+
6
+ attr_reader input: untyped
7
+
8
+ def initialize: (untyped input) -> void
9
+
10
+ @factory: RBSFactory
11
+
12
+ def factory: () -> RBSFactory
13
+
14
+ @response: untyped
15
+
16
+ def response: () -> untyped
17
+
18
+ def generate_rbs!: () -> void
19
+
20
+ def rbs_name: (String proto_name) -> String
21
+
22
+ def rbs_suffix: () -> ::String
23
+
24
+ def rbs_content: (String file) -> String
25
+
26
+ def comment_for_path: (untyped source_code_info, Array[Integer] path, options: untyped) -> RBS::AST::Comment?
27
+
28
+ def each_options_field: (untyped) { (Symbol, untyped) -> void } -> void
29
+
30
+ def base_type: (untyped `type`) -> RBS::Types::t
31
+
32
+ def message_type: (String) -> RBS::Types::ClassInstance
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,122 @@
1
+ module RBSProtobuf
2
+ module Translator
3
+ class ProtobufGem < Base
4
+ # Protobuf::Field::FieldArray[R, W]
5
+ FIELD_ARRAY: Name::Class
6
+
7
+ # Protobuf::Field::FieldHash[K, RV, WV]
8
+ FIELD_HASH: Name::Class
9
+
10
+ # Protobuf::Enum
11
+ ENUM: Name::Class
12
+
13
+ # Protobuf::Message
14
+ MESSAGE: Name::Class
15
+
16
+ # _ToProto
17
+ TO_PROTO: Name::Interface
18
+
19
+ # Protobuf::field_array[T]
20
+ FIELD_ARRAY_a: Name::Alias
21
+
22
+ # Protobuf::field_hash[K, V]
23
+ FIELD_HASH_a: Name::Alias
24
+
25
+ attr_reader stderr: IO
26
+
27
+ attr_reader accept_nil_writer: bool
28
+
29
+ def initialize: (
30
+ untyped input,
31
+ upcase_enum: bool,
32
+ nested_namespace: bool,
33
+ extension: bool | :print | nil,
34
+ accept_nil_writer: bool,
35
+ ?stderr: IO,
36
+ ) -> void
37
+
38
+ @upcase_enum: bool
39
+
40
+ @nested_namespace: bool
41
+
42
+ @extension: bool | :print | nil
43
+
44
+ # Returns true if extension should be ignored.
45
+ #
46
+ def ignore_extension?: () -> bool
47
+
48
+ # Returns true if documentation message about extension is requested.
49
+ def print_extension_message?: () -> bool
50
+
51
+ # Returns true if extension should be printed to stderr.
52
+ #
53
+ def print_extension?: () -> bool
54
+
55
+ # Returns true if enum names should be `upcase`.
56
+ #
57
+ def upcase_enum?: () -> bool
58
+
59
+ # Returns true if printing nested namespace is preferred.
60
+ #
61
+ def nested_namespace?: () -> bool
62
+
63
+ # The entry point.
64
+ # Generate RBS declarations from the `file` and returns the string representation of the declarations.
65
+ #
66
+ def rbs_content: (untyped file) -> String
67
+
68
+ # Returns the class declaration for given message.
69
+ #
70
+ def message_to_decl: (untyped message, prefix: RBS::Namespace, message_path: untyped, source_code_info: untyped, path: Array[Integer]) -> RBS::AST::Declarations::Class
71
+
72
+ # Returns the class declaration for given enum.
73
+ #
74
+ def enum_type_to_decl: (untyped enum_type, prefix: RBS::Namespace, source_code_info: untyped, path: Array[Integer]) -> RBS::AST::Declarations::Class
75
+
76
+ # Returns the class declaration for given extension.
77
+ #
78
+ def extension_to_decl: (untyped extension, prefix: RBS::Namespace, source_code_info: untyped, path: Array[Integer]) -> RBS::AST::Declarations::Class
79
+
80
+ # Returns service class stub.
81
+ #
82
+ def service_to_decl: (untyped service, prefix: RBS::Namespace, source_code_info: untyped, path: Array[Integer]) -> RBS::AST::Declarations::Class
83
+
84
+ # Returns a triple of types of a field.
85
+ #
86
+ # - The first one is the type of the attribute. (read and write)
87
+ # - The second one is the array of type of additional possibilities for write.
88
+ # - The last one is the type of `initialize` parameter.
89
+ #
90
+ def field_type: (untyped field, Hash[String, [untyped, untyped]] maps) -> [RBS::Types::t, Array[RBS::Types::t], RBS::Types::t]
91
+
92
+ def message_to_proto_type: (RBS::Types::ClassInstance) -> RBS::Types::Interface
93
+
94
+ def message_array_type: (RBS::Types::ClassInstance) -> RBS::Types::Alias
95
+
96
+ def message_field_array_type: (RBS::Types::ClassInstance) -> RBS::Types::Alias
97
+
98
+ def message_hash_type: (RBS::Types::ClassInstance, RBS::Types::t key) -> RBS::Types::Alias
99
+
100
+ def message_field_hash_type: (RBS::Types::ClassInstance, RBS::Types::t key) -> RBS::Types::Alias
101
+
102
+ def message_init_type: (RBS::Types::ClassInstance) -> RBS::Types::Alias
103
+
104
+ # Returns enum names with respect to `#upcase_enum?`.
105
+ #
106
+ def enum_name: (String name) -> Symbol
107
+
108
+ # Add field to `members`. It adds
109
+ #
110
+ # - `attr_accessor` of the field `name` with `read_type`
111
+ # - Overloads for attribute writer with `write_types`
112
+ #
113
+ def add_field: (Array[RBS::AST::Declarations::Class::member] members, name: Symbol, read_type: RBS::Types::t, write_types: Array[RBS::Types::t], comment: RBS::AST::Comment?) -> void
114
+
115
+ # Returns true if `write_type` is an _interface type_ or an optional type of _interface type_.
116
+ #
117
+ def interface_type?: (RBS::Types::t write_type) -> [RBS::AST::TypeParam, RBS::Types::t]?
118
+
119
+ def service_base_class: () -> RBS::AST::Declarations::Class::Super
120
+ end
121
+ end
122
+ end
@@ -0,0 +1,3 @@
1
+ module RBSProtobuf
2
+ VERSION: String
3
+ end
@@ -0,0 +1,5 @@
1
+ module RBSProtobuf
2
+ attr_reader self.logger: Logger
3
+
4
+ self.@logger: Logger
5
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rbs_protobuf
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Soutaro Matsumoto
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-02-10 00:00:00.000000000 Z
11
+ date: 2022-04-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rbs
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: 1.0.4
19
+ version: 2.2.0
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: 1.0.4
26
+ version: 2.2.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: activesupport
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -52,26 +52,40 @@ files:
52
52
  - ".protoc-version"
53
53
  - ".rakeTasks"
54
54
  - ".travis.yml"
55
+ - CHANGELOG.md
55
56
  - Gemfile
57
+ - Gemfile.lock
56
58
  - LICENSE.txt
57
59
  - README.md
58
60
  - Rakefile
61
+ - Steepfile
59
62
  - bin/console
60
63
  - bin/protoc-gen-dumper
61
64
  - bin/protoc-gen-ruby
62
65
  - bin/rpc_server
63
66
  - bin/setup
67
+ - bin/steep
64
68
  - example/Steepfile
65
69
  - example/a.proto
66
70
  - example/b.proto
71
+ - example/c.proto
67
72
  - example/protobuf_gem_example.rb
68
73
  - exe/protoc-gen-rbs
69
74
  - lib/rbs_protobuf.rb
75
+ - lib/rbs_protobuf/name.rb
70
76
  - lib/rbs_protobuf/rbs_factory.rb
71
77
  - lib/rbs_protobuf/translator/base.rb
72
78
  - lib/rbs_protobuf/translator/protobuf_gem.rb
73
79
  - lib/rbs_protobuf/version.rb
80
+ - rbs_collection.lock.yaml
81
+ - rbs_collection.yaml
74
82
  - rbs_protobuf.gemspec
83
+ - sig/rbs_protobuf.rbs
84
+ - sig/rbs_protobuf/name.rbs
85
+ - sig/rbs_protobuf/rbs_factory.rbs
86
+ - sig/rbs_protobuf/translator/base.rbs
87
+ - sig/rbs_protobuf/translator/protobuf_gem.rbs
88
+ - sig/rbs_protobuf/version.rbs
75
89
  homepage: https://github.com/square/rbs_protobuf
76
90
  licenses:
77
91
  - MIT
@@ -87,14 +101,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
87
101
  requirements:
88
102
  - - ">="
89
103
  - !ruby/object:Gem::Version
90
- version: 2.3.0
104
+ version: 2.7.0
91
105
  required_rubygems_version: !ruby/object:Gem::Requirement
92
106
  requirements:
93
107
  - - ">="
94
108
  - !ruby/object:Gem::Version
95
109
  version: '0'
96
110
  requirements: []
97
- rubygems_version: 3.2.3
111
+ rubygems_version: 3.3.7
98
112
  signing_key:
99
113
  specification_version: 4
100
114
  summary: Generate RBS files from .proto files