statelydb 0.12.2 → 0.14.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/api/auth/get_auth_token_pb.rb +18 -0
- data/lib/api/auth/service_pb.rb +18 -0
- data/lib/api/auth/service_services_pb.rb +29 -0
- data/lib/api/db/get_pb.rb +1 -1
- data/lib/api/db/list_pb.rb +3 -3
- data/lib/api/db/put_pb.rb +1 -1
- data/lib/api/db/service_pb.rb +8 -8
- data/lib/api/db/service_services_pb.rb +1 -1
- data/lib/api/db/sync_list_pb.rb +2 -2
- data/lib/api/db/transaction_pb.rb +7 -7
- data/lib/common/auth/{auth0_token_provider.rb → auth_token_provider.rb} +52 -44
- data/lib/common/auth/interceptor.rb +1 -1
- data/lib/common/auth/token_fetcher.rb +104 -0
- data/lib/error.rb +0 -5
- data/lib/statelydb.rb +3 -7
- data/lib/token.rb +2 -3
- data/lib/transaction/transaction.rb +1 -1
- data/sig/grpc.rbs +80 -0
- data/sig/statelydb.rbi +1201 -0
- data/sig/statelydb.rbs +1053 -0
- metadata +12 -5
data/sig/statelydb.rbi
ADDED
@@ -0,0 +1,1201 @@
|
|
1
|
+
# typed: strong
|
2
|
+
# A module for Stately Cloud auth code
|
3
|
+
module StatelyDB
|
4
|
+
# UUID is a helper class for working with UUIDs in StatelyDB. The ruby version of a StatelyDB is a binary string,
|
5
|
+
# and this class provides convenience methods for converting to the base16 representation specified in RFC 9562.
|
6
|
+
# Internally this class uses the byte_string attribute to store the UUID as a string with the Encoding::ASCII_8BIT
|
7
|
+
# encoding.
|
8
|
+
class UUID
|
9
|
+
# _@param_ `byte_string` — A binary-encoded string (eg: Encoding::ASCII_8BIT encoding)
|
10
|
+
sig { params(byte_string: String).void }
|
11
|
+
def initialize(byte_string); end
|
12
|
+
|
13
|
+
# to_s returns the UUID as a base16 string (eg: "f4a8a24a-129d-411f-91d2-6d19d0eaa096")
|
14
|
+
sig { returns(String) }
|
15
|
+
def to_s; end
|
16
|
+
|
17
|
+
# to_str returns the UUID as a base16 string (eg: "f4a8a24a-129d-411f-91d2-6d19d0eaa096")
|
18
|
+
#
|
19
|
+
# Note: to_str is a type coercion method that is called by Ruby when an object is coerced to a string.
|
20
|
+
sig { returns(String) }
|
21
|
+
def to_str; end
|
22
|
+
|
23
|
+
# Encodes the byte string as a url-safe base64 string with padding removed.
|
24
|
+
sig { returns(String) }
|
25
|
+
def to_base64; end
|
26
|
+
|
27
|
+
# UUIDs are equal if their byte_strings are equal.
|
28
|
+
#
|
29
|
+
# _@param_ `other`
|
30
|
+
sig { params(other: StatelyDB::UUID).returns(T::Boolean) }
|
31
|
+
def ==(other); end
|
32
|
+
|
33
|
+
# UUIDs are sorted lexigraphically by their base16 representation.
|
34
|
+
#
|
35
|
+
# _@param_ `other`
|
36
|
+
sig { params(other: StatelyDB::UUID).returns(Integer) }
|
37
|
+
def <=>(other); end
|
38
|
+
|
39
|
+
# Returns true if the UUID is empty.
|
40
|
+
sig { returns(T::Boolean) }
|
41
|
+
def empty?; end
|
42
|
+
|
43
|
+
# Parses a base16 string (eg: "f4a8a24a-129d-411f-91d2-6d19d0eaa096") into a UUID object.
|
44
|
+
# The string can be the following:
|
45
|
+
# 1. Encoded as Encoding::ASCII_8BIT (also aliased as Encoding::BINARY) and be 16 bytes long.
|
46
|
+
# 2. A string of the form "f4a8a24a-129d-411f-91d2-6d19d0eaa096"
|
47
|
+
#
|
48
|
+
# _@param_ `byte_string` — A binary-encoded string (eg: Encoding::ASCII_8BIT encoding) that is 16 bytes in length, or a base16-formatted UUID string.
|
49
|
+
sig { params(byte_string: String).returns(StatelyDB::UUID) }
|
50
|
+
def self.parse(byte_string); end
|
51
|
+
|
52
|
+
# Not all bytes values in StatelyDB are UUIDs. This method checks if a byte string is a valid UUID.
|
53
|
+
#
|
54
|
+
# _@param_ `byte_string` — A binary-encoded string (eg: Encoding::ASCII_8BIT encoding)
|
55
|
+
sig { params(byte_string: String).returns(T::Boolean) }
|
56
|
+
def self.valid_uuid?(byte_string); end
|
57
|
+
|
58
|
+
# Returns the value of attribute byte_string.
|
59
|
+
sig { returns(T.untyped) }
|
60
|
+
attr_accessor :byte_string
|
61
|
+
end
|
62
|
+
|
63
|
+
# The Error class contains common StatelyDB error types.
|
64
|
+
class Error < StandardError
|
65
|
+
# _@param_ `message`
|
66
|
+
#
|
67
|
+
# _@param_ `code`
|
68
|
+
#
|
69
|
+
# _@param_ `stately_code`
|
70
|
+
#
|
71
|
+
# _@param_ `cause`
|
72
|
+
sig do
|
73
|
+
params(
|
74
|
+
message: String,
|
75
|
+
code: T.nilable(Integer),
|
76
|
+
stately_code: T.nilable(String),
|
77
|
+
cause: T.nilable(Exception)
|
78
|
+
).void
|
79
|
+
end
|
80
|
+
def initialize(message, code: nil, stately_code: nil, cause: nil); end
|
81
|
+
|
82
|
+
# Convert any exception into a StatelyDB::Error.
|
83
|
+
#
|
84
|
+
# _@param_ `error`
|
85
|
+
sig { params(error: Exception).returns(StatelyDB::Error) }
|
86
|
+
def self.from(error); end
|
87
|
+
|
88
|
+
# Turn this error's gRPC status code into a human-readable string. e.g. 3 -> "InvalidArgument"
|
89
|
+
sig { returns(String) }
|
90
|
+
def code_string; end
|
91
|
+
|
92
|
+
# Turn a gRPC status code into a human-readable string. e.g. 3 -> "InvalidArgument"
|
93
|
+
#
|
94
|
+
# _@param_ `code`
|
95
|
+
sig { params(code: Integer).returns(String) }
|
96
|
+
def self.grpc_code_to_string(code); end
|
97
|
+
|
98
|
+
# The gRPC/Connect Code for this error.
|
99
|
+
sig { returns(Integer) }
|
100
|
+
attr_reader :code
|
101
|
+
|
102
|
+
# The more fine-grained Stately error code, which is a human-readable string.
|
103
|
+
sig { returns(String) }
|
104
|
+
attr_reader :stately_code
|
105
|
+
|
106
|
+
# The upstream cause of the error, if available.
|
107
|
+
sig { returns(Exception) }
|
108
|
+
attr_reader :cause
|
109
|
+
end
|
110
|
+
|
111
|
+
# The Token type contains a continuation token for list and sync operations along with metadata about the ability
|
112
|
+
# to sync or continue listing based on the last operation performed.
|
113
|
+
#
|
114
|
+
# Ths StatelyDB SDK vends this Token type for list and sync operations.
|
115
|
+
# Consumers should not need to construct this type directly.
|
116
|
+
class Token
|
117
|
+
# _@param_ `token_data`
|
118
|
+
#
|
119
|
+
# _@param_ `can_continue`
|
120
|
+
#
|
121
|
+
# _@param_ `can_sync`
|
122
|
+
#
|
123
|
+
# _@param_ `schema_version_id`
|
124
|
+
sig do
|
125
|
+
params(
|
126
|
+
token_data: String,
|
127
|
+
can_continue: T::Boolean,
|
128
|
+
can_sync: T::Boolean,
|
129
|
+
schema_version_id: Integer
|
130
|
+
).void
|
131
|
+
end
|
132
|
+
def initialize(token_data:, can_continue:, can_sync:, schema_version_id:); end
|
133
|
+
|
134
|
+
# Returns true if the list operation can be continued, otherwise false.
|
135
|
+
sig { returns(T::Boolean) }
|
136
|
+
def can_continue?; end
|
137
|
+
|
138
|
+
# Returns true if the sync operation can be continued, otherwise false.
|
139
|
+
sig { returns(T::Boolean) }
|
140
|
+
def can_sync?; end
|
141
|
+
|
142
|
+
# Returns the value of attribute token_data.
|
143
|
+
sig { returns(T.untyped) }
|
144
|
+
attr_accessor :token_data
|
145
|
+
|
146
|
+
# Returns the schema version ID associated with the token.
|
147
|
+
sig { returns(Integer) }
|
148
|
+
attr_reader :schema_version_id
|
149
|
+
end
|
150
|
+
|
151
|
+
# KeyPath is a helper class for constructing key paths.
|
152
|
+
class KeyPath
|
153
|
+
sig { void }
|
154
|
+
def initialize; end
|
155
|
+
|
156
|
+
# Appends a new path segment.
|
157
|
+
#
|
158
|
+
# _@param_ `namespace`
|
159
|
+
#
|
160
|
+
# _@param_ `identifier`
|
161
|
+
sig { params(namespace: String, identifier: T.nilable(T.any(String, StatelyDB::UUID, T.untyped))).returns(KeyPath) }
|
162
|
+
def with(namespace, identifier = nil); end
|
163
|
+
|
164
|
+
sig { returns(String) }
|
165
|
+
def to_str; end
|
166
|
+
|
167
|
+
sig { returns(String) }
|
168
|
+
def inspect; end
|
169
|
+
|
170
|
+
sig { returns(String) }
|
171
|
+
def to_s; end
|
172
|
+
|
173
|
+
# Appends a new path segment.
|
174
|
+
#
|
175
|
+
# _@param_ `namespace`
|
176
|
+
#
|
177
|
+
# _@param_ `identifier`
|
178
|
+
#
|
179
|
+
# ```ruby
|
180
|
+
# keypath = KeyPath.with("genres", "rock").with("artists", "the-beatles")
|
181
|
+
# ```
|
182
|
+
sig { params(namespace: String, identifier: T.nilable(T.any(String, StatelyDB::UUID, T.untyped))).returns(KeyPath) }
|
183
|
+
def self.with(namespace, identifier = nil); end
|
184
|
+
|
185
|
+
# If the value is a binary string, encode it as a url-safe base64 string with padding removed.
|
186
|
+
#
|
187
|
+
# _@param_ `value` — The value to convert to a key id.
|
188
|
+
sig { params(value: T.any(String, StatelyDB::UUID, T.untyped)).returns(String) }
|
189
|
+
def self.to_key_id(value); end
|
190
|
+
end
|
191
|
+
|
192
|
+
# CoreClient is a low level client for interacting with the Stately Cloud API.
|
193
|
+
# This client shouldn't be used directly in most cases. Instead, use the generated
|
194
|
+
# client for your schema.
|
195
|
+
class CoreClient
|
196
|
+
# Initialize a new StatelyDB CoreClient
|
197
|
+
#
|
198
|
+
# _@param_ `store_id` — the StatelyDB to use for all operations with this client.
|
199
|
+
#
|
200
|
+
# _@param_ `schema` — the generated Schema module to use for mapping StatelyDB Items.
|
201
|
+
#
|
202
|
+
# _@param_ `token_provider` — the token provider to use for authentication.
|
203
|
+
#
|
204
|
+
# _@param_ `endpoint` — the endpoint to connect to.
|
205
|
+
#
|
206
|
+
# _@param_ `region` — the region to connect to.
|
207
|
+
sig do
|
208
|
+
params(
|
209
|
+
store_id: Integer,
|
210
|
+
schema: Module,
|
211
|
+
token_provider: Common::Auth::TokenProvider,
|
212
|
+
endpoint: T.nilable(String),
|
213
|
+
region: T.nilable(String)
|
214
|
+
).void
|
215
|
+
end
|
216
|
+
def initialize(store_id:, schema:, token_provider: Common::Auth::AuthTokenProvider.new, endpoint: nil, region: nil); end
|
217
|
+
|
218
|
+
# _@return_ — nil
|
219
|
+
sig { void }
|
220
|
+
def close; end
|
221
|
+
|
222
|
+
# Set whether to allow stale results for all operations with this client. This produces a new client
|
223
|
+
# with the allow_stale flag set.
|
224
|
+
#
|
225
|
+
# _@param_ `allow_stale` — whether to allow stale results
|
226
|
+
#
|
227
|
+
# _@return_ — a new client with the allow_stale flag set
|
228
|
+
#
|
229
|
+
# ```ruby
|
230
|
+
# client.with_allow_stale(true).get("/ItemType-identifier")
|
231
|
+
# ```
|
232
|
+
sig { params(allow_stale: T::Boolean).returns(T.self_type) }
|
233
|
+
def with_allow_stale(allow_stale); end
|
234
|
+
|
235
|
+
# Fetch a single Item from a StatelyDB Store at the given key_path.
|
236
|
+
#
|
237
|
+
# _@param_ `key_path` — the path to the item
|
238
|
+
#
|
239
|
+
# _@return_ — the Item or nil if not found
|
240
|
+
#
|
241
|
+
# ```ruby
|
242
|
+
# client.get("/ItemType-identifier")
|
243
|
+
# ```
|
244
|
+
sig { params(key_path: String).returns(T.any(StatelyDB::Item, NilClass)) }
|
245
|
+
def get(key_path); end
|
246
|
+
|
247
|
+
# Fetch a batch of up to 100 Items from a StatelyDB Store at the given key_paths.
|
248
|
+
#
|
249
|
+
# _@param_ `key_paths` — the paths to the items. Max 100 key paths.
|
250
|
+
#
|
251
|
+
# _@return_ — the items or nil if not found
|
252
|
+
#
|
253
|
+
# ```ruby
|
254
|
+
# client.data.get_batch("/ItemType-identifier", "/ItemType-identifier2")
|
255
|
+
# ```
|
256
|
+
sig { params(key_paths: T.any(String, T::Array[String])).returns(T.any(T::Array[StatelyDB::Item], NilClass)) }
|
257
|
+
def get_batch(*key_paths); end
|
258
|
+
|
259
|
+
# Begin listing Items from a StatelyDB Store at the given prefix.
|
260
|
+
#
|
261
|
+
# _@param_ `prefix` — the prefix to list
|
262
|
+
#
|
263
|
+
# _@param_ `limit` — the maximum number of items to return
|
264
|
+
#
|
265
|
+
# _@param_ `sort_property` — the property to sort by
|
266
|
+
#
|
267
|
+
# _@param_ `sort_direction` — the direction to sort by (:ascending or :descending)
|
268
|
+
#
|
269
|
+
# _@return_ — the list of Items and the token
|
270
|
+
#
|
271
|
+
# ```ruby
|
272
|
+
# client.data.begin_list("/ItemType-identifier", limit: 10, sort_direction: :ascending)
|
273
|
+
# ```
|
274
|
+
sig do
|
275
|
+
params(
|
276
|
+
prefix: String,
|
277
|
+
limit: Integer,
|
278
|
+
sort_property: T.nilable(String),
|
279
|
+
sort_direction: Symbol
|
280
|
+
).returns(T.any(T::Array[StatelyDB::Item], StatelyDB::Token))
|
281
|
+
end
|
282
|
+
def begin_list(prefix, limit: 100, sort_property: nil, sort_direction: :ascending); end
|
283
|
+
|
284
|
+
# Continue listing Items from a StatelyDB Store using a token.
|
285
|
+
#
|
286
|
+
# _@param_ `token` — the token to continue from
|
287
|
+
#
|
288
|
+
# _@return_ — the list of Items and the token
|
289
|
+
#
|
290
|
+
# ```ruby
|
291
|
+
# (items, token) = client.data.begin_list("/ItemType-identifier")
|
292
|
+
# client.data.continue_list(token)
|
293
|
+
# ```
|
294
|
+
sig { params(token: StatelyDB::Token).returns(T.any(T::Array[StatelyDB::Item], StatelyDB::Token)) }
|
295
|
+
def continue_list(token); end
|
296
|
+
|
297
|
+
# Sync a list of Items from a StatelyDB Store.
|
298
|
+
#
|
299
|
+
# _@param_ `token` — the token to sync from
|
300
|
+
#
|
301
|
+
# _@return_ — the result of the sync operation
|
302
|
+
#
|
303
|
+
# ```ruby
|
304
|
+
# (items, token) = client.data.begin_list("/ItemType-identifier")
|
305
|
+
# client.data.sync_list(token)
|
306
|
+
# ```
|
307
|
+
sig { params(token: StatelyDB::Token).returns(StatelyDB::SyncResult) }
|
308
|
+
def sync_list(token); end
|
309
|
+
|
310
|
+
# Put an Item into a StatelyDB Store at the given key_path.
|
311
|
+
#
|
312
|
+
# _@param_ `item` — a StatelyDB Item
|
313
|
+
#
|
314
|
+
# _@param_ `must_not_exist` — A condition that indicates this item must not already exist at any of its key paths. If there is already an item at one of those paths, the Put operation will fail with a "ConditionalCheckFailed" error. Note that if the item has an `initialValue` field in its key, that initial value will automatically be chosen not to conflict with existing items, so this condition only applies to key paths that do not contain the `initialValue` field.
|
315
|
+
#
|
316
|
+
# _@return_ — the item that was stored
|
317
|
+
#
|
318
|
+
# client.data.put(my_item)
|
319
|
+
# ```ruby
|
320
|
+
# ```
|
321
|
+
#
|
322
|
+
# client.data.put(my_item, must_not_exist: true)
|
323
|
+
# ```ruby
|
324
|
+
# ```
|
325
|
+
sig { params(item: StatelyDB::Item, must_not_exist: T::Boolean).returns(StatelyDB::Item) }
|
326
|
+
def put(item, must_not_exist: false); end
|
327
|
+
|
328
|
+
# Put a batch of up to 50 Items into a StatelyDB Store.
|
329
|
+
#
|
330
|
+
# Max 50 items.
|
331
|
+
#
|
332
|
+
# _@param_ `items` — the items to store.
|
333
|
+
#
|
334
|
+
# _@return_ — the items that were stored
|
335
|
+
#
|
336
|
+
# ```ruby
|
337
|
+
# client.data.put_batch(item1, item2)
|
338
|
+
# ```
|
339
|
+
#
|
340
|
+
# ```ruby
|
341
|
+
# client.data.put_batch({ item: item1, must_not_exist: true }, item2)
|
342
|
+
# ```
|
343
|
+
sig { params(items: T.any(StatelyDB::Item, T::Array[StatelyDB::Item])).returns(T::Array[StatelyDB::Item]) }
|
344
|
+
def put_batch(*items); end
|
345
|
+
|
346
|
+
# Delete up to 50 Items from a StatelyDB Store at the given key_paths.
|
347
|
+
#
|
348
|
+
# _@param_ `key_paths` — the paths to the items. Max 50 key paths.
|
349
|
+
#
|
350
|
+
# _@return_ — nil
|
351
|
+
#
|
352
|
+
# ```ruby
|
353
|
+
# client.data.delete("/ItemType-identifier", "/ItemType-identifier2")
|
354
|
+
# ```
|
355
|
+
sig { params(key_paths: T.any(String, T::Array[String])).void }
|
356
|
+
def delete(*key_paths); end
|
357
|
+
|
358
|
+
# Transaction takes a block and executes the block within a transaction.
|
359
|
+
# If the block raises an exception, the transaction is rolled back.
|
360
|
+
# If the block completes successfully, the transaction is committed.
|
361
|
+
#
|
362
|
+
# _@return_ — the result of the transaction
|
363
|
+
#
|
364
|
+
# ```ruby
|
365
|
+
# client.data.transaction do |txn|
|
366
|
+
# txn.put(item: my_item)
|
367
|
+
# txn.put(item: another_item)
|
368
|
+
# end
|
369
|
+
# ```
|
370
|
+
sig { returns(StatelyDB::Transaction::Transaction::Result) }
|
371
|
+
def transaction; end
|
372
|
+
|
373
|
+
# Construct the API endpoint from the region and endpoint.
|
374
|
+
# If the endpoint is provided, it will be returned as-is.
|
375
|
+
# If the region is provided and the endpoint is not,
|
376
|
+
# then the region-specific endpoint will be returned.
|
377
|
+
# If neither the region nor the endpoint is provided,
|
378
|
+
# then the default endpoint will be returned.
|
379
|
+
#
|
380
|
+
# _@param_ `endpoint` — the endpoint to connect to
|
381
|
+
#
|
382
|
+
# _@param_ `region` — the region to connect to
|
383
|
+
#
|
384
|
+
# _@return_ — the constructed endpoint
|
385
|
+
sig { params(endpoint: T.nilable(String), region: T.nilable(Region)).returns(String) }
|
386
|
+
def self.make_endpoint(endpoint: nil, region: nil); end
|
387
|
+
|
388
|
+
# Process a list response from begin_list or continue_list
|
389
|
+
#
|
390
|
+
# _@param_ `resp` — the response to process
|
391
|
+
#
|
392
|
+
# _@return_ — the list of Items and the token
|
393
|
+
sig { params(resp: Stately::Db::ListResponse).returns([T::Array[StatelyDB::Item], StatelyDB::Token]) }
|
394
|
+
def process_list_response(resp); end
|
395
|
+
|
396
|
+
# Process a sync response from sync_list
|
397
|
+
#
|
398
|
+
# _@param_ `resp` — the response to process
|
399
|
+
#
|
400
|
+
# _@return_ — the result of the sync operation
|
401
|
+
sig { params(resp: Stately::Db::SyncResponse).returns(StatelyDB::SyncResult) }
|
402
|
+
def process_sync_response(resp); end
|
403
|
+
end
|
404
|
+
|
405
|
+
# SyncResult represents the results of a sync operation.
|
406
|
+
#
|
407
|
+
# @attr_reader changed_items [Array<StatelyDB::Item>] the items that were changed
|
408
|
+
# @attr_reader deleted_item_paths [Array<String>] the key paths that were deleted
|
409
|
+
# @attr_reader updated_outside_list_window_paths [Array<String>] the key paths of
|
410
|
+
# items that were updated but Stately cannot tell if they were in the sync window.
|
411
|
+
# Treat these as deleted in most cases.
|
412
|
+
# @attr_reader is_reset [Boolean] whether the sync operation reset the token
|
413
|
+
# @attr_reader token [StatelyDB::Token] the token to continue from
|
414
|
+
class SyncResult
|
415
|
+
# _@param_ `changed_items` — the items that were changed
|
416
|
+
#
|
417
|
+
# _@param_ `deleted_item_paths` — the key paths that were deleted
|
418
|
+
#
|
419
|
+
# _@param_ `updated_outside_list_window_paths` — key paths for items that were updated but do not currently use the sort property that the list window is based on
|
420
|
+
#
|
421
|
+
# _@param_ `is_reset` — whether the sync operation reset the token
|
422
|
+
#
|
423
|
+
# _@param_ `token` — the token to continue from
|
424
|
+
sig do
|
425
|
+
params(
|
426
|
+
changed_items: T::Array[StatelyDB::Item],
|
427
|
+
deleted_item_paths: T::Array[String],
|
428
|
+
updated_outside_list_window_paths: T::Array[String],
|
429
|
+
is_reset: T::Boolean,
|
430
|
+
token: StatelyDB::Token
|
431
|
+
).void
|
432
|
+
end
|
433
|
+
def initialize(changed_items:, deleted_item_paths:, updated_outside_list_window_paths:, is_reset:, token:); end
|
434
|
+
|
435
|
+
# the items that were changed
|
436
|
+
sig { returns(T::Array[StatelyDB::Item]) }
|
437
|
+
attr_reader :changed_items
|
438
|
+
|
439
|
+
# the key paths that were deleted
|
440
|
+
sig { returns(T::Array[String]) }
|
441
|
+
attr_reader :deleted_item_paths
|
442
|
+
|
443
|
+
# the key paths of
|
444
|
+
# items that were updated but Stately cannot tell if they were in the sync window.
|
445
|
+
# Treat these as deleted in most cases.
|
446
|
+
sig { returns(T::Array[String]) }
|
447
|
+
attr_reader :updated_outside_list_window_paths
|
448
|
+
|
449
|
+
# whether the sync operation reset the token
|
450
|
+
sig { returns(T::Boolean) }
|
451
|
+
attr_reader :is_reset
|
452
|
+
|
453
|
+
# the token to continue from
|
454
|
+
sig { returns(StatelyDB::Token) }
|
455
|
+
attr_reader :token
|
456
|
+
end
|
457
|
+
|
458
|
+
# StatelyDB::Item is a base class for all StatelyDB Items. This class is provided in documentation
|
459
|
+
# to show the expected interface for a StatelyDB Item, but in practice the SDK will return a subclass
|
460
|
+
# of this class that is generated from the schema.
|
461
|
+
class Item
|
462
|
+
end
|
463
|
+
|
464
|
+
module Common
|
465
|
+
# A module for Stately Cloud networking code
|
466
|
+
module Net
|
467
|
+
# Create a new gRPC channel
|
468
|
+
#
|
469
|
+
# _@param_ `endpoint` — The endpoint to connect to
|
470
|
+
#
|
471
|
+
# _@return_ — The new channel
|
472
|
+
sig { params(endpoint: String).returns(GRPC::Core::Channel) }
|
473
|
+
def self.new_channel(endpoint:); end
|
474
|
+
end
|
475
|
+
|
476
|
+
# A module for Stately Cloud auth code
|
477
|
+
module Auth
|
478
|
+
# GRPC interceptor to authenticate against Stately and append bearer tokens to outgoing requests
|
479
|
+
class Interceptor < GRPC::ClientInterceptor
|
480
|
+
# _@param_ `token_provider` — The token provider to use for authentication
|
481
|
+
sig { params(token_provider: TokenProvider).void }
|
482
|
+
def initialize(token_provider: AuthTokenProvider.new); end
|
483
|
+
|
484
|
+
# gRPC client unary interceptor
|
485
|
+
#
|
486
|
+
# _@param_ `request` — The request object
|
487
|
+
#
|
488
|
+
# _@param_ `call` — The active call object
|
489
|
+
#
|
490
|
+
# _@param_ `method` — The method being called
|
491
|
+
#
|
492
|
+
# _@param_ `metadata` — The metadata hash
|
493
|
+
#
|
494
|
+
# _@return_ — The response object
|
495
|
+
sig do
|
496
|
+
params(
|
497
|
+
request: Object,
|
498
|
+
call: GRPC::ActiveCall,
|
499
|
+
method: Symbol,
|
500
|
+
metadata: T::Hash[T.untyped, T.untyped]
|
501
|
+
).returns(Object)
|
502
|
+
end
|
503
|
+
def request_response(request:, call:, method:, metadata:); end
|
504
|
+
|
505
|
+
# gRPC client streaming interceptor
|
506
|
+
#
|
507
|
+
# _@param_ `requests` — The list of requests
|
508
|
+
#
|
509
|
+
# _@param_ `call` — The active call object
|
510
|
+
#
|
511
|
+
# _@param_ `method` — The method being called
|
512
|
+
#
|
513
|
+
# _@param_ `metadata` — The metadata hash
|
514
|
+
#
|
515
|
+
# _@return_ — The response enumerator
|
516
|
+
sig do
|
517
|
+
params(
|
518
|
+
requests: T::Enumerable[T.untyped],
|
519
|
+
call: GRPC::ActiveCall,
|
520
|
+
method: Symbol,
|
521
|
+
metadata: T::Hash[T.untyped, T.untyped]
|
522
|
+
).returns(T::Enumerator[T.untyped])
|
523
|
+
end
|
524
|
+
def client_streamer(requests:, call:, method:, metadata:); end
|
525
|
+
|
526
|
+
# gRPC server streaming interceptor
|
527
|
+
#
|
528
|
+
# _@param_ `request` — The request object
|
529
|
+
#
|
530
|
+
# _@param_ `call` — The active call object
|
531
|
+
#
|
532
|
+
# _@param_ `method` — The method being called
|
533
|
+
#
|
534
|
+
# _@param_ `metadata` — The metadata hash
|
535
|
+
#
|
536
|
+
# _@return_ — The response enumerator
|
537
|
+
sig do
|
538
|
+
params(
|
539
|
+
request: Object,
|
540
|
+
call: GRPC::ActiveCall,
|
541
|
+
method: Symbol,
|
542
|
+
metadata: T::Hash[T.untyped, T.untyped]
|
543
|
+
).returns(T::Enumerator[T.untyped])
|
544
|
+
end
|
545
|
+
def server_streamer(request:, call:, method:, metadata:); end
|
546
|
+
|
547
|
+
# gRPC bidirectional streaming interceptor
|
548
|
+
#
|
549
|
+
# _@param_ `requests` — The list of requests
|
550
|
+
#
|
551
|
+
# _@param_ `call` — The active call object
|
552
|
+
#
|
553
|
+
# _@param_ `method` — The method being called
|
554
|
+
#
|
555
|
+
# _@param_ `metadata` — The metadata hash
|
556
|
+
#
|
557
|
+
# _@return_ — The response enumerator
|
558
|
+
sig do
|
559
|
+
params(
|
560
|
+
requests: T::Enumerable[T.untyped],
|
561
|
+
call: GRPC::ActiveCall,
|
562
|
+
method: Symbol,
|
563
|
+
metadata: T::Hash[T.untyped, T.untyped]
|
564
|
+
).returns(T::Enumerator[T.untyped])
|
565
|
+
end
|
566
|
+
def bidi_streamer(requests:, call:, method:, metadata:); end
|
567
|
+
|
568
|
+
# Adds a JWT to the metadata hash
|
569
|
+
#
|
570
|
+
# _@param_ `metadata` — The metadata hash
|
571
|
+
sig { params(metadata: T::Hash[T.untyped, T.untyped]).void }
|
572
|
+
def add_jwt_to_grpc_request(metadata:); end
|
573
|
+
end
|
574
|
+
|
575
|
+
# Result from a token fetch operation
|
576
|
+
class TokenResult
|
577
|
+
# Create a new TokenResult
|
578
|
+
#
|
579
|
+
# _@param_ `token` — The access token
|
580
|
+
#
|
581
|
+
# _@param_ `expires_in_secs` — The number of seconds until the token expires
|
582
|
+
sig { params(token: String, expires_in_secs: Integer).void }
|
583
|
+
def initialize(token:, expires_in_secs:); end
|
584
|
+
|
585
|
+
# Returns the value of attribute token.
|
586
|
+
sig { returns(T.untyped) }
|
587
|
+
attr_reader :token
|
588
|
+
|
589
|
+
# Returns the value of attribute expires_in_secs.
|
590
|
+
sig { returns(T.untyped) }
|
591
|
+
attr_reader :expires_in_secs
|
592
|
+
end
|
593
|
+
|
594
|
+
# TokenFetcher is an abstract base class that should be extended
|
595
|
+
# for individual token fetcher implementations
|
596
|
+
class TokenFetcher
|
597
|
+
# Get the current access token
|
598
|
+
#
|
599
|
+
# _@return_ — The fetched TokenResult
|
600
|
+
sig { returns(TokenResult) }
|
601
|
+
def fetch; end
|
602
|
+
|
603
|
+
# Close the token provider and kill any background operations
|
604
|
+
sig { returns(T.untyped) }
|
605
|
+
def close; end
|
606
|
+
end
|
607
|
+
|
608
|
+
# Auth0TokenFetcher is a TokenFetcher that fetches tokens from an Auth0 server
|
609
|
+
class Auth0TokenFetcher < StatelyDB::Common::Auth::TokenFetcher
|
610
|
+
# _@param_ `origin` — The origin of the OAuth server
|
611
|
+
#
|
612
|
+
# _@param_ `audience` — The OAuth Audience for the token
|
613
|
+
#
|
614
|
+
# _@param_ `client_secret` — The StatelyDB client secret credential
|
615
|
+
#
|
616
|
+
# _@param_ `client_id` — The StatelyDB client ID credential
|
617
|
+
sig do
|
618
|
+
params(
|
619
|
+
origin: String,
|
620
|
+
audience: String,
|
621
|
+
client_secret: String,
|
622
|
+
client_id: String
|
623
|
+
).void
|
624
|
+
end
|
625
|
+
def initialize(origin:, audience:, client_secret:, client_id:); end
|
626
|
+
|
627
|
+
# Fetch a new token from auth0
|
628
|
+
#
|
629
|
+
# _@return_ — The fetched TokenResult
|
630
|
+
sig { returns(TokenResult) }
|
631
|
+
def fetch; end
|
632
|
+
|
633
|
+
sig { returns(T.untyped) }
|
634
|
+
def close; end
|
635
|
+
end
|
636
|
+
|
637
|
+
# StatelyAccessTokenFetcher is a TokenFetcher that fetches tokens from the StatelyDB API
|
638
|
+
class StatelyAccessTokenFetcher < StatelyDB::Common::Auth::TokenFetcher
|
639
|
+
# _@param_ `origin` — The origin of the OAuth server
|
640
|
+
#
|
641
|
+
# _@param_ `access_key` — The StatelyDB access key credential
|
642
|
+
sig { params(origin: String, access_key: String).void }
|
643
|
+
def initialize(origin:, access_key:); end
|
644
|
+
|
645
|
+
# Fetch a new token from the StatelyDB API
|
646
|
+
#
|
647
|
+
# _@return_ — The fetched TokenResult
|
648
|
+
sig { returns(TokenResult) }
|
649
|
+
def fetch; end
|
650
|
+
|
651
|
+
sig { returns(T.untyped) }
|
652
|
+
def close; end
|
653
|
+
end
|
654
|
+
|
655
|
+
# TokenProvider is an abstract base class that should be extended
|
656
|
+
# for individual token provider implementations
|
657
|
+
class TokenProvider
|
658
|
+
# Get the current access token
|
659
|
+
#
|
660
|
+
# _@param_ `force` — Whether to force a refresh of the token
|
661
|
+
#
|
662
|
+
# _@return_ — The current access token
|
663
|
+
sig { params(force: T::Boolean).returns(String) }
|
664
|
+
def get_token(force: false); end
|
665
|
+
|
666
|
+
# Close the token provider and kill any background operations
|
667
|
+
sig { returns(T.untyped) }
|
668
|
+
def close; end
|
669
|
+
end
|
670
|
+
|
671
|
+
# Auth0TokenProvider is an implementation of the TokenProvider abstract base class
|
672
|
+
# which vends tokens from auth0 with the given client_id and client_secret.
|
673
|
+
# It will default to using the values of `STATELY_CLIENT_ID` and `STATELY_CLIENT_SECRET` if
|
674
|
+
# no credentials are explicitly passed and will throw an error if none are found.
|
675
|
+
class AuthTokenProvider < StatelyDB::Common::Auth::TokenProvider
|
676
|
+
# _@param_ `origin` — The origin of the OAuth server
|
677
|
+
#
|
678
|
+
# _@param_ `audience` — The OAuth Audience for the token
|
679
|
+
#
|
680
|
+
# _@param_ `client_secret` — The StatelyDB client secret credential
|
681
|
+
#
|
682
|
+
# _@param_ `client_id` — The StatelyDB client ID credential
|
683
|
+
#
|
684
|
+
# _@param_ `access_key` — The StatelyDB access key credential
|
685
|
+
sig do
|
686
|
+
params(
|
687
|
+
origin: String,
|
688
|
+
audience: String,
|
689
|
+
client_secret: String,
|
690
|
+
client_id: String,
|
691
|
+
access_key: String
|
692
|
+
).void
|
693
|
+
end
|
694
|
+
def initialize(origin: "https://oauth.stately.cloud", audience: "api.stately.cloud", client_secret: ENV.fetch("STATELY_CLIENT_SECRET", nil), client_id: ENV.fetch("STATELY_CLIENT_ID", nil), access_key: ENV.fetch("STATELY_ACCESS_KEY", nil)); end
|
695
|
+
|
696
|
+
# Close the token provider and kill any background operations
|
697
|
+
# This just invokes the close method on the actor which should do the cleanup
|
698
|
+
sig { returns(T.untyped) }
|
699
|
+
def close; end
|
700
|
+
|
701
|
+
# Get the current access token
|
702
|
+
#
|
703
|
+
# _@return_ — The current access token
|
704
|
+
sig { params(force: T::Boolean).returns(String) }
|
705
|
+
def get_token(force: false); end
|
706
|
+
|
707
|
+
# Actor for managing the token refresh
|
708
|
+
# This is designed to be used with Async::Actor and run on a dedicated thread.
|
709
|
+
class Actor
|
710
|
+
# _@param_ `origin` — The origin of the OAuth server
|
711
|
+
#
|
712
|
+
# _@param_ `audience` — The OAuth Audience for the token
|
713
|
+
#
|
714
|
+
# _@param_ `client_secret` — The StatelyDB client secret credential
|
715
|
+
#
|
716
|
+
# _@param_ `client_id` — The StatelyDB client ID credential
|
717
|
+
sig do
|
718
|
+
params(
|
719
|
+
origin: String,
|
720
|
+
audience: String,
|
721
|
+
client_secret: String,
|
722
|
+
client_id: String,
|
723
|
+
access_key: T.untyped
|
724
|
+
).void
|
725
|
+
end
|
726
|
+
def initialize(origin:, audience:, client_secret:, client_id:, access_key:); end
|
727
|
+
|
728
|
+
# Initialize the actor. This runs on the actor thread which means
|
729
|
+
# we can dispatch async operations here.
|
730
|
+
sig { returns(T.untyped) }
|
731
|
+
def init; end
|
732
|
+
|
733
|
+
# Close the token provider and kill any background operations
|
734
|
+
sig { returns(T.untyped) }
|
735
|
+
def close; end
|
736
|
+
|
737
|
+
# Get the current access token
|
738
|
+
#
|
739
|
+
# _@param_ `force` — Whether to force a refresh of the token
|
740
|
+
#
|
741
|
+
# _@return_ — The current access token
|
742
|
+
sig { params(force: T::Boolean).returns(String) }
|
743
|
+
def get_token(force: false); end
|
744
|
+
|
745
|
+
# Get the current access token and whether it is valid
|
746
|
+
#
|
747
|
+
# _@return_ — The current access token and whether it is valid
|
748
|
+
sig { returns(T::Array[T.untyped]) }
|
749
|
+
def valid_access_token; end
|
750
|
+
|
751
|
+
# Refresh the access token
|
752
|
+
#
|
753
|
+
# _@return_ — A task that will resolve to the new access token
|
754
|
+
sig { returns(Task) }
|
755
|
+
def refresh_token; end
|
756
|
+
|
757
|
+
# Refresh the access token implementation
|
758
|
+
#
|
759
|
+
# _@return_ — The new access token
|
760
|
+
sig { returns(String) }
|
761
|
+
def refresh_token_impl; end
|
762
|
+
end
|
763
|
+
|
764
|
+
# Persistent state for the token provider
|
765
|
+
class TokenState
|
766
|
+
# Create a new TokenState
|
767
|
+
#
|
768
|
+
# _@param_ `token` — The access token
|
769
|
+
#
|
770
|
+
# _@param_ `expires_at_unix_secs` — The unix timestamp when the token expires
|
771
|
+
sig { params(token: String, expires_at_unix_secs: Integer).void }
|
772
|
+
def initialize(token:, expires_at_unix_secs:); end
|
773
|
+
|
774
|
+
# Returns the value of attribute token.
|
775
|
+
sig { returns(T.untyped) }
|
776
|
+
attr_reader :token
|
777
|
+
|
778
|
+
# Returns the value of attribute expires_at_unix_secs.
|
779
|
+
sig { returns(T.untyped) }
|
780
|
+
attr_reader :expires_at_unix_secs
|
781
|
+
end
|
782
|
+
end
|
783
|
+
end
|
784
|
+
|
785
|
+
# GRPC interceptor to convert errors to StatelyDB::Error
|
786
|
+
class ErrorInterceptor < GRPC::ClientInterceptor
|
787
|
+
# client unary interceptor
|
788
|
+
sig do
|
789
|
+
params(
|
790
|
+
request: T.untyped,
|
791
|
+
call: T.untyped,
|
792
|
+
method: T.untyped,
|
793
|
+
metadata: T.untyped
|
794
|
+
).returns(T.untyped)
|
795
|
+
end
|
796
|
+
def request_response(request:, call:, method:, metadata:); end
|
797
|
+
|
798
|
+
# client streaming interceptor
|
799
|
+
sig do
|
800
|
+
params(
|
801
|
+
requests: T.untyped,
|
802
|
+
call: T.untyped,
|
803
|
+
method: T.untyped,
|
804
|
+
metadata: T.untyped
|
805
|
+
).returns(T.untyped)
|
806
|
+
end
|
807
|
+
def client_streamer(requests:, call:, method:, metadata:); end
|
808
|
+
|
809
|
+
# server streaming interceptor
|
810
|
+
sig do
|
811
|
+
params(
|
812
|
+
request: T.untyped,
|
813
|
+
call: T.untyped,
|
814
|
+
method: T.untyped,
|
815
|
+
metadata: T.untyped
|
816
|
+
).returns(T.untyped)
|
817
|
+
end
|
818
|
+
def server_streamer(request:, call:, method:, metadata:); end
|
819
|
+
|
820
|
+
# bidirectional streaming interceptor
|
821
|
+
sig do
|
822
|
+
params(
|
823
|
+
requests: T.untyped,
|
824
|
+
call: T.untyped,
|
825
|
+
method: T.untyped,
|
826
|
+
metadata: T.untyped
|
827
|
+
).returns(T.untyped)
|
828
|
+
end
|
829
|
+
def bidi_streamer(requests:, call:, method:, metadata:); end
|
830
|
+
end
|
831
|
+
end
|
832
|
+
|
833
|
+
module Transaction
|
834
|
+
# TransactionQueue is a wrapper around Thread::Queue that implements Enumerable
|
835
|
+
class Queue < Thread::Queue
|
836
|
+
sig { void }
|
837
|
+
def initialize; end
|
838
|
+
|
839
|
+
# next_message_id returns the next message ID, which is the current size of the queue + 1.
|
840
|
+
# This value is consumed by the StatelyDB transaction as a monotonically increasing MessageID.
|
841
|
+
sig { returns(Integer) }
|
842
|
+
def next_message_id; end
|
843
|
+
|
844
|
+
# Iterates over each element in the queue, yielding each element to the given block.
|
845
|
+
sig { void }
|
846
|
+
def each; end
|
847
|
+
|
848
|
+
# Iterates over each item in the queue, yielding each item to the given block.
|
849
|
+
sig { void }
|
850
|
+
def each_item; end
|
851
|
+
|
852
|
+
# _@return_ — The ID of the last message, or nil if there is no message.
|
853
|
+
sig { returns(T.nilable(Integer)) }
|
854
|
+
attr_reader :last_message_id
|
855
|
+
end
|
856
|
+
|
857
|
+
# Transaction coordinates sending requests and waiting for responses. Consumers should not need
|
858
|
+
# to interact with this class directly, but instead use the methods provided by the StatelyDB::CoreClient.
|
859
|
+
#
|
860
|
+
# The example below demonstrates using a transaction, which accepts a block. The lines in the block
|
861
|
+
# are executed within the context of the transaction. The transaction is committed when the block
|
862
|
+
# completes successfully, OR is aborted if an exception is raised.
|
863
|
+
#
|
864
|
+
# @example
|
865
|
+
# result = client.transaction do |tx|
|
866
|
+
# key_path = StatelyDB::KeyPath.with('movie', 'The Shining')
|
867
|
+
# movie = tx.get(key_path:)
|
868
|
+
# tx.put(item: movie)
|
869
|
+
# end
|
870
|
+
class Transaction
|
871
|
+
# Initialize a new Transaction
|
872
|
+
#
|
873
|
+
# _@param_ `stub` — a StatelyDB gRPC stub
|
874
|
+
#
|
875
|
+
# _@param_ `store_id` — the StatelyDB Store to transact against
|
876
|
+
#
|
877
|
+
# _@param_ `schema` — the schema to use for marshalling and unmarshalling Items
|
878
|
+
sig { params(stub: Stately::Db::DatabaseService::Stub, store_id: Integer, schema: StatelyDB::Schema).void }
|
879
|
+
def initialize(stub:, store_id:, schema:); end
|
880
|
+
|
881
|
+
# Send a request and wait for a response
|
882
|
+
#
|
883
|
+
# _@param_ `req` — the request to send
|
884
|
+
#
|
885
|
+
# _@return_ — the response
|
886
|
+
sig { params(req: Stately::Db::TransactionRequest).returns(Stately::Db::TransactionResponse) }
|
887
|
+
def request_response(req); end
|
888
|
+
|
889
|
+
# Send a request and don't wait for a response
|
890
|
+
#
|
891
|
+
# _@param_ `req` — the request to send
|
892
|
+
#
|
893
|
+
# _@return_ — nil
|
894
|
+
sig { params(req: Stately::Db::TransactionRequest).void }
|
895
|
+
def request_only(req); end
|
896
|
+
|
897
|
+
# Send a request and process all responses, until we receive a finished message. This is used for list operations.
|
898
|
+
# Each response is processed by the block passed to this method, and the response for this method is a token.
|
899
|
+
#
|
900
|
+
# _@param_ `req` — the request to send
|
901
|
+
#
|
902
|
+
# _@return_ — the token
|
903
|
+
#
|
904
|
+
# ```ruby
|
905
|
+
# request_list_responses(req) do |resp|
|
906
|
+
# resp.result.items.each do |result|
|
907
|
+
# puts result.item.key_path
|
908
|
+
# end
|
909
|
+
# ```
|
910
|
+
sig { params(req: Stately::Db::TransactionRequest, blk: T.proc.params(resp: Stately::Db::TransactionListResponse).void).returns(Stately::Db::ListToken) }
|
911
|
+
def request_list_responses(req, &blk); end
|
912
|
+
|
913
|
+
# Begin a transaction. Begin is called implicitly when the block passed to transaction is called.
|
914
|
+
#
|
915
|
+
# _@return_ — nil
|
916
|
+
sig { void }
|
917
|
+
def begin; end
|
918
|
+
|
919
|
+
# Commit a transaction. Commit is called implicitly when the block passed to transaction completes.
|
920
|
+
sig { returns(StatelyDB::Transaction::Transaction::Result) }
|
921
|
+
def commit; end
|
922
|
+
|
923
|
+
# Abort a transaction. Abort is called implicitly if an exception is raised within the block passed to transaction.
|
924
|
+
sig { returns(Stately::Db::TransactionResponse) }
|
925
|
+
def abort; end
|
926
|
+
|
927
|
+
# Check if a transaction is open. A transaction is open if begin has been called and commit or abort has not been called.
|
928
|
+
#
|
929
|
+
# _@return_ — true if a transaction is open
|
930
|
+
sig { returns(T::Boolean) }
|
931
|
+
def open?; end
|
932
|
+
|
933
|
+
# Fetch Items from a StatelyDB Store at the given key_path. Note that Items need to exist before being retrieved inside a
|
934
|
+
# transaction.
|
935
|
+
#
|
936
|
+
# _@param_ `key_path` — the path to the item
|
937
|
+
#
|
938
|
+
# _@return_ — the item or nil if not found
|
939
|
+
#
|
940
|
+
# ```ruby
|
941
|
+
# client.data.transaction do |txn|
|
942
|
+
# item = txn.get("/ItemType-identifier")
|
943
|
+
# end
|
944
|
+
# ```
|
945
|
+
sig { params(key_path: String).returns(T.any(StatelyDB::Item, NilClass)) }
|
946
|
+
def get(key_path); end
|
947
|
+
|
948
|
+
# Fetch a batch of up to 100 Items from a StatelyDB Store at the given
|
949
|
+
# key_paths. Note that Items need to exist before being retrieved inside a
|
950
|
+
# transaction.
|
951
|
+
#
|
952
|
+
# key paths.
|
953
|
+
# Example:
|
954
|
+
# client.data.transaction do |txn|
|
955
|
+
# items = txn.get_batch("/foo", "/bar")
|
956
|
+
# end
|
957
|
+
#
|
958
|
+
# _@param_ `key_paths` — the paths to the items. Max 100
|
959
|
+
#
|
960
|
+
# _@return_ — the items
|
961
|
+
sig { params(key_paths: T.any(String, T::Array[String])).returns(T::Array[StatelyDB::Item]) }
|
962
|
+
def get_batch(*key_paths); end
|
963
|
+
|
964
|
+
# Put a single Item into a StatelyDB store. Results are not returned until the transaction is
|
965
|
+
# committed and will be available in the Result object returned by commit. An identifier for
|
966
|
+
# the item will be returned while inside the transaction block.
|
967
|
+
#
|
968
|
+
# results.puts.each do |result|
|
969
|
+
# puts result.key_path
|
970
|
+
# end
|
971
|
+
#
|
972
|
+
# _@param_ `item` — the item to store
|
973
|
+
#
|
974
|
+
# _@param_ `must_not_exist` — A condition that indicates this item must not already exist at any of its key paths. If there is already an item at one of those paths, the Put operation will fail with a "ConditionalCheckFailed" error. Note that if the item has an `initialValue` field in its key, that initial value will automatically be chosen not to conflict with existing items, so this condition only applies to key paths that do not contain the `initialValue` field.
|
975
|
+
#
|
976
|
+
# _@return_ — the id of the item
|
977
|
+
#
|
978
|
+
# ```ruby
|
979
|
+
# results = client.data.transaction do |txn|
|
980
|
+
# txn.put(my_item)
|
981
|
+
# end
|
982
|
+
# ```
|
983
|
+
sig { params(item: StatelyDB::Item, must_not_exist: T::Boolean).returns(T.any(String, Integer)) }
|
984
|
+
def put(item, must_not_exist: false); end
|
985
|
+
|
986
|
+
# Put a batch of up to 50 Items into a StatelyDB Store. Results are not
|
987
|
+
# returned until the transaction is committed and will be available in the
|
988
|
+
# Result object returned by commit. A list of identifiers for the items
|
989
|
+
# will be returned while inside the transaction block.
|
990
|
+
#
|
991
|
+
# 50 items.
|
992
|
+
# results.puts.each do |result|
|
993
|
+
# puts result.key_path
|
994
|
+
# end
|
995
|
+
#
|
996
|
+
# _@param_ `items` — the items to store. Max
|
997
|
+
#
|
998
|
+
# _@return_ — the ids of the items
|
999
|
+
#
|
1000
|
+
# ```ruby
|
1001
|
+
# results = client.data.transaction do |txn|
|
1002
|
+
# txn.put_batch(item1, item2)
|
1003
|
+
# end
|
1004
|
+
# ```
|
1005
|
+
sig { params(items: T.any(StatelyDB::Item, T::Array[StatelyDB::Item])).returns(T::Array[T.any(StatelyDB::UUID, String, Integer, NilClass)]) }
|
1006
|
+
def put_batch(*items); end
|
1007
|
+
|
1008
|
+
# Delete up to 50 Items from a StatelyDB Store at the given key_paths. Results are not returned until the transaction is
|
1009
|
+
# committed and will be available in the Result object returned by commit.
|
1010
|
+
#
|
1011
|
+
# Example:
|
1012
|
+
# client.data.transaction do |txn|
|
1013
|
+
# txn.delete("/ItemType-identifier", "/ItemType-identifier2")
|
1014
|
+
# end
|
1015
|
+
#
|
1016
|
+
# _@param_ `key_paths` — the paths to the items. Max 50 key paths.
|
1017
|
+
#
|
1018
|
+
# _@return_ — nil
|
1019
|
+
sig { params(key_paths: T.any(String, T::Array[String])).void }
|
1020
|
+
def delete(*key_paths); end
|
1021
|
+
|
1022
|
+
# Begin listing Items from a StatelyDB Store at the given prefix.
|
1023
|
+
#
|
1024
|
+
# Example:
|
1025
|
+
# client.data.transaction do |txn|
|
1026
|
+
# (items, token) = txn.begin_list("/ItemType-identifier")
|
1027
|
+
# (items, token) = txn.continue_list(token)
|
1028
|
+
# end
|
1029
|
+
#
|
1030
|
+
# _@param_ `prefix` — the prefix to list
|
1031
|
+
#
|
1032
|
+
# _@param_ `limit` — the maximum number of items to return
|
1033
|
+
#
|
1034
|
+
# _@param_ `sort_property` — the property to sort by
|
1035
|
+
#
|
1036
|
+
# _@param_ `sort_direction` — the direction to sort by (:ascending or :descending)
|
1037
|
+
#
|
1038
|
+
# _@return_ — the list of Items and the token
|
1039
|
+
sig do
|
1040
|
+
params(
|
1041
|
+
prefix: String,
|
1042
|
+
limit: Integer,
|
1043
|
+
sort_property: T.nilable(String),
|
1044
|
+
sort_direction: Symbol
|
1045
|
+
).returns([T::Array[StatelyDB::Item], Stately::Db::ListToken])
|
1046
|
+
end
|
1047
|
+
def begin_list(prefix, limit: 100, sort_property: nil, sort_direction: :ascending); end
|
1048
|
+
|
1049
|
+
# Continue listing Items from a StatelyDB Store using a token.
|
1050
|
+
#
|
1051
|
+
# Example:
|
1052
|
+
# client.data.transaction do |txn|
|
1053
|
+
# (items, token) = txn.begin_list("/foo")
|
1054
|
+
# (items, token) = txn.continue_list(token)
|
1055
|
+
# end
|
1056
|
+
#
|
1057
|
+
# _@param_ `token` — the token to continue from
|
1058
|
+
#
|
1059
|
+
# _@param_ `continue_direction` — the direction to continue by (:forward or :backward)
|
1060
|
+
#
|
1061
|
+
# _@return_ — the list of Items and the token
|
1062
|
+
sig { params(token: Stately::Db::ListToken, continue_direction: Symbol).returns([T::Array[StatelyDB::Item], Stately::Db::ListToken]) }
|
1063
|
+
def continue_list(token, continue_direction: :forward); end
|
1064
|
+
|
1065
|
+
# Processes a list response from begin_list or continue_list
|
1066
|
+
#
|
1067
|
+
# _@param_ `req` — the request to send
|
1068
|
+
#
|
1069
|
+
# _@return_ — the list of Items and the token
|
1070
|
+
sig { params(req: Stately::Db::TransactionRequest).returns([T::Array[StatelyDB::Item], Stately::Db::ListToken]) }
|
1071
|
+
def do_list_request_response(req); end
|
1072
|
+
|
1073
|
+
# We are using a oneof inside the TransactionRequest to determine the type of request. The ruby
|
1074
|
+
# generated code does not have a helper for the internal request type so we need to infer it.
|
1075
|
+
#
|
1076
|
+
# _@param_ `req` — the request
|
1077
|
+
#
|
1078
|
+
# _@return_ — the response type
|
1079
|
+
sig { params(req: Stately::Db::TransactionRequest).returns(Class) }
|
1080
|
+
def infer_response_type_from_request(req); end
|
1081
|
+
|
1082
|
+
# We are using a oneof inside the TransactionResponse to determine the type of response. The ruby
|
1083
|
+
# generated code does not have a helper for the internal response type so we need to infer it.
|
1084
|
+
#
|
1085
|
+
# _@param_ `resp` — the response
|
1086
|
+
#
|
1087
|
+
# _@return_ — the response type
|
1088
|
+
sig { params(resp: Stately::Db::TransactionResponse).returns(Class) }
|
1089
|
+
def infer_response_type_from_response(resp); end
|
1090
|
+
|
1091
|
+
# Result represents the results of a transaction
|
1092
|
+
#
|
1093
|
+
# @attr_reader puts [Array<StatelyDB::Item>] the items that were put
|
1094
|
+
# @attr_reader deletes [Array<String>] the key paths that were deleted
|
1095
|
+
class Result
|
1096
|
+
# Initialize a new Result
|
1097
|
+
#
|
1098
|
+
# _@param_ `puts` — the items that were put
|
1099
|
+
#
|
1100
|
+
# _@param_ `deletes` — the key paths that were deleted
|
1101
|
+
sig { params(puts: T::Array[StatelyDB::Item], deletes: T::Array[String]).void }
|
1102
|
+
def initialize(puts:, deletes:); end
|
1103
|
+
|
1104
|
+
# puts is an array of StatelyDB::Items that were put
|
1105
|
+
sig { returns(T::Array[StatelyDB::Item]) }
|
1106
|
+
attr_reader :puts
|
1107
|
+
|
1108
|
+
# deletes is an array of key paths that were deleted
|
1109
|
+
sig { returns(T::Array[String]) }
|
1110
|
+
attr_reader :deletes
|
1111
|
+
end
|
1112
|
+
end
|
1113
|
+
end
|
1114
|
+
end
|
1115
|
+
|
1116
|
+
module Stately
|
1117
|
+
module Db
|
1118
|
+
GetRequest = T.let(::Google::Protobuf::DescriptorPool.generated_pool.lookup("stately.db.GetRequest").msgclass, T.untyped)
|
1119
|
+
GetItem = T.let(::Google::Protobuf::DescriptorPool.generated_pool.lookup("stately.db.GetItem").msgclass, T.untyped)
|
1120
|
+
GetResponse = T.let(::Google::Protobuf::DescriptorPool.generated_pool.lookup("stately.db.GetResponse").msgclass, T.untyped)
|
1121
|
+
PutRequest = T.let(::Google::Protobuf::DescriptorPool.generated_pool.lookup("stately.db.PutRequest").msgclass, T.untyped)
|
1122
|
+
PutItem = T.let(::Google::Protobuf::DescriptorPool.generated_pool.lookup("stately.db.PutItem").msgclass, T.untyped)
|
1123
|
+
PutResponse = T.let(::Google::Protobuf::DescriptorPool.generated_pool.lookup("stately.db.PutResponse").msgclass, T.untyped)
|
1124
|
+
Item = T.let(::Google::Protobuf::DescriptorPool.generated_pool.lookup("stately.db.Item").msgclass, T.untyped)
|
1125
|
+
BeginListRequest = T.let(::Google::Protobuf::DescriptorPool.generated_pool.lookup("stately.db.BeginListRequest").msgclass, T.untyped)
|
1126
|
+
ListResponse = T.let(::Google::Protobuf::DescriptorPool.generated_pool.lookup("stately.db.ListResponse").msgclass, T.untyped)
|
1127
|
+
ListPartialResult = T.let(::Google::Protobuf::DescriptorPool.generated_pool.lookup("stately.db.ListPartialResult").msgclass, T.untyped)
|
1128
|
+
ListFinished = T.let(::Google::Protobuf::DescriptorPool.generated_pool.lookup("stately.db.ListFinished").msgclass, T.untyped)
|
1129
|
+
SortDirection = T.let(::Google::Protobuf::DescriptorPool.generated_pool.lookup("stately.db.SortDirection").enummodule, T.untyped)
|
1130
|
+
DeleteRequest = T.let(::Google::Protobuf::DescriptorPool.generated_pool.lookup("stately.db.DeleteRequest").msgclass, T.untyped)
|
1131
|
+
DeleteItem = T.let(::Google::Protobuf::DescriptorPool.generated_pool.lookup("stately.db.DeleteItem").msgclass, T.untyped)
|
1132
|
+
DeleteResult = T.let(::Google::Protobuf::DescriptorPool.generated_pool.lookup("stately.db.DeleteResult").msgclass, T.untyped)
|
1133
|
+
DeleteResponse = T.let(::Google::Protobuf::DescriptorPool.generated_pool.lookup("stately.db.DeleteResponse").msgclass, T.untyped)
|
1134
|
+
SyncListRequest = T.let(::Google::Protobuf::DescriptorPool.generated_pool.lookup("stately.db.SyncListRequest").msgclass, T.untyped)
|
1135
|
+
SyncListResponse = T.let(::Google::Protobuf::DescriptorPool.generated_pool.lookup("stately.db.SyncListResponse").msgclass, T.untyped)
|
1136
|
+
SyncListReset = T.let(::Google::Protobuf::DescriptorPool.generated_pool.lookup("stately.db.SyncListReset").msgclass, T.untyped)
|
1137
|
+
SyncListPartialResponse = T.let(::Google::Protobuf::DescriptorPool.generated_pool.lookup("stately.db.SyncListPartialResponse").msgclass, T.untyped)
|
1138
|
+
DeletedItem = T.let(::Google::Protobuf::DescriptorPool.generated_pool.lookup("stately.db.DeletedItem").msgclass, T.untyped)
|
1139
|
+
ListToken = T.let(::Google::Protobuf::DescriptorPool.generated_pool.lookup("stately.db.ListToken").msgclass, T.untyped)
|
1140
|
+
TransactionRequest = T.let(::Google::Protobuf::DescriptorPool.generated_pool.lookup("stately.db.TransactionRequest").msgclass, T.untyped)
|
1141
|
+
TransactionResponse = T.let(::Google::Protobuf::DescriptorPool.generated_pool.lookup("stately.db.TransactionResponse").msgclass, T.untyped)
|
1142
|
+
TransactionBegin = T.let(::Google::Protobuf::DescriptorPool.generated_pool.lookup("stately.db.TransactionBegin").msgclass, T.untyped)
|
1143
|
+
TransactionGet = T.let(::Google::Protobuf::DescriptorPool.generated_pool.lookup("stately.db.TransactionGet").msgclass, T.untyped)
|
1144
|
+
TransactionBeginList = T.let(::Google::Protobuf::DescriptorPool.generated_pool.lookup("stately.db.TransactionBeginList").msgclass, T.untyped)
|
1145
|
+
TransactionContinueList = T.let(::Google::Protobuf::DescriptorPool.generated_pool.lookup("stately.db.TransactionContinueList").msgclass, T.untyped)
|
1146
|
+
TransactionPut = T.let(::Google::Protobuf::DescriptorPool.generated_pool.lookup("stately.db.TransactionPut").msgclass, T.untyped)
|
1147
|
+
TransactionDelete = T.let(::Google::Protobuf::DescriptorPool.generated_pool.lookup("stately.db.TransactionDelete").msgclass, T.untyped)
|
1148
|
+
TransactionGetResponse = T.let(::Google::Protobuf::DescriptorPool.generated_pool.lookup("stately.db.TransactionGetResponse").msgclass, T.untyped)
|
1149
|
+
GeneratedID = T.let(::Google::Protobuf::DescriptorPool.generated_pool.lookup("stately.db.GeneratedID").msgclass, T.untyped)
|
1150
|
+
TransactionPutAck = T.let(::Google::Protobuf::DescriptorPool.generated_pool.lookup("stately.db.TransactionPutAck").msgclass, T.untyped)
|
1151
|
+
TransactionListResponse = T.let(::Google::Protobuf::DescriptorPool.generated_pool.lookup("stately.db.TransactionListResponse").msgclass, T.untyped)
|
1152
|
+
TransactionFinished = T.let(::Google::Protobuf::DescriptorPool.generated_pool.lookup("stately.db.TransactionFinished").msgclass, T.untyped)
|
1153
|
+
ContinueListRequest = T.let(::Google::Protobuf::DescriptorPool.generated_pool.lookup("stately.db.ContinueListRequest").msgclass, T.untyped)
|
1154
|
+
ContinueListDirection = T.let(::Google::Protobuf::DescriptorPool.generated_pool.lookup("stately.db.ContinueListDirection").enummodule, T.untyped)
|
1155
|
+
SortableProperty = T.let(::Google::Protobuf::DescriptorPool.generated_pool.lookup("stately.db.SortableProperty").enummodule, T.untyped)
|
1156
|
+
ScanRootPathsRequest = T.let(::Google::Protobuf::DescriptorPool.generated_pool.lookup("stately.db.ScanRootPathsRequest").msgclass, T.untyped)
|
1157
|
+
ScanRootPathsResponse = T.let(::Google::Protobuf::DescriptorPool.generated_pool.lookup("stately.db.ScanRootPathsResponse").msgclass, T.untyped)
|
1158
|
+
ScanRootPathResult = T.let(::Google::Protobuf::DescriptorPool.generated_pool.lookup("stately.db.ScanRootPathResult").msgclass, T.untyped)
|
1159
|
+
|
1160
|
+
module DatabaseService
|
1161
|
+
Stub = T.let(Service.rpc_stub_class, T.untyped)
|
1162
|
+
|
1163
|
+
# DatabaseService is the service for creating, reading, updating and deleting data
|
1164
|
+
# in a StatelyDB Store. Creating and modifying Stores is done by
|
1165
|
+
# stately.dbmanagement.ManagementService.
|
1166
|
+
class Service
|
1167
|
+
include GRPC::GenericService
|
1168
|
+
end
|
1169
|
+
end
|
1170
|
+
end
|
1171
|
+
|
1172
|
+
module Auth
|
1173
|
+
GetAuthTokenRequest = T.let(::Google::Protobuf::DescriptorPool.generated_pool.lookup("stately.auth.GetAuthTokenRequest").msgclass, T.untyped)
|
1174
|
+
GetAuthTokenResponse = T.let(::Google::Protobuf::DescriptorPool.generated_pool.lookup("stately.auth.GetAuthTokenResponse").msgclass, T.untyped)
|
1175
|
+
|
1176
|
+
module AuthService
|
1177
|
+
Stub = T.let(Service.rpc_stub_class, T.untyped)
|
1178
|
+
|
1179
|
+
# AuthService is the service for vending access tokens used to connect to
|
1180
|
+
# StatelyDB. This API is meant to be used from SDKs. Access Keys are created
|
1181
|
+
# and managed from the stately.dbmanagement.UserService.
|
1182
|
+
class Service
|
1183
|
+
include GRPC::GenericService
|
1184
|
+
end
|
1185
|
+
end
|
1186
|
+
end
|
1187
|
+
|
1188
|
+
module Errors
|
1189
|
+
StatelyErrorDetails = T.let(::Google::Protobuf::DescriptorPool.generated_pool.lookup("stately.errors.StatelyErrorDetails").msgclass, T.untyped)
|
1190
|
+
end
|
1191
|
+
end
|
1192
|
+
|
1193
|
+
module StatelyCode
|
1194
|
+
CACHED_SCHEMA_TOO_OLD = T.let("CachedSchemaTooOld", T.untyped)
|
1195
|
+
CONCURRENT_MODIFICATION = T.let("ConcurrentModification", T.untyped)
|
1196
|
+
CONDITIONAL_CHECK_FAILED = T.let("ConditionalCheckFailed", T.untyped)
|
1197
|
+
NON_RECOVERABLE_TRANSACTION = T.let("NonRecoverableTransaction", T.untyped)
|
1198
|
+
STORE_IN_USE = T.let("StoreInUse", T.untyped)
|
1199
|
+
STORE_REQUEST_LIMIT_EXCEEDED = T.let("StoreRequestLimitExceeded", T.untyped)
|
1200
|
+
STORE_THROUGHPUT_EXCEEDED = T.let("StoreThroughputExceeded", T.untyped)
|
1201
|
+
end
|