statelydb 0.10.0 → 0.11.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.
- checksums.yaml +4 -4
- data/lib/api/db/put_pb.rb +1 -1
- data/lib/api/db/service_services_pb.rb +1 -1
- data/lib/error.rb +5 -0
- data/lib/statelydb.rb +43 -15
- data/lib/transaction/transaction.rb +29 -12
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2a342b194da9de36c892bb4d9f7c15b5904b75a07c3a5d6b2a06c94c9df7615d
|
4
|
+
data.tar.gz: b5d1c84628d6fff0c186efc30912b52c81e637427456647e7856099bf0218996
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 92cc17e071ff1fd85f69c6a7716e123e81d5238727c8d09d9bf1f450e6082db65c4b724268cd4478489b532ab366a95208f8d81efc820fd697461daf5dcb740c
|
7
|
+
data.tar.gz: 7b90b2148bfcf696c91ed701233731dc0c7e6c027967bf266aa2cecbc023acdb5bcc3269998f997c47112de10f43555182560656e4bd73fcd29bb92092b55ca2
|
data/lib/api/db/put_pb.rb
CHANGED
@@ -7,7 +7,7 @@ require 'google/protobuf'
|
|
7
7
|
require 'db/item_pb'
|
8
8
|
|
9
9
|
|
10
|
-
descriptor_data = "\n\x0c\x64\x62/put.proto\x12\nstately.db\x1a\rdb/item.proto\"|\n\nPutRequest\x12\x19\n\x08store_id\x18\x01 \x01(\x04R\x07storeId\x12\'\n\x04puts\x18\x02 \x03(\x0b\x32\x13.stately.db.PutItemR\x04puts\x12*\n\x11schema_version_id\x18\x03 \x01(\rR\x0fschemaVersionId\"
|
10
|
+
descriptor_data = "\n\x0c\x64\x62/put.proto\x12\nstately.db\x1a\rdb/item.proto\"|\n\nPutRequest\x12\x19\n\x08store_id\x18\x01 \x01(\x04R\x07storeId\x12\'\n\x04puts\x18\x02 \x03(\x0b\x32\x13.stately.db.PutItemR\x04puts\x12*\n\x11schema_version_id\x18\x03 \x01(\rR\x0fschemaVersionId\"U\n\x07PutItem\x12$\n\x04item\x18\x01 \x01(\x0b\x32\x10.stately.db.ItemR\x04item\x12$\n\x0emust_not_exist\x18\x03 \x01(\x08R\x0cmustNotExist\"5\n\x0bPutResponse\x12&\n\x05items\x18\x01 \x03(\x0b\x32\x10.stately.db.ItemR\x05itemsBc\n\x0e\x63om.stately.dbB\x08PutProtoP\x01\xa2\x02\x03SDX\xaa\x02\nStately.Db\xca\x02\nStately\\Db\xe2\x02\x16Stately\\Db\\GPBMetadata\xea\x02\x0bStately::Dbb\x06proto3"
|
11
11
|
|
12
12
|
pool = Google::Protobuf::DescriptorPool.generated_pool
|
13
13
|
pool.add_serialized_file(descriptor_data)
|
@@ -35,7 +35,7 @@ module Stately
|
|
35
35
|
rpc :Get, ::Stately::Db::GetRequest, ::Stately::Db::GetResponse
|
36
36
|
# Delete removes one or more Items from the Store by their key paths. This
|
37
37
|
# will fail if the caller does not have permission to delete Items.
|
38
|
-
# Tombstones will be saved for deleted items for
|
38
|
+
# Tombstones will be saved for deleted items for some time, so
|
39
39
|
# that SyncList can return information about deleted items. Deletes are
|
40
40
|
# always applied atomically; all will fail or all will succeed.
|
41
41
|
rpc :Delete, ::Stately::Db::DeleteRequest, ::Stately::Db::DeleteResponse
|
data/lib/error.rb
CHANGED
@@ -11,10 +11,13 @@ module StatelyDB
|
|
11
11
|
# The Error class contains common StatelyDB error types.
|
12
12
|
class Error < StandardError
|
13
13
|
# The gRPC/Connect Code for this error.
|
14
|
+
# @return [Integer]
|
14
15
|
attr_reader :code
|
15
16
|
# The more fine-grained Stately error code, which is a human-readable string.
|
17
|
+
# @return [String]
|
16
18
|
attr_reader :stately_code
|
17
19
|
# The upstream cause of the error, if available.
|
20
|
+
# @return [Exception]
|
18
21
|
attr_reader :cause
|
19
22
|
|
20
23
|
# @param [String] message
|
@@ -53,6 +56,8 @@ module StatelyDB
|
|
53
56
|
new(error.message, code: GRPC::Core::StatusCodes::UNKNOWN, stately_code: "Unknown", cause: error)
|
54
57
|
end
|
55
58
|
|
59
|
+
# Turn this error's gRPC status code into a human-readable string. e.g. 3 -> "InvalidArgument"
|
60
|
+
# @return [String]
|
56
61
|
def code_string
|
57
62
|
self.class.grpc_code_to_string(@code)
|
58
63
|
end
|
data/lib/statelydb.rb
CHANGED
@@ -38,6 +38,16 @@ module StatelyDB
|
|
38
38
|
token_provider: Common::Auth::Auth0TokenProvider.new,
|
39
39
|
endpoint: nil,
|
40
40
|
region: nil)
|
41
|
+
if store_id.nil?
|
42
|
+
raise StatelyDB::Error.new("store_id is required",
|
43
|
+
code: GRPC::Core::StatusCodes::INVALID_ARGUMENT,
|
44
|
+
stately_code: "InvalidArgument")
|
45
|
+
end
|
46
|
+
if schema.nil?
|
47
|
+
raise StatelyDB::Error.new("schema is required",
|
48
|
+
code: GRPC::Core::StatusCodes::INVALID_ARGUMENT,
|
49
|
+
stately_code: "InvalidArgument")
|
50
|
+
end
|
41
51
|
|
42
52
|
endpoint = self.class.make_endpoint(endpoint:, region:)
|
43
53
|
channel = Common::Net.new_channel(endpoint:)
|
@@ -169,12 +179,19 @@ module StatelyDB
|
|
169
179
|
# Put an Item into a StatelyDB Store at the given key_path.
|
170
180
|
#
|
171
181
|
# @param item [StatelyDB::Item] a StatelyDB Item
|
182
|
+
# @param must_not_exist [Boolean] A condition that indicates this item must
|
183
|
+
# not already exist at any of its key paths. If there is already an item
|
184
|
+
# at one of those paths, the Put operation will fail with a
|
185
|
+
# "ConditionalCheckFailed" error. Note that if the item has an
|
186
|
+
# `initialValue` field in its key, that initial value will automatically
|
187
|
+
# be chosen not to conflict with existing items, so this condition only
|
188
|
+
# applies to key paths that do not contain the `initialValue` field.
|
172
189
|
# @return [StatelyDB::Item] the item that was stored
|
173
190
|
#
|
174
|
-
# @example
|
175
|
-
#
|
176
|
-
def put(item)
|
177
|
-
resp = put_batch(item)
|
191
|
+
# @example client.data.put(my_item)
|
192
|
+
# @example client.data.put(my_item, must_not_exist: true)
|
193
|
+
def put(item, must_not_exist: false)
|
194
|
+
resp = put_batch({ item:, must_not_exist: })
|
178
195
|
|
179
196
|
# Always return a single Item.
|
180
197
|
resp.first
|
@@ -182,21 +199,32 @@ module StatelyDB
|
|
182
199
|
|
183
200
|
# Put a batch of up to 50 Items into a StatelyDB Store.
|
184
201
|
#
|
185
|
-
# @param items [StatelyDB::Item, Array<StatelyDB::Item>] the items to store.
|
202
|
+
# @param items [StatelyDB::Item, Array<StatelyDB::Item>] the items to store.
|
203
|
+
# Max 50 items.
|
186
204
|
# @return [Array<StatelyDB::Item>] the items that were stored
|
187
205
|
#
|
188
206
|
# @example
|
189
207
|
# client.data.put_batch(item1, item2)
|
208
|
+
# @example
|
209
|
+
# client.data.put_batch({ item: item1, must_not_exist: true }, item2)
|
190
210
|
def put_batch(*items)
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
schema_version_id: @schema::SCHEMA_VERSION_ID,
|
195
|
-
puts: items.map do |item|
|
211
|
+
puts = Array(items).flatten.map do |input|
|
212
|
+
if input.is_a?(Hash)
|
213
|
+
item = input[:item]
|
196
214
|
Stately::Db::PutItem.new(
|
197
|
-
item: item.send("marshal_stately")
|
215
|
+
item: item.send("marshal_stately"),
|
216
|
+
must_not_exist: input[:must_not_exist]
|
217
|
+
)
|
218
|
+
else
|
219
|
+
Stately::Db::PutItem.new(
|
220
|
+
item: input.send("marshal_stately")
|
198
221
|
)
|
199
222
|
end
|
223
|
+
end
|
224
|
+
req = Stately::Db::PutRequest.new(
|
225
|
+
store_id: @store_id,
|
226
|
+
schema_version_id: @schema::SCHEMA_VERSION_ID,
|
227
|
+
puts:
|
200
228
|
)
|
201
229
|
resp = @stub.put(req)
|
202
230
|
|
@@ -208,8 +236,8 @@ module StatelyDB
|
|
208
236
|
# Delete up to 50 Items from a StatelyDB Store at the given key_paths.
|
209
237
|
#
|
210
238
|
# @param key_paths [String, Array<String>] the paths to the items. Max 50 key paths.
|
211
|
-
# @raise [StatelyDB::Error
|
212
|
-
# @raise [StatelyDB::Error
|
239
|
+
# @raise [StatelyDB::Error] if the parameters are invalid
|
240
|
+
# @raise [StatelyDB::Error] if the item is not found
|
213
241
|
# @return [void] nil
|
214
242
|
#
|
215
243
|
# @example
|
@@ -230,8 +258,8 @@ module StatelyDB
|
|
230
258
|
# If the block completes successfully, the transaction is committed.
|
231
259
|
#
|
232
260
|
# @return [StatelyDB::Transaction::Transaction::Result] the result of the transaction
|
233
|
-
# @raise [StatelyDB::Error
|
234
|
-
# @raise [StatelyDB::Error
|
261
|
+
# @raise [StatelyDB::Error] if the parameters are invalid
|
262
|
+
# @raise [StatelyDB::Error] if the item is not found
|
235
263
|
# @raise [Exception] if any other exception is raised
|
236
264
|
#
|
237
265
|
# @example
|
@@ -226,6 +226,13 @@ module StatelyDB
|
|
226
226
|
# the item will be returned while inside the transaction block.
|
227
227
|
#
|
228
228
|
# @param item [StatelyDB::Item] the item to store
|
229
|
+
# @param must_not_exist [Boolean] A condition that indicates this item must
|
230
|
+
# not already exist at any of its key paths. If there is already an item
|
231
|
+
# at one of those paths, the Put operation will fail with a
|
232
|
+
# "ConditionalCheckFailed" error. Note that if the item has an
|
233
|
+
# `initialValue` field in its key, that initial value will automatically
|
234
|
+
# be chosen not to conflict with existing items, so this condition only
|
235
|
+
# applies to key paths that do not contain the `initialValue` field.
|
229
236
|
# @return [String, Integer] the id of the item
|
230
237
|
#
|
231
238
|
# @example
|
@@ -235,16 +242,18 @@ module StatelyDB
|
|
235
242
|
# results.puts.each do |result|
|
236
243
|
# puts result.key_path
|
237
244
|
# end
|
238
|
-
def put(item)
|
239
|
-
resp = put_batch(item)
|
245
|
+
def put(item, must_not_exist: false)
|
246
|
+
resp = put_batch({ item:, must_not_exist: })
|
240
247
|
resp.first
|
241
248
|
end
|
242
249
|
|
243
|
-
# Put a batch of up to 50 Items into a StatelyDB Store. Results are not
|
244
|
-
# committed and will be available in the
|
245
|
-
#
|
250
|
+
# Put a batch of up to 50 Items into a StatelyDB Store. Results are not
|
251
|
+
# returned until the transaction is committed and will be available in the
|
252
|
+
# Result object returned by commit. A list of identifiers for the items
|
253
|
+
# will be returned while inside the transaction block.
|
246
254
|
#
|
247
|
-
# @param items [StatelyDB::Item, Array<StatelyDB::Item>] the items to store. Max
|
255
|
+
# @param items [StatelyDB::Item, Array<StatelyDB::Item>] the items to store. Max
|
256
|
+
# 50 items.
|
248
257
|
# @return [Array<StatelyDB::UUID, String, Integer, nil>] the ids of the items
|
249
258
|
#
|
250
259
|
# @example
|
@@ -255,14 +264,22 @@ module StatelyDB
|
|
255
264
|
# puts result.key_path
|
256
265
|
# end
|
257
266
|
def put_batch(*items)
|
258
|
-
|
267
|
+
puts = Array(items).flatten.map do |input|
|
268
|
+
if input.is_a?(Hash)
|
269
|
+
item = input[:item]
|
270
|
+
Stately::Db::PutItem.new(
|
271
|
+
item: item.send("marshal_stately"),
|
272
|
+
must_not_exist: input[:must_not_exist]
|
273
|
+
)
|
274
|
+
else
|
275
|
+
Stately::Db::PutItem.new(
|
276
|
+
item: input.send("marshal_stately")
|
277
|
+
)
|
278
|
+
end
|
279
|
+
end
|
259
280
|
req = Stately::Db::TransactionRequest.new(
|
260
281
|
put_items: Stately::Db::TransactionPut.new(
|
261
|
-
puts:
|
262
|
-
Stately::Db::PutItem.new(
|
263
|
-
item: item.send("marshal_stately")
|
264
|
-
)
|
265
|
-
end
|
282
|
+
puts:
|
266
283
|
)
|
267
284
|
)
|
268
285
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: statelydb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.11.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Stately Cloud, Inc.
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-11-
|
11
|
+
date: 2024-11-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: async
|