Skip to content

Commit 522d87b

Browse files
visheshjzhou77
authored andcommitted
Revert the order of setOption parameters per swifty coding practices
1 parent 55815f2 commit 522d87b

File tree

6 files changed

+33
-33
lines changed

6 files changed

+33
-33
lines changed

Sources/FoundationDB/Client.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -77,30 +77,30 @@ public final class FDBClient: Sendable {
7777
/// Sets a network option with an optional byte array value.
7878
///
7979
/// - Parameters:
80-
/// - option: The network option to set.
8180
/// - value: Optional byte array value for the option.
81+
/// - option: The network option to set.
8282
/// - Throws: `FDBError` if the option cannot be set.
83-
public static func setNetworkOption(_ option: FDB.NetworkOption, value: [UInt8]? = nil) throws {
83+
public static func setNetworkOption(to value: [UInt8]? = nil, forOption option: FDB.NetworkOption) throws {
8484
try FDBNetwork.shared.setNetworkOption(to: value, forOption: option)
8585
}
8686

8787
/// Sets a network option with a string value.
8888
///
8989
/// - Parameters:
90-
/// - option: The network option to set.
9190
/// - value: String value for the option.
91+
/// - option: The network option to set.
9292
/// - Throws: `FDBError` if the option cannot be set.
93-
public static func setNetworkOption(_ option: FDB.NetworkOption, value: String) throws {
93+
public static func setNetworkOption(to value: String, forOption option: FDB.NetworkOption) throws {
9494
try FDBNetwork.shared.setNetworkOption(to: value, forOption: option)
9595
}
9696

9797
/// Sets a network option with an integer value.
9898
///
9999
/// - Parameters:
100-
/// - option: The network option to set.
101100
/// - value: Integer value for the option.
101+
/// - option: The network option to set.
102102
/// - Throws: `FDBError` if the option cannot be set.
103-
public static func setNetworkOption(_ option: FDB.NetworkOption, value: Int) throws {
103+
public static func setNetworkOption(to value: Int, forOption option: FDB.NetworkOption) throws {
104104
try FDBNetwork.shared.setNetworkOption(to: value, forOption: option)
105105
}
106106
}

Sources/FoundationDB/Database.swift

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,10 @@ public final class FDBDatabase: DatabaseProtocol {
7070
/// Sets a database option with a byte array value.
7171
///
7272
/// - Parameters:
73-
/// - option: The database option to set.
7473
/// - value: The value for the option (optional).
74+
/// - option: The database option to set.
7575
/// - Throws: `FDBError` if the option cannot be set.
76-
public func setOption(_ option: FDB.DatabaseOption, value: FDB.Value? = nil) throws {
76+
public func setOption(to value: FDB.Value? = nil, forOption option: FDB.DatabaseOption) throws {
7777
let error: Int32
7878
if let value = value {
7979
error = value.withUnsafeBytes { bytes in
@@ -96,23 +96,23 @@ public final class FDBDatabase: DatabaseProtocol {
9696
/// Sets a database option with a string value.
9797
///
9898
/// - Parameters:
99-
/// - option: The database option to set.
10099
/// - value: The string value for the option.
100+
/// - option: The database option to set.
101101
/// - Throws: `FDBError` if the option cannot be set.
102-
public func setOption(_ option: FDB.DatabaseOption, value: String) throws {
103-
try setOption(option, value: Array(value.utf8))
102+
public func setOption(to value: String, forOption option: FDB.DatabaseOption) throws {
103+
try setOption(to: Array(value.utf8), forOption: option)
104104
}
105105

106106
/// Sets a database option with an integer value.
107107
///
108108
/// - Parameters:
109-
/// - option: The database option to set.
110109
/// - value: The integer value for the option.
110+
/// - option: The database option to set.
111111
/// - Throws: `FDBError` if the option cannot be set.
112-
public func setOption(_ option: FDB.DatabaseOption, value: Int) throws {
112+
public func setOption(to value: Int, forOption option: FDB.DatabaseOption) throws {
113113
var val = Int64(value).littleEndian
114114
try withUnsafeBytes(of: &val) { bytes in
115-
try setOption(option, value: Array(bytes))
115+
try setOption(to: Array(bytes), forOption: option)
116116
}
117117
}
118118
}

Sources/FoundationDB/FoundationdDB.swift

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -252,26 +252,26 @@ public protocol TransactionProtocol: Sendable {
252252
/// Sets a transaction option with an optional value.
253253
///
254254
/// - Parameters:
255-
/// - option: The transaction option to set.
256255
/// - value: Optional byte array value for the option.
256+
/// - option: The transaction option to set.
257257
/// - Throws: `FDBError` if the option cannot be set.
258-
func setOption(_ option: FDB.TransactionOption, value: FDB.Value?) throws
258+
func setOption(to value: FDB.Value?, forOption option: FDB.TransactionOption) throws
259259

260260
/// Sets a transaction option with a string value.
261261
///
262262
/// - Parameters:
263-
/// - option: The transaction option to set.
264263
/// - value: String value for the option.
264+
/// - option: The transaction option to set.
265265
/// - Throws: `FDBError` if the option cannot be set.
266-
func setOption(_ option: FDB.TransactionOption, value: String) throws
266+
func setOption(to value: String, forOption option: FDB.TransactionOption) throws
267267

268268
/// Sets a transaction option with an integer value.
269269
///
270270
/// - Parameters:
271-
/// - option: The transaction option to set.
272271
/// - value: Integer value for the option.
272+
/// - option: The transaction option to set.
273273
/// - Throws: `FDBError` if the option cannot be set.
274-
func setOption(_ option: FDB.TransactionOption, value: Int) throws
274+
func setOption(to value: Int, forOption option: FDB.TransactionOption) throws
275275
}
276276

277277
/// Default implementation of transaction retry logic for `DatabaseProtocol`.
@@ -394,17 +394,17 @@ extension TransactionProtocol {
394394
try await getRange(beginKey: beginKey, endKey: endKey, limit: limit, snapshot: snapshot)
395395
}
396396

397-
public func setOption(_ option: FDB.TransactionOption) throws {
398-
try setOption(option, value: nil)
397+
public func setOption(forOption option: FDB.TransactionOption) throws {
398+
try setOption(to: nil, forOption: option)
399399
}
400400

401-
public func setOption(_ option: FDB.TransactionOption, value: String) throws {
401+
public func setOption(to value: String, forOption option: FDB.TransactionOption) throws {
402402
let valueBytes = [UInt8](value.utf8)
403-
try setOption(option, value: valueBytes)
403+
try setOption(to: valueBytes, forOption: option)
404404
}
405405

406-
public func setOption(_ option: FDB.TransactionOption, value: Int) throws {
406+
public func setOption(to value: Int, forOption option: FDB.TransactionOption) throws {
407407
let valueBytes = withUnsafeBytes(of: Int64(value)) { [UInt8]($0) }
408-
try setOption(option, value: valueBytes)
408+
try setOption(to: valueBytes, forOption: option)
409409
}
410410
}

Sources/FoundationDB/Transaction.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ public final class FDBTransaction: TransactionProtocol, @unchecked Sendable {
9696
}
9797
}
9898

99-
public func setOption(_ option: FDB.TransactionOption, value: FDB.Value?) throws {
99+
public func setOption(to value: FDB.Value?, forOption option: FDB.TransactionOption) throws {
100100
let error: Int32
101101
if let value = value {
102102
error = value.withUnsafeBytes { bytes in

Tests/FoundationDBTests/FoundationDBTests.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1264,7 +1264,7 @@ func transactionTimeoutOption() async throws {
12641264
let newTransaction = try database.createTransaction()
12651265

12661266
// Set a very short timeout (1ms) to test timeout functionality
1267-
try newTransaction.setTimeout(1)
1267+
try newTransaction.setOption(to: 1, forOption: .timeout)
12681268

12691269
// This should timeout very quickly
12701270
do {
@@ -1293,7 +1293,7 @@ func transactionSizeLimitOption() async throws {
12931293
let newTransaction = try database.createTransaction()
12941294

12951295
// Set a very small size limit (100 bytes)
1296-
try newTransaction.setOption(.sizeLimit, 100)
1296+
try newTransaction.setOption(to: 100, forOption: .sizeLimit)
12971297

12981298
// Try to write more data than the limit allows
12991299
let largeValue = String(repeating: "x", count: 200)
@@ -1314,9 +1314,9 @@ func transactionOptionConvenienceMethods() throws {
13141314
// Note: These tests verify the API exists but don't actually set options
13151315

13161316
// Test timeout and retry methods
1317-
// transaction.setTimeout(30000) - would set timeout
1318-
// transaction.setRetryLimit(10) - would set retry limit
1319-
// transaction.setMaxRetryDelay(5000) - would set max retry delay
1317+
// transaction.setOption(to: 30000, forOption: .timeout) - would set timeout
1318+
// transaction.setOption(to: 10, forOption: .retryLimit) - would set retry limit
1319+
// transaction.setOption(to: 5000, forOption: .maxRetryDelay) - would set max retry delay
13201320
// transaction.setSizeLimit(1000000) - would set size limit
13211321

13221322
// Test idempotency methods

Tests/StackTester/Sources/StackTester/StackTester.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -507,7 +507,7 @@ class StackMachine {
507507
case "DISABLE_WRITE_CONFLICT":
508508
// Not directly available in Swift bindings, could use transaction option
509509
let transaction = try currentTransaction()
510-
try transaction.setOption(.nextWriteNoWriteConflictRange, value: nil)
510+
try transaction.setOption(to: nil, forOption: .nextWriteNoWriteConflictRange)
511511

512512
case "TUPLE_PACK":
513513
let numElements = waitAndPop().item as! Int64

0 commit comments

Comments
 (0)