Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## 1.5.1 (unreleased)

* Update core extension to 0.4.5 ([changelog](https://github.com/powersync-ja/powersync-sqlite-core/releases/tag/v0.4.5))
* Additional Swift 6 Strict Concurrency Checking declarations added for remaining protocols.

## 1.5.0

Expand Down
6 changes: 4 additions & 2 deletions Demo/PowerSyncExample.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -645,6 +645,7 @@
SDKROOT = iphoneos;
SWIFT_ACTIVE_COMPILATION_CONDITIONS = "DEBUG $(inherited)";
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_STRICT_CONCURRENCY = complete;
};
name = Debug;
};
Expand Down Expand Up @@ -701,6 +702,7 @@
OTHER_LDFLAGS = "-lsqlite3";
SDKROOT = iphoneos;
SWIFT_COMPILATION_MODE = wholemodule;
SWIFT_STRICT_CONCURRENCY = complete;
VALIDATE_PRODUCT = YES;
};
name = Release;
Expand Down Expand Up @@ -742,7 +744,7 @@
SWIFT_OBJC_BRIDGING_HEADER = "PowerSyncExample/PowerSyncExample-Bridging-Header.h";
"SWIFT_OBJC_BRIDGING_HEADER[arch=*]" = "";
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 5.0;
SWIFT_VERSION = 6.0;
TARGETED_DEVICE_FAMILY = "1,2";
};
name = Debug;
Expand Down Expand Up @@ -781,7 +783,7 @@
SUPPORTS_MAC_DESIGNED_FOR_IPHONE_IPAD = NO;
SWIFT_EMIT_LOC_STRINGS = YES;
SWIFT_OBJC_BRIDGING_HEADER = "PowerSyncExample/PowerSyncExample-Bridging-Header.h";
SWIFT_VERSION = 5.0;
SWIFT_VERSION = 6.0;
TARGETED_DEVICE_FAMILY = "1,2";
};
name = Release;
Expand Down
4 changes: 2 additions & 2 deletions Demo/PowerSyncExample/Components/AddListView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ struct AddListView: View {
Task {
do {
try await system.insertList(newList)
await completion(.success(true))
completion(.success(true))
} catch {
await completion(.failure(error))
completion(.failure(error))
throw error
}
}
Expand Down
4 changes: 2 additions & 2 deletions Demo/PowerSyncExample/Components/AddTodoListView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ struct AddTodoListView: View {
Task{
do {
try await system.insertTodo(newTodo, listId)
await completion(.success(true))
completion(.success(true))
} catch {
await completion(.failure(error))
completion(.failure(error))
throw error
}
}
Expand Down
3 changes: 2 additions & 1 deletion Demo/PowerSyncExample/PowerSync/SupabaseConnector.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,14 @@ private enum PostgresFatalCodes {
}

@Observable
@MainActor // _session is mutable, limiting to the MainActor satisfies Sendable constraints
final class SupabaseConnector: PowerSyncBackendConnectorProtocol {
let powerSyncEndpoint: String = Secrets.powerSyncEndpoint
let client: SupabaseClient = .init(
supabaseURL: Secrets.supabaseURL,
supabaseKey: Secrets.supabaseAnonKey,
)
var session: Session?
private(set) var session: Session?
private var errorCode: String?

@ObservationIgnored
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import Foundation
import PowerSync
import Supabase

class SupabaseRemoteStorage: RemoteStorageAdapter {
final class SupabaseRemoteStorage: RemoteStorageAdapter {
let storage: Supabase.StorageFileApi

init(storage: Supabase.StorageFileApi) {
Expand Down
28 changes: 12 additions & 16 deletions Demo/PowerSyncExample/PowerSync/SystemManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,16 @@ func getAttachmentsDirectoryPath() throws -> String {

let logTag = "SystemManager"

/// We use the MainActor SupabaseConnector synchronously here, this requires specifying that SystemManager runs on the MainActor
/// We don't actually block the MainActor with anything
@Observable
class SystemManager {
@MainActor
final class SystemManager {
let connector = SupabaseConnector()
let schema = AppSchema
let db: PowerSyncDatabaseProtocol

var attachments: AttachmentQueue?
let attachments: AttachmentQueue?

init() {
db = PowerSyncDatabase(
Expand Down Expand Up @@ -226,25 +229,18 @@ class SystemManager {
try await attachments.deleteFile(
attachmentId: photoId
) { transaction, _ in
try self.deleteTodoInTX(
id: todo.id,
tx: transaction
try transaction.execute(
sql: "DELETE FROM \(TODOS_TABLE) WHERE id = ?",
parameters: [todo.id]
)
}
} else {
try await db.writeTransaction { transaction in
try self.deleteTodoInTX(
id: todo.id,
tx: transaction
_ = try await db.writeTransaction { transaction in
try transaction.execute(
sql: "DELETE FROM \(TODOS_TABLE) WHERE id = ?",
parameters: [todo.id]
)
}
}
}

private func deleteTodoInTX(id: String, tx: ConnectionContext) throws {
_ = try tx.execute(
sql: "DELETE FROM \(TODOS_TABLE) WHERE id = ?",
parameters: [id]
)
}
}
4 changes: 4 additions & 0 deletions Sources/PowerSync/Kotlin/KotlinTypes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,7 @@ extension KotlinPowerSyncBackendConnector: @retroactive @unchecked Sendable {}
extension KotlinPowerSyncCredentials: @retroactive @unchecked Sendable {}
extension PowerSyncKotlin.KermitLogger: @retroactive @unchecked Sendable {}
extension PowerSyncKotlin.SyncStatus: @retroactive @unchecked Sendable {}

extension PowerSyncKotlin.CrudEntry: @retroactive @unchecked Sendable {}
extension PowerSyncKotlin.CrudBatch: @retroactive @unchecked Sendable {}
extension PowerSyncKotlin.CrudTransaction: @retroactive @unchecked Sendable {}
10 changes: 8 additions & 2 deletions Sources/PowerSync/Kotlin/sync/KotlinSyncStatusData.swift
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,17 @@ extension KotlinProgressWithOperationsProtocol {
}
}

struct KotlinProgressWithOperations: KotlinProgressWithOperationsProtocol {
struct KotlinProgressWithOperations: KotlinProgressWithOperationsProtocol,
// We can't mark PowerSyncKotlin.ProgressWithOperations as Sendable
@unchecked Sendable
{
let base: PowerSyncKotlin.ProgressWithOperations
}

struct KotlinSyncDownloadProgress: KotlinProgressWithOperationsProtocol, SyncDownloadProgress {
struct KotlinSyncDownloadProgress: KotlinProgressWithOperationsProtocol, SyncDownloadProgress,
// We can't mark PowerSyncKotlin.SyncDownloadProgress as Sendable
@unchecked Sendable
{
let progress: PowerSyncKotlin.SyncDownloadProgress

var base: any PowerSyncKotlin.ProgressWithOperations {
Expand Down
15 changes: 8 additions & 7 deletions Sources/PowerSync/Logger.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,10 @@ import OSLog
/// A log writer which prints to the standard output
///
/// This writer uses `os.Logger` on iOS/macOS/tvOS/watchOS 14+ and falls back to `print` for earlier versions.
public class PrintLogWriter: LogWriterProtocol {
public final class PrintLogWriter: LogWriterProtocol {
private let subsystem: String
private let category: String
private lazy var logger: Any? = {
if #available(iOS 14.0, macOS 11.0, tvOS 14.0, watchOS 7.0, *) {
return Logger(subsystem: subsystem, category: category)
}
return nil
}()
private let logger: Sendable?

/// Creates a new PrintLogWriter
/// - Parameters:
Expand All @@ -22,6 +17,12 @@ public class PrintLogWriter: LogWriterProtocol {
{
self.subsystem = subsystem
self.category = category

if #available(iOS 14.0, macOS 11.0, tvOS 14.0, watchOS 7.0, *) {
logger = Logger(subsystem: subsystem, category: category)
} else {
logger = nil
}
}

/// Logs a message with a given severity and optional tag.
Expand Down
2 changes: 1 addition & 1 deletion Sources/PowerSync/Protocol/LoggerProtocol.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public enum LogSeverity: Int, CaseIterable, Sendable {
/// A protocol for writing log messages to a specific backend or output.
///
/// Conformers handle the actual writing or forwarding of log messages.
public protocol LogWriterProtocol {
public protocol LogWriterProtocol: Sendable {
/// Logs a message with the given severity and optional tag.
///
/// - Parameters:
Expand Down
4 changes: 2 additions & 2 deletions Sources/PowerSync/Protocol/PowerSyncDatabaseProtocol.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import Foundation
///
/// Provides options to customize network behavior and logging for PowerSync
/// HTTP requests and responses.
public struct SyncClientConfiguration {
public struct SyncClientConfiguration: Sendable {
/// Optional configuration for logging PowerSync HTTP requests.
///
/// When provided, network requests will be logged according to the
Expand All @@ -23,7 +23,7 @@ public struct SyncClientConfiguration {
/// Options for configuring a PowerSync connection.
///
/// Provides optional parameters to customize sync behavior such as throttling and retry policies.
public struct ConnectOptions {
public struct ConnectOptions: Sendable {
/// Defaults to 1 second
public static let DefaultCrudThrottle: TimeInterval = 1

Expand Down
12 changes: 6 additions & 6 deletions Sources/PowerSync/Protocol/Schema/Column.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Foundation
import PowerSyncKotlin

public protocol ColumnProtocol: Equatable {
public protocol ColumnProtocol: Equatable, Sendable {
/// Name of the column.
var name: String { get }
/// Type of the column.
Expand All @@ -15,7 +15,7 @@ public protocol ColumnProtocol: Equatable {
var type: ColumnData { get }
}

public enum ColumnData {
public enum ColumnData: Sendable {
case text
case integer
case real
Expand All @@ -25,23 +25,23 @@ public enum ColumnData {
public struct Column: ColumnProtocol {
public let name: String
public let type: ColumnData

public init(
name: String,
type: ColumnData
) {
self.name = name
self.type = type
}

public static func text(_ name: String) -> Column {
Column(name: name, type: .text)
}

public static func integer(_ name: String) -> Column {
Column(name: name, type: .integer)
}

public static func real(_ name: String) -> Column {
Column(name: name, type: .real)
}
Expand Down
10 changes: 5 additions & 5 deletions Sources/PowerSync/Protocol/Schema/Index.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Foundation
import PowerSyncKotlin

public protocol IndexProtocol {
public protocol IndexProtocol: Sendable {
///
/// Descriptive name of the index.
///
Expand All @@ -15,22 +15,22 @@ public protocol IndexProtocol {
public struct Index: IndexProtocol {
public let name: String
public let columns: [IndexedColumnProtocol]

public init(
name: String,
columns: [IndexedColumnProtocol]
) {
self.name = name
self.columns = columns
}

public init(
name: String,
_ columns: IndexedColumnProtocol...
) {
self.init(name: name, columns: columns)
}

public static func ascending(
name: String,
columns: [String]
Expand All @@ -40,7 +40,7 @@ public struct Index: IndexProtocol {
columns: columns.map { IndexedColumn.ascending($0) }
)
}

public static func ascending(
name: String,
column: String
Expand Down
8 changes: 4 additions & 4 deletions Sources/PowerSync/Protocol/Schema/IndexedColumn.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import Foundation
///
/// Describes an indexed column.
///
public protocol IndexedColumnProtocol {
public protocol IndexedColumnProtocol: Sendable {
///
/// Name of the column to index.
///
Expand All @@ -17,22 +17,22 @@ public protocol IndexedColumnProtocol {
public struct IndexedColumn: IndexedColumnProtocol {
public let column: String
public let ascending: Bool

public init(
column: String,
ascending: Bool = true
) {
self.column = column
self.ascending = ascending
}

///
/// Creates ascending IndexedColumn
///
public static func ascending(_ column: String) -> IndexedColumn {
IndexedColumn(column: column, ascending: true)
}

///
/// Creates descending IndexedColumn
///
Expand Down
Loading