statelydb 0.34.0 → 0.35.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/api/db/service_pb.rb +1 -1
- data/lib/enum.rb +144 -0
- data/lib/key_path.rb +3 -1
- data/lib/statelydb.rb +1 -1
- data/lib/version.rb +2 -1
- data/rbi/statelydb.rbi +142 -10
- data/sig/statelydb.rbs +129 -11
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4b6f724702d4e1c401fc77cad630c2ae1421e4ba4c1ff6918b55d3d5c8a48caa
|
4
|
+
data.tar.gz: e8fed1cbf6031edfdeac07cd31a168d31952655a2cc4cdc2e86ec38db9767a83
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 10386b0674c297ed70e33917792d13eb747721b5dd74041a65e2d3c00e5bd49f118a5d61812266c2fc24c3421f40f5e7504aac9eb6d686502f313c30fae99811
|
7
|
+
data.tar.gz: 77fc630f3658052d89ad6f2b7f627b44fc9da01436dce38c688a60fbb4a041af669980f49f6e68ad2163ba8424790a756ecef0c6e70dabf355e3e5c8bc71eaf8
|
data/lib/api/db/service_pb.rb
CHANGED
@@ -15,7 +15,7 @@ require 'api/db/sync_list_pb'
|
|
15
15
|
require 'api/db/transaction_pb'
|
16
16
|
|
17
17
|
|
18
|
-
descriptor_data = "\n\x10\x64\x62/service.proto\x12\nstately.db\x1a\x16\x64\x62/continue_list.proto\x1a\x16\x64\x62/continue_scan.proto\x1a\x0f\x64\x62/delete.proto\x1a\x0c\x64\x62/get.proto\x1a\rdb/list.proto\x1a\x0c\x64\x62/put.proto\x1a\rdb/scan.proto\x1a\x12\x64\x62/sync_list.proto\x1a\x14\x64\x62/transaction.proto2\
|
18
|
+
descriptor_data = "\n\x10\x64\x62/service.proto\x12\nstately.db\x1a\x16\x64\x62/continue_list.proto\x1a\x16\x64\x62/continue_scan.proto\x1a\x0f\x64\x62/delete.proto\x1a\x0c\x64\x62/get.proto\x1a\rdb/list.proto\x1a\x0c\x64\x62/put.proto\x1a\rdb/scan.proto\x1a\x12\x64\x62/sync_list.proto\x1a\x14\x64\x62/transaction.proto2\xaf\x05\n\x0f\x44\x61tabaseService\x12;\n\x03Put\x12\x16.stately.db.PutRequest\x1a\x17.stately.db.PutResponse\"\x03\x90\x02\x02\x12;\n\x03Get\x12\x16.stately.db.GetRequest\x1a\x17.stately.db.GetResponse\"\x03\x90\x02\x01\x12\x44\n\x06\x44\x65lete\x12\x19.stately.db.DeleteRequest\x1a\x1a.stately.db.DeleteResponse\"\x03\x90\x02\x02\x12J\n\tBeginList\x12\x1c.stately.db.BeginListRequest\x1a\x18.stately.db.ListResponse\"\x03\x90\x02\x01\x30\x01\x12P\n\x0c\x43ontinueList\x12\x1f.stately.db.ContinueListRequest\x1a\x18.stately.db.ListResponse\"\x03\x90\x02\x01\x30\x01\x12J\n\tBeginScan\x12\x1c.stately.db.BeginScanRequest\x1a\x18.stately.db.ListResponse\"\x03\x90\x02\x01\x30\x01\x12P\n\x0c\x43ontinueScan\x12\x1f.stately.db.ContinueScanRequest\x1a\x18.stately.db.ListResponse\"\x03\x90\x02\x01\x30\x01\x12L\n\x08SyncList\x12\x1b.stately.db.SyncListRequest\x1a\x1c.stately.db.SyncListResponse\"\x03\x90\x02\x01\x30\x01\x12R\n\x0bTransaction\x12\x1e.stately.db.TransactionRequest\x1a\x1f.stately.db.TransactionResponse(\x01\x30\x01\x42g\n\x0e\x63om.stately.dbB\x0cServiceProtoP\x01\xa2\x02\x03SDX\xaa\x02\nStately.Db\xca\x02\nStately\\Db\xe2\x02\x16Stately\\Db\\GPBMetadata\xea\x02\x0bStately::Dbb\x06proto3"
|
19
19
|
|
20
20
|
pool = ::Google::Protobuf::DescriptorPool.generated_pool
|
21
21
|
pool.add_serialized_file(descriptor_data)
|
data/lib/enum.rb
ADDED
@@ -0,0 +1,144 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "grpc"
|
4
|
+
require "error"
|
5
|
+
|
6
|
+
module StatelyDB
|
7
|
+
# Base class for all Stately enums that supports undefined values
|
8
|
+
# and is forwards compatible with new enum values added in the Stately schema.
|
9
|
+
class StatelyEnum
|
10
|
+
# Check if the current Enum instance is a known enum member from
|
11
|
+
# the set. This will be false for any values that are not defined in the
|
12
|
+
# class definition.
|
13
|
+
#
|
14
|
+
# @return [Boolean] true if this is a known enum value, false for unknown values
|
15
|
+
def known?
|
16
|
+
!@name.start_with?("_")
|
17
|
+
end
|
18
|
+
|
19
|
+
# Compare this enum with another object
|
20
|
+
#
|
21
|
+
# @param other [StatelyDB::StatelyEnum, Integer, Object] the object to compare with
|
22
|
+
# @return [Boolean] true if equal, false otherwise
|
23
|
+
def ==(other)
|
24
|
+
case other
|
25
|
+
when StatelyDB::StatelyEnum
|
26
|
+
@value == other.value
|
27
|
+
when Integer
|
28
|
+
@value == other
|
29
|
+
else
|
30
|
+
false
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
# @param other [Object] the object to compare with
|
35
|
+
# @return [Boolean] true if equal, false otherwise
|
36
|
+
def eql?(other)
|
37
|
+
other.is_a?(self.class) && @value == other.value
|
38
|
+
end
|
39
|
+
|
40
|
+
# @return [Integer] the integer value of this enum
|
41
|
+
def to_i
|
42
|
+
@value
|
43
|
+
end
|
44
|
+
|
45
|
+
# @return [String] string representation of the enum
|
46
|
+
def to_s
|
47
|
+
known? ? @name.to_s : "UnknownEnumValue_(#{@value})"
|
48
|
+
end
|
49
|
+
|
50
|
+
protected
|
51
|
+
|
52
|
+
# @return [Integer] the integer value of this enum
|
53
|
+
attr_reader :value
|
54
|
+
# @return [Symbol, String] the name of this enum value, or a generated string name for unknown values
|
55
|
+
attr_reader :name
|
56
|
+
|
57
|
+
private
|
58
|
+
|
59
|
+
# Initialize a new Enum instance. This is private and should not be called
|
60
|
+
# directly; use the class methods to create instances.
|
61
|
+
# @param value [Integer] the integer value of the enum
|
62
|
+
# @param name [String, Symbol, nil] the name of the enum constant (nil for unknown values)
|
63
|
+
def initialize(value, name = nil)
|
64
|
+
@value = value.to_i
|
65
|
+
@name = name || "_#{@value}"
|
66
|
+
end
|
67
|
+
|
68
|
+
# Ensure @values is initialized for each subclass
|
69
|
+
# @param subclass [Class] the subclass being created
|
70
|
+
# @return [void]
|
71
|
+
def self.inherited(subclass)
|
72
|
+
subclass.instance_variable_set(:@values, {})
|
73
|
+
super
|
74
|
+
end
|
75
|
+
private_class_method :inherited
|
76
|
+
|
77
|
+
# Class methods for enum subclasses
|
78
|
+
class << self
|
79
|
+
# Returns the enum instance for a given string name
|
80
|
+
#
|
81
|
+
# @param str [String] the enum constant name
|
82
|
+
# @return [StatelyDB::StatelyEnum] the enum instance
|
83
|
+
# @raise [StatelyDB::Error] if the enum value is not defined
|
84
|
+
def from_string(str)
|
85
|
+
unless const_defined?(str)
|
86
|
+
raise StatelyDB::Error.new(
|
87
|
+
"Enum value '#{str}' is not defined in #{name}",
|
88
|
+
code: GRPC::Core::StatusCodes::INVALID_ARGUMENT,
|
89
|
+
stately_code: "InvalidArgument"
|
90
|
+
)
|
91
|
+
end
|
92
|
+
|
93
|
+
const_get(str)
|
94
|
+
end
|
95
|
+
|
96
|
+
# Create an enum instance from its integer value.
|
97
|
+
# Returns a known enum if the value is defined, otherwise creates
|
98
|
+
# a new instance for undefined values.
|
99
|
+
#
|
100
|
+
# @param value [Integer] the integer value
|
101
|
+
# @return [StatelyDB::StatelyEnum] the enum instance
|
102
|
+
def new(value)
|
103
|
+
int_value = value.to_i
|
104
|
+
@values[int_value] || super(int_value)
|
105
|
+
end
|
106
|
+
|
107
|
+
# Returns all defined enum values
|
108
|
+
#
|
109
|
+
# @return [Array<StatelyDB::StatelyEnum>] array of all defined enum instances
|
110
|
+
def all
|
111
|
+
@values.values
|
112
|
+
end
|
113
|
+
|
114
|
+
# Unmarshals a Stately proto enum value
|
115
|
+
#
|
116
|
+
# @param value [Integer, Symbol] the proto enum value. This can be an integer
|
117
|
+
# or a symbol depending on whether the proto value is defined for this version.
|
118
|
+
# @return [StatelyDB::StatelyEnum] the enum instance
|
119
|
+
def unmarshal_stately(value)
|
120
|
+
int_value = value.is_a?(Integer) ? value : self::Proto.resolve(value)
|
121
|
+
new(int_value)
|
122
|
+
end
|
123
|
+
|
124
|
+
private
|
125
|
+
|
126
|
+
# Defines a new enum value (used internally by generated code)
|
127
|
+
#
|
128
|
+
# @param name [Symbol] the constant name
|
129
|
+
# @param value [Integer] the integer value
|
130
|
+
# @return [StatelyDB::StatelyEnum] the created enum instance
|
131
|
+
def define_value(name, value)
|
132
|
+
# this basically allows us to bypass `new` which i want to leave as a
|
133
|
+
# public API that only accepts integers to be more consistent with the
|
134
|
+
# other languages. We manually allocate and go straight to the inherited
|
135
|
+
# initialize method where we set the name and value. We know they are
|
136
|
+
# always both defined since this is only called from the generated code.
|
137
|
+
enum_instance = allocate
|
138
|
+
enum_instance.send(:initialize, value, name)
|
139
|
+
@values[value] = enum_instance
|
140
|
+
enum_instance
|
141
|
+
end
|
142
|
+
end
|
143
|
+
end
|
144
|
+
end
|
data/lib/key_path.rb
CHANGED
@@ -38,7 +38,7 @@ module StatelyDB
|
|
38
38
|
|
39
39
|
# Appends a new path segment.
|
40
40
|
# @param namespace [String]
|
41
|
-
# @param identifier [String, StatelyDB::UUID, #to_s]
|
41
|
+
# @param identifier [String, StatelyDB::UUID, StatelyDB::StatelyEnum, #to_s]
|
42
42
|
# @return [StatelyDB::KeyPath]
|
43
43
|
#
|
44
44
|
# @example
|
@@ -55,6 +55,8 @@ module StatelyDB
|
|
55
55
|
def self.to_key_id(value)
|
56
56
|
if value.is_a?(StatelyDB::UUID)
|
57
57
|
value.to_s
|
58
|
+
elsif value.is_a?(StatelyDB::StatelyEnum)
|
59
|
+
value.to_i
|
58
60
|
elsif value.is_a?(String) && value.encoding == Encoding::BINARY
|
59
61
|
[value].pack("m0").tr("=", "").tr("+/", "-_")
|
60
62
|
else
|
data/lib/statelydb.rb
CHANGED
@@ -16,6 +16,7 @@ require "error"
|
|
16
16
|
require "key_path"
|
17
17
|
require "token"
|
18
18
|
require "uuid"
|
19
|
+
require "enum"
|
19
20
|
|
20
21
|
# StatelyDB -- the home of all StatelyDB Ruby SDK classes and modules.
|
21
22
|
module StatelyDB
|
@@ -173,7 +174,6 @@ module StatelyDB
|
|
173
174
|
# specified value based on lexicographic ordering.
|
174
175
|
# @param lte [StatelyDB::KeyPath, String] filters results to only include items with a key less than or equal to the
|
175
176
|
# specified value based on lexicographic ordering.
|
176
|
-
|
177
177
|
# @return [Array<StatelyDB::Item>, StatelyDB::Token] the list of Items and the token
|
178
178
|
#
|
179
179
|
# @example
|
data/lib/version.rb
CHANGED
data/rbi/statelydb.rbi
CHANGED
@@ -1,6 +1,107 @@
|
|
1
1
|
# typed: strong
|
2
2
|
# A module for Stately Cloud auth code
|
3
3
|
module StatelyDB
|
4
|
+
# Base class for all Stately enums that supports undefined values
|
5
|
+
# and is forwards compatible with new enum values added in the Stately schema.
|
6
|
+
class StatelyEnum
|
7
|
+
# Check if the current Enum instance is a known enum member from
|
8
|
+
# the set. This will be false for any values that are not defined in the
|
9
|
+
# class definition.
|
10
|
+
#
|
11
|
+
# _@return_ — true if this is a known enum value, false for unknown values
|
12
|
+
sig { returns(T::Boolean) }
|
13
|
+
def known?; end
|
14
|
+
|
15
|
+
# Compare this enum with another object
|
16
|
+
#
|
17
|
+
# _@param_ `other` — the object to compare with
|
18
|
+
#
|
19
|
+
# _@return_ — true if equal, false otherwise
|
20
|
+
sig { params(other: T.any(StatelyDB::StatelyEnum, Integer, Object)).returns(T::Boolean) }
|
21
|
+
def ==(other); end
|
22
|
+
|
23
|
+
# _@param_ `other` — the object to compare with
|
24
|
+
#
|
25
|
+
# _@return_ — true if equal, false otherwise
|
26
|
+
sig { params(other: Object).returns(T::Boolean) }
|
27
|
+
def eql?(other); end
|
28
|
+
|
29
|
+
# _@return_ — the integer value of this enum
|
30
|
+
sig { returns(Integer) }
|
31
|
+
def to_i; end
|
32
|
+
|
33
|
+
# _@return_ — string representation of the enum
|
34
|
+
sig { returns(String) }
|
35
|
+
def to_s; end
|
36
|
+
|
37
|
+
# Initialize a new Enum instance. This is private and should not be called
|
38
|
+
# directly; use the class methods to create instances.
|
39
|
+
#
|
40
|
+
# _@param_ `value` — the integer value of the enum
|
41
|
+
#
|
42
|
+
# _@param_ `name` — the name of the enum constant (nil for unknown values)
|
43
|
+
sig { params(value: Integer, name: T.nilable(T.any(String, Symbol))).void }
|
44
|
+
def initialize(value, name = nil); end
|
45
|
+
|
46
|
+
# Ensure @values is initialized for each subclass
|
47
|
+
#
|
48
|
+
# _@param_ `subclass` — the subclass being created
|
49
|
+
sig { params(subclass: T::Class[T.anything]).void }
|
50
|
+
def self.inherited(subclass); end
|
51
|
+
|
52
|
+
# Returns the enum instance for a given string name
|
53
|
+
#
|
54
|
+
# _@param_ `str` — the enum constant name
|
55
|
+
#
|
56
|
+
# _@return_ — the enum instance
|
57
|
+
sig { params(str: String).returns(StatelyDB::StatelyEnum) }
|
58
|
+
def self.from_string(str); end
|
59
|
+
|
60
|
+
# Create an enum instance from its integer value.
|
61
|
+
# Returns a known enum if the value is defined, otherwise creates
|
62
|
+
# a new instance for undefined values.
|
63
|
+
#
|
64
|
+
# _@param_ `value` — the integer value
|
65
|
+
#
|
66
|
+
# _@return_ — the enum instance
|
67
|
+
sig { params(value: Integer).returns(StatelyDB::StatelyEnum) }
|
68
|
+
def self.new(value); end
|
69
|
+
|
70
|
+
# Returns all defined enum values
|
71
|
+
#
|
72
|
+
# _@return_ — array of all defined enum instances
|
73
|
+
sig { returns(T::Array[StatelyDB::StatelyEnum]) }
|
74
|
+
def self.all; end
|
75
|
+
|
76
|
+
# Unmarshals a Stately proto enum value
|
77
|
+
#
|
78
|
+
# or a symbol depending on whether the proto value is defined for this version.
|
79
|
+
#
|
80
|
+
# _@param_ `value` — the proto enum value. This can be an integer
|
81
|
+
#
|
82
|
+
# _@return_ — the enum instance
|
83
|
+
sig { params(value: T.any(Integer, Symbol)).returns(StatelyDB::StatelyEnum) }
|
84
|
+
def self.unmarshal_stately(value); end
|
85
|
+
|
86
|
+
# Defines a new enum value (used internally by generated code)
|
87
|
+
#
|
88
|
+
# _@param_ `name` — the constant name
|
89
|
+
#
|
90
|
+
# _@param_ `value` — the integer value
|
91
|
+
#
|
92
|
+
# _@return_ — the created enum instance
|
93
|
+
sig { params(name: Symbol, value: Integer).returns(StatelyDB::StatelyEnum) }
|
94
|
+
def self.define_value(name, value); end
|
95
|
+
|
96
|
+
# _@return_ — the integer value of this enum
|
97
|
+
sig { returns(Integer) }
|
98
|
+
attr_reader :value
|
99
|
+
|
100
|
+
# _@return_ — the name of this enum value, or a generated string name for unknown values
|
101
|
+
sig { returns(T.any(Symbol, String)) }
|
102
|
+
attr_reader :name
|
103
|
+
end
|
104
|
+
|
4
105
|
# UUID is a helper class for working with UUIDs in StatelyDB. The ruby version of a StatelyDB is a binary string,
|
5
106
|
# and this class provides convenience methods for converting to the base16 representation specified in RFC 9562.
|
6
107
|
# Internally this class uses the byte_string attribute to store the UUID as a string with the Encoding::ASCII_8BIT
|
@@ -179,7 +280,7 @@ module StatelyDB
|
|
179
280
|
# ```ruby
|
180
281
|
# keypath = KeyPath.with("genres", "rock").with("artists", "the-beatles")
|
181
282
|
# ```
|
182
|
-
sig { params(namespace: String, identifier: T.nilable(T.any(String, StatelyDB::UUID, T.untyped))).returns(StatelyDB::KeyPath) }
|
283
|
+
sig { params(namespace: String, identifier: T.nilable(T.any(String, StatelyDB::UUID, StatelyDB::StatelyEnum, T.untyped))).returns(StatelyDB::KeyPath) }
|
183
284
|
def self.with(namespace, identifier = nil); end
|
184
285
|
|
185
286
|
# If the value is a binary string, encode it as a url-safe
|
@@ -267,6 +368,37 @@ module StatelyDB
|
|
267
368
|
sig { params(key_paths: T.any(StatelyDB::KeyPath, String, T::Array[T.any(StatelyDB::KeyPath, String)])).returns(T::Array[StatelyDB::Item]) }
|
268
369
|
def get_batch(*key_paths); end
|
269
370
|
|
371
|
+
# begin_list retrieves Items that start with a specified key_path_prefix
|
372
|
+
# from a single Group. Because it can only list items from a single Group,
|
373
|
+
# the key path prefix must at least start with a full Group Key (a single
|
374
|
+
# key segment with a namespace and an ID, e.g. `/user-1234`).
|
375
|
+
#
|
376
|
+
# begin_list will return an empty result set if there are no items matching
|
377
|
+
# that key prefix. This API returns a token that you can pass to
|
378
|
+
# continue_list to expand the result set, or to sync_list to get updates
|
379
|
+
# within the result set.
|
380
|
+
#
|
381
|
+
# You can list items of different types in a single begin_list, and you can
|
382
|
+
# use `isinstance` to handle different item types.
|
383
|
+
#
|
384
|
+
# _@param_ `prefix` — The key path prefix to query for. It must be at least a full Group Key (e.g. `/user-1234`).
|
385
|
+
#
|
386
|
+
# _@param_ `limit` — The max number of items to retrieve. If set to 0 then the full set will be returned. Defaults to 0.
|
387
|
+
#
|
388
|
+
# _@param_ `sort_direction` — the direction to sort by (:ascending or :descending, default is :ascending).
|
389
|
+
#
|
390
|
+
# _@param_ `item_types` — the item types to filter by. The returned items will be instances of one of these types.
|
391
|
+
#
|
392
|
+
# _@param_ `cel_filters` — ] An optional list of item_type, cel_expression tuples that represent CEL expressions to filter the results set by. Use the cel_filter helper function to build these expressions. CEL expressions are only evaluated for the item type they are defined for, and do not affect other item types in the result set. This means if an item type has no CEL filter and there are no item_type filters constraints, it will be included in the result set. In the context of a CEL expression, the key-word `this` refers to the item being evaluated, and property properties should be accessed by the names as they appear in schema -- not necessarily as they appear in the generated code for a particular language. For example, if you have a `Movie` item type with the property `rating`, you could write a CEL expression like `this.rating == 'R'` to return only movies that are rated `R`. Find the full CEL language definition here: https://github.com/google/cel-spec/blob/master/doc/langdef.md
|
393
|
+
#
|
394
|
+
# _@param_ `gt` — filters results to only include items with a key greater than the specified value based on lexicographic ordering.
|
395
|
+
#
|
396
|
+
# _@param_ `gte` — filters results to only include items with a key greater than or equal to the specified value based on lexicographic ordering.
|
397
|
+
#
|
398
|
+
# _@param_ `lt` — filters results to only include items with a key less than the specified value based on lexicographic ordering.
|
399
|
+
#
|
400
|
+
# _@param_ `lte` — filters results to only include items with a key less than or equal to the specified value based on lexicographic ordering.
|
401
|
+
#
|
270
402
|
# _@return_ — the list of Items and the token
|
271
403
|
#
|
272
404
|
# ```ruby
|
@@ -274,15 +406,15 @@ module StatelyDB
|
|
274
406
|
# ```
|
275
407
|
sig do
|
276
408
|
params(
|
277
|
-
prefix: T.
|
278
|
-
limit:
|
279
|
-
sort_direction: T.
|
280
|
-
item_types: T.
|
281
|
-
cel_filters: T.
|
282
|
-
gt: T.
|
283
|
-
gte: T.
|
284
|
-
lt: T.
|
285
|
-
lte: T.
|
409
|
+
prefix: T.any(StatelyDB::KeyPath, String),
|
410
|
+
limit: Integer,
|
411
|
+
sort_direction: T.any(Symbol, String, Integer),
|
412
|
+
item_types: T::Array[T.any(T.class_of(StatelyDB::Item), String)],
|
413
|
+
cel_filters: T::Array[T.any(T::Array[T.any(T::Class[T.anything], String)], String)],
|
414
|
+
gt: T.nilable(T.any(StatelyDB::KeyPath, String)),
|
415
|
+
gte: T.nilable(T.any(StatelyDB::KeyPath, String)),
|
416
|
+
lt: T.nilable(T.any(StatelyDB::KeyPath, String)),
|
417
|
+
lte: T.nilable(T.any(StatelyDB::KeyPath, String))
|
286
418
|
).returns(T.any(T::Array[StatelyDB::Item], StatelyDB::Token))
|
287
419
|
end
|
288
420
|
def begin_list(prefix, limit: 100, sort_direction: :ascending, item_types: [], cel_filters: [], gt: nil, gte: nil, lt: nil, lte: nil); end
|
data/sig/statelydb.rbs
CHANGED
@@ -1,6 +1,93 @@
|
|
1
1
|
# A module for Stately Cloud auth code
|
2
2
|
module StatelyDB
|
3
|
-
VERSION:
|
3
|
+
VERSION: String
|
4
|
+
|
5
|
+
# Base class for all Stately enums that supports undefined values
|
6
|
+
# and is forwards compatible with new enum values added in the Stately schema.
|
7
|
+
class StatelyEnum
|
8
|
+
# Check if the current Enum instance is a known enum member from
|
9
|
+
# the set. This will be false for any values that are not defined in the
|
10
|
+
# class definition.
|
11
|
+
#
|
12
|
+
# _@return_ — true if this is a known enum value, false for unknown values
|
13
|
+
def known?: () -> bool
|
14
|
+
|
15
|
+
# Compare this enum with another object
|
16
|
+
#
|
17
|
+
# _@param_ `other` — the object to compare with
|
18
|
+
#
|
19
|
+
# _@return_ — true if equal, false otherwise
|
20
|
+
def ==: ((StatelyDB::StatelyEnum | Integer | Object) other) -> bool
|
21
|
+
|
22
|
+
# _@param_ `other` — the object to compare with
|
23
|
+
#
|
24
|
+
# _@return_ — true if equal, false otherwise
|
25
|
+
def eql?: (Object other) -> bool
|
26
|
+
|
27
|
+
# _@return_ — the integer value of this enum
|
28
|
+
def to_i: () -> Integer
|
29
|
+
|
30
|
+
# _@return_ — string representation of the enum
|
31
|
+
def to_s: () -> String
|
32
|
+
|
33
|
+
# Initialize a new Enum instance. This is private and should not be called
|
34
|
+
# directly; use the class methods to create instances.
|
35
|
+
#
|
36
|
+
# _@param_ `value` — the integer value of the enum
|
37
|
+
#
|
38
|
+
# _@param_ `name` — the name of the enum constant (nil for unknown values)
|
39
|
+
def initialize: (Integer value, ?(String | Symbol)? name) -> void
|
40
|
+
|
41
|
+
# Ensure @values is initialized for each subclass
|
42
|
+
#
|
43
|
+
# _@param_ `subclass` — the subclass being created
|
44
|
+
def self.inherited: (Class subclass) -> void
|
45
|
+
|
46
|
+
# Returns the enum instance for a given string name
|
47
|
+
#
|
48
|
+
# _@param_ `str` — the enum constant name
|
49
|
+
#
|
50
|
+
# _@return_ — the enum instance
|
51
|
+
def self.from_string: (String str) -> StatelyDB::StatelyEnum
|
52
|
+
|
53
|
+
# Create an enum instance from its integer value.
|
54
|
+
# Returns a known enum if the value is defined, otherwise creates
|
55
|
+
# a new instance for undefined values.
|
56
|
+
#
|
57
|
+
# _@param_ `value` — the integer value
|
58
|
+
#
|
59
|
+
# _@return_ — the enum instance
|
60
|
+
def self.new: (Integer value) -> StatelyDB::StatelyEnum
|
61
|
+
|
62
|
+
# Returns all defined enum values
|
63
|
+
#
|
64
|
+
# _@return_ — array of all defined enum instances
|
65
|
+
def self.all: () -> ::Array[StatelyDB::StatelyEnum]
|
66
|
+
|
67
|
+
# Unmarshals a Stately proto enum value
|
68
|
+
#
|
69
|
+
# or a symbol depending on whether the proto value is defined for this version.
|
70
|
+
#
|
71
|
+
# _@param_ `value` — the proto enum value. This can be an integer
|
72
|
+
#
|
73
|
+
# _@return_ — the enum instance
|
74
|
+
def self.unmarshal_stately: ((Integer | Symbol) value) -> StatelyDB::StatelyEnum
|
75
|
+
|
76
|
+
# Defines a new enum value (used internally by generated code)
|
77
|
+
#
|
78
|
+
# _@param_ `name` — the constant name
|
79
|
+
#
|
80
|
+
# _@param_ `value` — the integer value
|
81
|
+
#
|
82
|
+
# _@return_ — the created enum instance
|
83
|
+
def self.define_value: (Symbol name, Integer value) -> StatelyDB::StatelyEnum
|
84
|
+
|
85
|
+
# _@return_ — the integer value of this enum
|
86
|
+
attr_reader value: Integer
|
87
|
+
|
88
|
+
# _@return_ — the name of this enum value, or a generated string name for unknown values
|
89
|
+
attr_reader name: (Symbol | String)
|
90
|
+
end
|
4
91
|
|
5
92
|
# UUID is a helper class for working with UUIDs in StatelyDB. The ruby version of a StatelyDB is a binary string,
|
6
93
|
# and this class provides convenience methods for converting to the base16 representation specified in RFC 9562.
|
@@ -149,7 +236,7 @@ module StatelyDB
|
|
149
236
|
# ```ruby
|
150
237
|
# keypath = KeyPath.with("genres", "rock").with("artists", "the-beatles")
|
151
238
|
# ```
|
152
|
-
def self.with: (String namespace, ?(String | StatelyDB::UUID | _ToS)? identifier) -> StatelyDB::KeyPath
|
239
|
+
def self.with: (String namespace, ?(String | StatelyDB::UUID | StatelyDB::StatelyEnum | _ToS)? identifier) -> StatelyDB::KeyPath
|
153
240
|
|
154
241
|
# If the value is a binary string, encode it as a url-safe
|
155
242
|
# base64 string with padding removed.
|
@@ -228,21 +315,52 @@ module StatelyDB
|
|
228
315
|
# ```
|
229
316
|
def get_batch: (*(StatelyDB::KeyPath | String | ::Array[(StatelyDB::KeyPath | String)]) key_paths) -> ::Array[StatelyDB::Item]
|
230
317
|
|
318
|
+
# begin_list retrieves Items that start with a specified key_path_prefix
|
319
|
+
# from a single Group. Because it can only list items from a single Group,
|
320
|
+
# the key path prefix must at least start with a full Group Key (a single
|
321
|
+
# key segment with a namespace and an ID, e.g. `/user-1234`).
|
322
|
+
#
|
323
|
+
# begin_list will return an empty result set if there are no items matching
|
324
|
+
# that key prefix. This API returns a token that you can pass to
|
325
|
+
# continue_list to expand the result set, or to sync_list to get updates
|
326
|
+
# within the result set.
|
327
|
+
#
|
328
|
+
# You can list items of different types in a single begin_list, and you can
|
329
|
+
# use `isinstance` to handle different item types.
|
330
|
+
#
|
331
|
+
# _@param_ `prefix` — The key path prefix to query for. It must be at least a full Group Key (e.g. `/user-1234`).
|
332
|
+
#
|
333
|
+
# _@param_ `limit` — The max number of items to retrieve. If set to 0 then the full set will be returned. Defaults to 0.
|
334
|
+
#
|
335
|
+
# _@param_ `sort_direction` — the direction to sort by (:ascending or :descending, default is :ascending).
|
336
|
+
#
|
337
|
+
# _@param_ `item_types` — the item types to filter by. The returned items will be instances of one of these types.
|
338
|
+
#
|
339
|
+
# _@param_ `cel_filters` — ] An optional list of item_type, cel_expression tuples that represent CEL expressions to filter the results set by. Use the cel_filter helper function to build these expressions. CEL expressions are only evaluated for the item type they are defined for, and do not affect other item types in the result set. This means if an item type has no CEL filter and there are no item_type filters constraints, it will be included in the result set. In the context of a CEL expression, the key-word `this` refers to the item being evaluated, and property properties should be accessed by the names as they appear in schema -- not necessarily as they appear in the generated code for a particular language. For example, if you have a `Movie` item type with the property `rating`, you could write a CEL expression like `this.rating == 'R'` to return only movies that are rated `R`. Find the full CEL language definition here: https://github.com/google/cel-spec/blob/master/doc/langdef.md
|
340
|
+
#
|
341
|
+
# _@param_ `gt` — filters results to only include items with a key greater than the specified value based on lexicographic ordering.
|
342
|
+
#
|
343
|
+
# _@param_ `gte` — filters results to only include items with a key greater than or equal to the specified value based on lexicographic ordering.
|
344
|
+
#
|
345
|
+
# _@param_ `lt` — filters results to only include items with a key less than the specified value based on lexicographic ordering.
|
346
|
+
#
|
347
|
+
# _@param_ `lte` — filters results to only include items with a key less than or equal to the specified value based on lexicographic ordering.
|
348
|
+
#
|
231
349
|
# _@return_ — the list of Items and the token
|
232
350
|
#
|
233
351
|
# ```ruby
|
234
352
|
# client.data.begin_list("/ItemType-identifier", limit: 10, sort_direction: :ascending)
|
235
353
|
# ```
|
236
354
|
def begin_list: (
|
237
|
-
|
238
|
-
?limit:
|
239
|
-
?sort_direction:
|
240
|
-
?item_types:
|
241
|
-
?cel_filters:
|
242
|
-
?gt:
|
243
|
-
?gte:
|
244
|
-
?lt:
|
245
|
-
?lte:
|
355
|
+
(StatelyDB::KeyPath | String) prefix,
|
356
|
+
?limit: Integer,
|
357
|
+
?sort_direction: (Symbol | String | Integer),
|
358
|
+
?item_types: ::Array[(singleton(StatelyDB::Item) | String)],
|
359
|
+
?cel_filters: ::Array[(::Array[(Class | String)] | String)],
|
360
|
+
?gt: (StatelyDB::KeyPath | String)?,
|
361
|
+
?gte: (StatelyDB::KeyPath | String)?,
|
362
|
+
?lt: (StatelyDB::KeyPath | String)?,
|
363
|
+
?lte: (StatelyDB::KeyPath | String)?
|
246
364
|
) -> (::Array[StatelyDB::Item] | StatelyDB::Token)
|
247
365
|
|
248
366
|
# continue_list takes the token from a begin_list call and returns the next
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: statelydb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.35.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Stately Cloud, Inc.
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2025-
|
11
|
+
date: 2025-09-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: async
|
@@ -115,6 +115,7 @@ files:
|
|
115
115
|
- lib/common/build_filters.rb
|
116
116
|
- lib/common/error_interceptor.rb
|
117
117
|
- lib/common/net/conn.rb
|
118
|
+
- lib/enum.rb
|
118
119
|
- lib/error.rb
|
119
120
|
- lib/key_path.rb
|
120
121
|
- lib/stately_codes.rb
|