spikard 0.2.5 → 0.3.1

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 (103) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE +1 -1
  3. data/README.md +659 -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 +386 -374
  8. data/lib/spikard/background.rb +27 -27
  9. data/lib/spikard/config.rb +396 -396
  10. data/lib/spikard/converters.rb +13 -85
  11. data/lib/spikard/handler_wrapper.rb +113 -116
  12. data/lib/spikard/provide.rb +214 -228
  13. data/lib/spikard/response.rb +173 -109
  14. data/lib/spikard/schema.rb +243 -243
  15. data/lib/spikard/sse.rb +111 -111
  16. data/lib/spikard/streaming_response.rb +44 -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 +360 -349
  23. data/vendor/bundle/ruby/3.4.0/gems/rake-compiler-dock-1.10.0/build/buildkitd.toml +2 -0
  24. metadata +5 -85
  25. data/vendor/crates/spikard-core/Cargo.toml +0 -40
  26. data/vendor/crates/spikard-core/src/bindings/mod.rs +0 -3
  27. data/vendor/crates/spikard-core/src/bindings/response.rs +0 -133
  28. data/vendor/crates/spikard-core/src/debug.rs +0 -63
  29. data/vendor/crates/spikard-core/src/di/container.rs +0 -726
  30. data/vendor/crates/spikard-core/src/di/dependency.rs +0 -273
  31. data/vendor/crates/spikard-core/src/di/error.rs +0 -118
  32. data/vendor/crates/spikard-core/src/di/factory.rs +0 -538
  33. data/vendor/crates/spikard-core/src/di/graph.rs +0 -545
  34. data/vendor/crates/spikard-core/src/di/mod.rs +0 -192
  35. data/vendor/crates/spikard-core/src/di/resolved.rs +0 -411
  36. data/vendor/crates/spikard-core/src/di/value.rs +0 -283
  37. data/vendor/crates/spikard-core/src/http.rs +0 -153
  38. data/vendor/crates/spikard-core/src/lib.rs +0 -28
  39. data/vendor/crates/spikard-core/src/lifecycle.rs +0 -422
  40. data/vendor/crates/spikard-core/src/parameters.rs +0 -719
  41. data/vendor/crates/spikard-core/src/problem.rs +0 -310
  42. data/vendor/crates/spikard-core/src/request_data.rs +0 -189
  43. data/vendor/crates/spikard-core/src/router.rs +0 -249
  44. data/vendor/crates/spikard-core/src/schema_registry.rs +0 -183
  45. data/vendor/crates/spikard-core/src/type_hints.rs +0 -304
  46. data/vendor/crates/spikard-core/src/validation.rs +0 -699
  47. data/vendor/crates/spikard-http/Cargo.toml +0 -58
  48. data/vendor/crates/spikard-http/src/auth.rs +0 -247
  49. data/vendor/crates/spikard-http/src/background.rs +0 -249
  50. data/vendor/crates/spikard-http/src/bindings/mod.rs +0 -3
  51. data/vendor/crates/spikard-http/src/bindings/response.rs +0 -1
  52. data/vendor/crates/spikard-http/src/body_metadata.rs +0 -8
  53. data/vendor/crates/spikard-http/src/cors.rs +0 -490
  54. data/vendor/crates/spikard-http/src/debug.rs +0 -63
  55. data/vendor/crates/spikard-http/src/di_handler.rs +0 -423
  56. data/vendor/crates/spikard-http/src/handler_response.rs +0 -190
  57. data/vendor/crates/spikard-http/src/handler_trait.rs +0 -228
  58. data/vendor/crates/spikard-http/src/handler_trait_tests.rs +0 -284
  59. data/vendor/crates/spikard-http/src/lib.rs +0 -529
  60. data/vendor/crates/spikard-http/src/lifecycle/adapter.rs +0 -149
  61. data/vendor/crates/spikard-http/src/lifecycle.rs +0 -428
  62. data/vendor/crates/spikard-http/src/middleware/mod.rs +0 -285
  63. data/vendor/crates/spikard-http/src/middleware/multipart.rs +0 -86
  64. data/vendor/crates/spikard-http/src/middleware/urlencoded.rs +0 -147
  65. data/vendor/crates/spikard-http/src/middleware/validation.rs +0 -287
  66. data/vendor/crates/spikard-http/src/openapi/mod.rs +0 -309
  67. data/vendor/crates/spikard-http/src/openapi/parameter_extraction.rs +0 -190
  68. data/vendor/crates/spikard-http/src/openapi/schema_conversion.rs +0 -308
  69. data/vendor/crates/spikard-http/src/openapi/spec_generation.rs +0 -195
  70. data/vendor/crates/spikard-http/src/parameters.rs +0 -1
  71. data/vendor/crates/spikard-http/src/problem.rs +0 -1
  72. data/vendor/crates/spikard-http/src/query_parser.rs +0 -369
  73. data/vendor/crates/spikard-http/src/response.rs +0 -399
  74. data/vendor/crates/spikard-http/src/router.rs +0 -1
  75. data/vendor/crates/spikard-http/src/schema_registry.rs +0 -1
  76. data/vendor/crates/spikard-http/src/server/handler.rs +0 -80
  77. data/vendor/crates/spikard-http/src/server/lifecycle_execution.rs +0 -98
  78. data/vendor/crates/spikard-http/src/server/mod.rs +0 -805
  79. data/vendor/crates/spikard-http/src/server/request_extraction.rs +0 -119
  80. data/vendor/crates/spikard-http/src/sse.rs +0 -447
  81. data/vendor/crates/spikard-http/src/testing/form.rs +0 -14
  82. data/vendor/crates/spikard-http/src/testing/multipart.rs +0 -60
  83. data/vendor/crates/spikard-http/src/testing/test_client.rs +0 -285
  84. data/vendor/crates/spikard-http/src/testing.rs +0 -377
  85. data/vendor/crates/spikard-http/src/type_hints.rs +0 -1
  86. data/vendor/crates/spikard-http/src/validation.rs +0 -1
  87. data/vendor/crates/spikard-http/src/websocket.rs +0 -324
  88. data/vendor/crates/spikard-rb/Cargo.toml +0 -42
  89. data/vendor/crates/spikard-rb/build.rs +0 -8
  90. data/vendor/crates/spikard-rb/src/background.rs +0 -63
  91. data/vendor/crates/spikard-rb/src/config.rs +0 -294
  92. data/vendor/crates/spikard-rb/src/conversion.rs +0 -392
  93. data/vendor/crates/spikard-rb/src/di.rs +0 -409
  94. data/vendor/crates/spikard-rb/src/handler.rs +0 -534
  95. data/vendor/crates/spikard-rb/src/lib.rs +0 -2020
  96. data/vendor/crates/spikard-rb/src/lifecycle.rs +0 -267
  97. data/vendor/crates/spikard-rb/src/server.rs +0 -283
  98. data/vendor/crates/spikard-rb/src/sse.rs +0 -231
  99. data/vendor/crates/spikard-rb/src/test_client.rs +0 -404
  100. data/vendor/crates/spikard-rb/src/test_sse.rs +0 -143
  101. data/vendor/crates/spikard-rb/src/test_websocket.rs +0 -221
  102. data/vendor/crates/spikard-rb/src/websocket.rs +0 -233
  103. /data/vendor/bundle/ruby/{3.3.0 → 3.4.0}/gems/diff-lcs-1.6.2/mise.toml +0 -0
