spikard 0.2.1 → 0.2.5

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 (101) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE +1 -1
  3. data/README.md +626 -626
  4. data/ext/spikard_rb/Cargo.toml +17 -17
  5. data/ext/spikard_rb/extconf.rb +10 -10
  6. data/ext/spikard_rb/src/lib.rs +6 -6
  7. data/lib/spikard/app.rb +374 -374
  8. data/lib/spikard/background.rb +27 -27
  9. data/lib/spikard/config.rb +396 -396
  10. data/lib/spikard/converters.rb +85 -85
  11. data/lib/spikard/handler_wrapper.rb +116 -116
  12. data/lib/spikard/provide.rb +228 -228
  13. data/lib/spikard/response.rb +109 -109
  14. data/lib/spikard/schema.rb +243 -243
  15. data/lib/spikard/sse.rb +111 -111
  16. data/lib/spikard/streaming_response.rb +21 -21
  17. data/lib/spikard/testing.rb +221 -221
  18. data/lib/spikard/upload_file.rb +131 -131
  19. data/lib/spikard/version.rb +5 -5
  20. data/lib/spikard/websocket.rb +59 -59
  21. data/lib/spikard.rb +43 -43
  22. data/sig/spikard.rbs +349 -349
  23. data/vendor/crates/spikard-core/Cargo.toml +40 -0
  24. data/vendor/crates/spikard-core/src/bindings/mod.rs +3 -0
  25. data/vendor/crates/spikard-core/src/bindings/response.rs +133 -0
  26. data/vendor/crates/spikard-core/src/debug.rs +63 -0
  27. data/vendor/crates/spikard-core/src/di/container.rs +726 -0
  28. data/vendor/crates/spikard-core/src/di/dependency.rs +273 -0
  29. data/vendor/crates/spikard-core/src/di/error.rs +118 -0
  30. data/vendor/crates/spikard-core/src/di/factory.rs +538 -0
  31. data/vendor/crates/spikard-core/src/di/graph.rs +545 -0
  32. data/vendor/crates/spikard-core/src/di/mod.rs +192 -0
  33. data/vendor/crates/spikard-core/src/di/resolved.rs +411 -0
  34. data/vendor/crates/spikard-core/src/di/value.rs +283 -0
  35. data/vendor/crates/spikard-core/src/http.rs +153 -0
  36. data/vendor/crates/spikard-core/src/lib.rs +28 -0
  37. data/vendor/crates/spikard-core/src/lifecycle.rs +422 -0
  38. data/vendor/crates/spikard-core/src/parameters.rs +719 -0
  39. data/vendor/crates/spikard-core/src/problem.rs +310 -0
  40. data/vendor/crates/spikard-core/src/request_data.rs +189 -0
  41. data/vendor/crates/spikard-core/src/router.rs +249 -0
  42. data/vendor/crates/spikard-core/src/schema_registry.rs +183 -0
  43. data/vendor/crates/spikard-core/src/type_hints.rs +304 -0
  44. data/vendor/crates/spikard-core/src/validation.rs +699 -0
  45. data/vendor/crates/spikard-http/Cargo.toml +58 -0
  46. data/vendor/crates/spikard-http/src/auth.rs +247 -0
  47. data/vendor/crates/spikard-http/src/background.rs +249 -0
  48. data/vendor/crates/spikard-http/src/bindings/mod.rs +3 -0
  49. data/vendor/crates/spikard-http/src/bindings/response.rs +1 -0
  50. data/vendor/crates/spikard-http/src/body_metadata.rs +8 -0
  51. data/vendor/crates/spikard-http/src/cors.rs +490 -0
  52. data/vendor/crates/spikard-http/src/debug.rs +63 -0
  53. data/vendor/crates/spikard-http/src/di_handler.rs +423 -0
  54. data/vendor/crates/spikard-http/src/handler_response.rs +190 -0
  55. data/vendor/crates/spikard-http/src/handler_trait.rs +228 -0
  56. data/vendor/crates/spikard-http/src/handler_trait_tests.rs +284 -0
  57. data/vendor/crates/spikard-http/src/lib.rs +529 -0
  58. data/vendor/crates/spikard-http/src/lifecycle/adapter.rs +149 -0
  59. data/vendor/crates/spikard-http/src/lifecycle.rs +428 -0
  60. data/vendor/crates/spikard-http/src/middleware/mod.rs +285 -0
  61. data/vendor/crates/spikard-http/src/middleware/multipart.rs +86 -0
  62. data/vendor/crates/spikard-http/src/middleware/urlencoded.rs +147 -0
  63. data/vendor/crates/spikard-http/src/middleware/validation.rs +287 -0
  64. data/vendor/crates/spikard-http/src/openapi/mod.rs +309 -0
  65. data/vendor/crates/spikard-http/src/openapi/parameter_extraction.rs +190 -0
  66. data/vendor/crates/spikard-http/src/openapi/schema_conversion.rs +308 -0
  67. data/vendor/crates/spikard-http/src/openapi/spec_generation.rs +195 -0
  68. data/vendor/crates/spikard-http/src/parameters.rs +1 -0
  69. data/vendor/crates/spikard-http/src/problem.rs +1 -0
  70. data/vendor/crates/spikard-http/src/query_parser.rs +369 -0
  71. data/vendor/crates/spikard-http/src/response.rs +399 -0
  72. data/vendor/crates/spikard-http/src/router.rs +1 -0
  73. data/vendor/crates/spikard-http/src/schema_registry.rs +1 -0
  74. data/vendor/crates/spikard-http/src/server/handler.rs +80 -0
  75. data/vendor/crates/spikard-http/src/server/lifecycle_execution.rs +98 -0
  76. data/vendor/crates/spikard-http/src/server/mod.rs +805 -0
  77. data/vendor/crates/spikard-http/src/server/request_extraction.rs +119 -0
  78. data/vendor/crates/spikard-http/src/sse.rs +447 -0
  79. data/vendor/crates/spikard-http/src/testing/form.rs +14 -0
  80. data/vendor/crates/spikard-http/src/testing/multipart.rs +60 -0
  81. data/vendor/crates/spikard-http/src/testing/test_client.rs +285 -0
  82. data/vendor/crates/spikard-http/src/testing.rs +377 -0
  83. data/vendor/crates/spikard-http/src/type_hints.rs +1 -0
  84. data/vendor/crates/spikard-http/src/validation.rs +1 -0
  85. data/vendor/crates/spikard-http/src/websocket.rs +324 -0
  86. data/vendor/crates/spikard-rb/Cargo.toml +42 -0
  87. data/vendor/crates/spikard-rb/build.rs +8 -0
  88. data/vendor/crates/spikard-rb/src/background.rs +63 -0
  89. data/vendor/crates/spikard-rb/src/config.rs +294 -0
  90. data/vendor/crates/spikard-rb/src/conversion.rs +392 -0
  91. data/vendor/crates/spikard-rb/src/di.rs +409 -0
  92. data/vendor/crates/spikard-rb/src/handler.rs +534 -0
  93. data/vendor/crates/spikard-rb/src/lib.rs +2020 -0
  94. data/vendor/crates/spikard-rb/src/lifecycle.rs +267 -0
  95. data/vendor/crates/spikard-rb/src/server.rs +283 -0
  96. data/vendor/crates/spikard-rb/src/sse.rs +231 -0
  97. data/vendor/crates/spikard-rb/src/test_client.rs +404 -0
  98. data/vendor/crates/spikard-rb/src/test_sse.rs +143 -0
  99. data/vendor/crates/spikard-rb/src/test_websocket.rs +221 -0
  100. data/vendor/crates/spikard-rb/src/websocket.rs +233 -0
  101. metadata +80 -2
