Skip to content

Commit 5166c0b

Browse files
committed
Avoid importing Kotlin in interface
1 parent 89fc335 commit 5166c0b

File tree

5 files changed

+48
-43
lines changed

5 files changed

+48
-43
lines changed

Package.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ if let kotlinSdkPath = localKotlinSdkOverride {
3232
// Not using a local build, so download from releases
3333
conditionalTargets.append(.binaryTarget(
3434
name: "PowerSyncKotlin",
35-
url: "https://github.com/powersync-ja/powersync-kotlin/releases/download/v1.5.1/PowersyncKotlinRelease.zip",
36-
checksum: "3a2de1863d2844d49cebf4428d0ab49956ba384dcab9f3cc2ddbc7836013c434"
35+
url: "https://github.com/powersync-ja/powersync-kotlin/releases/download/v1.6.0/PowersyncKotlinRelease.zip",
36+
checksum: "4f70331c11e30625eecf4ebcebe7b562e2e0165774890d2a43480ebc3a9081cc"
3737
))
3838
}
3939

Sources/PowerSync/Kotlin/KotlinPowerSyncDatabaseImpl.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,8 @@ final class KotlinPowerSyncDatabaseImpl: PowerSyncDatabaseProtocol,
7575
)
7676
}
7777

78-
func getCrudTransactions() -> CrudTransactions {
79-
return CrudTransactions(db: kotlinDatabase)
78+
func getCrudTransactions() -> any CrudTransactions {
79+
return KotlinCrudTransactions(db: kotlinDatabase)
8080
}
8181

8282
func getPowerSyncVersion() async throws -> String {
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import PowerSyncKotlin
2+
3+
struct KotlinCrudTransactions: CrudTransactions {
4+
typealias Element = KotlinCrudTransaction
5+
6+
private let db: KotlinPowerSyncDatabase
7+
8+
init(db: KotlinPowerSyncDatabase) {
9+
self.db = db
10+
}
11+
12+
public func makeAsyncIterator() -> CrudTransactionIterator {
13+
let kotlinIterator = errorHandledCrudTransactions(db: self.db).makeAsyncIterator()
14+
return CrudTransactionIterator(inner: kotlinIterator)
15+
}
16+
17+
struct CrudTransactionIterator: CrudTransactionsIterator {
18+
private var inner: PowerSyncKotlin.SkieSwiftFlowIterator<PowerSyncKotlin.PowerSyncResult>
19+
20+
internal init(inner: PowerSyncKotlin.SkieSwiftFlowIterator<PowerSyncKotlin.PowerSyncResult>) {
21+
self.inner = inner
22+
}
23+
24+
public mutating func next() async throws -> KotlinCrudTransaction? {
25+
if let innerTx = await self.inner.next() {
26+
if let success = innerTx as? PowerSyncResult.Success {
27+
let tx = success.value as! PowerSyncKotlin.CrudTransaction
28+
return try KotlinCrudTransaction(transaction: tx)
29+
} else if let failure = innerTx as? PowerSyncResult.Failure {
30+
try throwPowerSyncException(exception: failure.exception)
31+
}
32+
33+
fatalError("unreachable")
34+
} else {
35+
return nil
36+
}
37+
}
38+
}
39+
}

Sources/PowerSync/Protocol/PowerSyncDatabaseProtocol.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ public protocol PowerSyncDatabaseProtocol: Queries, Sendable {
205205
/// ```Swift
206206
///
207207
/// ```
208-
func getCrudTransactions() -> CrudTransactions
208+
func getCrudTransactions() -> any CrudTransactions
209209

210210
/// Convenience method to get the current version of PowerSync.
211211
func getPowerSyncVersion() async throws -> String
Lines changed: 4 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import Foundation
2-
import PowerSyncKotlin
32

43
/// A transaction of client-side changes.
54
public protocol CrudTransaction: Sendable {
@@ -29,40 +28,7 @@ public extension CrudTransaction {
2928
/// A sequence of crud transactions in a PowerSync database.
3029
///
3130
/// For details, see ``PowerSyncDatabaseProtocol/getCrudTransactions()``.
32-
public struct CrudTransactions: AsyncSequence {
33-
private let db: KotlinPowerSyncDatabase
34-
35-
init(db: KotlinPowerSyncDatabase) {
36-
self.db = db
37-
}
38-
39-
public func makeAsyncIterator() -> CrudTransactionIterator {
40-
let kotlinIterator = errorHandledCrudTransactions(db: self.db).makeAsyncIterator()
41-
return CrudTransactionIterator(inner: kotlinIterator)
42-
}
43-
44-
public struct CrudTransactionIterator: AsyncIteratorProtocol {
45-
public typealias Element = any CrudTransaction
46-
47-
private var inner: PowerSyncKotlin.SkieSwiftFlowIterator<PowerSyncKotlin.PowerSyncResult>
48-
49-
internal init(inner: PowerSyncKotlin.SkieSwiftFlowIterator<PowerSyncKotlin.PowerSyncResult>) {
50-
self.inner = inner
51-
}
52-
53-
public mutating func next() async throws -> (any CrudTransaction)? {
54-
if let innerTx = await self.inner.next() {
55-
if let success = innerTx as? PowerSyncResult.Success {
56-
let tx = success.value as! PowerSyncKotlin.CrudTransaction
57-
return try KotlinCrudTransaction(transaction: tx)
58-
} else if let failure = innerTx as? PowerSyncResult.Failure {
59-
try throwPowerSyncException(exception: failure.exception)
60-
}
61-
62-
fatalError("unreachable")
63-
} else {
64-
return nil
65-
}
66-
}
67-
}
68-
}
31+
public protocol CrudTransactions: AsyncSequence where Element: CrudTransaction, AsyncIterator: CrudTransactionsIterator {}
32+
33+
/// The iterator returned by ``CrudTransactions``.
34+
public protocol CrudTransactionsIterator: AsyncIteratorProtocol where Element: CrudTransaction {}

0 commit comments

Comments
 (0)