data/lib/spikard/sse.rb CHANGED
@@ -1,111 +1,111 @@
1
- # frozen_string_literal: true
2
-
3
- module Spikard
4
- # Represents a Server-Sent Event.
5
- #
6
- # @!attribute [rw] data
7
- # @return [Hash] Event data (will be JSON serialized)
8
- # @!attribute [rw] event_type
9
- # @return [String, nil] Optional event type
10
- # @!attribute [rw] id
11
- # @return [String, nil] Optional event ID for client reconnection support
12
- # @!attribute [rw] retry_ms
13
- # @return [Integer, nil] Optional retry timeout in milliseconds
14
- class SseEvent
15
- attr_accessor :data, :event_type, :id, :retry_ms
16
-
17
- # Create a new SSE event.
18
- #
19
- # @param data [Hash] Event data (will be JSON serialized)
20
- # @param event_type [String, nil] Optional event type
21
- # @param id [String, nil] Optional event ID for client reconnection support
22
- # @param retry_ms [Integer, nil] Optional retry timeout in milliseconds
23
- def initialize(data:, event_type: nil, id: nil, retry_ms: nil)
24
- @data = data
25
- @event_type = event_type
26
- @id = id
27
- @retry_ms = retry_ms
28
- end
29
-
30
- # Convert to hash for JSON serialization.
31
- #
32
- # @return [Hash] Hash representation of the event
33
- def to_h
34
- {
35
- data: @data,
36
- event_type: @event_type,
37
- id: @id,
38
- retry: @retry_ms
39
- }.compact
40
- end
41
- end
42
-
43
- # Base class for SSE event producers.
44
- #
45
- # Implement this class to generate Server-Sent Events.
46
- #
47
- # @example
48
- # class NotificationProducer < Spikard::SseEventProducer
49
- # def initialize
50
- # @count = 0
51
- # end
52
- #
53
- # def next_event
54
- # sleep 1 # Wait 1 second between events
55
- #
56
- # return nil if @count >= 10 # End stream after 10 events
57
- #
58
- # event = Spikard::SseEvent.new(
59
- # data: { message: "Notification #{@count}" },
60
- # event_type: 'notification',
61
- # id: @count.to_s
62
- # )
63
- # @count += 1
64
- # event
65
- # end
66
- #
67
- # def on_connect
68
- # puts "Client connected to SSE stream"
69
- # end
70
- #
71
- # def on_disconnect
72
- # puts "Client disconnected from SSE stream"
73
- # end
74
- # end
75
- #
76
- # app = Spikard::App.new
77
- #
78
- # app.sse('/notifications') do
79
- # NotificationProducer.new
80
- # end
81
- #
82
- # app.run
83
- class SseEventProducer
84
- # Generate the next event.
85
- #
86
- # This method is called repeatedly to produce the event stream.
87
- #
88
- # @return [SseEvent, nil] SseEvent when an event is ready, or nil to end the stream.
89
- def next_event
90
- raise NotImplementedError, "#{self.class.name} must implement #next_event"
91
- end
92
-
93
- # Called when a client connects to the SSE endpoint.
94
- #
95
- # Override this method to perform initialization when a client connects.
96
- #
97
- # @return [void]
98
- def on_connect
99
- # Optional hook - default implementation does nothing
100
- end
101
-
102
- # Called when a client disconnects from the SSE endpoint.
103
- #
104
- # Override this method to perform cleanup when a client disconnects.
105
- #
106
- # @return [void]
107
- def on_disconnect
108
- # Optional hook - default implementation does nothing
109
- end
110
- end
111
- end
1
+ # frozen_string_literal: true
2
+
3
+ module Spikard
4
+ # Represents a Server-Sent Event.
5
+ #
6
+ # @!attribute [rw] data
7
+ # @return [Hash] Event data (will be JSON serialized)
8
+ # @!attribute [rw] event_type
9
+ # @return [String, nil] Optional event type
10
+ # @!attribute [rw] id
11
+ # @return [String, nil] Optional event ID for client reconnection support
12
+ # @!attribute [rw] retry_ms
13
+ # @return [Integer, nil] Optional retry timeout in milliseconds
14
+ class SseEvent
15
+ attr_accessor :data, :event_type, :id, :retry_ms
16
+
17
+ # Create a new SSE event.
18
+ #
19
+ # @param data [Hash] Event data (will be JSON serialized)
20
+ # @param event_type [String, nil] Optional event type
21
+ # @param id [String, nil] Optional event ID for client reconnection support
22
+ # @param retry_ms [Integer, nil] Optional retry timeout in milliseconds
23
+ def initialize(data:, event_type: nil, id: nil, retry_ms: nil)
24
+ @data = data
25
+ @event_type = event_type
26
+ @id = id
27
+ @retry_ms = retry_ms
28
+ end
29
+
30
+ # Convert to hash for JSON serialization.
31
+ #
32
+ # @return [Hash] Hash representation of the event
33
+ def to_h
34
+ {
35
+ data: @data,
36
+ event_type: @event_type,
37
+ id: @id,
38
+ retry: @retry_ms
39
+ }.compact
40
+ end
41
+ end
42
+
43
+ # Base class for SSE event producers.
44
+ #
45
+ # Implement this class to generate Server-Sent Events.
46
+ #
47
+ # @example
48
+ # class NotificationProducer < Spikard::SseEventProducer
49
+ # def initialize
50
+ # @count = 0
51
+ # end
52
+ #
53
+ # def next_event
54
+ # sleep 1 # Wait 1 second between events
55
+ #
56
+ # return nil if @count >= 10 # End stream after 10 events
57
+ #
58
+ # event = Spikard::SseEvent.new(
59
+ # data: { message: "Notification #{@count}" },
60
+ # event_type: 'notification',
61
+ # id: @count.to_s
62
+ # )
63
+ # @count += 1
64
+ # event
65
+ # end
66
+ #
67
+ # def on_connect
68
+ # puts "Client connected to SSE stream"
69
+ # end
70
+ #
71
+ # def on_disconnect
72
+ # puts "Client disconnected from SSE stream"
73
+ # end
74
+ # end
75
+ #
76
+ # app = Spikard::App.new
77
+ #
78
+ # app.sse('/notifications') do
79
+ # NotificationProducer.new
80
+ # end
81
+ #
82
+ # app.run
83
+ class SseEventProducer
84
+ # Generate the next event.
85
+ #
86
+ # This method is called repeatedly to produce the event stream.
87
+ #
88
+ # @return [SseEvent, nil] SseEvent when an event is ready, or nil to end the stream.
89
+ def next_event
90
+ raise NotImplementedError, "#{self.class.name} must implement #next_event"
91
+ end
92
+
93
+ # Called when a client connects to the SSE endpoint.
94
+ #
95
+ # Override this method to perform initialization when a client connects.
96
+ #
97
+ # @return [void]
98
+ def on_connect
99
+ # Optional hook - default implementation does nothing
100
+ end
101
+
102
+ # Called when a client disconnects from the SSE endpoint.
103
+ #
104
+ # Override this method to perform cleanup when a client disconnects.
105
+ #
106
+ # @return [void]
107
+ def on_disconnect
108
+ # Optional hook - default implementation does nothing
109
+ end
110
+ end
111
+ end
@@ -1,21 +1,44 @@
1
- # frozen_string_literal: true
2
-
3
- module Spikard
4
- # Represents a streaming HTTP response made of chunks produced lazily.
5
- class StreamingResponse
6
- attr_reader :stream, :status_code, :headers
7
-
8
- def initialize(stream, status_code: 200, headers: nil)
9
- unless stream.respond_to?(:next) || stream.respond_to?(:each)
10
- raise ArgumentError, 'StreamingResponse requires an object responding to #next or #each'
11
- end
12
-
13
- @stream = stream.respond_to?(:to_enum) ? stream.to_enum : stream
14
- @status_code = Integer(status_code || 200)
15
- header_hash = headers || {}
16
- @headers = header_hash.each_with_object({}) do |(key, value), memo|
17
- memo[String(key)] = String(value)
18
- end
19
- end
20
- end
21
- end
1
+ # frozen_string_literal: true
2
+
3
+ module Spikard
4
+ # Represents a streaming HTTP response made of chunks produced lazily.
5
+ class StreamingResponse
6
+ attr_reader :stream, :status_code, :headers, :native_response
7
+
8
+ def initialize(stream, status_code: 200, headers: nil)
9
+ unless stream.respond_to?(:next) || stream.respond_to?(:each)
10
+ raise ArgumentError, 'StreamingResponse requires an object responding to #next or #each'
11
+ end
12
+
13
+ @stream = stream.respond_to?(:to_enum) ? stream.to_enum : stream
14
+ @status_code = Integer(status_code || 200)
15
+ header_hash = headers || {}
16
+ @headers = header_hash.each_with_object({}) do |(key, value), memo|
17
+ memo[String(key)] = String(value)
18
+ end
19
+
20
+ rebuild_native!
21
+ end
22
+
23
+ def to_native_response
24
+ @native_response
25
+ end
26
+
27
+ private
28
+
29
+ def rebuild_native!
30
+ ensure_native!
31
+ @native_response = Spikard::Native.build_streaming_response(@stream, @status_code, @headers)
32
+ return unless @native_response
33
+
34
+ @status_code = @native_response.status_code
35
+ @headers = @native_response.headers
36
+ end
37
+
38
+ def ensure_native!
39
+ return if defined?(Spikard::Native) && Spikard::Native.respond_to?(:build_streaming_response)
40
+
41
+ raise 'Spikard native extension is not loaded'
42
+ end
43
+ end
44
+ end