Skip to content

Commit

Permalink
Merge branch 'main' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
mickael-menu committed Oct 11, 2024
2 parents 0cfb105 + cca64ec commit 7ffbdd6
Show file tree
Hide file tree
Showing 34 changed files with 60 additions and 54 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,11 @@ All notable changes to this project will be documented in this file. Take a look
* `Publication.localizedTitle` is now optional, as we cannot guarantee a publication will always have a title.


## [2.7.3]

* [#483](https://github.com/readium/swift-toolkit/issues/483) Fix build on Xcode 16.


## [2.7.2]

### Fixed
Expand Down Expand Up @@ -754,5 +759,6 @@ progression. Now if no reading progression is set, the `effectiveReadingProgress
[2.7.0]: https://github.com/readium/swift-toolkit/compare/2.6.1...2.7.0
[2.7.1]: https://github.com/readium/swift-toolkit/compare/2.7.0...2.7.1
[2.7.2]: https://github.com/readium/swift-toolkit/compare/2.7.1...2.7.2
[2.7.3]: https://github.com/readium/swift-toolkit/compare/2.7.2...2.7.3
[3.0.0-alpha.1]: https://github.com/readium/swift-toolkit/compare/2.7.1...3.0.0-alpha.1
[3.0.0-alpha.2]: https://github.com/readium/swift-toolkit/compare/3.0.0-alpha.1...3.0.0-alpha.2
2 changes: 1 addition & 1 deletion Sources/Adapters/GCDWebServer/GCDHTTPServer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ public class GCDHTTPServer: HTTPServer, Loggable {
private extension Resource {
func length() async -> ReadResult<UInt64> {
await estimatedLength()
.flatMap { length in
.asyncFlatMap { length in
if let length = length {
return .success(length)
} else {
Expand Down
12 changes: 6 additions & 6 deletions Sources/Adapters/LCPSQLite/SQLiteLCPLicenseRepository.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ import SQLite

public class LCPSQLiteLicenseRepository: LCPLicenseRepository {
let licenses = Table("Licenses")
let id = Expression<String>("id")
let printsLeft = Expression<Int?>("printsLeft")
let copiesLeft = Expression<Int?>("copiesLeft")
let registered = Expression<Bool>("registered")
let id = SQLite.Expression<String>("id")
let printsLeft = SQLite.Expression<Int?>("printsLeft")
let copiesLeft = SQLite.Expression<Int?>("copiesLeft")
let registered = SQLite.Expression<Bool>("registered")

private let db: Connection

Expand Down Expand Up @@ -98,15 +98,15 @@ public class LCPSQLiteLicenseRepository: LCPLicenseRepository {
((try? db.scalar(licenses.filter(id == licenseID).count)) ?? 0) != 0
}

private func get(_ column: Expression<Int?>, for licenseId: String) throws -> Int? {
private func get(_ column: SQLite.Expression<Int?>, for licenseId: String) throws -> Int? {
let query = licenses.select(column).filter(id == licenseId)
for row in try db.prepare(query) {
return try row.get(column)
}
return nil
}

private func set(_ column: Expression<Int?>, to value: Int?, for licenseId: String) throws {
private func set(_ column: SQLite.Expression<Int?>, to value: Int?, for licenseId: String) throws {
let filterLicense = licenses.filter(id == licenseId)
try db.run(filterLicense.update(column <- value))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ import SQLite

public class LCPSQLitePassphraseRepository: LCPPassphraseRepository, Loggable {
let transactions = Table("Transactions")
let licenseId = Expression<String>("licenseId")
let provider = Expression<String>("origin")
let userId = Expression<String?>("userId")
let passphrase = Expression<String>("passphrase") // hashed.
let licenseId = SQLite.Expression<String>("licenseId")
let provider = SQLite.Expression<String>("origin")
let userId = SQLite.Expression<String?>("userId")
let passphrase = SQLite.Expression<String>("passphrase") // hashed.

private let db: Connection

Expand Down
2 changes: 1 addition & 1 deletion Sources/Internal/Extensions/NSRegularExpression.swift
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public extension NSRange {
}
}

public final class ReplacingRegularExpression: NSRegularExpression {
public final class ReplacingRegularExpression: NSRegularExpression, @unchecked Sendable {
public typealias Replace = (NSTextCheckingResult, [String]) -> String

private let replace: Replace
Expand Down
4 changes: 2 additions & 2 deletions Sources/Internal/Extensions/Optional.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import Foundation

public extension Optional {
/// Asynchronous variant of `map`.
@inlinable func map<U>(_ transform: (Wrapped) async throws -> U) async rethrows -> U? {
@inlinable func asyncMap<U>(_ transform: (Wrapped) async throws -> U) async rethrows -> U? {
switch self {
case let .some(wrapped):
return try await .some(transform(wrapped))
Expand All @@ -18,7 +18,7 @@ public extension Optional {
}

/// Asynchronous variant of `flatMap`.
@inlinable func flatMap<U>(_ transform: (Wrapped) async throws -> U?) async rethrows -> U? {
@inlinable func asyncFlatMap<U>(_ transform: (Wrapped) async throws -> U?) async rethrows -> U? {
switch self {
case let .some(wrapped):
return try await transform(wrapped)
Expand Down
6 changes: 3 additions & 3 deletions Sources/Internal/Extensions/Result.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import Foundation

public extension Result {
/// Asynchronous variant of `map`.
@inlinable func map<NewSuccess>(
@inlinable func asyncMap<NewSuccess>(
_ transform: (Success) async throws -> NewSuccess
) async rethrows -> Result<NewSuccess, Failure> {
switch self {
Expand All @@ -20,7 +20,7 @@ public extension Result {
}

/// Asynchronous variant of `flatMap`.
@inlinable func flatMap<NewSuccess>(
@inlinable func asyncFlatMap<NewSuccess>(
_ transform: (Success) async throws -> Result<NewSuccess, Failure>
) async rethrows -> Result<NewSuccess, Failure> {
switch self {
Expand All @@ -31,7 +31,7 @@ public extension Result {
}
}

@inlinable func recover(
@inlinable func asyncRecover(
_ catching: (Failure) async throws -> Self
) async rethrows -> Self {
switch self {
Expand Down
2 changes: 1 addition & 1 deletion Sources/LCP/Content Protection/EncryptionParser.swift
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ private func parseEPUBEncryptionData(in container: Container) async -> ReadResul
}

return await encryptionResource.read()
.flatMap { data -> ReadResult<XMLDocument> in
.asyncFlatMap { data -> ReadResult<XMLDocument> in
do {
let doc = try await DefaultXMLDocumentFactory().open(
data: data,
Expand Down
2 changes: 1 addition & 1 deletion Sources/LCP/Content Protection/LCPContentProtection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ final class LCPContentProtection: ContentProtection, Loggable {

return await parseEncryptionData(in: asset)
.mapError { ContentProtectionOpenError.reading(.decoding($0)) }
.flatMap { encryptionData in
.asyncFlatMap { encryptionData in
let authentication = credentials.map { LCPPassphraseAuthentication($0, fallback: self.authentication) }
?? self.authentication

Expand Down
4 changes: 2 additions & 2 deletions Sources/LCP/Content Protection/LCPDecryptor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ final class LCPDecryptor {
private lazy var plainTextSize = memoize(_plainTextSize)

private func _plainTextSize() async -> ReadResult<UInt64?> {
await resource.estimatedLength().flatMap { length in
await resource.estimatedLength().asyncFlatMap { length in
guard let length = length else {
return failure(.requiredEstimatedLength)
}
Expand Down Expand Up @@ -156,7 +156,7 @@ final class LCPDecryptor {
}
}

return await resource.estimatedLength().flatMap { encryptedLength in
return await resource.estimatedLength().asyncFlatMap { encryptedLength in
guard let encryptedLength = encryptedLength else {
return failure(.requiredEstimatedLength)
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/Navigator/Audiobook/PublicationMediaLoader.swift
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ extension URL {
extension Resource {
func length() async -> ReadResult<UInt64> {
await estimatedLength()
.flatMap { length in
.asyncFlatMap { length in
if let length = length {
return .success(length)
} else {
Expand Down
4 changes: 2 additions & 2 deletions Sources/Navigator/EPUB/EPUBNavigatorViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -222,9 +222,9 @@ open class EPUBNavigatorViewController: UIViewController,
// Disable user interaction while transitioning, to avoid UX issues.
switch state {
case .initializing, .loading, .jumping, .moving:
paginationView.isUserInteractionEnabled = false
paginationView?.isUserInteractionEnabled = false
case .idle:
paginationView.isUserInteractionEnabled = true
paginationView?.isUserInteractionEnabled = true
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/Navigator/EPUB/EPUBSpreadView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import ReadiumShared
import SwiftSoup
import WebKit
@preconcurrency import WebKit

protocol EPUBSpreadViewDelegate: AnyObject {
/// Called when the spread view finished loading.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public class HTMLResourceContentIterator: ContentIterator {
.eraseToAnyError()
.tryMap { try SwiftSoup.parse($0) }
.tryMap { try parse(document: $0, locator: locator, beforeMaxLength: beforeMaxLength) }
.map { await adjustProgressions(of: $0) }
.asyncMap { await adjustProgressions(of: $0) }
resource.close()
return try result.get()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public extension SearchIterator {
@discardableResult
func forEach(_ block: @escaping (LocatorCollection) -> Void) async -> SearchResult<Void> {
func next() async -> SearchResult<Void> {
await self.next().flatMap { locators in
await self.next().asyncFlatMap { locators in
if let locators = locators {
block(locators)
return await next()
Expand Down
6 changes: 3 additions & 3 deletions Sources/Shared/Toolkit/Data/Asset/AssetRetriever.swift
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public final class AssetRetriever {
/// Retrieves an asset from a URL and a known format.
public func retrieve(url: AbsoluteURL, format: Format) async -> Result<Asset, AssetRetrieveURLError> {
await openResource(at: url)
.flatMap { resource in
.asyncFlatMap { resource in
await tryOpenArchive(with: resource, format: format)
.mapError { .reading($0) }
.map { container in
Expand All @@ -101,7 +101,7 @@ public final class AssetRetriever {
/// Retrieves an asset from a URL of unknown format.
public func retrieve(url: AbsoluteURL, hints: FormatHints = FormatHints()) async -> Result<Asset, AssetRetrieveURLError> {
await openResource(at: url)
.flatMap { resource in
.asyncFlatMap { resource in
await retrieve(resource: resource, hints: hints)
.mapError { AssetRetrieveURLError($0) }
}
Expand All @@ -111,7 +111,7 @@ public final class AssetRetriever {
public func retrieve(resource: Resource, hints: FormatHints = FormatHints()) async -> Result<Asset, AssetRetrieveError> {
await resource.fill(hints: hints)
.mapError { .reading($0) }
.flatMap { hints in
.asyncFlatMap { hints in
await refine(
format: formatSniffer.sniffHints(hints) ?? .null,
of: .resource(ResourceAsset(resource: resource, format: .null))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import Foundation
/// resource by chunks. The buffer is ignored when reading backward or far
/// ahead.
public actor BufferingResource: Resource {
private let resource: Resource
private nonisolated let resource: Resource
private let bufferSize: UInt64

/// - Parameter bufferSize: Size of the buffer chunks to read.
Expand Down
2 changes: 1 addition & 1 deletion Sources/Shared/Toolkit/Data/Resource/CachingResource.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import Foundation
/// **Warning**: Bytes are read and cached entirely the first time, even if only a `range` is
/// requested. So this is not appropriate for large resources.
public actor CachingResource: Resource {
private let resource: Resource
private nonisolated let resource: Resource

public init(resource: Resource) {
self.resource = resource
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class _HTMLResourceContentExtractor: _ResourceContentExtractor {

func extractText(of resource: Resource) async -> ReadResult<String> {
await resource.readAsString()
.flatMap { content in
.asyncFlatMap { content in
do {
// First try to parse a valid XML document, then fallback on SwiftSoup, which is slower.
var text = await parse(xml: content)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ open class TransformingResource: Resource {
/// Convenient shortcuts to create a `TransformingResource`.
public extension Resource {
func map(transform: @escaping (Data) async -> Data) -> Resource {
TransformingResource(self, transform: { await $0.map(transform) })
TransformingResource(self, transform: { await $0.asyncMap(transform) })
}

func mapAsString(encoding: String.Encoding = .utf8, transform: @escaping (String) -> String) -> Resource {
Expand Down
6 changes: 3 additions & 3 deletions Sources/Shared/Toolkit/Format/FormatSnifferBlob.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public actor FormatSnifferBlob {
func read() async -> ReadResult<Data?> {
if bytes == nil {
bytes = await length()
.flatMap { length in
.asyncFlatMap { length in
guard let length = length, length < 5 * 1000 * 1000 else {
return .success(nil)
}
Expand Down Expand Up @@ -72,8 +72,8 @@ public actor FormatSnifferBlob {
/// Reads the whole content as an XML document.
func readAsXML() async -> ReadResult<XMLDocument?> {
if xml == nil {
xml = await read().map {
await $0.flatMap {
xml = await read().asyncMap {
await $0.asyncFlatMap {
try? await xmlDocumentFactory.open(data: $0, namespaces: [])
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public struct EPUBFormatSniffer: FormatSniffer {
}

return await resource.readAsString()
.flatMap { mimetype in
.asyncFlatMap { mimetype in
if MediaType.epub.matches(MediaType(mimetype.trimmingCharacters(in: .whitespacesAndNewlines))) {
var format = format
format.addSpecifications(.epub)
Expand Down Expand Up @@ -66,7 +66,7 @@ public struct EPUBFormatSniffer: FormatSniffer {
}

return await resource.read()
.map { try? await xmlDocumentFactory.open(data: $0, namespaces: []) }
.asyncMap { try? await xmlDocumentFactory.open(data: $0, namespaces: []) }
.map { document in
guard let document = document else {
return format
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public struct HTMLFormatSniffer: FormatSniffer {

public func sniffBlob(_ blob: FormatSnifferBlob, refining format: Format) async -> ReadResult<Format?> {
await blob.readAsXML()
.map { document in
.asyncMap { document in
if let format = sniffDocument(document) {
return format
} else if let format = await sniffString(blob) {
Expand Down
8 changes: 4 additions & 4 deletions Sources/Shared/Toolkit/HTTP/DefaultHTTPClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -185,12 +185,12 @@ public final class DefaultHTTPClient: HTTPClient, Loggable {
consume: @escaping (Data, Double?) -> Void
) async -> HTTPResult<HTTPResponse> {
await request.httpRequest()
.flatMap(willStartRequest)
.flatMap { request in
.asyncFlatMap(willStartRequest)
.asyncFlatMap { request in
await startTask(for: request, consume: consume)
.recover { error in
.asyncRecover { error in
await recover(request, from: error)
.flatMap { newRequest in
.asyncFlatMap { newRequest in
await stream(request: newRequest, consume: consume)
}
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/Streamer/Parser/Readium/ReadiumWebPubParser.swift
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public class ReadiumWebPubParser: PublicationParser, Loggable {
))
}
.mapError { .reading($0) }
.flatMap { container in
.asyncFlatMap { container in
await parse(
container: container,
format: FormatSpecifications(.rpf),
Expand Down
2 changes: 1 addition & 1 deletion TestApp/Integrations/Carthage/project+lcp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ options:
packages:
GRDB:
url: https://github.com/groue/GRDB.swift.git
from: 5.8.0
from: 6.9.23
Kingfisher:
url: https://github.com/onevcat/Kingfisher.git
from: 5.15.8
Expand Down
2 changes: 1 addition & 1 deletion TestApp/Integrations/Carthage/project.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ options:
packages:
GRDB:
url: https://github.com/groue/GRDB.swift.git
from: 5.8.0
from: 6.9.23
Kingfisher:
url: https://github.com/onevcat/Kingfisher.git
from: 5.15.8
Expand Down
2 changes: 1 addition & 1 deletion TestApp/Integrations/CocoaPods/Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ target 'TestApp' do
# Required for R2Streamer and ReadiumAdapterGCDWebServer.
pod 'ReadiumGCDWebServer', podspec: 'https://raw.githubusercontent.com/readium/GCDWebServer/master/GCDWebServer.podspec'

pod 'GRDB.swift', '~> 5.0'
pod 'GRDB.swift', '~> 6.0'
pod 'Kingfisher', '~> 5.0'
pod 'MBProgressHUD', '~> 1.0'
pod 'SwiftSoup', '~> 2.0'
Expand Down
2 changes: 1 addition & 1 deletion TestApp/Integrations/CocoaPods/Podfile+lcp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ target 'TestApp' do
# Required for ReadiumStreamer and ReadiumAdapterGCDWebServer.
pod 'ReadiumGCDWebServer', podspec: 'https://raw.githubusercontent.com/readium/GCDWebServer/master/GCDWebServer.podspec'

pod 'GRDB.swift', '~> 5.0'
pod 'GRDB.swift', '~> 6.0'
pod 'Kingfisher', '~> 5.0'
pod 'MBProgressHUD', '~> 1.0'
pod 'SwiftSoup', '~> 2.0'
Expand Down
2 changes: 1 addition & 1 deletion TestApp/Integrations/Local/project+lcp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ packages:
path: R2LCPClient
GRDB:
url: https://github.com/groue/GRDB.swift.git
from: 5.8.0
from: 6.9.23
Kingfisher:
url: https://github.com/onevcat/Kingfisher.git
from: 5.15.8
Expand Down
Loading

0 comments on commit 7ffbdd6

Please sign in to comment.