diff --git a/Sources/FoundationDB/Database.swift b/Sources/FoundationDB/Database.swift index cce6200..65cc447 100644 --- a/Sources/FoundationDB/Database.swift +++ b/Sources/FoundationDB/Database.swift @@ -73,7 +73,7 @@ public final class FDBDatabase: DatabaseProtocol { /// - value: The value for the option (optional). /// - option: The database option to set. /// - Throws: `FDBError` if the option cannot be set. - public func setOption(to value: FDB.Value? = nil, forOption option: FDB.DatabaseOption) throws { + public func setOption(to value: FDB.Bytes? = nil, forOption option: FDB.DatabaseOption) throws { let error: Int32 if let value = value { error = value.withUnsafeBytes { bytes in diff --git a/Sources/FoundationDB/Fdb+AsyncKVSequence.swift b/Sources/FoundationDB/Fdb+AsyncKVSequence.swift index fad3ed6..0571042 100644 --- a/Sources/FoundationDB/Fdb+AsyncKVSequence.swift +++ b/Sources/FoundationDB/Fdb+AsyncKVSequence.swift @@ -61,7 +61,7 @@ extension FDB { /// /// This design minimizes the impact of network latency on iteration performance. public struct AsyncKVSequence: AsyncSequence { - public typealias Element = KeyValue + public typealias Element = (Bytes, Bytes) /// The transaction used for range queries let transaction: TransactionProtocol @@ -172,7 +172,7 @@ extension FDB { /// /// - Returns: The next key-value pair, or `nil` if sequence is exhausted /// - Throws: `FDBError` if the database operation fails - public mutating func next() async throws -> KeyValue? { + public mutating func next() async throws -> Element? { if isExhausted { return nil } diff --git a/Sources/FoundationDB/FoundationdDB.swift b/Sources/FoundationDB/FoundationdDB.swift index 5c8f77f..e259446 100644 --- a/Sources/FoundationDB/FoundationdDB.swift +++ b/Sources/FoundationDB/FoundationdDB.swift @@ -60,26 +60,26 @@ protocol TransactionProtocol: Sendable { /// - snapshot: Whether to perform a snapshot read. /// - Returns: The value associated with the key, or nil if not found. /// - Throws: `FDBError` if the operation fails. - func getValue(for key: FDB.Key, snapshot: Bool) async throws -> FDB.Value? + func getValue(for key: FDB.Bytes, snapshot: Bool) async throws -> FDB.Bytes? /// Sets a value for the given key. /// /// - Parameters: /// - value: The value to set as a byte array. /// - key: The key to associate with the value. - func setValue(_ value: FDB.Value, for key: FDB.Key) + func setValue(_ value: FDB.Bytes, for key: FDB.Bytes) /// Removes a key-value pair from the database. /// /// - Parameter key: The key to remove as a byte array. - func clear(key: FDB.Key) + func clear(key: FDB.Bytes) /// Removes all key-value pairs in the given range. /// /// - Parameters: /// - beginKey: The start of the range (inclusive) as a byte array. /// - endKey: The end of the range (exclusive) as a byte array. - func clearRange(beginKey: FDB.Key, endKey: FDB.Key) + func clearRange(beginKey: FDB.Bytes, endKey: FDB.Bytes) /// Resolves a key selector to an actual key. /// @@ -88,7 +88,7 @@ protocol TransactionProtocol: Sendable { /// - snapshot: Whether to perform a snapshot read. /// - Returns: The resolved key, or nil if no key matches. /// - Throws: `FDBError` if the operation fails. - func getKey(selector: FDB.Selectable, snapshot: Bool) async throws -> FDB.Key? + func getKey(selector: FDB.Selectable, snapshot: Bool) async throws -> FDB.Bytes? /// Resolves a key selector to an actual key. /// @@ -97,7 +97,7 @@ protocol TransactionProtocol: Sendable { /// - snapshot: Whether to perform a snapshot read. /// - Returns: The resolved key, or nil if no key matches. /// - Throws: `FDBError` if the operation fails. - func getKey(selector: FDB.KeySelector, snapshot: Bool) async throws -> FDB.Key? + func getKey(selector: FDB.KeySelector, snapshot: Bool) async throws -> FDB.Bytes? /// Returns an AsyncSequence that yields key-value pairs within a range. /// @@ -139,7 +139,7 @@ protocol TransactionProtocol: Sendable { /// - Returns: A `ResultRange` containing the key-value pairs and more flag. /// - Throws: `FDBError` if the operation fails. func getRangeNative( - beginKey: FDB.Key, endKey: FDB.Key, limit: Int, snapshot: Bool + beginKey: FDB.Bytes, endKey: FDB.Bytes, limit: Int, snapshot: Bool ) async throws -> ResultRange /// Commits the transaction. @@ -159,7 +159,7 @@ protocol TransactionProtocol: Sendable { /// /// - Returns: The transaction's versionstamp as a key, or nil if not available. /// - Throws: `FDBError` if the operation fails. - func getVersionstamp() async throws -> FDB.Key? + func getVersionstamp() async throws -> FDB.Bytes? /// Sets the read version for snapshot reads. /// @@ -191,7 +191,7 @@ protocol TransactionProtocol: Sendable { /// - endKey: The end of the range (exclusive). /// - Returns: The estimated size in bytes. /// - Throws: `FDBError` if the operation fails. - func getEstimatedRangeSizeBytes(beginKey: FDB.Key, endKey: FDB.Key) async throws -> Int + func getEstimatedRangeSizeBytes(beginKey: FDB.Bytes, endKey: FDB.Bytes) async throws -> Int /// Returns a list of keys that can split the given range into roughly equal chunks. /// @@ -203,7 +203,7 @@ protocol TransactionProtocol: Sendable { /// - chunkSize: The desired size of each chunk in bytes. /// - Returns: An array of keys representing split points. /// - Throws: `FDBError` if the operation fails. - func getRangeSplitPoints(beginKey: FDB.Key, endKey: FDB.Key, chunkSize: Int) async throws -> [[UInt8]] + func getRangeSplitPoints(beginKey: FDB.Bytes, endKey: FDB.Bytes, chunkSize: Int) async throws -> [[UInt8]] /// Returns the version number at which a committed transaction modified the database. /// @@ -228,7 +228,7 @@ protocol TransactionProtocol: Sendable { /// - key: The key to operate on. /// - param: The parameter for the atomic operation. /// - mutationType: The type of atomic operation to perform. - func atomicOp(key: FDB.Key, param: FDB.Value, mutationType: FDB.MutationType) + func atomicOp(key: FDB.Bytes, param: FDB.Bytes, mutationType: FDB.MutationType) /// Adds a conflict range to the transaction. /// @@ -240,7 +240,7 @@ protocol TransactionProtocol: Sendable { /// - endKey: The end of the range (exclusive) as a byte array. /// - type: The type of conflict range (read or write). /// - Throws: `FDBError` if the operation fails. - func addConflictRange(beginKey: FDB.Key, endKey: FDB.Key, type: FDB.ConflictRangeType) throws + func addConflictRange(beginKey: FDB.Bytes, endKey: FDB.Bytes, type: FDB.ConflictRangeType) throws // MARK: - Transaction option methods @@ -250,7 +250,7 @@ protocol TransactionProtocol: Sendable { /// - value: Optional byte array value for the option. /// - option: The transaction option to set. /// - Throws: `FDBError` if the option cannot be set. - func setOption(to value: FDB.Value?, forOption option: FDB.TransactionOption) throws + func setOption(to value: FDB.Bytes?, forOption option: FDB.TransactionOption) throws /// Sets a transaction option with a string value. /// @@ -313,15 +313,15 @@ extension DatabaseProtocol { } extension TransactionProtocol { - public func getValue(for key: FDB.Key, snapshot: Bool = false) async throws -> FDB.Value? { + public func getValue(for key: FDB.Bytes, snapshot: Bool = false) async throws -> FDB.Bytes? { try await getValue(for: key, snapshot: snapshot) } - public func getKey(selector: FDB.Selectable, snapshot: Bool = false) async throws -> FDB.Key? { + public func getKey(selector: FDB.Selectable, snapshot: Bool = false) async throws -> FDB.Bytes? { try await getKey(selector: selector.toKeySelector(), snapshot: snapshot) } - public func getKey(selector: FDB.KeySelector, snapshot: Bool = false) async throws -> FDB.Key? { + public func getKey(selector: FDB.KeySelector, snapshot: Bool = false) async throws -> FDB.Bytes? { try await getKey(selector: selector, snapshot: snapshot) } @@ -354,8 +354,9 @@ extension TransactionProtocol { ) } + public func getRange( - beginKey: FDB.Key, endKey: FDB.Key, snapshot: Bool = false + beginKey: FDB.Bytes, endKey: FDB.Bytes, snapshot: Bool = false ) -> FDB.AsyncKVSequence { let beginSelector = FDB.KeySelector.firstGreaterOrEqual(beginKey) let endSelector = FDB.KeySelector.firstGreaterOrEqual(endKey) diff --git a/Sources/FoundationDB/Future.swift b/Sources/FoundationDB/Future.swift index 7e4db10..7c643be 100644 --- a/Sources/FoundationDB/Future.swift +++ b/Sources/FoundationDB/Future.swift @@ -190,7 +190,7 @@ struct ResultInt64: FutureResult { /// Used for operations like key selectors that resolve to actual keys. struct ResultKey: FutureResult { /// The extracted key, or nil if no key was returned. - let value: FDB.Key? + let value: FDB.Bytes? /// Extracts a key from the future. /// @@ -220,7 +220,7 @@ struct ResultKey: FutureResult { /// Used for get operations that retrieve values associated with keys. struct ResultValue: FutureResult { /// The extracted value, or nil if no value was found. - let value: FDB.Value? + let value: FDB.Bytes? /// Extracts a value from the future. /// @@ -253,6 +253,7 @@ struct ResultValue: FutureResult { public struct ResultRange: FutureResult { /// The array of key-value pairs returned by the range operation. public let records: FDB.KeyValueArray + /// Indicates whether there are more records beyond this result. public let more: Bool diff --git a/Sources/FoundationDB/Transaction.swift b/Sources/FoundationDB/Transaction.swift index a59b3fe..2e8315c 100644 --- a/Sources/FoundationDB/Transaction.swift +++ b/Sources/FoundationDB/Transaction.swift @@ -30,7 +30,7 @@ public final class FDBTransaction: TransactionProtocol, @unchecked Sendable { fdb_transaction_destroy(transaction) } - public func getValue(for key: FDB.Key, snapshot: Bool) async throws -> FDB.Value? { + public func getValue(for key: FDB.Bytes, snapshot: Bool) async throws -> FDB.Bytes? { try await key.withUnsafeBytes { keyBytes in Future( fdb_transaction_get( @@ -43,7 +43,7 @@ public final class FDBTransaction: TransactionProtocol, @unchecked Sendable { }.getAsync()?.value } - public func setValue(_ value: FDB.Value, for key: FDB.Key) { + public func setValue(_ value: FDB.Bytes, for key: FDB.Bytes) { key.withUnsafeBytes { keyBytes in value.withUnsafeBytes { valueBytes in fdb_transaction_set( @@ -57,7 +57,7 @@ public final class FDBTransaction: TransactionProtocol, @unchecked Sendable { } } - public func clear(key: FDB.Key) { + public func clear(key: FDB.Bytes) { key.withUnsafeBytes { keyBytes in fdb_transaction_clear( transaction, @@ -67,7 +67,7 @@ public final class FDBTransaction: TransactionProtocol, @unchecked Sendable { } } - public func clearRange(beginKey: FDB.Key, endKey: FDB.Key) { + public func clearRange(beginKey: FDB.Bytes, endKey: FDB.Bytes) { beginKey.withUnsafeBytes { beginKeyBytes in endKey.withUnsafeBytes { endKeyBytes in fdb_transaction_clear_range( @@ -81,7 +81,7 @@ public final class FDBTransaction: TransactionProtocol, @unchecked Sendable { } } - public func atomicOp(key: FDB.Key, param: FDB.Value, mutationType: FDB.MutationType) { + public func atomicOp(key: FDB.Bytes, param: FDB.Bytes, mutationType: FDB.MutationType) { key.withUnsafeBytes { keyBytes in param.withUnsafeBytes { paramBytes in fdb_transaction_atomic_op( @@ -96,7 +96,7 @@ public final class FDBTransaction: TransactionProtocol, @unchecked Sendable { } } - public func setOption(to value: FDB.Value?, forOption option: FDB.TransactionOption) throws { + public func setOption(to value: FDB.Bytes?, forOption option: FDB.TransactionOption) throws { let error: Int32 if let value = value { error = value.withUnsafeBytes { bytes in @@ -116,7 +116,7 @@ public final class FDBTransaction: TransactionProtocol, @unchecked Sendable { } } - public func getKey(selector: FDB.KeySelector, snapshot: Bool) async throws -> FDB.Key? { + public func getKey(selector: FDB.KeySelector, snapshot: Bool) async throws -> FDB.Bytes? { try await selector.key.withUnsafeBytes { keyBytes in Future( fdb_transaction_get_key( @@ -141,7 +141,7 @@ public final class FDBTransaction: TransactionProtocol, @unchecked Sendable { fdb_transaction_cancel(transaction) } - public func getVersionstamp() async throws -> FDB.Key? { + public func getVersionstamp() async throws -> FDB.Bytes? { try await Future( fdb_transaction_get_versionstamp(transaction) ).getAsync()?.value @@ -163,7 +163,7 @@ public final class FDBTransaction: TransactionProtocol, @unchecked Sendable { ).getAsync() } - public func getEstimatedRangeSizeBytes(beginKey: FDB.Key, endKey: FDB.Key) async throws -> Int { + public func getEstimatedRangeSizeBytes(beginKey: FDB.Bytes, endKey: FDB.Bytes) async throws -> Int { try Int(await beginKey.withUnsafeBytes { beginKeyBytes in endKey.withUnsafeBytes { endKeyBytes in Future( @@ -179,7 +179,7 @@ public final class FDBTransaction: TransactionProtocol, @unchecked Sendable { }.getAsync()?.value ?? 0) } - public func getRangeSplitPoints(beginKey: FDB.Key, endKey: FDB.Key, chunkSize: Int) async throws -> [[UInt8]] { + public func getRangeSplitPoints(beginKey: FDB.Bytes, endKey: FDB.Bytes, chunkSize: Int) async throws -> [[UInt8]] { try await beginKey.withUnsafeBytes { beginKeyBytes in endKey.withUnsafeBytes { endKeyBytes in Future( @@ -211,7 +211,7 @@ public final class FDBTransaction: TransactionProtocol, @unchecked Sendable { ).getAsync()?.value ?? 0) } - public func addConflictRange(beginKey: FDB.Key, endKey: FDB.Key, type: FDB.ConflictRangeType) throws { + public func addConflictRange(beginKey: FDB.Bytes, endKey: FDB.Bytes, type: FDB.ConflictRangeType) throws { let error = beginKey.withUnsafeBytes { beginKeyBytes in endKey.withUnsafeBytes { endKeyBytes in fdb_transaction_add_conflict_range( @@ -261,8 +261,9 @@ public final class FDBTransaction: TransactionProtocol, @unchecked Sendable { return try await future.getAsync() ?? ResultRange(records: [], more: false) } + func getRangeNative( - beginKey: FDB.Key, endKey: FDB.Key, limit: Int = 0, snapshot: Bool + beginKey: FDB.Bytes, endKey: FDB.Bytes, limit: Int = 0, snapshot: Bool ) async throws -> ResultRange { let future = beginKey.withUnsafeBytes { beginKeyBytes in endKey.withUnsafeBytes { endKeyBytes in diff --git a/Sources/FoundationDB/Types.swift b/Sources/FoundationDB/Types.swift index 5593716..4e22bf9 100644 --- a/Sources/FoundationDB/Types.swift +++ b/Sources/FoundationDB/Types.swift @@ -33,16 +33,12 @@ typealias CCallback = @convention(c) (UnsafeRawPointer?, UnsafeRawPointer?) -> V public enum FDB { /// A FoundationDB version number (64-bit integer). public typealias Version = Int64 + /// Raw byte data used throughout the FoundationDB API. public typealias Bytes = [UInt8] - /// A FoundationDB key (sequence of bytes). - public typealias Key = Bytes - /// A FoundationDB value (sequence of bytes). - public typealias Value = Bytes - /// A key-value pair tuple. - public typealias KeyValue = (Key, Value) + /// An array of key-value pairs. - public typealias KeyValueArray = [KeyValue] + public typealias KeyValueArray = [(Bytes, Bytes)] /// Protocol for types that can be converted to key selectors. /// @@ -70,7 +66,7 @@ public enum FDB { /// ``` public struct KeySelector: Selectable, Sendable { /// The reference key for this selector. - public let key: Key + public let key: Bytes /// Whether to include the reference key itself in selection. public let orEqual: Bool /// Offset from the selected key position. @@ -82,7 +78,7 @@ public enum FDB { /// - key: The reference key. /// - orEqual: Whether to include the reference key itself. /// - offset: Offset from the selected position. - public init(key: Key, orEqual: Bool, offset: Int) { + public init(key: Bytes, orEqual: Bool, offset: Int) { self.key = key self.orEqual = orEqual self.offset = offset @@ -101,7 +97,7 @@ public enum FDB { /// /// - Parameter key: The reference key as a byte array. /// - Returns: A key selector that selects the first key >= the reference key. - public static func firstGreaterOrEqual(_ key: Key) -> KeySelector { + public static func firstGreaterOrEqual(_ key: FDB.Bytes) -> KeySelector { return KeySelector(key: key, orEqual: false, offset: 1) } @@ -109,7 +105,7 @@ public enum FDB { /// /// - Parameter key: The reference key as a byte array. /// - Returns: A key selector that selects the first key > the reference key. - public static func firstGreaterThan(_ key: Key) -> KeySelector { + public static func firstGreaterThan(_ key: FDB.Bytes) -> KeySelector { return KeySelector(key: key, orEqual: true, offset: 1) } @@ -117,7 +113,7 @@ public enum FDB { /// /// - Parameter key: The reference key as a byte array. /// - Returns: A key selector that selects the last key <= the reference key. - public static func lastLessOrEqual(_ key: Key) -> KeySelector { + public static func lastLessOrEqual(_ key: FDB.Bytes) -> KeySelector { return KeySelector(key: key, orEqual: true, offset: 0) } @@ -125,7 +121,7 @@ public enum FDB { /// /// - Parameter key: The reference key as a byte array. /// - Returns: A key selector that selects the last key < the reference key. - public static func lastLessThan(_ key: Key) -> KeySelector { + public static func lastLessThan(_ key: FDB.Bytes) -> KeySelector { return KeySelector(key: key, orEqual: false, offset: 0) } } @@ -135,7 +131,7 @@ public enum FDB { /// /// This allows key byte arrays to be used directly in range operations /// by converting them to "first greater or equal" key selectors. -extension FDB.Key: FDB.Selectable { +extension FDB.Bytes: FDB.Selectable { /// Converts this key to a key selector using "first greater or equal" semantics. /// /// - Returns: A key selector that selects the first key >= this key. diff --git a/Tests/FoundationDBTests/FoundationDBTests.swift b/Tests/FoundationDBTests/FoundationDBTests.swift index 8c71c2e..ee5a253 100644 --- a/Tests/FoundationDBTests/FoundationDBTests.swift +++ b/Tests/FoundationDBTests/FoundationDBTests.swift @@ -46,7 +46,7 @@ extension String { } extension TransactionProtocol { - func getValue(for key: String, snapshot: Bool = false) async throws -> FDB.Value? { + func getValue(for key: String, snapshot: Bool = false) async throws -> FDB.Bytes? { let keyBytes = [UInt8](key.utf8) return try await getValue(for: keyBytes, snapshot: snapshot) } @@ -137,8 +137,8 @@ func setValueBytes() async throws { _ = try await transaction.commit() let newTransaction = try database.createTransaction() - let key: FDB.Key = [UInt8]("test_byte_key".utf8) - let value: FDB.Value = [UInt8]("test_byte_value".utf8) + let key: FDB.Bytes = [UInt8]("test_byte_key".utf8) + let value: FDB.Bytes = [UInt8]("test_byte_value".utf8) newTransaction.setValue(value, for: key) @@ -177,8 +177,8 @@ func clearBytes() async throws { _ = try await transaction.commit() let newTransaction = try database.createTransaction() - let key: FDB.Key = [UInt8]("test_clear_key".utf8) - let value: FDB.Value = [UInt8]("test_clear_value".utf8) + let key: FDB.Bytes = [UInt8]("test_clear_key".utf8) + let value: FDB.Bytes = [UInt8]("test_clear_value".utf8) newTransaction.setValue(value, for: key) let retrievedValueBefore = try await newTransaction.getValue(for: key) @@ -224,13 +224,13 @@ func clearRangeBytes() async throws { _ = try await transaction.commit() let newTransaction = try database.createTransaction() - let key1: FDB.Key = [UInt8]("test_range_key_a".utf8) - let key2: FDB.Key = [UInt8]("test_range_key_b".utf8) - let key3: FDB.Key = [UInt8]("test_range_key_c".utf8) - let value: FDB.Value = [UInt8]("test_value".utf8) + let key1: FDB.Bytes = [UInt8]("test_range_key_a".utf8) + let key2: FDB.Bytes = [UInt8]("test_range_key_b".utf8) + let key3: FDB.Bytes = [UInt8]("test_range_key_c".utf8) + let value: FDB.Bytes = [UInt8]("test_value".utf8) - let beginKey: FDB.Key = [UInt8]("test_range_key_a".utf8) - let endKey: FDB.Key = [UInt8]("test_range_key_c".utf8) + let beginKey: FDB.Bytes = [UInt8]("test_range_key_a".utf8) + let endKey: FDB.Bytes = [UInt8]("test_range_key_c".utf8) newTransaction.setValue(value, for: key1) newTransaction.setValue(value, for: key2) @@ -371,16 +371,16 @@ func getKeyWithSelectable() async throws { _ = try await transaction.commit() let newTransaction = try database.createTransaction() - let key: FDB.Key = [UInt8]("test_selectable_key".utf8) - let value: FDB.Value = [UInt8]("test_selectable_value".utf8) + let key: FDB.Bytes = [UInt8]("test_selectable_key".utf8) + let value: FDB.Bytes = [UInt8]("test_selectable_value".utf8) newTransaction.setValue(value, for: key) _ = try await newTransaction.commit() let readTransaction = try database.createTransaction() - // Test with FDB.Key (which implements Selectable) + // Test with FDB.Bytes (which implements Selectable) let resultWithKey = try await readTransaction.getKey(selector: key) - #expect(resultWithKey == key, "getKey with FDB.Key should work") + #expect(resultWithKey == key, "getKey with FDB.Bytes should work") // Test with String (which implements Selectable) let stringKey = "test_selectable_key" @@ -503,12 +503,12 @@ func getRangeBytes() async throws { let newTransaction = try database.createTransaction() // Set up test data with byte arrays - let key1: FDB.Key = [UInt8]("test_byte_range_001".utf8) - let key2: FDB.Key = [UInt8]("test_byte_range_002".utf8) - let key3: FDB.Key = [UInt8]("test_byte_range_003".utf8) - let value1: FDB.Value = [UInt8]("byte_value1".utf8) - let value2: FDB.Value = [UInt8]("byte_value2".utf8) - let value3: FDB.Value = [UInt8]("byte_value3".utf8) + let key1: FDB.Bytes = [UInt8]("test_byte_range_001".utf8) + let key2: FDB.Bytes = [UInt8]("test_byte_range_002".utf8) + let key3: FDB.Bytes = [UInt8]("test_byte_range_003".utf8) + let value1: FDB.Bytes = [UInt8]("byte_value1".utf8) + let value2: FDB.Bytes = [UInt8]("byte_value2".utf8) + let value3: FDB.Bytes = [UInt8]("byte_value3".utf8) newTransaction.setValue(value1, for: key1) newTransaction.setValue(value2, for: key2) @@ -517,8 +517,8 @@ func getRangeBytes() async throws { // Test range query with byte arrays let readTransaction = try database.createTransaction() - let beginKey: FDB.Key = [UInt8]("test_byte_range_001".utf8) - let endKey: FDB.Key = [UInt8]("test_byte_range_003".utf8) + let beginKey: FDB.Bytes = [UInt8]("test_byte_range_001".utf8) + let endKey: FDB.Bytes = [UInt8]("test_byte_range_003".utf8) let result = try await readTransaction.getRangeNative(beginKey: beginKey, endKey: endKey, limit: 0, snapshot: false) #expect(!result.more) @@ -610,12 +610,12 @@ func getRangeNativeWithKeySelectors() async throws { let newTransaction = try database.createTransaction() // Set up test data - let key1: FDB.Key = [UInt8]("test_selector_001".utf8) - let key2: FDB.Key = [UInt8]("test_selector_002".utf8) - let key3: FDB.Key = [UInt8]("test_selector_003".utf8) - let value1: FDB.Value = [UInt8]("selector_value1".utf8) - let value2: FDB.Value = [UInt8]("selector_value2".utf8) - let value3: FDB.Value = [UInt8]("selector_value3".utf8) + let key1: FDB.Bytes = [UInt8]("test_selector_001".utf8) + let key2: FDB.Bytes = [UInt8]("test_selector_002".utf8) + let key3: FDB.Bytes = [UInt8]("test_selector_003".utf8) + let value1: FDB.Bytes = [UInt8]("selector_value1".utf8) + let value2: FDB.Bytes = [UInt8]("selector_value2".utf8) + let value3: FDB.Bytes = [UInt8]("selector_value3".utf8) newTransaction.setValue(value1, for: key1) newTransaction.setValue(value2, for: key2) @@ -699,7 +699,7 @@ func getRangeWithSelectable() async throws { // Test using the general Selectable protocol with mixed key types let readTransaction = try database.createTransaction() - let beginKey: FDB.Key = [UInt8]("test_mixed_001".utf8) + let beginKey: FDB.Bytes = [UInt8]("test_mixed_001".utf8) let endKey = [UInt8]("test_mixed_003".utf8) let result = try await readTransaction.getRangeNative(beginKey: beginKey, endKey: endKey, limit: 0, snapshot: false) @@ -934,14 +934,14 @@ func atomicOpAdd() async throws { _ = try await transaction.commit() let newTransaction = try database.createTransaction() - let key: FDB.Key = [UInt8]("test_atomic_add".utf8) + let key: FDB.Bytes = [UInt8]("test_atomic_add".utf8) // Initial value: little-endian 64-bit integer 10 - let initialValue: FDB.Value = withUnsafeBytes(of: Int64(10).littleEndian) { Array($0) } + let initialValue: FDB.Bytes = withUnsafeBytes(of: Int64(10).littleEndian) { Array($0) } newTransaction.setValue(initialValue, for: key) // Add 5 using atomic operation - let addValue: FDB.Value = withUnsafeBytes(of: Int64(5).littleEndian) { Array($0) } + let addValue: FDB.Bytes = withUnsafeBytes(of: Int64(5).littleEndian) { Array($0) } newTransaction.atomicOp(key: key, param: addValue, mutationType: .add) _ = try await newTransaction.commit() @@ -966,14 +966,14 @@ func atomicOpBitAnd() async throws { _ = try await transaction.commit() let newTransaction = try database.createTransaction() - let key: FDB.Key = [UInt8]("test_atomic_and".utf8) + let key: FDB.Bytes = [UInt8]("test_atomic_and".utf8) // Initial value: 0xFF (255) - let initialValue: FDB.Value = [0xFF] + let initialValue: FDB.Bytes = [0xFF] newTransaction.setValue(initialValue, for: key) // AND with 0x0F (15) - let andValue: FDB.Value = [0x0F] + let andValue: FDB.Bytes = [0x0F] newTransaction.atomicOp(key: key, param: andValue, mutationType: .bitAnd) _ = try await newTransaction.commit() @@ -997,14 +997,14 @@ func atomicOpBitOr() async throws { _ = try await transaction.commit() let newTransaction = try database.createTransaction() - let key: FDB.Key = [UInt8]("test_atomic_or".utf8) + let key: FDB.Bytes = [UInt8]("test_atomic_or".utf8) // Initial value: 0x0F (15) - let initialValue: FDB.Value = [0x0F] + let initialValue: FDB.Bytes = [0x0F] newTransaction.setValue(initialValue, for: key) // OR with 0xF0 (240) - let orValue: FDB.Value = [0xF0] + let orValue: FDB.Bytes = [0xF0] newTransaction.atomicOp(key: key, param: orValue, mutationType: .bitOr) _ = try await newTransaction.commit() @@ -1028,14 +1028,14 @@ func atomicOpBitXor() async throws { _ = try await transaction.commit() let newTransaction = try database.createTransaction() - let key: FDB.Key = [UInt8]("test_atomic_xor".utf8) + let key: FDB.Bytes = [UInt8]("test_atomic_xor".utf8) // Initial value: 0xFF (255) - let initialValue: FDB.Value = [0xFF] + let initialValue: FDB.Bytes = [0xFF] newTransaction.setValue(initialValue, for: key) // XOR with 0x0F (15) - let xorValue: FDB.Value = [0x0F] + let xorValue: FDB.Bytes = [0x0F] newTransaction.atomicOp(key: key, param: xorValue, mutationType: .bitXor) _ = try await newTransaction.commit() @@ -1059,14 +1059,14 @@ func atomicOpMax() async throws { _ = try await transaction.commit() let newTransaction = try database.createTransaction() - let key: FDB.Key = [UInt8]("test_atomic_max".utf8) + let key: FDB.Bytes = [UInt8]("test_atomic_max".utf8) // Initial value: little-endian 64-bit integer 10 - let initialValue: FDB.Value = withUnsafeBytes(of: Int64(10).littleEndian) { Array($0) } + let initialValue: FDB.Bytes = withUnsafeBytes(of: Int64(10).littleEndian) { Array($0) } newTransaction.setValue(initialValue, for: key) // Max with 15 - let maxValue: FDB.Value = withUnsafeBytes(of: Int64(15).littleEndian) { Array($0) } + let maxValue: FDB.Bytes = withUnsafeBytes(of: Int64(15).littleEndian) { Array($0) } newTransaction.atomicOp(key: key, param: maxValue, mutationType: .max) _ = try await newTransaction.commit() @@ -1091,14 +1091,14 @@ func atomicOpMin() async throws { _ = try await transaction.commit() let newTransaction = try database.createTransaction() - let key: FDB.Key = [UInt8]("test_atomic_min".utf8) + let key: FDB.Bytes = [UInt8]("test_atomic_min".utf8) // Initial value: little-endian 64-bit integer 10 - let initialValue: FDB.Value = withUnsafeBytes(of: Int64(10).littleEndian) { Array($0) } + let initialValue: FDB.Bytes = withUnsafeBytes(of: Int64(10).littleEndian) { Array($0) } newTransaction.setValue(initialValue, for: key) // Min with 5 - let minValue: FDB.Value = withUnsafeBytes(of: Int64(5).littleEndian) { Array($0) } + let minValue: FDB.Bytes = withUnsafeBytes(of: Int64(5).littleEndian) { Array($0) } newTransaction.atomicOp(key: key, param: minValue, mutationType: .min) _ = try await newTransaction.commit() @@ -1123,14 +1123,14 @@ func atomicOpAppendIfFits() async throws { _ = try await transaction.commit() let newTransaction = try database.createTransaction() - let key: FDB.Key = [UInt8]("test_atomic_append".utf8) + let key: FDB.Bytes = [UInt8]("test_atomic_append".utf8) // Initial value: "Hello" - let initialValue: FDB.Value = [UInt8]("Hello".utf8) + let initialValue: FDB.Bytes = [UInt8]("Hello".utf8) newTransaction.setValue(initialValue, for: key) // Append " World" - let appendValue: FDB.Value = [UInt8](" World".utf8) + let appendValue: FDB.Bytes = [UInt8](" World".utf8) newTransaction.atomicOp(key: key, param: appendValue, mutationType: .appendIfFits) _ = try await newTransaction.commit() @@ -1155,14 +1155,14 @@ func atomicOpByteMin() async throws { _ = try await transaction.commit() let newTransaction = try database.createTransaction() - let key: FDB.Key = [UInt8]("test_atomic_byte_min".utf8) + let key: FDB.Bytes = [UInt8]("test_atomic_byte_min".utf8) // Initial value: "zebra" - let initialValue: FDB.Value = [UInt8]("zebra".utf8) + let initialValue: FDB.Bytes = [UInt8]("zebra".utf8) newTransaction.setValue(initialValue, for: key) // Compare with "apple" (lexicographically smaller) - let compareValue: FDB.Value = [UInt8]("apple".utf8) + let compareValue: FDB.Bytes = [UInt8]("apple".utf8) newTransaction.atomicOp(key: key, param: compareValue, mutationType: .byteMin) _ = try await newTransaction.commit() @@ -1187,14 +1187,14 @@ func atomicOpByteMax() async throws { _ = try await transaction.commit() let newTransaction = try database.createTransaction() - let key: FDB.Key = [UInt8]("test_atomic_byte_max".utf8) + let key: FDB.Bytes = [UInt8]("test_atomic_byte_max".utf8) // Initial value: "apple" - let initialValue: FDB.Value = [UInt8]("apple".utf8) + let initialValue: FDB.Bytes = [UInt8]("apple".utf8) newTransaction.setValue(initialValue, for: key) // Compare with "zebra" (lexicographically larger) - let compareValue: FDB.Value = [UInt8]("zebra".utf8) + let compareValue: FDB.Bytes = [UInt8]("zebra".utf8) newTransaction.atomicOp(key: key, param: compareValue, mutationType: .byteMax) _ = try await newTransaction.commit() @@ -1486,8 +1486,8 @@ func testGetEstimatedRangeSizeBytes() async throws { // Get estimated size let transaction = try database.createTransaction() - let beginKey: FDB.Key = Array("test_size_".utf8) - let endKey: FDB.Key = Array("test_size`".utf8) + let beginKey: FDB.Bytes = Array("test_size_".utf8) + let endKey: FDB.Bytes = Array("test_size`".utf8) let estimatedSize = try await transaction.getEstimatedRangeSizeBytes(beginKey: beginKey, endKey: endKey) // Size should be positive (may not be exact due to sampling) @@ -1512,8 +1512,8 @@ func testGetRangeSplitPoints() async throws { // Get split points with 10KB chunks let transaction = try database.createTransaction() - let beginKey: FDB.Key = Array("test_split_".utf8) - let endKey: FDB.Key = Array("test_split`".utf8) + let beginKey: FDB.Bytes = Array("test_split_".utf8) + let endKey: FDB.Bytes = Array("test_split`".utf8) let splitPoints = try await transaction.getRangeSplitPoints( beginKey: beginKey, endKey: endKey, @@ -1592,8 +1592,8 @@ func addReadConflictRange() async throws { // Test adding read conflict range let transaction = try database.createTransaction() - let beginKey: FDB.Key = Array("test_conflict_a".utf8) - let endKey: FDB.Key = Array("test_conflict_b".utf8) + let beginKey: FDB.Bytes = Array("test_conflict_a".utf8) + let endKey: FDB.Bytes = Array("test_conflict_b".utf8) // Add read conflict range - should succeed try transaction.addConflictRange(beginKey: beginKey, endKey: endKey, type: .read) @@ -1615,8 +1615,8 @@ func addWriteConflictRange() async throws { // Test adding write conflict range let transaction = try database.createTransaction() - let beginKey: FDB.Key = Array("test_write_conflict_a".utf8) - let endKey: FDB.Key = Array("test_write_conflict_b".utf8) + let beginKey: FDB.Bytes = Array("test_write_conflict_a".utf8) + let endKey: FDB.Bytes = Array("test_write_conflict_b".utf8) // Add write conflict range - should succeed try transaction.addConflictRange(beginKey: beginKey, endKey: endKey, type: .write) @@ -1643,8 +1643,8 @@ func conflictRangeDetectsConcurrentWrites() async throws { // Create first transaction and add a write conflict range let transaction1 = try database.createTransaction() - let beginKey: FDB.Key = Array("test_concurrent_key".utf8) - var endKey: FDB.Key = beginKey + let beginKey: FDB.Bytes = Array("test_concurrent_key".utf8) + var endKey: FDB.Bytes = beginKey endKey.append(0x00) try transaction1.addConflictRange(beginKey: beginKey, endKey: endKey, type: .write) @@ -1678,17 +1678,17 @@ func addMultipleConflictRanges() async throws { let transaction = try database.createTransaction() // Add multiple read conflict ranges - let beginKey1: FDB.Key = Array("test_multi_a".utf8) - let endKey1: FDB.Key = Array("test_multi_b".utf8) + let beginKey1: FDB.Bytes = Array("test_multi_a".utf8) + let endKey1: FDB.Bytes = Array("test_multi_b".utf8) try transaction.addConflictRange(beginKey: beginKey1, endKey: endKey1, type: .read) - let beginKey2: FDB.Key = Array("test_multi_c".utf8) - let endKey2: FDB.Key = Array("test_multi_d".utf8) + let beginKey2: FDB.Bytes = Array("test_multi_c".utf8) + let endKey2: FDB.Bytes = Array("test_multi_d".utf8) try transaction.addConflictRange(beginKey: beginKey2, endKey: endKey2, type: .read) // Add write conflict range - let beginKey3: FDB.Key = Array("test_multi_x".utf8) - let endKey3: FDB.Key = Array("test_multi_y".utf8) + let beginKey3: FDB.Bytes = Array("test_multi_x".utf8) + let endKey3: FDB.Bytes = Array("test_multi_y".utf8) try transaction.addConflictRange(beginKey: beginKey3, endKey: endKey3, type: .write) // Should be able to commit with multiple conflict ranges