ultimate_json_rpc 1.0.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.
@@ -0,0 +1,208 @@
1
+ module UltimateJsonRpc
2
+ VERSION: String
3
+
4
+ module Core
5
+ class Error < StandardError
6
+ end
7
+
8
+ class InvalidRequest < Error
9
+ end
10
+
11
+ class InvalidParams < Error
12
+ end
13
+
14
+ class MethodNotFound < Error
15
+ attr_reader method_name: String
16
+
17
+ def initialize: (String) -> void
18
+ end
19
+
20
+ class ApplicationError < Error
21
+ attr_reader code: Integer
22
+ attr_reader rpc_data: untyped
23
+
24
+ def initialize: (code: Integer, message: String, ?data: untyped) -> void
25
+ end
26
+
27
+ class ServerError < Error
28
+ attr_reader code: Integer
29
+ attr_reader rpc_data: untyped
30
+
31
+ def initialize: (code: Integer, message: String, ?data: untyped) -> void
32
+ end
33
+
34
+ REQUEST_TIMEOUT: Integer
35
+
36
+ class RequestTimeout < ServerError
37
+ def initialize: (?untyped) -> void
38
+ end
39
+
40
+ PARSE_ERROR: Integer
41
+ INVALID_REQUEST: Integer
42
+ METHOD_NOT_FOUND: Integer
43
+ INVALID_PARAMS: Integer
44
+ INTERNAL_ERROR: Integer
45
+ SERVER_ERROR_MIN: Integer
46
+ SERVER_ERROR_MAX: Integer
47
+ RESERVED_ERROR_MIN: Integer
48
+ RESERVED_ERROR_MAX: Integer
49
+ ERROR_MESSAGES: Hash[Integer, String]
50
+
51
+ class Request
52
+ MAX_NESTING: Integer
53
+
54
+ attr_reader method_name: String
55
+ attr_reader params: Array[untyped] | Hash[String, untyped] | nil
56
+ attr_reader id: String | Numeric | nil
57
+ attr_reader context: Hash[Symbol, untyped]
58
+
59
+ def initialize: (Hash[String, untyped]) -> void
60
+ def notification?: () -> bool
61
+ end
62
+
63
+ module Response
64
+ def self.success: (untyped, untyped) -> Hash[String, untyped]
65
+ def self.error: (Integer, untyped, ?data: untyped, ?message: String?) -> Hash[String, untyped]
66
+ end
67
+
68
+ class Handler
69
+ def initialize: () -> void
70
+ def expose: (Module | Object, ?namespace: String | Symbol | nil, ?only: Array[Symbol | String] | Symbol | String | nil, ?except: Array[Symbol | String] | Symbol | String | nil, ?descriptions: Hash[Symbol | String, String]?, ?returns: Hash[Symbol | String, untyped]?, ?deprecated: Hash[Symbol | String, untyped]?, ?params_schema: Hash[Symbol | String, untyped]?) -> void
71
+ def expose_method: (String | Symbol, ?callable, ?description: String?, ?returns: untyped, ?deprecated: (bool | String)?, ?params_schema: Hash[String | Symbol, untyped]?) ?{ (*untyped) -> untyped } -> void
72
+ def call: (String, Array[untyped] | Hash[String, untyped] | nil) -> untyped
73
+ def method?: (String) -> bool
74
+ def methods_list: () -> Array[String]
75
+ def methods_info: () -> Array[Hash[String, untyped]]
76
+ def size: () -> Integer
77
+ def empty?: () -> bool
78
+ def freeze: () -> self
79
+ end
80
+ end
81
+
82
+ interface _Callable
83
+ def call: (*untyped) -> untyped
84
+ end
85
+
86
+ interface _JsonAdapter
87
+ def parse: (String) -> untyped
88
+ def generate: (untyped) -> String
89
+ end
90
+
91
+ type callable = Proc | Method | _Callable
92
+
93
+ class Server
94
+ attr_reader name: String?
95
+ attr_reader version: String?
96
+ attr_reader description: String?
97
+ attr_reader max_batch_size: Integer?
98
+ attr_reader timeout: Numeric?
99
+ attr_reader json_adapter: _JsonAdapter
100
+
101
+ def initialize: (?name: String?, ?version: String?, ?description: String?, ?max_batch_size: Integer?, ?expose_errors: bool, ?timeout: Numeric?, ?concurrent_batches: bool, ?max_concurrency: Integer, ?json: _JsonAdapter) -> void
102
+ def expose: (Module | Object, ?namespace: String | Symbol | nil, ?only: Array[Symbol | String] | Symbol | String | nil, ?except: Array[Symbol | String] | Symbol | String | nil, ?descriptions: Hash[Symbol | String, String]?, ?returns: Hash[Symbol | String, untyped]?, ?deprecated: Hash[Symbol | String, untyped]?, ?params_schema: Hash[Symbol | String, untyped]?) -> self
103
+ def expose_method: (String | Symbol, ?callable, ?description: String?, ?returns: untyped, ?deprecated: (bool | String)?, ?params_schema: Hash[String | Symbol, untyped]?) ?{ (*untyped) -> untyped } -> self
104
+ def use: (?only: Array[String | Symbol] | String | Symbol | nil, ?except: Array[String | Symbol] | String | Symbol | nil) { (Core::Request, Proc) -> untyped } -> self
105
+ def on: (Symbol) { (*untyped) -> void } -> self
106
+ def register_error: (code: Integer, message: String, ?description: String?) -> self
107
+ def authorize: (*String, ?code: Integer, ?message: String) { (Core::Request) -> boolish } -> self
108
+ def to_proc: () -> Proc
109
+ def inspect: () -> String
110
+ def expose_errors?: () -> bool
111
+ def concurrent_batches?: () -> bool
112
+ def method?: (String) -> bool
113
+ def handle: (String) -> String?
114
+ alias call handle
115
+ def handle_parsed: (untyped) -> String?
116
+ def methods_list: () -> Array[String]
117
+ def methods_info: () -> Array[Hash[String, untyped]]
118
+ def size: () -> Integer
119
+ def empty?: () -> bool
120
+ def freeze: () -> self
121
+ end
122
+
123
+ module Transport
124
+ class Stdio
125
+ def initialize: (Server, ?input: IO, ?output: IO) -> void
126
+ def run: () -> void
127
+ def stop: () -> void
128
+ def running?: () -> bool
129
+ end
130
+
131
+ class Rack
132
+ def initialize: (Server) -> void
133
+ def call: (Hash[String, untyped]) -> [Integer, Hash[String, String], Array[String]]
134
+ def freeze: () -> self
135
+ end
136
+
137
+ class TCP
138
+ DEFAULT_MAX_CONNECTIONS: Integer
139
+ MAX_LINE_BYTES: Integer
140
+
141
+ def initialize: (Server, port: Integer, ?host: String, ?max_connections: Integer) -> void
142
+ def run: () -> void
143
+ def stop: () -> void
144
+ def running?: () -> bool
145
+ def port: () -> Integer?
146
+ end
147
+
148
+ class WebSocket
149
+ attr_reader server: Server
150
+
151
+ def initialize: (Server) -> void
152
+ def on_message: (untyped) -> String?
153
+ def call: (untyped, untyped) -> void
154
+ def freeze: () -> self
155
+ end
156
+ end
157
+
158
+ module Extras
159
+ class MCP
160
+ PROTOCOL_VERSION: String
161
+
162
+ def initialize: (Server, ?input: IO, ?output: IO, ?json: _JsonAdapter) -> void
163
+ def run: () -> void
164
+ def stop: () -> void
165
+ def running?: () -> bool
166
+ end
167
+
168
+ class Profiler
169
+ DEFAULT_MAX_SAMPLES: Integer
170
+
171
+ def initialize: (Server, ?max_samples: Integer) -> void
172
+ def []: (String) -> Hash[Symbol, untyped]?
173
+ def tracked_methods: () -> Array[String]
174
+ alias method_names tracked_methods
175
+ def stats: () -> Hash[String, Hash[Symbol, untyped]]
176
+ def reset: () -> void
177
+ end
178
+
179
+ class RateLimiter
180
+ def initialize: (Server, max: Integer, period: Numeric, ?key: (Symbol | Proc)?, ?code: Integer, ?message: String, ?only: Array[String | Symbol] | String | Symbol | nil, ?except: Array[String | Symbol] | String | Symbol | nil) -> void
181
+ end
182
+
183
+ class Logging
184
+ def initialize: (Server, untyped, ?level: Symbol) -> void
185
+ end
186
+
187
+ class Recorder
188
+ def initialize: (Server, ?output: IO?, ?max_exchanges: Integer?, ?json: _JsonAdapter) -> void
189
+ def exchanges: () -> Array[Hash[String, untyped]]
190
+ def clear: () -> void
191
+ def size: () -> Integer
192
+ end
193
+
194
+ class Docs
195
+ def initialize: (Server, ?json: _JsonAdapter) -> void
196
+ def to_markdown: () -> String
197
+ end
198
+
199
+ module TestHelpers
200
+ def rpc_call: (Server, String, ?params: untyped, ?id: String | Integer) -> Hash[String, untyped]
201
+ def rpc_notify: (Server, String, ?params: untyped) -> String?
202
+ def rpc_batch: (Server, *Hash[String, untyped]) -> Array[Hash[String, untyped]]?
203
+ def assert_rpc_success: (Hash[String, untyped], ?expected: untyped, ?msg: String?) -> void
204
+ def assert_rpc_error: (Hash[String, untyped], ?code: Integer?, ?message: String?, ?msg: String?) -> void
205
+ def assert_rpc_notification: (Server, String, ?params: untyped, ?msg: String?) -> void
206
+ end
207
+ end
208
+ end
metadata ADDED
@@ -0,0 +1,75 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ultimate_json_rpc
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Andriy Tyurnikov
8
+ bindir: bin
9
+ cert_chain: []
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
+ dependencies: []
12
+ description: Network-agnostic JSON-RPC server that exposes Ruby modules, classes,
13
+ instances, and namespaces as callable RPC endpoints.
14
+ email:
15
+ - Andriy.Tyurnikov@gmail.com
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - CHANGELOG.md
21
+ - LICENSE.txt
22
+ - README.md
23
+ - Rakefile
24
+ - examples/error_handling.rb
25
+ - examples/mcp_server.rb
26
+ - examples/multi_namespace.rb
27
+ - examples/rack_server.ru
28
+ - examples/testing_patterns.rb
29
+ - examples/websocket_server.ru
30
+ - lib/ultimate_json_rpc.rb
31
+ - lib/ultimate_json_rpc/core/errors.rb
32
+ - lib/ultimate_json_rpc/core/handler.rb
33
+ - lib/ultimate_json_rpc/core/request.rb
34
+ - lib/ultimate_json_rpc/core/response.rb
35
+ - lib/ultimate_json_rpc/extras/docs.rb
36
+ - lib/ultimate_json_rpc/extras/logging.rb
37
+ - lib/ultimate_json_rpc/extras/mcp.rb
38
+ - lib/ultimate_json_rpc/extras/profiler.rb
39
+ - lib/ultimate_json_rpc/extras/rate_limit.rb
40
+ - lib/ultimate_json_rpc/extras/recorder.rb
41
+ - lib/ultimate_json_rpc/extras/test_helpers.rb
42
+ - lib/ultimate_json_rpc/server.rb
43
+ - lib/ultimate_json_rpc/transport/rack.rb
44
+ - lib/ultimate_json_rpc/transport/stdio.rb
45
+ - lib/ultimate_json_rpc/transport/tcp.rb
46
+ - lib/ultimate_json_rpc/transport/websocket.rb
47
+ - lib/ultimate_json_rpc/version.rb
48
+ - sig/ultimate_json_rpc.rbs
49
+ homepage: https://github.com/rubakas/ultimate_json_rpc
50
+ licenses:
51
+ - MIT
52
+ metadata:
53
+ allowed_push_host: https://rubygems.org
54
+ homepage_uri: https://github.com/rubakas/ultimate_json_rpc
55
+ source_code_uri: https://github.com/rubakas/ultimate_json_rpc
56
+ changelog_uri: https://github.com/rubakas/ultimate_json_rpc/blob/main/CHANGELOG.md
57
+ rubygems_mfa_required: 'true'
58
+ rdoc_options: []
59
+ require_paths:
60
+ - lib
61
+ required_ruby_version: !ruby/object:Gem::Requirement
62
+ requirements:
63
+ - - ">="
64
+ - !ruby/object:Gem::Version
65
+ version: 3.2.0
66
+ required_rubygems_version: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - ">="
69
+ - !ruby/object:Gem::Version
70
+ version: '0'
71
+ requirements: []
72
+ rubygems_version: 4.0.8
73
+ specification_version: 4
74
+ summary: Expose Ruby objects through JSON-RPC
75
+ test_files: []