Skip to content

Commit b1698b5

Browse files
authored
Remove relativeURL and absoluteURL helpers on URLConvertible (#561)
1 parent 497bc6b commit b1698b5

File tree

14 files changed

+50
-58
lines changed

14 files changed

+50
-58
lines changed

CHANGELOG.md

+11-4
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,19 @@ All notable changes to this project will be documented in this file. Take a look
66

77
## [Unreleased]
88

9+
### Added
10+
11+
#### LCP
12+
13+
* Support for streaming an LCP-protected publication from its License Document (LCPL). [Take a look at the LCP guide for more information](docs/Guides/Readium%20LCP.md#streaming-an-lcp-protected-package).
14+
915
### Changed
1016

17+
#### Shared
18+
19+
* The `absoluteURL` and `relativeURL` extensions on `URLConvertible` were removed as they conflict with the native `URL.absoluteURL`.
20+
* If you were using them, you can for example still use `anyURL.absoluteURL` instead.
21+
1122
#### Streamer
1223

1324
* A `self` link is not required anymore when parsing a RWPM.
@@ -21,10 +32,6 @@ All notable changes to this project will be documented in this file. Take a look
2132

2233
* Support for streaming ZIP packages over HTTP. This lets you open a remote EPUB, audiobook, or any other ZIP-based publication without needing to download it first.
2334

24-
#### LCP
25-
26-
* Support for streaming an LCP-protected publication from its License Document (LCPL). [Take a look at the LCP guide for more information](docs/Guides/Readium%20LCP.md#streaming-an-lcp-protected-package).
27-
2835
### Deprecated
2936

3037
* The `close()` and `Closeable` APIs are now deprecated. Resources are automatically released upon `deinit`, which aligns better with Swift.

Sources/Navigator/Audiobook/PublicationMediaLoader.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ private let schemePrefix = "readium"
193193

194194
extension URL {
195195
var audioHREF: AnyURL? {
196-
guard let url = absoluteURL, url.scheme.rawValue.hasPrefix(schemePrefix) == true else {
196+
guard let url = anyURL.absoluteURL, url.scheme.rawValue.hasPrefix(schemePrefix) == true else {
197197
return nil
198198
}
199199

Sources/Shared/Toolkit/File/FileContainer.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public final class FileContainer: Container, Loggable {
2626

2727
public subscript(url: any URLConvertible) -> Resource? {
2828
guard
29-
let url = url.relativeURL?.normalized,
29+
let url = url.anyURL.relativeURL?.normalized,
3030
let file = files[url]
3131
else {
3232
return nil

Sources/Shared/Toolkit/URL/Absolute URL/AbsoluteURL.swift

+3-5
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public extension AbsoluteURL {
5959
/// returns bar/baz
6060
func relativize<T: URLConvertible>(_ other: T) -> RelativeURL? {
6161
guard
62-
let absoluteURL = other.absoluteURL,
62+
let absoluteURL = other.anyURL.absoluteURL,
6363
scheme == absoluteURL.scheme,
6464
origin == absoluteURL.origin
6565
else {
@@ -75,16 +75,14 @@ public extension AbsoluteURL {
7575

7676
/// Indicates whether the receiver is relative to the given `base` URL.
7777
func isRelative<T: URLConvertible>(to base: T) -> Bool {
78-
base.absoluteURL?.scheme == scheme
79-
&& base.absoluteURL?.origin == origin
78+
base.anyURL.absoluteURL?.scheme == scheme
79+
&& base.anyURL.absoluteURL?.origin == origin
8080
}
8181
}
8282

8383
/// Implements ``URLConvertible``.
8484
public extension AbsoluteURL {
8585
var anyURL: AnyURL { .absolute(self) }
86-
var relativeURL: RelativeURL? { nil }
87-
var absoluteURL: AbsoluteURL? { self }
8886
}
8987

9088
/// A URL scheme, e.g. http or file.

Sources/Shared/Toolkit/URL/Absolute URL/FileURL.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,6 @@ public struct FileURL: AbsoluteURL, Hashable, Sendable {
7979
public extension URLConvertible {
8080
/// Returns a `FileURL` if the URL has a `file` scheme.
8181
var fileURL: FileURL? {
82-
(absoluteURL as? FileURL) ?? FileURL(url: anyURL.url)
82+
(anyURL.absoluteURL as? FileURL) ?? FileURL(url: anyURL.url)
8383
}
8484
}

Sources/Shared/Toolkit/URL/Absolute URL/HTTPURL.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,6 @@ public struct HTTPURL: AbsoluteURL, Hashable, Sendable {
5151
public extension URLConvertible {
5252
/// Returns an `HTTPURL` if the URL has an `http` or `https` scheme.
5353
var httpURL: HTTPURL? {
54-
(absoluteURL as? HTTPURL) ?? HTTPURL(url: anyURL.url)
54+
(anyURL.absoluteURL as? HTTPURL) ?? HTTPURL(url: anyURL.url)
5555
}
5656
}

Sources/Shared/Toolkit/URL/AnyURL.swift

+16-14
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,22 @@ public enum AnyURL: URLProtocol {
5858
}
5959
}
6060

61+
/// Returns the wrapped ``RelativeURL``, if this URL is relative.
62+
public var relativeURL: RelativeURL? {
63+
guard case let .relative(url) = self else {
64+
return nil
65+
}
66+
return url
67+
}
68+
69+
/// Returns the wrapped ``AbsoluteURL``, if this URL is absolute.
70+
public var absoluteURL: AbsoluteURL? {
71+
guard case let .absolute(url) = self else {
72+
return nil
73+
}
74+
return url
75+
}
76+
6177
private var wrapped: URLProtocol {
6278
switch self {
6379
case let .absolute(url):
@@ -104,20 +120,6 @@ public enum AnyURL: URLProtocol {
104120
/// Implements `URLConvertible`.
105121
extension AnyURL: URLConvertible {
106122
public var anyURL: AnyURL { self }
107-
108-
public var relativeURL: RelativeURL? {
109-
guard case let .relative(url) = self else {
110-
return nil
111-
}
112-
return url
113-
}
114-
115-
public var absoluteURL: AbsoluteURL? {
116-
guard case let .absolute(url) = self else {
117-
return nil
118-
}
119-
return url
120-
}
121123
}
122124

123125
/// Implements `Hashable` and `Equatable`.

Sources/Shared/Toolkit/URL/RelativeURL.swift

+2-4
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public struct RelativeURL: URLProtocol, Hashable {
3535
/// returns foo/baz
3636
public func resolve<T: URLConvertible>(_ other: T) -> AnyURL? {
3737
// other is absolute?
38-
guard let relativeURL = other.relativeURL else {
38+
guard let relativeURL = other.anyURL.relativeURL else {
3939
return other.anyURL
4040
}
4141
return resolve(relativeURL)?.anyURL
@@ -84,7 +84,7 @@ public struct RelativeURL: URLProtocol, Hashable {
8484
/// returns baz
8585
public func relativize<T: URLConvertible>(_ other: T) -> RelativeURL? {
8686
guard
87-
let relativeURL = other.relativeURL,
87+
let relativeURL = other.anyURL.relativeURL,
8888
relativeURL.string.hasPrefix(string)
8989
else {
9090
return nil
@@ -112,8 +112,6 @@ public struct RelativeURL: URLProtocol, Hashable {
112112
/// Implements `URLConvertible`.
113113
extension RelativeURL: URLConvertible {
114114
public var anyURL: AnyURL { .relative(self) }
115-
public var relativeURL: RelativeURL? { self }
116-
public var absoluteURL: AbsoluteURL? { nil }
117115
}
118116

119117
public extension RelativeURL {

Sources/Shared/Toolkit/URL/URLConvertible.swift

-13
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,6 @@ import Foundation
1010
public protocol URLConvertible {
1111
/// Converts the receiver to an ``AnyURL``.
1212
var anyURL: AnyURL { get }
13-
14-
/// Converts the receiver to a ``RelativeURL``, if the represented URL is
15-
/// relative.
16-
var relativeURL: RelativeURL? { get }
17-
18-
/// Converts the receiver to an ``AnyAbsoluteURL``, if the represented URL
19-
/// is absolute.
20-
var absoluteURL: AbsoluteURL? { get }
21-
}
22-
23-
public extension URLConvertible {
24-
var relativeURL: RelativeURL? { anyURL.relativeURL }
25-
var absoluteURL: AbsoluteURL? { anyURL.absoluteURL }
2613
}
2714

2815
extension URL: URLConvertible {

Sources/Shared/Toolkit/ZIP/Minizip/MinizipContainer.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ final class MinizipContainer: Container, Loggable {
6060

6161
subscript(url: any URLConvertible) -> (any Resource)? {
6262
guard
63-
let url = url.relativeURL?.normalized,
63+
let url = url.anyURL.relativeURL?.normalized,
6464
let metadata = entriesMetadata[url]
6565
else {
6666
return nil

Sources/Shared/Toolkit/ZIP/ZIPFoundation/ZIPFoundationContainer.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ final class ZIPFoundationContainer: Container, Loggable {
6060

6161
subscript(url: any URLConvertible) -> (any Resource)? {
6262
guard
63-
let url = url.relativeURL?.normalized,
63+
let url = url.anyURL.relativeURL?.normalized,
6464
let entry = entriesByPath[url]
6565
else {
6666
return nil

TestApp/Integrations/Local/TestApp.xctestplan

+10-10
Original file line numberDiff line numberDiff line change
@@ -20,36 +20,36 @@
2020
{
2121
"target" : {
2222
"containerPath" : "container:..",
23-
"identifier" : "R2NavigatorTests",
24-
"name" : "R2NavigatorTests"
23+
"identifier" : "ReadiumInternalTests",
24+
"name" : "ReadiumInternalTests"
2525
}
2626
},
2727
{
2828
"target" : {
2929
"containerPath" : "container:..",
30-
"identifier" : "R2SharedTests",
31-
"name" : "R2SharedTests"
30+
"identifier" : "ReadiumOPDSTests",
31+
"name" : "ReadiumOPDSTests"
3232
}
3333
},
3434
{
3535
"target" : {
3636
"containerPath" : "container:..",
37-
"identifier" : "R2StreamerTests",
38-
"name" : "R2StreamerTests"
37+
"identifier" : "ReadiumNavigatorTests",
38+
"name" : "ReadiumNavigatorTests"
3939
}
4040
},
4141
{
4242
"target" : {
4343
"containerPath" : "container:..",
44-
"identifier" : "ReadiumInternalTests",
45-
"name" : "ReadiumInternalTests"
44+
"identifier" : "ReadiumSharedTests",
45+
"name" : "ReadiumSharedTests"
4646
}
4747
},
4848
{
4949
"target" : {
5050
"containerPath" : "container:..",
51-
"identifier" : "ReadiumOPDSTests",
52-
"name" : "ReadiumOPDSTests"
51+
"identifier" : "ReadiumStreamerTests",
52+
"name" : "ReadiumStreamerTests"
5353
}
5454
}
5555
],

TestApp/Sources/AppDelegate.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
5353
}
5454

5555
func application(_ application: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey: Any] = [:]) -> Bool {
56-
guard let url = url.absoluteURL, let vc = window?.rootViewController else {
56+
guard let url = url.anyURL.absoluteURL, let vc = window?.rootViewController else {
5757
return false
5858
}
5959

TestApp/Sources/Library/LibraryService.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ final class LibraryService: Loggable {
8181
/// Imports a bunch of publications.
8282
func importPublications(from sourceURLs: [URL], sender: UIViewController) async throws {
8383
for url in sourceURLs {
84-
guard let url = url.absoluteURL else {
84+
guard let url = url.anyURL.absoluteURL else {
8585
continue
8686
}
8787
try await importPublication(from: url, sender: sender, progress: { _ in })

0 commit comments

Comments
 (0)