statelydb 0.12.1 → 0.13.0

Sign up to get free protection for your applications and to get access to all the features.
data/sig/statelydb.rbi ADDED
@@ -0,0 +1,1085 @@
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::Auth0TokenProvider.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: Auth0TokenProvider.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
+ # TokenProvider is an abstract base class that should be extended
576
+ # for individual token provider implementations
577
+ class TokenProvider
578
+ # Get the current access token
579
+ #
580
+ # _@param_ `force` — Whether to force a refresh of the token
581
+ #
582
+ # _@return_ — The current access token
583
+ sig { params(force: T::Boolean).returns(String) }
584
+ def get_token(force: false); end
585
+
586
+ # Close the token provider and kill any background operations
587
+ sig { returns(T.untyped) }
588
+ def close; end
589
+ end
590
+
591
+ # Auth0TokenProvider is an implementation of the TokenProvider abstract base class
592
+ # which vends tokens from auth0 with the given client_id and client_secret.
593
+ # It will default to using the values of `STATELY_CLIENT_ID` and `STATELY_CLIENT_SECRET` if
594
+ # no credentials are explicitly passed and will throw an error if none are found.
595
+ class Auth0TokenProvider < StatelyDB::Common::Auth::TokenProvider
596
+ # _@param_ `origin` — The origin of the OAuth server
597
+ #
598
+ # _@param_ `audience` — The OAuth Audience for the token
599
+ #
600
+ # _@param_ `client_secret` — The StatelyDB client secret credential
601
+ #
602
+ # _@param_ `client_id` — The StatelyDB client ID credential
603
+ sig do
604
+ params(
605
+ origin: String,
606
+ audience: String,
607
+ client_secret: String,
608
+ client_id: String
609
+ ).void
610
+ end
611
+ def initialize(origin: "https://oauth.stately.cloud", audience: "api.stately.cloud", client_secret: ENV.fetch("STATELY_CLIENT_SECRET"), client_id: ENV.fetch("STATELY_CLIENT_ID")); end
612
+
613
+ # Close the token provider and kill any background operations
614
+ # This just invokes the close method on the actor which should do the cleanup
615
+ sig { returns(T.untyped) }
616
+ def close; end
617
+
618
+ # Get the current access token
619
+ #
620
+ # _@return_ — The current access token
621
+ sig { params(force: T::Boolean).returns(String) }
622
+ def get_token(force: false); end
623
+
624
+ # Actor for managing the token refresh
625
+ # This is designed to be used with Async::Actor and run on a dedicated thread.
626
+ class Actor
627
+ # _@param_ `origin` — The origin of the OAuth server
628
+ #
629
+ # _@param_ `audience` — The OAuth Audience for the token
630
+ #
631
+ # _@param_ `client_secret` — The StatelyDB client secret credential
632
+ #
633
+ # _@param_ `client_id` — The StatelyDB client ID credential
634
+ sig do
635
+ params(
636
+ origin: String,
637
+ audience: String,
638
+ client_secret: String,
639
+ client_id: String
640
+ ).void
641
+ end
642
+ def initialize(origin:, audience:, client_secret:, client_id:); end
643
+
644
+ # Initialize the actor. This runs on the actor thread which means
645
+ # we can dispatch async operations here.
646
+ sig { returns(T.untyped) }
647
+ def init; end
648
+
649
+ # Close the token provider and kill any background operations
650
+ sig { returns(T.untyped) }
651
+ def close; end
652
+
653
+ # Get the current access token
654
+ #
655
+ # _@param_ `force` — Whether to force a refresh of the token
656
+ #
657
+ # _@return_ — The current access token
658
+ sig { params(force: T::Boolean).returns(String) }
659
+ def get_token(force: false); end
660
+
661
+ # Get the current access token and whether it is valid
662
+ #
663
+ # _@return_ — The current access token and whether it is valid
664
+ sig { returns(T::Array[T.untyped]) }
665
+ def valid_access_token; end
666
+
667
+ # Refresh the access token
668
+ #
669
+ # _@return_ — A task that will resolve to the new access token
670
+ sig { returns(Task) }
671
+ def refresh_token; end
672
+
673
+ # Refresh the access token implementation
674
+ #
675
+ # _@return_ — The new access token
676
+ sig { returns(String) }
677
+ def refresh_token_impl; end
678
+
679
+ sig { returns(T.untyped) }
680
+ def make_auth0_request; end
681
+ end
682
+ end
683
+ end
684
+
685
+ # GRPC interceptor to convert errors to StatelyDB::Error
686
+ class ErrorInterceptor < GRPC::ClientInterceptor
687
+ # client unary interceptor
688
+ sig do
689
+ params(
690
+ request: T.untyped,
691
+ call: T.untyped,
692
+ method: T.untyped,
693
+ metadata: T.untyped
694
+ ).returns(T.untyped)
695
+ end
696
+ def request_response(request:, call:, method:, metadata:); end
697
+
698
+ # client streaming interceptor
699
+ sig do
700
+ params(
701
+ requests: T.untyped,
702
+ call: T.untyped,
703
+ method: T.untyped,
704
+ metadata: T.untyped
705
+ ).returns(T.untyped)
706
+ end
707
+ def client_streamer(requests:, call:, method:, metadata:); end
708
+
709
+ # server streaming interceptor
710
+ sig do
711
+ params(
712
+ request: T.untyped,
713
+ call: T.untyped,
714
+ method: T.untyped,
715
+ metadata: T.untyped
716
+ ).returns(T.untyped)
717
+ end
718
+ def server_streamer(request:, call:, method:, metadata:); end
719
+
720
+ # bidirectional streaming interceptor
721
+ sig do
722
+ params(
723
+ requests: T.untyped,
724
+ call: T.untyped,
725
+ method: T.untyped,
726
+ metadata: T.untyped
727
+ ).returns(T.untyped)
728
+ end
729
+ def bidi_streamer(requests:, call:, method:, metadata:); end
730
+ end
731
+ end
732
+
733
+ module Transaction
734
+ # TransactionQueue is a wrapper around Thread::Queue that implements Enumerable
735
+ class Queue < Thread::Queue
736
+ sig { void }
737
+ def initialize; end
738
+
739
+ # next_message_id returns the next message ID, which is the current size of the queue + 1.
740
+ # This value is consumed by the StatelyDB transaction as a monotonically increasing MessageID.
741
+ sig { returns(Integer) }
742
+ def next_message_id; end
743
+
744
+ # Iterates over each element in the queue, yielding each element to the given block.
745
+ sig { void }
746
+ def each; end
747
+
748
+ # Iterates over each item in the queue, yielding each item to the given block.
749
+ sig { void }
750
+ def each_item; end
751
+
752
+ # _@return_ — The ID of the last message, or nil if there is no message.
753
+ sig { returns(T.nilable(Integer)) }
754
+ attr_reader :last_message_id
755
+ end
756
+
757
+ # Transaction coordinates sending requests and waiting for responses. Consumers should not need
758
+ # to interact with this class directly, but instead use the methods provided by the StatelyDB::CoreClient.
759
+ #
760
+ # The example below demonstrates using a transaction, which accepts a block. The lines in the block
761
+ # are executed within the context of the transaction. The transaction is committed when the block
762
+ # completes successfully, OR is aborted if an exception is raised.
763
+ #
764
+ # @example
765
+ # result = client.transaction do |tx|
766
+ # key_path = StatelyDB::KeyPath.with('movie', 'The Shining')
767
+ # movie = tx.get(key_path:)
768
+ # tx.put(item: movie)
769
+ # end
770
+ class Transaction
771
+ # Initialize a new Transaction
772
+ #
773
+ # _@param_ `stub` — a StatelyDB gRPC stub
774
+ #
775
+ # _@param_ `store_id` — the StatelyDB Store to transact against
776
+ #
777
+ # _@param_ `schema` — the schema to use for marshalling and unmarshalling Items
778
+ sig { params(stub: Stately::Db::DatabaseService::Stub, store_id: Integer, schema: StatelyDB::Schema).void }
779
+ def initialize(stub:, store_id:, schema:); end
780
+
781
+ # Send a request and wait for a response
782
+ #
783
+ # _@param_ `req` — the request to send
784
+ #
785
+ # _@return_ — the response
786
+ sig { params(req: Stately::Db::TransactionRequest).returns(Stately::Db::TransactionResponse) }
787
+ def request_response(req); end
788
+
789
+ # Send a request and don't wait for a response
790
+ #
791
+ # _@param_ `req` — the request to send
792
+ #
793
+ # _@return_ — nil
794
+ sig { params(req: Stately::Db::TransactionRequest).void }
795
+ def request_only(req); end
796
+
797
+ # Send a request and process all responses, until we receive a finished message. This is used for list operations.
798
+ # Each response is processed by the block passed to this method, and the response for this method is a token.
799
+ #
800
+ # _@param_ `req` — the request to send
801
+ #
802
+ # _@return_ — the token
803
+ #
804
+ # ```ruby
805
+ # request_list_responses(req) do |resp|
806
+ # resp.result.items.each do |result|
807
+ # puts result.item.key_path
808
+ # end
809
+ # ```
810
+ sig { params(req: Stately::Db::TransactionRequest, blk: T.proc.params(resp: Stately::Db::TransactionListResponse).void).returns(Stately::Db::ListToken) }
811
+ def request_list_responses(req, &blk); end
812
+
813
+ # Begin a transaction. Begin is called implicitly when the block passed to transaction is called.
814
+ #
815
+ # _@return_ — nil
816
+ sig { void }
817
+ def begin; end
818
+
819
+ # Commit a transaction. Commit is called implicitly when the block passed to transaction completes.
820
+ sig { returns(StatelyDB::Transaction::Transaction::Result) }
821
+ def commit; end
822
+
823
+ # Abort a transaction. Abort is called implicitly if an exception is raised within the block passed to transaction.
824
+ sig { returns(Stately::Db::TransactionResponse) }
825
+ def abort; end
826
+
827
+ # Check if a transaction is open. A transaction is open if begin has been called and commit or abort has not been called.
828
+ #
829
+ # _@return_ — true if a transaction is open
830
+ sig { returns(T::Boolean) }
831
+ def open?; end
832
+
833
+ # Fetch Items from a StatelyDB Store at the given key_path. Note that Items need to exist before being retrieved inside a
834
+ # transaction.
835
+ #
836
+ # _@param_ `key_path` — the path to the item
837
+ #
838
+ # _@return_ — the item or nil if not found
839
+ #
840
+ # ```ruby
841
+ # client.data.transaction do |txn|
842
+ # item = txn.get("/ItemType-identifier")
843
+ # end
844
+ # ```
845
+ sig { params(key_path: String).returns(T.any(StatelyDB::Item, NilClass)) }
846
+ def get(key_path); end
847
+
848
+ # Fetch a batch of up to 100 Items from a StatelyDB Store at the given
849
+ # key_paths. Note that Items need to exist before being retrieved inside a
850
+ # transaction.
851
+ #
852
+ # key paths.
853
+ # Example:
854
+ # client.data.transaction do |txn|
855
+ # items = txn.get_batch("/foo", "/bar")
856
+ # end
857
+ #
858
+ # _@param_ `key_paths` — the paths to the items. Max 100
859
+ #
860
+ # _@return_ — the items
861
+ sig { params(key_paths: T.any(String, T::Array[String])).returns(T::Array[StatelyDB::Item]) }
862
+ def get_batch(*key_paths); end
863
+
864
+ # Put a single Item into a StatelyDB store. Results are not returned until the transaction is
865
+ # committed and will be available in the Result object returned by commit. An identifier for
866
+ # the item will be returned while inside the transaction block.
867
+ #
868
+ # results.puts.each do |result|
869
+ # puts result.key_path
870
+ # end
871
+ #
872
+ # _@param_ `item` — the item to store
873
+ #
874
+ # _@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.
875
+ #
876
+ # _@return_ — the id of the item
877
+ #
878
+ # ```ruby
879
+ # results = client.data.transaction do |txn|
880
+ # txn.put(my_item)
881
+ # end
882
+ # ```
883
+ sig { params(item: StatelyDB::Item, must_not_exist: T::Boolean).returns(T.any(String, Integer)) }
884
+ def put(item, must_not_exist: false); end
885
+
886
+ # Put a batch of up to 50 Items into a StatelyDB Store. Results are not
887
+ # returned until the transaction is committed and will be available in the
888
+ # Result object returned by commit. A list of identifiers for the items
889
+ # will be returned while inside the transaction block.
890
+ #
891
+ # 50 items.
892
+ # results.puts.each do |result|
893
+ # puts result.key_path
894
+ # end
895
+ #
896
+ # _@param_ `items` — the items to store. Max
897
+ #
898
+ # _@return_ — the ids of the items
899
+ #
900
+ # ```ruby
901
+ # results = client.data.transaction do |txn|
902
+ # txn.put_batch(item1, item2)
903
+ # end
904
+ # ```
905
+ sig { params(items: T.any(StatelyDB::Item, T::Array[StatelyDB::Item])).returns(T::Array[T.any(StatelyDB::UUID, String, Integer, NilClass)]) }
906
+ def put_batch(*items); end
907
+
908
+ # Delete up to 50 Items from a StatelyDB Store at the given key_paths. Results are not returned until the transaction is
909
+ # committed and will be available in the Result object returned by commit.
910
+ #
911
+ # Example:
912
+ # client.data.transaction do |txn|
913
+ # txn.delete("/ItemType-identifier", "/ItemType-identifier2")
914
+ # end
915
+ #
916
+ # _@param_ `key_paths` — the paths to the items. Max 50 key paths.
917
+ #
918
+ # _@return_ — nil
919
+ sig { params(key_paths: T.any(String, T::Array[String])).void }
920
+ def delete(*key_paths); end
921
+
922
+ # Begin listing Items from a StatelyDB Store at the given prefix.
923
+ #
924
+ # Example:
925
+ # client.data.transaction do |txn|
926
+ # (items, token) = txn.begin_list("/ItemType-identifier")
927
+ # (items, token) = txn.continue_list(token)
928
+ # end
929
+ #
930
+ # _@param_ `prefix` — the prefix to list
931
+ #
932
+ # _@param_ `limit` — the maximum number of items to return
933
+ #
934
+ # _@param_ `sort_property` — the property to sort by
935
+ #
936
+ # _@param_ `sort_direction` — the direction to sort by (:ascending or :descending)
937
+ #
938
+ # _@return_ — the list of Items and the token
939
+ sig do
940
+ params(
941
+ prefix: String,
942
+ limit: Integer,
943
+ sort_property: T.nilable(String),
944
+ sort_direction: Symbol
945
+ ).returns([T::Array[StatelyDB::Item], Stately::Db::ListToken])
946
+ end
947
+ def begin_list(prefix, limit: 100, sort_property: nil, sort_direction: :ascending); end
948
+
949
+ # Continue listing Items from a StatelyDB Store using a token.
950
+ #
951
+ # Example:
952
+ # client.data.transaction do |txn|
953
+ # (items, token) = txn.begin_list("/foo")
954
+ # (items, token) = txn.continue_list(token)
955
+ # end
956
+ #
957
+ # _@param_ `token` — the token to continue from
958
+ #
959
+ # _@param_ `continue_direction` — the direction to continue by (:forward or :backward)
960
+ #
961
+ # _@return_ — the list of Items and the token
962
+ sig { params(token: Stately::Db::ListToken, continue_direction: Symbol).returns([T::Array[StatelyDB::Item], Stately::Db::ListToken]) }
963
+ def continue_list(token, continue_direction: :forward); end
964
+
965
+ # Processes a list response from begin_list or continue_list
966
+ #
967
+ # _@param_ `req` — the request to send
968
+ #
969
+ # _@return_ — the list of Items and the token
970
+ sig { params(req: Stately::Db::TransactionRequest).returns([T::Array[StatelyDB::Item], Stately::Db::ListToken]) }
971
+ def do_list_request_response(req); end
972
+
973
+ # We are using a oneof inside the TransactionRequest to determine the type of request. The ruby
974
+ # generated code does not have a helper for the internal request type so we need to infer it.
975
+ #
976
+ # _@param_ `req` — the request
977
+ #
978
+ # _@return_ — the response type
979
+ sig { params(req: Stately::Db::TransactionRequest).returns(Class) }
980
+ def infer_response_type_from_request(req); end
981
+
982
+ # We are using a oneof inside the TransactionResponse to determine the type of response. The ruby
983
+ # generated code does not have a helper for the internal response type so we need to infer it.
984
+ #
985
+ # _@param_ `resp` — the response
986
+ #
987
+ # _@return_ — the response type
988
+ sig { params(resp: Stately::Db::TransactionResponse).returns(Class) }
989
+ def infer_response_type_from_response(resp); end
990
+
991
+ # Result represents the results of a transaction
992
+ #
993
+ # @attr_reader puts [Array<StatelyDB::Item>] the items that were put
994
+ # @attr_reader deletes [Array<String>] the key paths that were deleted
995
+ class Result
996
+ # Initialize a new Result
997
+ #
998
+ # _@param_ `puts` — the items that were put
999
+ #
1000
+ # _@param_ `deletes` — the key paths that were deleted
1001
+ sig { params(puts: T::Array[StatelyDB::Item], deletes: T::Array[String]).void }
1002
+ def initialize(puts:, deletes:); end
1003
+
1004
+ # puts is an array of StatelyDB::Items that were put
1005
+ sig { returns(T::Array[StatelyDB::Item]) }
1006
+ attr_reader :puts
1007
+
1008
+ # deletes is an array of key paths that were deleted
1009
+ sig { returns(T::Array[String]) }
1010
+ attr_reader :deletes
1011
+ end
1012
+ end
1013
+ end
1014
+ end
1015
+
1016
+ module Stately
1017
+ module Db
1018
+ GetRequest = T.let(::Google::Protobuf::DescriptorPool.generated_pool.lookup("stately.db.GetRequest").msgclass, T.untyped)
1019
+ GetItem = T.let(::Google::Protobuf::DescriptorPool.generated_pool.lookup("stately.db.GetItem").msgclass, T.untyped)
1020
+ GetResponse = T.let(::Google::Protobuf::DescriptorPool.generated_pool.lookup("stately.db.GetResponse").msgclass, T.untyped)
1021
+ PutRequest = T.let(::Google::Protobuf::DescriptorPool.generated_pool.lookup("stately.db.PutRequest").msgclass, T.untyped)
1022
+ PutItem = T.let(::Google::Protobuf::DescriptorPool.generated_pool.lookup("stately.db.PutItem").msgclass, T.untyped)
1023
+ PutResponse = T.let(::Google::Protobuf::DescriptorPool.generated_pool.lookup("stately.db.PutResponse").msgclass, T.untyped)
1024
+ Item = T.let(::Google::Protobuf::DescriptorPool.generated_pool.lookup("stately.db.Item").msgclass, T.untyped)
1025
+ BeginListRequest = T.let(::Google::Protobuf::DescriptorPool.generated_pool.lookup("stately.db.BeginListRequest").msgclass, T.untyped)
1026
+ ListResponse = T.let(::Google::Protobuf::DescriptorPool.generated_pool.lookup("stately.db.ListResponse").msgclass, T.untyped)
1027
+ ListPartialResult = T.let(::Google::Protobuf::DescriptorPool.generated_pool.lookup("stately.db.ListPartialResult").msgclass, T.untyped)
1028
+ ListFinished = T.let(::Google::Protobuf::DescriptorPool.generated_pool.lookup("stately.db.ListFinished").msgclass, T.untyped)
1029
+ SortDirection = T.let(::Google::Protobuf::DescriptorPool.generated_pool.lookup("stately.db.SortDirection").enummodule, T.untyped)
1030
+ DeleteRequest = T.let(::Google::Protobuf::DescriptorPool.generated_pool.lookup("stately.db.DeleteRequest").msgclass, T.untyped)
1031
+ DeleteItem = T.let(::Google::Protobuf::DescriptorPool.generated_pool.lookup("stately.db.DeleteItem").msgclass, T.untyped)
1032
+ DeleteResult = T.let(::Google::Protobuf::DescriptorPool.generated_pool.lookup("stately.db.DeleteResult").msgclass, T.untyped)
1033
+ DeleteResponse = T.let(::Google::Protobuf::DescriptorPool.generated_pool.lookup("stately.db.DeleteResponse").msgclass, T.untyped)
1034
+ SyncListRequest = T.let(::Google::Protobuf::DescriptorPool.generated_pool.lookup("stately.db.SyncListRequest").msgclass, T.untyped)
1035
+ SyncListResponse = T.let(::Google::Protobuf::DescriptorPool.generated_pool.lookup("stately.db.SyncListResponse").msgclass, T.untyped)
1036
+ SyncListReset = T.let(::Google::Protobuf::DescriptorPool.generated_pool.lookup("stately.db.SyncListReset").msgclass, T.untyped)
1037
+ SyncListPartialResponse = T.let(::Google::Protobuf::DescriptorPool.generated_pool.lookup("stately.db.SyncListPartialResponse").msgclass, T.untyped)
1038
+ DeletedItem = T.let(::Google::Protobuf::DescriptorPool.generated_pool.lookup("stately.db.DeletedItem").msgclass, T.untyped)
1039
+ ListToken = T.let(::Google::Protobuf::DescriptorPool.generated_pool.lookup("stately.db.ListToken").msgclass, T.untyped)
1040
+ TransactionRequest = T.let(::Google::Protobuf::DescriptorPool.generated_pool.lookup("stately.db.TransactionRequest").msgclass, T.untyped)
1041
+ TransactionResponse = T.let(::Google::Protobuf::DescriptorPool.generated_pool.lookup("stately.db.TransactionResponse").msgclass, T.untyped)
1042
+ TransactionBegin = T.let(::Google::Protobuf::DescriptorPool.generated_pool.lookup("stately.db.TransactionBegin").msgclass, T.untyped)
1043
+ TransactionGet = T.let(::Google::Protobuf::DescriptorPool.generated_pool.lookup("stately.db.TransactionGet").msgclass, T.untyped)
1044
+ TransactionBeginList = T.let(::Google::Protobuf::DescriptorPool.generated_pool.lookup("stately.db.TransactionBeginList").msgclass, T.untyped)
1045
+ TransactionContinueList = T.let(::Google::Protobuf::DescriptorPool.generated_pool.lookup("stately.db.TransactionContinueList").msgclass, T.untyped)
1046
+ TransactionPut = T.let(::Google::Protobuf::DescriptorPool.generated_pool.lookup("stately.db.TransactionPut").msgclass, T.untyped)
1047
+ TransactionDelete = T.let(::Google::Protobuf::DescriptorPool.generated_pool.lookup("stately.db.TransactionDelete").msgclass, T.untyped)
1048
+ TransactionGetResponse = T.let(::Google::Protobuf::DescriptorPool.generated_pool.lookup("stately.db.TransactionGetResponse").msgclass, T.untyped)
1049
+ GeneratedID = T.let(::Google::Protobuf::DescriptorPool.generated_pool.lookup("stately.db.GeneratedID").msgclass, T.untyped)
1050
+ TransactionPutAck = T.let(::Google::Protobuf::DescriptorPool.generated_pool.lookup("stately.db.TransactionPutAck").msgclass, T.untyped)
1051
+ TransactionListResponse = T.let(::Google::Protobuf::DescriptorPool.generated_pool.lookup("stately.db.TransactionListResponse").msgclass, T.untyped)
1052
+ TransactionFinished = T.let(::Google::Protobuf::DescriptorPool.generated_pool.lookup("stately.db.TransactionFinished").msgclass, T.untyped)
1053
+ ContinueListRequest = T.let(::Google::Protobuf::DescriptorPool.generated_pool.lookup("stately.db.ContinueListRequest").msgclass, T.untyped)
1054
+ ContinueListDirection = T.let(::Google::Protobuf::DescriptorPool.generated_pool.lookup("stately.db.ContinueListDirection").enummodule, T.untyped)
1055
+ SortableProperty = T.let(::Google::Protobuf::DescriptorPool.generated_pool.lookup("stately.db.SortableProperty").enummodule, T.untyped)
1056
+ ScanRootPathsRequest = T.let(::Google::Protobuf::DescriptorPool.generated_pool.lookup("stately.db.ScanRootPathsRequest").msgclass, T.untyped)
1057
+ ScanRootPathsResponse = T.let(::Google::Protobuf::DescriptorPool.generated_pool.lookup("stately.db.ScanRootPathsResponse").msgclass, T.untyped)
1058
+ ScanRootPathResult = T.let(::Google::Protobuf::DescriptorPool.generated_pool.lookup("stately.db.ScanRootPathResult").msgclass, T.untyped)
1059
+
1060
+ module DatabaseService
1061
+ Stub = T.let(Service.rpc_stub_class, T.untyped)
1062
+
1063
+ # DatabaseService is the service for creating, reading, updating and deleting data
1064
+ # in a StatelyDB Store. Creating and modifying Stores is done by
1065
+ # stately.dbmanagement.ManagementService.
1066
+ class Service
1067
+ include GRPC::GenericService
1068
+ end
1069
+ end
1070
+ end
1071
+
1072
+ module Errors
1073
+ StatelyErrorDetails = T.let(::Google::Protobuf::DescriptorPool.generated_pool.lookup("stately.errors.StatelyErrorDetails").msgclass, T.untyped)
1074
+ end
1075
+ end
1076
+
1077
+ module StatelyCode
1078
+ CACHED_SCHEMA_TOO_OLD = T.let("CachedSchemaTooOld", T.untyped)
1079
+ CONCURRENT_MODIFICATION = T.let("ConcurrentModification", T.untyped)
1080
+ CONDITIONAL_CHECK_FAILED = T.let("ConditionalCheckFailed", T.untyped)
1081
+ NON_RECOVERABLE_TRANSACTION = T.let("NonRecoverableTransaction", T.untyped)
1082
+ STORE_IN_USE = T.let("StoreInUse", T.untyped)
1083
+ STORE_REQUEST_LIMIT_EXCEEDED = T.let("StoreRequestLimitExceeded", T.untyped)
1084
+ STORE_THROUGHPUT_EXCEEDED = T.let("StoreThroughputExceeded", T.untyped)
1085
+ end