jsonrpc-middleware 0.1.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.
Files changed (49) hide show
  1. checksums.yaml +7 -0
  2. data/.claude/settings.local.json +9 -0
  3. data/.editorconfig +11 -0
  4. data/.overcommit.yml +31 -0
  5. data/.rspec +3 -0
  6. data/.rubocop.yml +74 -0
  7. data/.tool-versions +1 -0
  8. data/.yardstick.yml +22 -0
  9. data/CHANGELOG.md +37 -0
  10. data/CODE_OF_CONDUCT.md +132 -0
  11. data/Guardfile +22 -0
  12. data/LICENSE.txt +21 -0
  13. data/README.md +248 -0
  14. data/Rakefile +41 -0
  15. data/Steepfile +7 -0
  16. data/docs/JSON-RPC-2.0-Specification.md +278 -0
  17. data/examples/procedures.rb +55 -0
  18. data/examples/rack/Gemfile +8 -0
  19. data/examples/rack/Gemfile.lock +68 -0
  20. data/examples/rack/README.md +7 -0
  21. data/examples/rack/app.rb +48 -0
  22. data/examples/rack/config.ru +19 -0
  23. data/examples/rack-echo/Gemfile +8 -0
  24. data/examples/rack-echo/Gemfile.lock +68 -0
  25. data/examples/rack-echo/README.md +7 -0
  26. data/examples/rack-echo/app.rb +43 -0
  27. data/examples/rack-echo/config.ru +18 -0
  28. data/lib/jsonrpc/batch_request.rb +102 -0
  29. data/lib/jsonrpc/batch_response.rb +85 -0
  30. data/lib/jsonrpc/configuration.rb +85 -0
  31. data/lib/jsonrpc/error.rb +96 -0
  32. data/lib/jsonrpc/errors/internal_error.rb +27 -0
  33. data/lib/jsonrpc/errors/invalid_params_error.rb +27 -0
  34. data/lib/jsonrpc/errors/invalid_request_error.rb +31 -0
  35. data/lib/jsonrpc/errors/method_not_found_error.rb +31 -0
  36. data/lib/jsonrpc/errors/parse_error.rb +29 -0
  37. data/lib/jsonrpc/helpers.rb +83 -0
  38. data/lib/jsonrpc/middleware.rb +190 -0
  39. data/lib/jsonrpc/notification.rb +94 -0
  40. data/lib/jsonrpc/parser.rb +176 -0
  41. data/lib/jsonrpc/request.rb +112 -0
  42. data/lib/jsonrpc/response.rb +127 -0
  43. data/lib/jsonrpc/validator.rb +140 -0
  44. data/lib/jsonrpc/version.rb +5 -0
  45. data/lib/jsonrpc.rb +25 -0
  46. data/sig/jsonrpc/middleware.rbs +6 -0
  47. data/sig/jsonrpc/parser.rbs +7 -0
  48. data/sig/jsonrpc.rbs +164 -0
  49. metadata +120 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 4e61b560d7db3538454d0d5206eaea1fc2a86a01b25294c4d56de4b6237dd120
