dapr 0.3.3 → 0.4.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.
- checksums.yaml +4 -4
- data/.release-please-manifest.json +1 -1
- data/.version.txt +1 -1
- data/CHANGELOG.md +18 -0
- data/Readme.adoc +25 -1
- data/coverage/coverage.json +1 -1
- data/lib/dapr/client/state.rb +73 -0
- data/lib/dapr/client.rb +2 -1
- data/lib/dapr/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 724a4181910c345d6d4b86b0a2ba19f746b9929c8fda03ad5e6b63f98b14b0ba
|
4
|
+
data.tar.gz: 5398c729f64961d9b3ea88546e5724584dd68c819642d1ebe084d5203ec6b848
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4f3258854fdfe62627b8038f699b81c968a09972f59814f01cc357097e17a2777c7d78df7449d97158ec1032ff2c782daf5316f9229fcce65583b189375d1665
|
7
|
+
data.tar.gz: 9fba6543b90f3174d1ef00fd5ffc26791c61ae39d1b62da224c7228adc624da233c32e38e1476bce27f478a5f022810ab23485ad8b8df2ce72182857605f1eae
|
data/.version.txt
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.4.1
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,23 @@
|
|
1
1
|
## [Unreleased]
|
2
2
|
|
3
|
+
## [0.4.1](https://github.com/rubyists/dapr-ruby-client/compare/v0.4.0...v0.4.1) (2024-10-24)
|
4
|
+
|
5
|
+
|
6
|
+
### Bug Fixes
|
7
|
+
|
8
|
+
* **state:** Updates State#get to return a Hash instead of an Array ([#76](https://github.com/rubyists/dapr-ruby-client/issues/76)) ([052fcfa](https://github.com/rubyists/dapr-ruby-client/commit/052fcfa6ca6077e13343738d38b5768e693b4c9b))
|
9
|
+
|
10
|
+
## [0.4.0](https://github.com/rubyists/dapr-ruby-client/compare/v0.3.3...v0.4.0) (2024-10-23)
|
11
|
+
|
12
|
+
|
13
|
+
### ⚠ BREAKING CHANGES
|
14
|
+
|
15
|
+
* **state:** Adds state management component ([#74](https://github.com/rubyists/dapr-ruby-client/issues/74))
|
16
|
+
|
17
|
+
### Features
|
18
|
+
|
19
|
+
* **state:** Adds state management component ([#74](https://github.com/rubyists/dapr-ruby-client/issues/74)) ([2fc596d](https://github.com/rubyists/dapr-ruby-client/commit/2fc596dad1439c5d52a03bdf763d8b0d38aa9bab))
|
20
|
+
|
3
21
|
## [0.3.3](https://github.com/rubyists/dapr-ruby-client/compare/v0.3.2...v0.3.3) (2024-10-08)
|
4
22
|
|
5
23
|
|
data/Readme.adoc
CHANGED
@@ -126,6 +126,30 @@ TIP: Multiple topics can be subscribed to simultaneously by passing an array of
|
|
126
126
|
|
127
127
|
Implementation of {state-block}
|
128
128
|
|
129
|
+
==== Set state key(s)
|
130
|
+
|
131
|
+
[source,ruby]
|
132
|
+
----
|
133
|
+
require 'dapr/client/state' <1>
|
134
|
+
desired_state = { key1: 'value1', key2: { nested: 'value2' }.to_json } <2>
|
135
|
+
Rubyists::Dapr::Client::State.set(desired_state) <3>
|
136
|
+
----
|
137
|
+
<1> Require the state client.
|
138
|
+
<2> Define the desired state. This must be a hash with simple keys, and the values must be strings (thus the #to_json)
|
139
|
+
<3> Set the state. This will overwrite any existing state with the same key(s) (and update the etag of any updated keys)
|
140
|
+
|
141
|
+
==== Get state key(s)
|
142
|
+
|
143
|
+
[source,ruby]
|
144
|
+
----
|
145
|
+
require 'dapr/client/state' <1>
|
146
|
+
states = Rubyists::Dapr::Client::State.get('key1', 'key2') <2>
|
147
|
+
puts states['key1'].data <3>
|
148
|
+
----
|
149
|
+
<1> Require the state client.
|
150
|
+
<2> Get the state for the specified key(s). This will return a hash whose values respond to #data.
|
151
|
+
<3> Access the data of the state for the `key1` key.
|
152
|
+
|
129
153
|
=== Actors
|
130
154
|
|
131
155
|
Implementation of {actors-block}
|
@@ -178,7 +202,7 @@ Releases are handled by release-please in github actions.
|
|
178
202
|
|
179
203
|
== Contributing
|
180
204
|
|
181
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/rubyists/dapr.
|
205
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/rubyists/dapr-ruby-client.
|
182
206
|
|
183
207
|
=== Conventional Commits
|
184
208
|
|
data/coverage/coverage.json
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"timestamp":
|
1
|
+
{"timestamp":1729724582,"command_name":"Unit Tests","files":[{"filename":"/home/bougyman/rubyists/dapr/lib/dapr.rb","covered_percent":100.0,"coverage":{"lines":[null,null,1,1,null,null,1,1,7,null,null,null,1,1,1,1,1,null,null]},"covered_strength":1.6,"covered_lines":10,"lines_of_code":10},{"filename":"/home/bougyman/rubyists/dapr/lib/dapr/client.rb","covered_percent":100.0,"coverage":{"lines":[null,null,1,1,1,1,1,null,1,1,null,1,1,1,1,1,1,null,1,4,null,1,1,null,null,1,11,null,null,1,1,null,null,1,14,null,null,null,1,1,null,1,5,null,null,1,1,1,1,null,1,null,null,1,1,null,null,null,null,null]},"covered_strength":1.8823529411764706,"covered_lines":34,"lines_of_code":34},{"filename":"/home/bougyman/rubyists/dapr/lib/dapr/client/configuration.rb","covered_percent":100.0,"coverage":{"lines":[null,null,1,null,1,1,1,null,1,null,1,1,null,null,1,null,null,1,null,1,1,null,1,1,1,null,null,null,null,null,null,null,1,1,1,1,null,null,1,1,1,null,null,null,null,null]},"covered_strength":1.0,"covered_lines":21,"lines_of_code":21},{"filename":"/home/bougyman/rubyists/dapr/lib/dapr/client/lock.rb","covered_percent":100.0,"coverage":{"lines":[null,null,1,1,null,1,1,1,null,1,null,1,1,null,null,1,null,null,1,null,1,1,null,null,null,null,null,null,1,6,6,null,null,null,null,null,null,1,6,6,null,null,null,1,6,6,5,5,null,null,1,null,null,null,1,4,4,4,null,3,3,null,null,1,null,null,1,18,null,null,null,null,null,1,6,null,null,null,null,null]},"covered_strength":3.085714285714286,"covered_lines":35,"lines_of_code":35},{"filename":"/home/bougyman/rubyists/dapr/lib/dapr/client/state.rb","covered_percent":100.0,"coverage":{"lines":[null,null,1,null,1,1,1,null,null,1,null,1,1,null,1,null,1,1,1,1,1,1,1,null,null,null,null,null,null,1,1,null,null,null,null,null,null,null,1,1,null,null,null,null,null,1,2,null,null,null,null,null,null,1,1,1,3,null,null,null,null,1,3,1,1,1,null,null,null,null,null]},"covered_strength":1.1666666666666667,"covered_lines":30,"lines_of_code":30},{"filename":"/home/bougyman/rubyists/dapr/lib/dapr/version.rb","covered_percent":100.0,"coverage":{"lines":[null,null,1,1,null,1,null,null,null]},"covered_strength":1.0,"covered_lines":3,"lines_of_code":3}],"metrics":{"covered_percent":100.0,"covered_strength":1.8571428571428572,"covered_lines":133,"total_lines":133}}
|
@@ -0,0 +1,73 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative '../client'
|
4
|
+
|
5
|
+
module Rubyists
|
6
|
+
module Dapr
|
7
|
+
module Client
|
8
|
+
# The State class is a client for the Dapr State Management Building block
|
9
|
+
# Info here: https://docs.dapr.io/developing-applications/building-blocks/state-management/
|
10
|
+
class State
|
11
|
+
# Include the client module
|
12
|
+
include Client
|
13
|
+
include SemanticLogger::Loggable
|
14
|
+
|
15
|
+
attr_reader :store_name
|
16
|
+
|
17
|
+
Item = Struct.new(:data, :etag, :metadata)
|
18
|
+
Empty = Google::Protobuf::Empty
|
19
|
+
Runtime = Client::Runtime
|
20
|
+
GetBulkStateResponse = Runtime::GetBulkStateResponse
|
21
|
+
GetStateRequest = Runtime::GetBulkStateRequest
|
22
|
+
SaveStateRequest = Runtime::SaveStateRequest
|
23
|
+
DEFAULT_STORE_NAME = 'statestore'
|
24
|
+
|
25
|
+
# @param keys [Array<String>] keys to retrieve from the state store
|
26
|
+
# @param store_name [String] name of the State Management component, defaults to 'dapr-statestore'
|
27
|
+
# @param metadata [Hash] metadata to include
|
28
|
+
#
|
29
|
+
# @return [GetBulkStateResponse] The response from the Dapr State Management component
|
30
|
+
def self.get(*keys, store_name: DEFAULT_STORE_NAME, metadata: {})
|
31
|
+
new(store_name).get(keys, metadata:)
|
32
|
+
end
|
33
|
+
|
34
|
+
# @param states [Hash] states to set in the state store, key/value pairs
|
35
|
+
# @param store_name [String] name of the State Management component, defaults to 'dapr-statestore'
|
36
|
+
# @param metadata [Hash] metadata to include
|
37
|
+
#
|
38
|
+
# @return [Empty] The response from the Dapr State Management component
|
39
|
+
def self.set(states, store_name: DEFAULT_STORE_NAME, metadata: {})
|
40
|
+
new(store_name).set(states, metadata:)
|
41
|
+
end
|
42
|
+
|
43
|
+
# Initialize the State Management client
|
44
|
+
#
|
45
|
+
# @param store_name [String] name of the Dapr Configuration component to use
|
46
|
+
def initialize(store_name)
|
47
|
+
@store_name = store_name
|
48
|
+
end
|
49
|
+
|
50
|
+
# @param keys [Array<String>] keys to retrieve from the state store
|
51
|
+
# @param metadata [Hash] metadata to include
|
52
|
+
#
|
53
|
+
# @return [Array<BulkStateItem>] Array of items returned by the state store
|
54
|
+
def get(keys, metadata: {})
|
55
|
+
logger.debug('Getting state', keys:, store_name:, metadata:)
|
56
|
+
response = singleton.get_bulk_state GetStateRequest.new(store_name:, keys:, metadata:)
|
57
|
+
response.items.to_h { |i| [i.key, Item.new(data: i.data, etag: i.etag, metadata: i.metadata)] }
|
58
|
+
end
|
59
|
+
|
60
|
+
# @param states [Hash] states to set (key/values in the state store)
|
61
|
+
# @param metadata [Hash] metadata to include
|
62
|
+
#
|
63
|
+
# @return [Empty] The response from the Dapr State Management component (Empty means success)
|
64
|
+
def set(states, metadata: {})
|
65
|
+
states = states.map { |key, value| { key:, value:, metadata: } }
|
66
|
+
request = SaveStateRequest.new(store_name:, states:)
|
67
|
+
logger.debug('Setting state', states:, store_name:)
|
68
|
+
singleton.save_state request
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
data/lib/dapr/client.rb
CHANGED
@@ -11,9 +11,10 @@ module Rubyists
|
|
11
11
|
# The namespace for the Dapr client
|
12
12
|
module Client
|
13
13
|
include SemanticLogger::Loggable
|
14
|
+
Runtime = ::Dapr::Proto::Runtime::V1
|
14
15
|
DAPR_PORT = ENV.fetch('DAPR_GRPC_PORT', nil)
|
15
16
|
DAPR_URI = ENV.fetch('DAPR_GRPC_HOST', 'localhost')
|
16
|
-
DAPR_STUB =
|
17
|
+
DAPR_STUB = Runtime::Dapr::Stub
|
17
18
|
|
18
19
|
def self.client(dapr_port: DAPR_PORT, dapr_uri: DAPR_URI)
|
19
20
|
return DummyClient.new if dapr_port.nil?
|
data/lib/dapr/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dapr
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tj (bougyman) Vanderpoel
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: exe
|
11
11
|
cert_chain: []
|
12
|
-
date: 2024-10-
|
12
|
+
date: 2024-10-24 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: dapr-ruby
|
@@ -63,6 +63,7 @@ files:
|
|
63
63
|
- lib/dapr/client/configuration.rb
|
64
64
|
- lib/dapr/client/lock.rb
|
65
65
|
- lib/dapr/client/publisher.rb
|
66
|
+
- lib/dapr/client/state.rb
|
66
67
|
- lib/dapr/service.rb
|
67
68
|
- lib/dapr/service/subscriber.rb
|
68
69
|
- lib/dapr/version.rb
|