11import Foundation
22
3+ /// Configuration for the sync client used to connect to the PowerSync service.
4+ ///
5+ /// Provides options to customize network behavior and logging for PowerSync
6+ /// HTTP requests and responses.
7+ public struct SyncClientConfiguration {
8+ /// Optional configuration for logging PowerSync HTTP requests.
9+ ///
10+ /// When provided, network requests will be logged according to the
11+ /// specified `NetworkLogLevel`. The `logLevel` is set during initialization
12+ /// and remains constant throughout the PowerSync session.
13+ ///
14+ /// Set to `nil` to disable network logging entirely.
15+ ///
16+ /// - SeeAlso: `NetworkLoggerConfig` for configuration options
17+ public let networkLogger : NetworkLoggerConfig ?
18+
19+ /// Creates a new sync client configuration.
20+ /// - Parameter networkLogger: Optional network logger configuration
21+ public init ( networkLogger: NetworkLoggerConfig ? = nil ) {
22+ self . networkLogger = networkLogger
23+ }
24+ }
25+
326/// Options for configuring a PowerSync connection.
427///
528/// Provides optional parameters to customize sync behavior such as throttling and retry policies.
@@ -41,31 +64,37 @@ public struct ConnectOptions {
4164 /// We encourage interested users to try the new client.
4265 @_spi ( PowerSyncExperimental)
4366 public var newClientImplementation : Bool
44-
45- /// The connection method used to connect to the Powersync service .
67+
68+ /// Configuration for the sync client used for PowerSync requests .
4669 ///
47- /// The default method is ``ConnectionMethod/http``. Using ``ConnectionMethod/webSocket(_:)`` can
48- /// improve performance as a more efficient binary protocol is used. However, using the websocket connection method
49- /// requires enabling ``ConnectOptions/newClientImplementation``.
50- @_spi ( PowerSyncExperimental)
51- public var connectionMethod : ConnectionMethod
70+ /// Provides options to customize network behavior including logging of HTTP
71+ /// requests and responses. When `nil`, default HTTP client settings are used
72+ /// with no network logging.
73+ ///
74+ /// Set this to configure network logging or other HTTP client behaviors
75+ /// specific to PowerSync operations.
76+ ///
77+ /// - SeeAlso: `SyncClientConfiguration` for available configuration options
78+ public var clientConfiguration : SyncClientConfiguration ?
5279
5380 /// Initializes a `ConnectOptions` instance with optional values.
5481 ///
5582 /// - Parameters:
5683 /// - crudThrottle: TimeInterval between CRUD operations in milliseconds. Defaults to `1` second.
5784 /// - retryDelay: Delay TimeInterval between retry attempts in milliseconds. Defaults to `5` seconds.
5885 /// - params: Custom sync parameters to send to the server. Defaults to an empty dictionary.
86+ /// - clientConfiguration: Configuration for the HTTP client used to connect to PowerSync.
5987 public init (
6088 crudThrottle: TimeInterval = 1 ,
6189 retryDelay: TimeInterval = 5 ,
62- params: JsonParam = [ : ]
90+ params: JsonParam = [ : ] ,
91+ clientConfiguration: SyncClientConfiguration ? = nil
6392 ) {
6493 self . crudThrottle = crudThrottle
6594 self . retryDelay = retryDelay
6695 self . params = params
6796 self . newClientImplementation = false
68- self . connectionMethod = . http
97+ self . clientConfiguration = clientConfiguration
6998 }
7099
71100 /// Initializes a ``ConnectOptions`` instance with optional values, including experimental options.
@@ -75,22 +104,16 @@ public struct ConnectOptions {
75104 retryDelay: TimeInterval = 5 ,
76105 params: JsonParam = [ : ] ,
77106 newClientImplementation: Bool = false ,
78- connectionMethod : ConnectionMethod = . http
107+ clientConfiguration : SyncClientConfiguration ? = nil
79108 ) {
80109 self . crudThrottle = crudThrottle
81110 self . retryDelay = retryDelay
82111 self . params = params
83112 self . newClientImplementation = newClientImplementation
84- self . connectionMethod = connectionMethod
113+ self . clientConfiguration = clientConfiguration
85114 }
86115}
87116
88- @_spi ( PowerSyncExperimental)
89- public enum ConnectionMethod {
90- case http
91- case webSocket
92- }
93-
94117/// A PowerSync managed database.
95118///
96119/// Use one instance per database file.
@@ -108,7 +131,6 @@ public protocol PowerSyncDatabaseProtocol: Queries {
108131 /// Wait for the first sync to occur
109132 func waitForFirstSync( ) async throws
110133
111-
112134 /// Replace the schema with a new version. This is for advanced use cases - typically the schema
113135 /// should just be specified once in the constructor.
114136 ///
@@ -247,7 +269,7 @@ public extension PowerSyncDatabaseProtocol {
247269 }
248270
249271 func disconnectAndClear( clearLocal: Bool = true ) async throws {
250- try await self . disconnectAndClear ( clearLocal: clearLocal)
272+ try await disconnectAndClear ( clearLocal: clearLocal)
251273 }
252274
253275 func getCrudBatch( limit: Int32 = 100 ) async throws -> CrudBatch ? {
0 commit comments