@@ -1,85 +1,85 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative 'upload_file'
4
-
5
- module Spikard
6
- # Type conversion utilities for handler parameters
7
- #
8
- # This module handles converting validated JSON data from Rust into Ruby types,
9
- # particularly for UploadFile instances.
10
- module Converters
11
- module_function
12
-
13
- # Check if a value looks like file metadata from Rust
14
- #
15
- # @param value [Object] Value to check
16
- # @return [Boolean]
17
- def file_metadata?(value)
18
- value.is_a?(Hash) && value.key?('filename') && value.key?('content')
19
- end
20
-
21
- # Convert file metadata hash to UploadFile instance
22
- #
23
- # @param file_data [Hash] File metadata from Rust (filename, content, size, content_type)
24
- # @return [UploadFile] UploadFile instance
25
- def convert_file_metadata_to_upload_file(file_data)
26
- UploadFile.new(
27
- file_data['filename'],
28
- file_data['content'],
29
- content_type: file_data['content_type'],
30
- size: file_data['size'],
31
- headers: file_data['headers'],
32
- content_encoding: file_data['content_encoding']
33
- )
34
- end
35
-
36
- # Process handler parameters, converting file metadata to UploadFile instances
37
- #
38
- # This method recursively processes the body parameter, looking for file metadata
39
- # structures and converting them to UploadFile instances.
40
- #
41
- # @param value [Object] The value to process (can be Hash, Array, or primitive)
42
- # @return [Object] Processed value with UploadFile instances
43
- def process_upload_file_fields(value)
44
- # Handle nil
45
- return value if value.nil?
46
-
47
- # Handle primitives (String, Numeric, Boolean)
48
- return value unless value.is_a?(Hash) || value.is_a?(Array)
49
-
50
- # Handle arrays - recursively process each element
51
- if value.is_a?(Array)
52
- return value.map do |item|
53
- # Check if this array item is file metadata
54
- if file_metadata?(item)
55
- convert_file_metadata_to_upload_file(item)
56
- else
57
- # Recursively process nested arrays/hashes
58
- process_upload_file_fields(item)
59
- end
60
- end
61
- end
62
-
63
- # Handle hashes - check if it's file metadata first
64
- return convert_file_metadata_to_upload_file(value) if file_metadata?(value)
65
-
66
- # Otherwise, recursively process hash values
67
- value.transform_values { |v| process_upload_file_fields(v) }
68
- end
69
-
70
- # Process handler body parameter, handling UploadFile conversion
71
- #
72
- # This is the main entry point for converting Rust-provided request data
73
- # into Ruby types. It handles:
74
- # - Single UploadFile
75
- # - Arrays of UploadFile
76
- # - Hashes with UploadFile fields
77
- # - Nested structures
78
- #
79
- # @param body [Object] The body parameter from Rust (already JSON-parsed)
80
- # @return [Object] Processed body with UploadFile instances
81
- def convert_handler_body(body)
82
- process_upload_file_fields(body)
83
- end
84
- end
85
- end
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'upload_file'
4
+
5
+ module Spikard
6
+ # Type conversion utilities for handler parameters
7
+ #
8
+ # This module handles converting validated JSON data from Rust into Ruby types,
9
+ # particularly for UploadFile instances.
10
+ module Converters
11
+ module_function
12
+
13
+ # Check if a value looks like file metadata from Rust
14
+ #
15
+ # @param value [Object] Value to check
16
+ # @return [Boolean]
17
+ def file_metadata?(value)
18
+ value.is_a?(Hash) && value.key?('filename') && value.key?('content')
19
+ end
20
+
21
+ # Convert file metadata hash to UploadFile instance
22
+ #
23
+ # @param file_data [Hash] File metadata from Rust (filename, content, size, content_type)
24
+ # @return [UploadFile] UploadFile instance
25
+ def convert_file_metadata_to_upload_file(file_data)
26
+ UploadFile.new(
27
+ file_data['filename'],
28
+ file_data['content'],
29
+ content_type: file_data['content_type'],
30
+ size: file_data['size'],
31
+ headers: file_data['headers'],
32
+ content_encoding: file_data['content_encoding']
33
+ )
34
+ end
35
+
36
+ # Process handler parameters, converting file metadata to UploadFile instances
37
+ #
38
+ # This method recursively processes the body parameter, looking for file metadata
39
+ # structures and converting them to UploadFile instances.
40
+ #
41
+ # @param value [Object] The value to process (can be Hash, Array, or primitive)
42
+ # @return [Object] Processed value with UploadFile instances
43
+ def process_upload_file_fields(value)
44
+ # Handle nil
45
+ return value if value.nil?
46
+
47
+ # Handle primitives (String, Numeric, Boolean)
48
+ return value unless value.is_a?(Hash) || value.is_a?(Array)
49
+
50
+ # Handle arrays - recursively process each element
51
+ if value.is_a?(Array)
52
+ return value.map do |item|
53
+ # Check if this array item is file metadata
54
+ if file_metadata?(item)
55
+ convert_file_metadata_to_upload_file(item)
56
+ else
57
+ # Recursively process nested arrays/hashes
58
+ process_upload_file_fields(item)
59
+ end
60
+ end
61
+ end
62
+
63
+ # Handle hashes - check if it's file metadata first
64
+ return convert_file_metadata_to_upload_file(value) if file_metadata?(value)
65
+
66
+ # Otherwise, recursively process hash values
67
+ value.transform_values { |v| process_upload_file_fields(v) }
68
+ end
69
+
70
+ # Process handler body parameter, handling UploadFile conversion
71
+ #
72
+ # This is the main entry point for converting Rust-provided request data
73
+ # into Ruby types. It handles:
74
+ # - Single UploadFile
75
+ # - Arrays of UploadFile
76
+ # - Hashes with UploadFile fields
77
+ # - Nested structures
78
+ #
79
+ # @param body [Object] The body parameter from Rust (already JSON-parsed)
80
+ # @return [Object] Processed body with UploadFile instances
81
+ def convert_handler_body(body)
82
+ process_upload_file_fields(body)
83
+ end
84
+ end
85
+ end
@@ -1,116 +1,116 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative 'converters'
4
-
5
- module Spikard
6
- # Handler wrapper utilities for automatic file metadata conversion
7
- #
8
- # Provides ergonomic handler patterns that automatically convert
9
- # file metadata to UploadFile instances, eliminating boilerplate.
10
- #
11
- # @example Basic usage with body only
12
- # app.post('/upload', &wrap_body_handler do |body|
13
- # {
14
- # filename: body[:file].filename,
15
- # content: body[:file].read
16
- # }
17
- # end)
18
- #
19
- # @example With all parameters
20
- # app.post('/upload', &wrap_handler do |params, query, body|
21
- # {
22
- # id: params[:id],
23
- # search: query[:q],
24
- # file: body[:file].filename
25
- # }
26
- # end)
27
- module HandlerWrapper
28
- module_function
29
-
30
- # Wrap a handler that receives only the request body
31
- #
32
- # Automatically converts file metadata in the body to UploadFile instances.
33
- #
34
- # @yield [body] Handler block that receives converted body
35
- # @yieldparam body [Hash] Request body with file metadata converted to UploadFile
36
- # @yieldreturn [Hash, Spikard::Response] Response data or Response object
37
- # @return [Proc] Wrapped handler proc
38
- #
39
- # @example
40
- # app.post('/upload', &wrap_body_handler do |body|
41
- # { filename: body[:file].filename }
42
- # end)
43
- def wrap_body_handler(&handler)
44
- raise ArgumentError, 'block required for wrap_body_handler' unless handler
45
-
46
- # Return a proc that matches the signature expected by Spikard::App
47
- # The actual handler receives path params, query params, and body from Rust
48
- lambda do |_params, _query, body|
49
- converted_body = Converters.convert_handler_body(body)
50
- handler.call(converted_body)
51
- end
52
- end
53
-
54
- # Wrap a handler that receives path params, query params, and body
55
- #
56
- # Automatically converts file metadata in the body to UploadFile instances.
57
- #
58
- # @yield [params, query, body] Handler block that receives all request data
59
- # @yieldparam params [Hash] Path parameters
60
- # @yieldparam query [Hash] Query parameters
61
- # @yieldparam body [Hash] Request body with file metadata converted to UploadFile
62
- # @yieldreturn [Hash, Spikard::Response] Response data or Response object
63
- # @return [Proc] Wrapped handler proc
64
- #
65
- # @example
66
- # app.post('/users/{id}/upload', &wrap_handler do |params, query, body|
67
- # {
68
- # user_id: params[:id],
69
- # description: query[:desc],
70
- # file: body[:file].filename
71
- # }
72
- # end)
73
- def wrap_handler(&handler)
74
- raise ArgumentError, 'block required for wrap_handler' unless handler
75
-
76
- lambda do |params, query, body|
77
- converted_body = Converters.convert_handler_body(body)
78
- handler.call(params, query, converted_body)
79
- end
80
- end
81
-
82
- # Wrap a handler that receives a context hash with all request data
83
- #
84
- # Automatically converts file metadata in the body to UploadFile instances.
85
- # Useful when you want all request data in a single hash.
86
- #
87
- # @yield [context] Handler block that receives context hash
88
- # @yieldparam context [Hash] Request context with:
89
- # - :params [Hash] Path parameters
90
- # - :query [Hash] Query parameters
91
- # - :body [Hash] Request body with file metadata converted to UploadFile
92
- # @yieldreturn [Hash, Spikard::Response] Response data or Response object
93
- # @return [Proc] Wrapped handler proc
94
- #
95
- # @example
96
- # app.post('/upload', &wrap_handler_with_context do |ctx|
97
- # {
98
- # file: ctx[:body][:file].filename,
99
- # query_params: ctx[:query]
100
- # }
101
- # end)
102
- def wrap_handler_with_context(&handler)
103
- raise ArgumentError, 'block required for wrap_handler_with_context' unless handler
104
-
105
- lambda do |params, query, body|
106
- converted_body = Converters.convert_handler_body(body)
107
- context = {
108
- params: params,
109
- query: query,
110
- body: converted_body
111
- }
112
- handler.call(context)
113
- end
114
- end
115
- end
116
- end
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'converters'
4
+
5
+ module Spikard
6
+ # Handler wrapper utilities for automatic file metadata conversion
7
+ #
8
+ # Provides ergonomic handler patterns that automatically convert
9
+ # file metadata to UploadFile instances, eliminating boilerplate.
10
+ #
11
+ # @example Basic usage with body only
12
+ # app.post('/upload', &wrap_body_handler do |body|
13
+ # {
14
+ # filename: body[:file].filename,
15
+ # content: body[:file].read
16
+ # }
17
+ # end)
18
+ #
19
+ # @example With all parameters
20
+ # app.post('/upload', &wrap_handler do |params, query, body|
21
+ # {
22
+ # id: params[:id],
23
+ # search: query[:q],
24
+ # file: body[:file].filename
25
+ # }
26
+ # end)
27
+ module HandlerWrapper
28
+ module_function
29
+
30
+ # Wrap a handler that receives only the request body
31
+ #
32
+ # Automatically converts file metadata in the body to UploadFile instances.
33
+ #
34
+ # @yield [body] Handler block that receives converted body
35
+ # @yieldparam body [Hash] Request body with file metadata converted to UploadFile
36
+ # @yieldreturn [Hash, Spikard::Response] Response data or Response object
37
+ # @return [Proc] Wrapped handler proc
38
+ #
39
+ # @example
40
+ # app.post('/upload', &wrap_body_handler do |body|
41
+ # { filename: body[:file].filename }
42
+ # end)
43
+ def wrap_body_handler(&handler)
44
+ raise ArgumentError, 'block required for wrap_body_handler' unless handler
45
+
46
+ # Return a proc that matches the signature expected by Spikard::App
47
+ # The actual handler receives path params, query params, and body from Rust
48
+ lambda do |_params, _query, body|
49
+ converted_body = Converters.convert_handler_body(body)
50
+ handler.call(converted_body)
51
+ end
52
+ end
53
+
54
+ # Wrap a handler that receives path params, query params, and body
55
+ #
56
+ # Automatically converts file metadata in the body to UploadFile instances.
57
+ #
58
+ # @yield [params, query, body] Handler block that receives all request data
59
+ # @yieldparam params [Hash] Path parameters
60
+ # @yieldparam query [Hash] Query parameters
61
+ # @yieldparam body [Hash] Request body with file metadata converted to UploadFile
62
+ # @yieldreturn [Hash, Spikard::Response] Response data or Response object
63
+ # @return [Proc] Wrapped handler proc
64
+ #
65
+ # @example
66
+ # app.post('/users/{id}/upload', &wrap_handler do |params, query, body|
67
+ # {
68
+ # user_id: params[:id],
69
+ # description: query[:desc],
70
+ # file: body[:file].filename
71
+ # }
72
+ # end)
73
+ def wrap_handler(&handler)
74
+ raise ArgumentError, 'block required for wrap_handler' unless handler
75
+
76
+ lambda do |params, query, body|
77
+ converted_body = Converters.convert_handler_body(body)
78
+ handler.call(params, query, converted_body)
79
+ end
80
+ end
81
+
82
+ # Wrap a handler that receives a context hash with all request data
83
+ #
84
+ # Automatically converts file metadata in the body to UploadFile instances.
85
+ # Useful when you want all request data in a single hash.
86
+ #
87
+ # @yield [context] Handler block that receives context hash
88
+ # @yieldparam context [Hash] Request context with:
89
+ # - :params [Hash] Path parameters
90
+ # - :query [Hash] Query parameters
91
+ # - :body [Hash] Request body with file metadata converted to UploadFile
92
+ # @yieldreturn [Hash, Spikard::Response] Response data or Response object
93
+ # @return [Proc] Wrapped handler proc
94
+ #
95
+ # @example
96
+ # app.post('/upload', &wrap_handler_with_context do |ctx|
97
+ # {
98
+ # file: ctx[:body][:file].filename,
99
+ # query_params: ctx[:query]
100
+ # }
101
+ # end)
102
+ def wrap_handler_with_context(&handler)
103
+ raise ArgumentError, 'block required for wrap_handler_with_context' unless handler
104
+
105
+ lambda do |params, query, body|
106
+ converted_body = Converters.convert_handler_body(body)
107
+ context = {
108
+ params: params,
109
+ query: query,
110
+ body: converted_body
111
+ }
112
+ handler.call(context)
113
+ end
114
+ end
115
+ end
116
+ end