From 03b65dd784e5daaaee955336c2d174740561c098 Mon Sep 17 00:00:00 2001 From: Tony Li Date: Thu, 4 Dec 2025 22:20:59 +1300 Subject: [PATCH 1/5] Change WordPressAPI and WordPressApiCache from actor to class --- .../wordpress-api-cache/WordPressApiCache.swift | 8 ++++---- .../swift/Sources/wordpress-api/WordPressAPI.swift | 14 +++++++------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/native/swift/Sources/wordpress-api-cache/WordPressApiCache.swift b/native/swift/Sources/wordpress-api-cache/WordPressApiCache.swift index 8c29e73eb..b202273f4 100644 --- a/native/swift/Sources/wordpress-api-cache/WordPressApiCache.swift +++ b/native/swift/Sources/wordpress-api-cache/WordPressApiCache.swift @@ -1,9 +1,9 @@ import Foundation import WordPressAPIInternal -public actor WordPressApiCache { +public final class WordPressApiCache: Sendable { - private let cache: WpApiCache + public let cache: WpApiCache private let delegate: any DatabaseDelegate public struct Notifications { @@ -24,12 +24,12 @@ public actor WordPressApiCache { } /// Creates a new in-memory cache - public init(delegate: DatabaseDelegate = ApiCacheDelegate()) throws { + public convenience init(delegate: DatabaseDelegate = ApiCacheDelegate()) throws { try self.init(path: ":memory:", delegate: delegate) } /// Creates a new cache at the specified file system URL - public init(url: URL, delegate: DatabaseDelegate = ApiCacheDelegate()) throws { + public convenience init(url: URL, delegate: DatabaseDelegate = ApiCacheDelegate()) throws { try self.init(path: url.absoluteString, delegate: delegate) } diff --git a/native/swift/Sources/wordpress-api/WordPressAPI.swift b/native/swift/Sources/wordpress-api/WordPressAPI.swift index 4a5efd3f0..ab8d87b86 100644 --- a/native/swift/Sources/wordpress-api/WordPressAPI.swift +++ b/native/swift/Sources/wordpress-api/WordPressAPI.swift @@ -9,7 +9,7 @@ import FoundationNetworking import Combine #endif -public actor WordPressAPI { +public final class WordPressAPI: Sendable { enum Errors: Error { case unableToParseResponse @@ -17,10 +17,10 @@ public actor WordPressAPI { private let apiUrlResolver: ApiUrlResolver let requestExecutor: SafeRequestExecutor - private let apiClientDelegate: WpApiClientDelegate + public let apiClientDelegate: WpApiClientDelegate package let requestBuilder: UniffiWpApiClient - public init( + public convenience init( urlSession: URLSession, apiRootUrl: ParsedUrl, authentication: WpAuthentication, @@ -36,7 +36,7 @@ public actor WordPressAPI { ) } - public init( + public convenience init( urlSession: URLSession, apiRootUrl: ParsedUrl, authenticationProvider: WpAuthenticationProvider, @@ -52,7 +52,7 @@ public actor WordPressAPI { ) } - public init( + public convenience init( urlSession: URLSession, apiUrlResolver: ApiUrlResolver, authenticationProvider: WpAuthenticationProvider, @@ -68,7 +68,7 @@ public actor WordPressAPI { ) } - public init( + public convenience init( urlSession: URLSession, siteUrl: String, apiRootUrl: ParsedUrl, @@ -93,7 +93,7 @@ public actor WordPressAPI { ) } - public init( + public convenience init( urlSession: URLSession, details: AutoDiscoveryAttemptSuccess, username: String, From 2d121622e7b083d6efa1445db4d03e8389f9aba0 Mon Sep 17 00:00:00 2001 From: Tony Li Date: Fri, 5 Dec 2025 09:23:53 +1300 Subject: [PATCH 2/5] Revert apiDelegate to private --- native/swift/Sources/wordpress-api/WordPressAPI.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/native/swift/Sources/wordpress-api/WordPressAPI.swift b/native/swift/Sources/wordpress-api/WordPressAPI.swift index ab8d87b86..cb21b87ce 100644 --- a/native/swift/Sources/wordpress-api/WordPressAPI.swift +++ b/native/swift/Sources/wordpress-api/WordPressAPI.swift @@ -17,7 +17,7 @@ public final class WordPressAPI: Sendable { private let apiUrlResolver: ApiUrlResolver let requestExecutor: SafeRequestExecutor - public let apiClientDelegate: WpApiClientDelegate + private let apiClientDelegate: WpApiClientDelegate package let requestBuilder: UniffiWpApiClient public convenience init( From bc972f7f2eb59d4c4567c064f5a77837af2df4bf Mon Sep 17 00:00:00 2001 From: Tony Li Date: Mon, 8 Dec 2025 20:12:17 +1300 Subject: [PATCH 3/5] Remove an unneeded `await` --- .../Tests/wordpress-api-cache/WordPressApiCacheTests.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/native/swift/Tests/wordpress-api-cache/WordPressApiCacheTests.swift b/native/swift/Tests/wordpress-api-cache/WordPressApiCacheTests.swift index 706635d37..2cfa0180a 100644 --- a/native/swift/Tests/wordpress-api-cache/WordPressApiCacheTests.swift +++ b/native/swift/Tests/wordpress-api-cache/WordPressApiCacheTests.swift @@ -26,7 +26,7 @@ actor Test { } } - await self.cache.startListeningForUpdates() + self.cache.startListeningForUpdates() let migrationCount = try await self.cache.performMigrations() // Wait for NotificationCenter to finish delivery From 5c5e9b18d0a4b5442d36c7ea636c1915acda15dd Mon Sep 17 00:00:00 2001 From: Tony Li Date: Mon, 8 Dec 2025 22:04:43 +1300 Subject: [PATCH 4/5] Remove another unneeded await --- .../swift/Sources/wordpress-api-cache/WordPressApiCache.swift | 2 +- .../Tests/wordpress-api-cache/WordPressApiCacheTests.swift | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/native/swift/Sources/wordpress-api-cache/WordPressApiCache.swift b/native/swift/Sources/wordpress-api-cache/WordPressApiCache.swift index b202273f4..33fc03ab3 100644 --- a/native/swift/Sources/wordpress-api-cache/WordPressApiCache.swift +++ b/native/swift/Sources/wordpress-api-cache/WordPressApiCache.swift @@ -39,7 +39,7 @@ public final class WordPressApiCache: Sendable { self.delegate = delegate } - public func performMigrations() async throws -> Int { + public func performMigrations() throws -> Int { return Int(try self.cache.performMigrations()) } diff --git a/native/swift/Tests/wordpress-api-cache/WordPressApiCacheTests.swift b/native/swift/Tests/wordpress-api-cache/WordPressApiCacheTests.swift index 2cfa0180a..e45a7db36 100644 --- a/native/swift/Tests/wordpress-api-cache/WordPressApiCacheTests.swift +++ b/native/swift/Tests/wordpress-api-cache/WordPressApiCacheTests.swift @@ -12,7 +12,7 @@ actor Test { } @Test func testMigrationsWork() async throws { - let migrationsPerformed = try await self.cache.performMigrations() + let migrationsPerformed = try self.cache.performMigrations() #expect(migrationsPerformed == 6) } @@ -27,7 +27,7 @@ actor Test { } self.cache.startListeningForUpdates() - let migrationCount = try await self.cache.performMigrations() + let migrationCount = try self.cache.performMigrations() // Wait for NotificationCenter to finish delivery try await Task.sleep(nanoseconds: 10 * NSEC_PER_MSEC) From 263ecf2dfbf768c5270371408259b49235738e8a Mon Sep 17 00:00:00 2001 From: Tony Li Date: Mon, 8 Dec 2025 22:04:58 +1300 Subject: [PATCH 5/5] Add sleep to make unit test pass --- .../Tests/wordpress-api-cache/WordPressApiCacheTests.swift | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/native/swift/Tests/wordpress-api-cache/WordPressApiCacheTests.swift b/native/swift/Tests/wordpress-api-cache/WordPressApiCacheTests.swift index e45a7db36..ae8021984 100644 --- a/native/swift/Tests/wordpress-api-cache/WordPressApiCacheTests.swift +++ b/native/swift/Tests/wordpress-api-cache/WordPressApiCacheTests.swift @@ -26,11 +26,14 @@ actor Test { } } + // Wait for the observer Task to start running. + try await Task.sleep(nanoseconds: 100 * NSEC_PER_MSEC) + self.cache.startListeningForUpdates() let migrationCount = try self.cache.performMigrations() // Wait for NotificationCenter to finish delivery - try await Task.sleep(nanoseconds: 10 * NSEC_PER_MSEC) + try await Task.sleep(nanoseconds: 100 * NSEC_PER_MSEC) #expect(migrationCount == self.changeCount) handle.cancel()