4
+ data.tar.gz: 1d7255ba3a462bbc9d53efbec3ba9b242f773b2c4fa270de280b951ea3b05743
5
+ SHA512:
6
+ metadata.gz: b3d9b2f802ac5ffd1f342c45d00e001113ebf857e09208deac8560dd75a06f6201bcc4e7a99f0184cb6c1a48497d70e922d59d7f6b476c93f530584b60fa0066
7
+ data.tar.gz: b07c00f97c85c9a41f82decf00dbf58f10c2655e1011f0e3e6d5e63ff2f90cee88e310f6c892a8d49c2ec94aea5cfa7dccdf9292b7940256f82b1591823df2e2
@@ -0,0 +1,9 @@
1
+ {
2
+ "permissions": {
3
+ "allow": [
4
+ "Bash(bundle exec rspec:*)",
5
+ "Bash(bundle exec rubocop:*)"
6
+ ]
7
+ },
8
+ "enableAllProjectMcpServers": false
9
+ }
data/.editorconfig ADDED
@@ -0,0 +1,11 @@
1
+ # Unix-style newlines with a newline ending every file
2
+ [*]
3
+ end_of_line = lf
4
+ insert_final_newline = true
5
+ max_line_length = 120
6
+ trim_trailing_whitespace = true
7
+
8
+ # 2 space indentation
9
+ [*.rb]
10
+ indent_style = space
11
+ indent_size = 2
data/.overcommit.yml ADDED
@@ -0,0 +1,31 @@
1
+ # Use this file to configure the Overcommit hooks you wish to use. This will
2
+ # extend the default configuration defined in:
3
+ # https://github.com/sds/overcommit/blob/master/config/default.yml
4
+ #
5
+ # At the topmost level of this YAML file is a key representing type of hook
6
+ # being run (e.g. pre-commit, commit-msg, etc.). Within each type you can
7
+ # customize each hook, such as whether to only run it on certain files (via
8
+ # `include`), whether to only display output if it fails (via `quiet`), etc.
9
+ #
10
+ # For a complete list of hooks, see:
11
+ # https://github.com/sds/overcommit/tree/master/lib/overcommit/hook
12
+ #
13
+ # For a complete list of options that you can use to customize hooks, see:
14
+ # https://github.com/sds/overcommit#configuration
15
+ #
16
+ # Uncomment the following lines to make the configuration take effect.
17
+
18
+ PreCommit:
19
+ RuboCop:
20
+ enabled: true
21
+ on_warn: fail # Treat all warnings as failures
22
+
23
+ TrailingWhitespace:
24
+ enabled: true
25
+
26
+ #PostCheckout:
27
+ # ALL: # Special hook name that customizes all hooks of this type
28
+ # quiet: true # Change all post-checkout hooks to only display output on failure
29
+ #
30
+ # IndexTags:
31
+ # enabled: true # Generate a tags file with `ctags` each time HEAD changes
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,74 @@
1
+ plugins:
2
+ - rubocop-factory_bot
3
+ - rubocop-performance
4
+ - rubocop-rake
5
+ - rubocop-rspec
6
+
7
+ AllCops:
8
+ TargetRubyVersion: 3.4
9
+ DisplayCopNames: true
10
+ NewCops: enable
11
+
12
+ # ----------------------- Gemspec -----------------------
13
+
14
+ Gemspec/DevelopmentDependencies:
15
+ Enabled: false
16
+
17
+ # ----------------------- Style -----------------------
18
+
19
+ Style/MixinUsage:
20
+ Exclude:
21
+ - bin/console
22
+
23
+ Style/StringLiterals:
24
+ Enabled: true
25
+ EnforcedStyle: single_quotes
26
+
27
+ Style/StringLiteralsInInterpolation:
28
+ Enabled: true
29
+ EnforcedStyle: double_quotes
30
+
31
+ # ----------------------- Layout ----------------------
32
+
33
+ Layout/LineLength:
34
+ Max: 120
35
+ Exclude:
36
+ - jsonrpc-middleware.gemspec
37
+
38
+ # ---------------------- Metrics ----------------------
39
+
40
+ Metrics/AbcSize:
41
+ Enabled: false
42
+
43
+ Metrics/BlockLength:
44
+ Enabled: false
45
+
46
+ Metrics/CyclomaticComplexity:
47
+ Enabled: false
48
+
49
+ Metrics/ClassLength:
50
+ Enabled: false
51
+
52
+ Metrics/MethodLength:
53
+ Enabled: false
54
+
55
+ Metrics/ParameterLists:
56
+ CountKeywordArgs: false
57
+
58
+ Metrics/PerceivedComplexity:
59
+ Enabled: false
60
+
61
+ # ----------------------- RSpec -----------------------
62
+
63
+ RSpec/ExampleLength:
64
+ Enabled: false
65
+
66
+ RSpec/NestedGroups:
67
+ Enabled: false
68
+
69
+ RSpec/MultipleExpectations:
70
+ Enabled: false
71
+
72
+ # RuboCop does not like the gem's name.
73
+ RSpec/SpecFilePathFormat:
74
+ Enabled: false
data/.tool-versions ADDED
@@ -0,0 +1 @@
1
+ ruby 3.4.4
data/.yardstick.yml ADDED
@@ -0,0 +1,22 @@
1
+ threshold: 100
2
+ rules:
3
+ ApiTag::Presence:
4
+ enabled: true
5
+ ApiTag::Inclusion:
6
+ enabled: true
7
+ ApiTag::ProtectedMethod:
8
+ enabled: true
9
+ ApiTag::PrivateMethod:
10
+ enabled: true
11
+ ExampleTag:
12
+ enabled: true
13
+ ReturnTag:
14
+ enabled: true
15
+ Summary::Presence:
16
+ enabled: true
17
+ Summary::Length:
18
+ enabled: false
19
+ Summary::Delimiter:
20
+ enabled: true
21
+ Summary::SingleLine:
22
+ enabled: false
data/CHANGELOG.md ADDED
@@ -0,0 +1,37 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
+
8
+ ## [Unreleased]
9
+
10
+ ## [0.1.0] - 2025-06-14
11
+
12
+ ### Added
13
+ - Initial release of the JSON-RPC 2.0 middleware for Rack applications
14
+ - Complete implementation of the [JSON-RPC 2.0 specification](https://www.jsonrpc.org/specification)
15
+ - Core components:
16
+ - `JSONRPC::Middleware` for handling JSON-RPC requests in Rack applications
17
+ - `JSONRPC::Parser` for parsing and validating JSON-RPC requests
18
+ - `JSONRPC::Validator` for validating procedure parameters
19
+ - `JSONRPC::Configuration` for registering and managing procedures
20
+ - Support for all JSON-RPC request types:
21
+ - Single requests with responses
22
+ - Notifications (requests without responses)
23
+ - Batch requests (multiple requests/notifications in a single call)
24
+ - Parameter validation via Dry::Validation:
25
+ - Support for both positional and named arguments
26
+ - Customizable validation rules and error messages
27
+ - Comprehensive error handling:
28
+ - Parse errors
29
+ - Invalid request errors
30
+ - Method not found errors
31
+ - Invalid params errors
32
+ - Internal errors
33
+ - Helper methods for request and response processing
34
+ - Examples for basic and advanced usage scenarios
35
+
36
+ [Unreleased]: https://github.com/wilsonsilva/jsonrpc-middleware/compare/v0.1.0...HEAD
37
+ [0.1.0]: https://github.com/wilsonsilva/jsonrpc-middleware/releases/tag/v0.1.0
@@ -0,0 +1,132 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ We as members, contributors, and leaders pledge to make participation in our
6
+ community a harassment-free experience for everyone, regardless of age, body
7
+ size, visible or invisible disability, ethnicity, sex characteristics, gender
8
+ identity and expression, level of experience, education, socio-economic status,
9
+ nationality, personal appearance, race, caste, color, religion, or sexual
10
+ identity and orientation.
11
+
12
+ We pledge to act and interact in ways that contribute to an open, welcoming,
13
+ diverse, inclusive, and healthy community.
14
+
15
+ ## Our Standards
16
+
17
+ Examples of behavior that contributes to a positive environment for our
18
+ community include:
19
+
20
+ * Demonstrating empathy and kindness toward other people
21
+ * Being respectful of differing opinions, viewpoints, and experiences
22
+ * Giving and gracefully accepting constructive feedback
23
+ * Accepting responsibility and apologizing to those affected by our mistakes,
24
+ and learning from the experience
25
+ * Focusing on what is best not just for us as individuals, but for the overall
26
+ community
27
+
28
+ Examples of unacceptable behavior include:
29
+
30
+ * The use of sexualized language or imagery, and sexual attention or advances of
31
+ any kind
32
+ * Trolling, insulting or derogatory comments, and personal or political attacks
33
+ * Public or private harassment
34
+ * Publishing others' private information, such as a physical or email address,
35
+ without their explicit permission
36
+ * Other conduct which could reasonably be considered inappropriate in a
37
+ professional setting
38
+
39
+ ## Enforcement Responsibilities
40
+
41
+ Community leaders are responsible for clarifying and enforcing our standards of
42
+ acceptable behavior and will take appropriate and fair corrective action in
43
+ response to any behavior that they deem inappropriate, threatening, offensive,
44
+ or harmful.
45
+
46
+ Community leaders have the right and responsibility to remove, edit, or reject
47
+ comments, commits, code, wiki edits, issues, and other contributions that are
48
+ not aligned to this Code of Conduct, and will communicate reasons for moderation
49
+ decisions when appropriate.
50
+
51
+ ## Scope
52
+
53
+ This Code of Conduct applies within all community spaces, and also applies when
54
+ an individual is officially representing the community in public spaces.
55
+ Examples of representing our community include using an official email address,
56
+ posting via an official social media account, or acting as an appointed
57
+ representative at an online or offline event.
58
+
59
+ ## Enforcement
60
+
61
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
62
+ reported to the community leaders responsible for enforcement at
63
+ [INSERT CONTACT METHOD].
64
+ All complaints will be reviewed and investigated promptly and fairly.
65
+
66
+ All community leaders are obligated to respect the privacy and security of the
67
+ reporter of any incident.
68
+
69
+ ## Enforcement Guidelines
70
+
71
+ Community leaders will follow these Community Impact Guidelines in determining
72
+ the consequences for any action they deem in violation of this Code of Conduct:
73
+
74
+ ### 1. Correction
75
+
76
+ **Community Impact**: Use of inappropriate language or other behavior deemed
77
+ unprofessional or unwelcome in the community.
78
+
79
+ **Consequence**: A private, written warning from community leaders, providing
80
+ clarity around the nature of the violation and an explanation of why the
81
+ behavior was inappropriate. A public apology may be requested.
82
+
83
+ ### 2. Warning
84
+
85
+ **Community Impact**: A violation through a single incident or series of
86
+ actions.
87
+
88
+ **Consequence**: A warning with consequences for continued behavior. No
89
+ interaction with the people involved, including unsolicited interaction with
90
+ those enforcing the Code of Conduct, for a specified period of time. This
91
+ includes avoiding interactions in community spaces as well as external channels
92
+ like social media. Violating these terms may lead to a temporary or permanent
93
+ ban.
94
+
95
+ ### 3. Temporary Ban
96
+
97
+ **Community Impact**: A serious violation of community standards, including
98
+ sustained inappropriate behavior.
99
+
100
+ **Consequence**: A temporary ban from any sort of interaction or public
101
+ communication with the community for a specified period of time. No public or
102
+ private interaction with the people involved, including unsolicited interaction
103
+ with those enforcing the Code of Conduct, is allowed during this period.
104
+ Violating these terms may lead to a permanent ban.
105
+
106
+ ### 4. Permanent Ban
107
+
108
+ **Community Impact**: Demonstrating a pattern of violation of community
109
+ standards, including sustained inappropriate behavior, harassment of an
110
+ individual, or aggression toward or disparagement of classes of individuals.
111
+
112
+ **Consequence**: A permanent ban from any sort of public interaction within the
113
+ community.
114
+
115
+ ## Attribution
116
+
117
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage],
118
+ version 2.1, available at
119
+ [https://www.contributor-covenant.org/version/2/1/code_of_conduct.html][v2.1].
120
+
121
+ Community Impact Guidelines were inspired by
122
+ [Mozilla's code of conduct enforcement ladder][Mozilla CoC].
123
+
124
+ For answers to common questions about this code of conduct, see the FAQ at
125
+ [https://www.contributor-covenant.org/faq][FAQ]. Translations are available at
126
+ [https://www.contributor-covenant.org/translations][translations].
127
+
128
+ [homepage]: https://www.contributor-covenant.org
129
+ [v2.1]: https://www.contributor-covenant.org/version/2/1/code_of_conduct.html
130
+ [Mozilla CoC]: https://github.com/mozilla/diversity
131
+ [FAQ]: https://www.contributor-covenant.org/faq
132
+ [translations]: https://www.contributor-covenant.org/translations
data/Guardfile ADDED
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ guard 'bundler' do
4
+ watch('jsonrpc-middleware.gemspec')
5
+ end
6
+
7
+ guard 'bundler_audit', run_on_start: true do
8
+ watch('Gemfile.lock')
9
+ end
10
+
11
+ group 'tests' do
12
+ guard 'rspec', all_on_start: true, failed_mode: :focus, cmd: 'COVERAGE=false bundle exec rspec --format progress' do
13
+ watch(%r{^spec/.+_spec\.rb$})
14
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
15
+ watch('spec/spec_helper.rb') { 'spec' }
16
+ end
17
+ end
18
+
19
+ guard 'rubocop' do
20
+ watch(/.+\.rb$/)
21
+ watch(%r{(?:.+/)?\.rubocop\.yml$}) { |m| File.dirname(m[0]) }
22
+ end
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2025 Wilson Silva
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,248 @@
1
+ # JSONRPC::Middleware - Ruby JSON-RPC Implementation
2
+
3
+ [![Gem Version](https://badge.fury.io/rb/jsonrpc-middleware.svg)](https://badge.fury.io/rb/jsonrpc-middleware)
4
+ ![Build](https://github.com/wilsonsilva/jsonrpc-middleware/actions/workflows/main.yml/badge.svg)
5
+ [![Maintainability](https://qlty.sh/badges/73ebc4bb-d1db-4b5b-9a7c-a4acd59dfe69/maintainability.svg)](https://qlty.sh/gh/wilsonsilva/projects/jsonrpc-middleware)
6
+ [![Code Coverage](https://qlty.sh/badges/73ebc4bb-d1db-4b5b-9a7c-a4acd59dfe69/test_coverage.svg)](https://qlty.sh/gh/wilsonsilva/projects/jsonrpc-middleware)
7
+
8
+ A Ruby implementation of the JSON-RPC protocol, enabling standardized communication between systems via remote procedure
9
+ calls encoded in JSON.
10
+
11
+ ## Table of contents
12
+
13
+ - [Key features](#-key-features)
14
+ - [Installation](#-installation)
15
+ - [Quickstart](#-quickstart)
16
+ - [Documentation](#-documentation)
17
+ - [Development](#-development)
18
+ * [Type checking](#type-checking)
19
+ - [Contributing](#-contributing)
20
+ - [License](#-license)
21
+ - [Code of Conduct](#-code-of-conduct)
22
+
23
+ ## 🔑 Key features
24
+
25
+ - **Complete JSON-RPC 2.0 Implementation**: Fully implements the [JSON-RPC 2.0 specification](https://www.jsonrpc.org/specification)
26
+ - **Rack Middleware integration**: Seamlessly integrates with Rack applications
27
+ - **Advanced request validation**: Define request parameter specifications and validations using `Dry::Validation`
28
+ - **Support for all request types**: Handles single requests, notifications, and batch requests
29
+ - **Parameter validation**: Supports both positional and named arguments with customizable validation rules
30
+ - **Error handling**: Comprehensive error handling with standard JSON-RPC error responses
31
+ - **Helper methods**: Convenient helper methods to simplify request and response processing
32
+ - **Type checking**: Ruby type checking support via RBS definitions
33
+
34
+ ## 📦 Installation
35
+
36
+ Install the gem by executing:
37
+
38
+ $ gem install jsonrpc-middleware
39
+
40
+ ## ⚡️ Quickstart
41
+
42
+ ### Basic Setup with Rack
43
+
44
+ ```ruby
45
+ # Gemfile
46
+ source 'https://rubygems.org'
47
+ gem 'jsonrpc-middleware'
48
+ gem 'rack'
49
+ ```
50
+
51
+ ```ruby
52
+ # config.ru
53
+ require 'jsonrpc'
54
+ require_relative 'app'
55
+
56
+ # Use the middleware
57
+ use JSONRPC::Middleware
58
+
59
+ # Your application
60
+ run App.new
61
+ ```
62
+
63
+ ### Define Your JSON-RPC Procedures
64
+
65
+ Define your available procedures with validation rules:
66
+
67
+ ```ruby
68
+ # procedures.rb
69
+ require 'jsonrpc'
70
+
71
+ JSONRPC.configure do
72
+ # Define a procedure that accepts both positional and named arguments
73
+ procedure(:add, allow_positional_arguments: true) do
74
+ params do
75
+ required(:addends).filled(:array)
76
+ required(:addends).value(:array).each(type?: Numeric)
77
+ end
78
+
79
+ rule(:addends) do
80
+ key.failure('must contain at least one addend') if value.empty?
81
+ end
82
+ end
83
+
84
+ # Define a procedure with named arguments only
85
+ procedure(:subtract) do
86
+ params do
87
+ required(:minuend).filled(:integer)
88
+ required(:subtrahend).filled(:integer)
89
+ end
90
+ end
91
+ end
92
+ ```
93
+
94
+ ### Create Your Application
95
+
96
+ ```ruby
97
+ # app.rb
98
+ class App
99
+ include JSONRPC::Helpers
100
+
101
+ def call(env)
102
+ @env = env # Set the env instance variable to use JSONRPC helpers
103
+
104
+ if jsonrpc_request?
105
+ # Handle a standard JSON-RPC request
106
+ result = handle_single(jsonrpc_request)
107
+ jsonrpc_response(result)
108
+ elsif jsonrpc_notification?
109
+ # Handle a notification (no response needed)
110
+ handle_single(jsonrpc_notification)
111
+ jsonrpc_notification_response
112
+ else
113
+ # Handle batch requests
114
+ responses = handle_batch(jsonrpc_batch)
115
+ jsonrpc_batch_response(responses)
116
+ end
117
+ end
118
+
119
+ private
120
+
121
+ def handle_single(request_or_notification)
122
+ params = request_or_notification.params
123
+
124
+ case request_or_notification.method
125
+ when 'add'
126
+ # Handle both positional and named arguments
127
+ addends = params.is_a?(Array) ? params : params['addends']
128
+ addends.sum
129
+ when 'subtract'
130
+ params['minuend'] - params['subtrahend']
131
+ end
132
+ end
133
+
134
+ def handle_batch(batch)
135
+ batch.flat_map do |request_or_notification|
136
+ result = handle_single(request_or_notification)
137
+ # Only create responses for requests, not notifications
138
+ JSONRPC::Response.new(id: request_or_notification.id, result: result) if request_or_notification.is_a?(JSONRPC::Request)
139
+ end.compact
140
+ end
141
+ end
142
+ ```
143
+
144
+ ### Example Requests
145
+
146
+ Here are example JSON-RPC requests you can make to your application:
147
+
148
+ ```json
149
+ // Standard request with named params
150
+ {
151
+ "jsonrpc": "2.0",
152
+ "method": "subtract",
153
+ "params": {
154
+ "minuend": 42,
155
+ "subtrahend": 23
156
+ },
157
+ "id": 1
158
+ }
159
+
160
+ // Request with positional params (if allowed)
161
+ {
162
+ "jsonrpc": "2.0",
163
+ "method": "add",
164
+ "params": [1, 2, 3, 4, 5],
165
+ "id": 2
166
+ }
167
+
168
+ // Notification (no response)
169
+ {
170
+ "jsonrpc": "2.0",
171
+ "method": "add",
172
+ "params": {"addends": [1, 2, 3]}
173
+ }
174
+
175
+ // Batch request
176
+ [
177
+ {"jsonrpc": "2.0", "method": "add", "params": {"addends": [1, 2]}, "id": 1},
178
+ {"jsonrpc": "2.0", "method": "subtract", "params": {"minuend": 10, "subtrahend": 5}, "id": 2}
179
+ ]
180
+ ```
181
+
182
+ ## 📚 Documentation
183
+
184
+ - [YARD documentation](https://rubydoc.info/gems/jsonrpc-middleware)
185
+
186
+ ## 🔨 Development
187
+
188
+ After checking out the repo, run `bin/setup` to install dependencies.
189
+
190
+ To install this gem onto your local machine, run `bundle exec rake install`.
191
+
192
+ You can also run `bin/console` for an interactive prompt that will allow you to experiment.
193
+
194
+ To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`,
195
+ which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file
196
+ to [rubygems.org](https://rubygems.org).
197
+
198
+ The health and maintainability of the codebase is ensured through a set of
199
+ Rake tasks to test, lint and audit the gem for security vulnerabilities and documentation:
200
+
201
+ ```
202
+ rake build # Build jsonrpc-middleware.gem into the pkg directory
203
+ rake build:checksum # Generate SHA512 checksum if jsonrpc-middleware.gem into the checksums directory
204
+ rake bundle:audit:check # Checks the Gemfile.lock for insecure dependencies
205
+ rake bundle:audit:update # Updates the bundler-audit vulnerability database
206
+ rake clean # Remove any temporary products
207
+ rake clobber # Remove any generated files
208
+ rake coverage # Run spec with coverage
209
+ rake install # Build and install jsonrpc-middleware.gem into system gems
210
+ rake install:local # Build and install jsonrpc-middleware.gem into system gems without network access
211
+ rake qa # Test, lint and perform security and documentation audits
212
+ rake release[remote] # Create a tag, build and push jsonrpc-middleware.gem to rubygems.org
213
+ rake rubocop # Run RuboCop
214
+ rake rubocop:autocorrect # Autocorrect RuboCop offenses (only when it's safe)
215
+ rake rubocop:autocorrect_all # Autocorrect RuboCop offenses (safe and unsafe)
216
+ rake spec # Run RSpec code examples
217
+ rake verify_measurements # Verify that yardstick coverage is at least 100%
218
+ rake yard # Generate YARD Documentation
219
+ rake yard:junk # Check the junk in your YARD Documentation
220
+ rake yardstick_measure # Measure docs in lib/**/*.rb with yardstick
221
+ ```
222
+
223
+ ### Type checking
224
+
225
+ This gem leverages [RBS](https://github.com/ruby/rbs), a language to describe the structure of Ruby programs. It is
226
+ used to provide type checking and autocompletion in your editor. Run `bundle exec typeprof FILENAME` to generate
227
+ an RBS definition for the given Ruby file. And validate all definitions using [Steep](https://github.com/soutaro/steep)
228
+ with the command `bundle exec steep check`.
229
+
230
+ ## 🐞 Issues & Bugs
231
+
232
+ If you find any issues or bugs, please report them [here](https://github.com/wilsonsilva/jsonrpc-middleware/issues), I will be happy
233
+ to have a look at them and fix them as soon as possible.
234
+
235
+ ## 🤝 Contributing
236
+
237
+ Bug reports and pull requests are welcome on GitHub at https://github.com/wilsonsilva/jsonrpc-middleware.
238
+ This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere
239
+ to the [code of conduct](https://github.com/wilsonsilva/jsonrpc-middleware/blob/main/CODE_OF_CONDUCT.md).
240
+
241
+ ## 📜 License
242
+
243
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
244
+
245
+ ## 👔 Code of Conduct
246
+
247
+ Everyone interacting in the JSONRPC::Middleware Ruby project's codebases, issue trackers, chat rooms and mailing lists is expected
248
+ to follow the [code of conduct](https://github.com/wilsonsilva/jsonrpc-middleware/blob/main/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,41 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/audit/task'
4
+ require 'bundler/gem_tasks'
5
+ require 'rspec/core/rake_task'
6
+ require 'rubocop/rake_task'
7
+ require 'yaml'
8
+ require 'yard/rake/yardoc_task'
9
+ require 'yard-junk/rake'
10
+ require 'yardstick/rake/measurement'
11
+ require 'yardstick/rake/verify'
12
+
13
+ yardstick_options = YAML.load_file('.yardstick.yml')
14
+
15
+ Bundler::Audit::Task.new
16
+ RSpec::Core::RakeTask.new(:spec)
17
+ RuboCop::RakeTask.new do |task|
18
+ task.requires << 'rubocop-yard'
19
+ end
20
+ YARD::Rake::YardocTask.new
21
+ YardJunk::Rake.define_task
22
+ Yardstick::Rake::Measurement.new(:yardstick_measure, yardstick_options)
23
+ Yardstick::Rake::Verify.new
24
+
25
+ task default: %i[spec rubocop]
26
+
27
+ # Remove the report on rake clobber
28
+ CLEAN.include('measurements', 'doc', '.yardoc', 'tmp')
29
+
30
+ # Delete these files and folders when running rake clobber.
31
+ CLOBBER.include('coverage', '.rspec_status')
32
+
33
+ desc 'Run spec with coverage'
34
+ task :coverage do
35
+ ENV['COVERAGE'] = 'true'
36
+ Rake::Task['spec'].execute
37
+ `open coverage/index.html`
38
+ end
39
+
40
+ desc 'Test, lint and perform security and documentation audits'
41
+ task qa: %w[spec rubocop yard:junk verify_measurements bundle:audit]
data/Steepfile ADDED
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ target :lib do
4
+ signature 'sig'
5
+
6
+ check 'lib'
7
+ end