1
1
import Foundation
2
2
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 `SyncRequestLoggerConfiguration`. Set to `nil` to disable request logging entirely.
12
+ ///
13
+ /// - SeeAlso: `SyncRequestLoggerConfiguration` for configuration options
14
+ public let requestLogger : SyncRequestLoggerConfiguration ?
15
+
16
+ /// Creates a new sync client configuration.
17
+ /// - Parameter requestLogger: Optional network logger configuration
18
+ public init ( requestLogger: SyncRequestLoggerConfiguration ? = nil ) {
19
+ self . requestLogger = requestLogger
20
+ }
21
+ }
22
+
3
23
/// Options for configuring a PowerSync connection.
4
24
///
5
25
/// Provides optional parameters to customize sync behavior such as throttling and retry policies.
@@ -42,21 +62,36 @@ public struct ConnectOptions {
42
62
@_spi ( PowerSyncExperimental)
43
63
public var newClientImplementation : Bool
44
64
65
+ /// Configuration for the sync client used for PowerSync requests.
66
+ ///
67
+ /// Provides options to customize network behavior including logging of HTTP
68
+ /// requests and responses. When `nil`, default HTTP client settings are used
69
+ /// with no network logging.
70
+ ///
71
+ /// Set this to configure network logging or other HTTP client behaviors
72
+ /// specific to PowerSync operations.
73
+ ///
74
+ /// - SeeAlso: `SyncClientConfiguration` for available configuration options
75
+ public var clientConfiguration : SyncClientConfiguration ?
76
+
45
77
/// Initializes a `ConnectOptions` instance with optional values.
46
78
///
47
79
/// - Parameters:
48
80
/// - crudThrottle: TimeInterval between CRUD operations in milliseconds. Defaults to `1` second.
49
81
/// - retryDelay: Delay TimeInterval between retry attempts in milliseconds. Defaults to `5` seconds.
50
82
/// - params: Custom sync parameters to send to the server. Defaults to an empty dictionary.
83
+ /// - clientConfiguration: Configuration for the HTTP client used to connect to PowerSync.
51
84
public init (
52
85
crudThrottle: TimeInterval = 1 ,
53
86
retryDelay: TimeInterval = 5 ,
54
- params: JsonParam = [ : ]
87
+ params: JsonParam = [ : ] ,
88
+ clientConfiguration: SyncClientConfiguration ? = nil
55
89
) {
56
90
self . crudThrottle = crudThrottle
57
91
self . retryDelay = retryDelay
58
92
self . params = params
59
93
self . newClientImplementation = false
94
+ self . clientConfiguration = clientConfiguration
60
95
}
61
96
62
97
/// Initializes a ``ConnectOptions`` instance with optional values, including experimental options.
@@ -65,12 +100,14 @@ public struct ConnectOptions {
65
100
crudThrottle: TimeInterval = 1 ,
66
101
retryDelay: TimeInterval = 5 ,
67
102
params: JsonParam = [ : ] ,
68
- newClientImplementation: Bool = false
103
+ newClientImplementation: Bool = false ,
104
+ clientConfiguration: SyncClientConfiguration ? = nil
69
105
) {
70
106
self . crudThrottle = crudThrottle
71
107
self . retryDelay = retryDelay
72
108
self . params = params
73
109
self . newClientImplementation = newClientImplementation
110
+ self . clientConfiguration = clientConfiguration
74
111
}
75
112
}
76
113
@@ -91,7 +128,6 @@ public protocol PowerSyncDatabaseProtocol: Queries {
91
128
/// Wait for the first sync to occur
92
129
func waitForFirstSync( ) async throws
93
130
94
-
95
131
/// Replace the schema with a new version. This is for advanced use cases - typically the schema
96
132
/// should just be specified once in the constructor.
97
133
///
@@ -179,7 +215,7 @@ public protocol PowerSyncDatabaseProtocol: Queries {
179
215
/// The database can still be queried after this is called, but the tables
180
216
/// would be empty.
181
217
///
182
- /// - Parameter clearLocal: Set to false to preserve data in local-only tables.
218
+ /// - Parameter clearLocal: Set to false to preserve data in local-only tables. Defaults to `true`.
183
219
func disconnectAndClear( clearLocal: Bool ) async throws
184
220
185
221
/// Close the database, releasing resources.
@@ -229,8 +265,8 @@ public extension PowerSyncDatabaseProtocol {
229
265
)
230
266
}
231
267
232
- func disconnectAndClear( clearLocal : Bool = true ) async throws {
233
- try await self . disconnectAndClear ( clearLocal: clearLocal )
268
+ func disconnectAndClear( ) async throws {
269
+ try await disconnectAndClear ( clearLocal: true )
234
270
}
235
271
236
272
func getCrudBatch( limit: Int32 = 100 ) async throws -> CrudBatch ? {
0 commit comments