Skip to content

Commit e231ce6

Browse files
authored
Remove unnecessary type-aliases (#10)
1 parent 32b7192 commit e231ce6

File tree

7 files changed

+120
-121
lines changed

7 files changed

+120
-121
lines changed

Sources/FoundationDB/Database.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public final class FDBDatabase: DatabaseProtocol {
7373
/// - value: The value for the option (optional).
7474
/// - option: The database option to set.
7575
/// - Throws: `FDBError` if the option cannot be set.
76-
public func setOption(to value: FDB.Value? = nil, forOption option: FDB.DatabaseOption) throws {
76+
public func setOption(to value: FDB.Bytes? = nil, forOption option: FDB.DatabaseOption) throws {
7777
let error: Int32
7878
if let value = value {
7979
error = value.withUnsafeBytes { bytes in

Sources/FoundationDB/Fdb+AsyncKVSequence.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ extension FDB {
6161
///
6262
/// This design minimizes the impact of network latency on iteration performance.
6363
public struct AsyncKVSequence: AsyncSequence {
64-
public typealias Element = KeyValue
64+
public typealias Element = (Bytes, Bytes)
6565

6666
/// The transaction used for range queries
6767
let transaction: TransactionProtocol
@@ -172,7 +172,7 @@ extension FDB {
172172
///
173173
/// - Returns: The next key-value pair, or `nil` if sequence is exhausted
174174
/// - Throws: `FDBError` if the database operation fails
175-
public mutating func next() async throws -> KeyValue? {
175+
public mutating func next() async throws -> Element? {
176176
if isExhausted {
177177
return nil
178178
}

Sources/FoundationDB/FoundationdDB.swift

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -60,26 +60,26 @@ protocol TransactionProtocol: Sendable {
6060
/// - snapshot: Whether to perform a snapshot read.
6161
/// - Returns: The value associated with the key, or nil if not found.
6262
/// - Throws: `FDBError` if the operation fails.
63-
func getValue(for key: FDB.Key, snapshot: Bool) async throws -> FDB.Value?
63+
func getValue(for key: FDB.Bytes, snapshot: Bool) async throws -> FDB.Bytes?
6464

6565
/// Sets a value for the given key.
6666
///
6767
/// - Parameters:
6868
/// - value: The value to set as a byte array.
6969
/// - key: The key to associate with the value.
70-
func setValue(_ value: FDB.Value, for key: FDB.Key)
70+
func setValue(_ value: FDB.Bytes, for key: FDB.Bytes)
7171

7272
/// Removes a key-value pair from the database.
7373
///
7474
/// - Parameter key: The key to remove as a byte array.
75-
func clear(key: FDB.Key)
75+
func clear(key: FDB.Bytes)
7676

7777
/// Removes all key-value pairs in the given range.
7878
///
7979
/// - Parameters:
8080
/// - beginKey: The start of the range (inclusive) as a byte array.
8181
/// - endKey: The end of the range (exclusive) as a byte array.
82-
func clearRange(beginKey: FDB.Key, endKey: FDB.Key)
82+
func clearRange(beginKey: FDB.Bytes, endKey: FDB.Bytes)
8383

8484
/// Resolves a key selector to an actual key.
8585
///
@@ -88,7 +88,7 @@ protocol TransactionProtocol: Sendable {
8888
/// - snapshot: Whether to perform a snapshot read.
8989
/// - Returns: The resolved key, or nil if no key matches.
9090
/// - Throws: `FDBError` if the operation fails.
91-
func getKey(selector: FDB.Selectable, snapshot: Bool) async throws -> FDB.Key?
91+
func getKey(selector: FDB.Selectable, snapshot: Bool) async throws -> FDB.Bytes?
9292

9393
/// Resolves a key selector to an actual key.
9494
///
@@ -97,7 +97,7 @@ protocol TransactionProtocol: Sendable {
9797
/// - snapshot: Whether to perform a snapshot read.
9898
/// - Returns: The resolved key, or nil if no key matches.
9999
/// - Throws: `FDBError` if the operation fails.
100-
func getKey(selector: FDB.KeySelector, snapshot: Bool) async throws -> FDB.Key?
100+
func getKey(selector: FDB.KeySelector, snapshot: Bool) async throws -> FDB.Bytes?
101101

102102
/// Returns an AsyncSequence that yields key-value pairs within a range.
103103
///
@@ -139,7 +139,7 @@ protocol TransactionProtocol: Sendable {
139139
/// - Returns: A `ResultRange` containing the key-value pairs and more flag.
140140
/// - Throws: `FDBError` if the operation fails.
141141
func getRangeNative(
142-
beginKey: FDB.Key, endKey: FDB.Key, limit: Int, snapshot: Bool
142+
beginKey: FDB.Bytes, endKey: FDB.Bytes, limit: Int, snapshot: Bool
143143
) async throws -> ResultRange
144144

145145
/// Commits the transaction.
@@ -159,7 +159,7 @@ protocol TransactionProtocol: Sendable {
159159
///
160160
/// - Returns: The transaction's versionstamp as a key, or nil if not available.
161161
/// - Throws: `FDBError` if the operation fails.
162-
func getVersionstamp() async throws -> FDB.Key?
162+
func getVersionstamp() async throws -> FDB.Bytes?
163163

164164
/// Sets the read version for snapshot reads.
165165
///
@@ -191,7 +191,7 @@ protocol TransactionProtocol: Sendable {
191191
/// - endKey: The end of the range (exclusive).
192192
/// - Returns: The estimated size in bytes.
193193
/// - Throws: `FDBError` if the operation fails.
194-
func getEstimatedRangeSizeBytes(beginKey: FDB.Key, endKey: FDB.Key) async throws -> Int
194+
func getEstimatedRangeSizeBytes(beginKey: FDB.Bytes, endKey: FDB.Bytes) async throws -> Int
195195

196196
/// Returns a list of keys that can split the given range into roughly equal chunks.
197197
///
@@ -203,7 +203,7 @@ protocol TransactionProtocol: Sendable {
203203
/// - chunkSize: The desired size of each chunk in bytes.
204204
/// - Returns: An array of keys representing split points.
205205
/// - Throws: `FDBError` if the operation fails.
206-
func getRangeSplitPoints(beginKey: FDB.Key, endKey: FDB.Key, chunkSize: Int) async throws -> [[UInt8]]
206+
func getRangeSplitPoints(beginKey: FDB.Bytes, endKey: FDB.Bytes, chunkSize: Int) async throws -> [[UInt8]]
207207

208208
/// Returns the version number at which a committed transaction modified the database.
209209
///
@@ -228,7 +228,7 @@ protocol TransactionProtocol: Sendable {
228228
/// - key: The key to operate on.
229229
/// - param: The parameter for the atomic operation.
230230
/// - mutationType: The type of atomic operation to perform.
231-
func atomicOp(key: FDB.Key, param: FDB.Value, mutationType: FDB.MutationType)
231+
func atomicOp(key: FDB.Bytes, param: FDB.Bytes, mutationType: FDB.MutationType)
232232

233233
/// Adds a conflict range to the transaction.
234234
///
@@ -240,7 +240,7 @@ protocol TransactionProtocol: Sendable {
240240
/// - endKey: The end of the range (exclusive) as a byte array.
241241
/// - type: The type of conflict range (read or write).
242242
/// - Throws: `FDBError` if the operation fails.
243-
func addConflictRange(beginKey: FDB.Key, endKey: FDB.Key, type: FDB.ConflictRangeType) throws
243+
func addConflictRange(beginKey: FDB.Bytes, endKey: FDB.Bytes, type: FDB.ConflictRangeType) throws
244244

245245
// MARK: - Transaction option methods
246246

@@ -250,7 +250,7 @@ protocol TransactionProtocol: Sendable {
250250
/// - value: Optional byte array value for the option.
251251
/// - option: The transaction option to set.
252252
/// - Throws: `FDBError` if the option cannot be set.
253-
func setOption(to value: FDB.Value?, forOption option: FDB.TransactionOption) throws
253+
func setOption(to value: FDB.Bytes?, forOption option: FDB.TransactionOption) throws
254254

255255
/// Sets a transaction option with a string value.
256256
///
@@ -313,15 +313,15 @@ extension DatabaseProtocol {
313313
}
314314

315315
extension TransactionProtocol {
316-
public func getValue(for key: FDB.Key, snapshot: Bool = false) async throws -> FDB.Value? {
316+
public func getValue(for key: FDB.Bytes, snapshot: Bool = false) async throws -> FDB.Bytes? {
317317
try await getValue(for: key, snapshot: snapshot)
318318
}
319319

320-
public func getKey(selector: FDB.Selectable, snapshot: Bool = false) async throws -> FDB.Key? {
320+
public func getKey(selector: FDB.Selectable, snapshot: Bool = false) async throws -> FDB.Bytes? {
321321
try await getKey(selector: selector.toKeySelector(), snapshot: snapshot)
322322
}
323323

324-
public func getKey(selector: FDB.KeySelector, snapshot: Bool = false) async throws -> FDB.Key? {
324+
public func getKey(selector: FDB.KeySelector, snapshot: Bool = false) async throws -> FDB.Bytes? {
325325
try await getKey(selector: selector, snapshot: snapshot)
326326
}
327327

@@ -354,8 +354,9 @@ extension TransactionProtocol {
354354
)
355355
}
356356

357+
357358
public func getRange(
358-
beginKey: FDB.Key, endKey: FDB.Key, snapshot: Bool = false
359+
beginKey: FDB.Bytes, endKey: FDB.Bytes, snapshot: Bool = false
359360
) -> FDB.AsyncKVSequence {
360361
let beginSelector = FDB.KeySelector.firstGreaterOrEqual(beginKey)
361362
let endSelector = FDB.KeySelector.firstGreaterOrEqual(endKey)

Sources/FoundationDB/Future.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ struct ResultInt64: FutureResult {
190190
/// Used for operations like key selectors that resolve to actual keys.
191191
struct ResultKey: FutureResult {
192192
/// The extracted key, or nil if no key was returned.
193-
let value: FDB.Key?
193+
let value: FDB.Bytes?
194194

195195
/// Extracts a key from the future.
196196
///
@@ -220,7 +220,7 @@ struct ResultKey: FutureResult {
220220
/// Used for get operations that retrieve values associated with keys.
221221
struct ResultValue: FutureResult {
222222
/// The extracted value, or nil if no value was found.
223-
let value: FDB.Value?
223+
let value: FDB.Bytes?
224224

225225
/// Extracts a value from the future.
226226
///
@@ -253,6 +253,7 @@ struct ResultValue: FutureResult {
253253
public struct ResultRange: FutureResult {
254254
/// The array of key-value pairs returned by the range operation.
255255
public let records: FDB.KeyValueArray
256+
256257
/// Indicates whether there are more records beyond this result.
257258
public let more: Bool
258259

Sources/FoundationDB/Transaction.swift

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public final class FDBTransaction: TransactionProtocol, @unchecked Sendable {
3030
fdb_transaction_destroy(transaction)
3131
}
3232

33-
public func getValue(for key: FDB.Key, snapshot: Bool) async throws -> FDB.Value? {
33+
public func getValue(for key: FDB.Bytes, snapshot: Bool) async throws -> FDB.Bytes? {
3434
try await key.withUnsafeBytes { keyBytes in
3535
Future<ResultValue>(
3636
fdb_transaction_get(
@@ -43,7 +43,7 @@ public final class FDBTransaction: TransactionProtocol, @unchecked Sendable {
4343
}.getAsync()?.value
4444
}
4545

46-
public func setValue(_ value: FDB.Value, for key: FDB.Key) {
46+
public func setValue(_ value: FDB.Bytes, for key: FDB.Bytes) {
4747
key.withUnsafeBytes { keyBytes in
4848
value.withUnsafeBytes { valueBytes in
4949
fdb_transaction_set(
@@ -57,7 +57,7 @@ public final class FDBTransaction: TransactionProtocol, @unchecked Sendable {
5757
}
5858
}
5959

60-
public func clear(key: FDB.Key) {
60+
public func clear(key: FDB.Bytes) {
6161
key.withUnsafeBytes { keyBytes in
6262
fdb_transaction_clear(
6363
transaction,
@@ -67,7 +67,7 @@ public final class FDBTransaction: TransactionProtocol, @unchecked Sendable {
6767
}
6868
}
6969

70-
public func clearRange(beginKey: FDB.Key, endKey: FDB.Key) {
70+
public func clearRange(beginKey: FDB.Bytes, endKey: FDB.Bytes) {
7171
beginKey.withUnsafeBytes { beginKeyBytes in
7272
endKey.withUnsafeBytes { endKeyBytes in
7373
fdb_transaction_clear_range(
@@ -81,7 +81,7 @@ public final class FDBTransaction: TransactionProtocol, @unchecked Sendable {
8181
}
8282
}
8383

84-
public func atomicOp(key: FDB.Key, param: FDB.Value, mutationType: FDB.MutationType) {
84+
public func atomicOp(key: FDB.Bytes, param: FDB.Bytes, mutationType: FDB.MutationType) {
8585
key.withUnsafeBytes { keyBytes in
8686
param.withUnsafeBytes { paramBytes in
8787
fdb_transaction_atomic_op(
@@ -96,7 +96,7 @@ public final class FDBTransaction: TransactionProtocol, @unchecked Sendable {
9696
}
9797
}
9898

99-
public func setOption(to value: FDB.Value?, forOption option: FDB.TransactionOption) throws {
99+
public func setOption(to value: FDB.Bytes?, forOption option: FDB.TransactionOption) throws {
100100
let error: Int32
101101
if let value = value {
102102
error = value.withUnsafeBytes { bytes in
@@ -116,7 +116,7 @@ public final class FDBTransaction: TransactionProtocol, @unchecked Sendable {
116116
}
117117
}
118118

119-
public func getKey(selector: FDB.KeySelector, snapshot: Bool) async throws -> FDB.Key? {
119+
public func getKey(selector: FDB.KeySelector, snapshot: Bool) async throws -> FDB.Bytes? {
120120
try await selector.key.withUnsafeBytes { keyBytes in
121121
Future<ResultKey>(
122122
fdb_transaction_get_key(
@@ -141,7 +141,7 @@ public final class FDBTransaction: TransactionProtocol, @unchecked Sendable {
141141
fdb_transaction_cancel(transaction)
142142
}
143143

144-
public func getVersionstamp() async throws -> FDB.Key? {
144+
public func getVersionstamp() async throws -> FDB.Bytes? {
145145
try await Future<ResultKey>(
146146
fdb_transaction_get_versionstamp(transaction)
147147
).getAsync()?.value
@@ -163,7 +163,7 @@ public final class FDBTransaction: TransactionProtocol, @unchecked Sendable {
163163
).getAsync()
164164
}
165165

166-
public func getEstimatedRangeSizeBytes(beginKey: FDB.Key, endKey: FDB.Key) async throws -> Int {
166+
public func getEstimatedRangeSizeBytes(beginKey: FDB.Bytes, endKey: FDB.Bytes) async throws -> Int {
167167
try Int(await beginKey.withUnsafeBytes { beginKeyBytes in
168168
endKey.withUnsafeBytes { endKeyBytes in
169169
Future<ResultInt64>(
@@ -179,7 +179,7 @@ public final class FDBTransaction: TransactionProtocol, @unchecked Sendable {
179179
}.getAsync()?.value ?? 0)
180180
}
181181

182-
public func getRangeSplitPoints(beginKey: FDB.Key, endKey: FDB.Key, chunkSize: Int) async throws -> [[UInt8]] {
182+
public func getRangeSplitPoints(beginKey: FDB.Bytes, endKey: FDB.Bytes, chunkSize: Int) async throws -> [[UInt8]] {
183183
try await beginKey.withUnsafeBytes { beginKeyBytes in
184184
endKey.withUnsafeBytes { endKeyBytes in
185185
Future<ResultKeyArray>(
@@ -211,7 +211,7 @@ public final class FDBTransaction: TransactionProtocol, @unchecked Sendable {
211211
).getAsync()?.value ?? 0)
212212
}
213213

214-
public func addConflictRange(beginKey: FDB.Key, endKey: FDB.Key, type: FDB.ConflictRangeType) throws {
214+
public func addConflictRange(beginKey: FDB.Bytes, endKey: FDB.Bytes, type: FDB.ConflictRangeType) throws {
215215
let error = beginKey.withUnsafeBytes { beginKeyBytes in
216216
endKey.withUnsafeBytes { endKeyBytes in
217217
fdb_transaction_add_conflict_range(
@@ -261,8 +261,9 @@ public final class FDBTransaction: TransactionProtocol, @unchecked Sendable {
261261
return try await future.getAsync() ?? ResultRange(records: [], more: false)
262262
}
263263

264+
264265
func getRangeNative(
265-
beginKey: FDB.Key, endKey: FDB.Key, limit: Int = 0, snapshot: Bool
266+
beginKey: FDB.Bytes, endKey: FDB.Bytes, limit: Int = 0, snapshot: Bool
266267
) async throws -> ResultRange {
267268
let future = beginKey.withUnsafeBytes { beginKeyBytes in
268269
endKey.withUnsafeBytes { endKeyBytes in

Sources/FoundationDB/Types.swift

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,12 @@ typealias CCallback = @convention(c) (UnsafeRawPointer?, UnsafeRawPointer?) -> V
3333
public enum FDB {
3434
/// A FoundationDB version number (64-bit integer).
3535
public typealias Version = Int64
36+
3637
/// Raw byte data used throughout the FoundationDB API.
3738
public typealias Bytes = [UInt8]
38-
/// A FoundationDB key (sequence of bytes).
39-
public typealias Key = Bytes
40-
/// A FoundationDB value (sequence of bytes).
41-
public typealias Value = Bytes
42-
/// A key-value pair tuple.
43-
public typealias KeyValue = (Key, Value)
39+
4440
/// An array of key-value pairs.
45-
public typealias KeyValueArray = [KeyValue]
41+
public typealias KeyValueArray = [(Bytes, Bytes)]
4642

4743
/// Protocol for types that can be converted to key selectors.
4844
///
@@ -70,7 +66,7 @@ public enum FDB {
7066
/// ```
7167
public struct KeySelector: Selectable, Sendable {
7268
/// The reference key for this selector.
73-
public let key: Key
69+
public let key: Bytes
7470
/// Whether to include the reference key itself in selection.
7571
public let orEqual: Bool
7672
/// Offset from the selected key position.
@@ -82,7 +78,7 @@ public enum FDB {
8278
/// - key: The reference key.
8379
/// - orEqual: Whether to include the reference key itself.
8480
/// - offset: Offset from the selected position.
85-
public init(key: Key, orEqual: Bool, offset: Int) {
81+
public init(key: Bytes, orEqual: Bool, offset: Int) {
8682
self.key = key
8783
self.orEqual = orEqual
8884
self.offset = offset
@@ -101,31 +97,31 @@ public enum FDB {
10197
///
10298
/// - Parameter key: The reference key as a byte array.
10399
/// - Returns: A key selector that selects the first key >= the reference key.
104-
public static func firstGreaterOrEqual(_ key: Key) -> KeySelector {
100+
public static func firstGreaterOrEqual(_ key: FDB.Bytes) -> KeySelector {
105101
return KeySelector(key: key, orEqual: false, offset: 1)
106102
}
107103

108104
/// Creates a key selector for the first key greater than the given key.
109105
///
110106
/// - Parameter key: The reference key as a byte array.
111107
/// - Returns: A key selector that selects the first key > the reference key.
112-
public static func firstGreaterThan(_ key: Key) -> KeySelector {
108+
public static func firstGreaterThan(_ key: FDB.Bytes) -> KeySelector {
113109
return KeySelector(key: key, orEqual: true, offset: 1)
114110
}
115111

116112
/// Creates a key selector for the last key less than or equal to the given key.
117113
///
118114
/// - Parameter key: The reference key as a byte array.
119115
/// - Returns: A key selector that selects the last key <= the reference key.
120-
public static func lastLessOrEqual(_ key: Key) -> KeySelector {
116+
public static func lastLessOrEqual(_ key: FDB.Bytes) -> KeySelector {
121117
return KeySelector(key: key, orEqual: true, offset: 0)
122118
}
123119

124120
/// Creates a key selector for the last key less than the given key.
125121
///
126122
/// - Parameter key: The reference key as a byte array.
127123
/// - Returns: A key selector that selects the last key < the reference key.
128-
public static func lastLessThan(_ key: Key) -> KeySelector {
124+
public static func lastLessThan(_ key: FDB.Bytes) -> KeySelector {
129125
return KeySelector(key: key, orEqual: false, offset: 0)
130126
}
131127
}
@@ -135,7 +131,7 @@ public enum FDB {
135131
///
136132
/// This allows key byte arrays to be used directly in range operations
137133
/// by converting them to "first greater or equal" key selectors.
138-
extension FDB.Key: FDB.Selectable {
134+
extension FDB.Bytes: FDB.Selectable {
139135
/// Converts this key to a key selector using "first greater or equal" semantics.
140136
///
141137
/// - Returns: A key selector that selects the first key >= this key.

0 commit comments

Comments
 (0)