From 05e9a0e886ef2cab4d4add67c006684c4874010c Mon Sep 17 00:00:00 2001 From: Dimitri Bouniol Date: Thu, 26 Dec 2024 01:40:29 -0800 Subject: [PATCH] Updated Foundation imports to lower binary size on linux Fixes #54 --- Sources/WebPush/Errors/BadSubscriberError.swift | 4 ++++ Sources/WebPush/Errors/Base64URLDecodingError.swift | 4 ++++ Sources/WebPush/Errors/MessageTooLargeError.swift | 4 ++++ Sources/WebPush/Errors/PushServiceError.swift | 4 ++++ Sources/WebPush/Errors/UserAgentKeyMaterialError.swift | 4 ++++ Sources/WebPush/Errors/VAPIDConfigurationError.swift | 4 ++++ Sources/WebPush/Helpers/DataProtocol+Base64URLCoding.swift | 4 ++++ Sources/WebPush/Helpers/PrintLogHandler.swift | 4 ++++ Sources/WebPush/Helpers/URL+Origin.swift | 4 ++++ Sources/WebPush/Subscriber.swift | 4 ++++ Sources/WebPush/Topic.swift | 4 ++++ Sources/WebPush/VAPID/VAPID.swift | 4 ++++ Sources/WebPush/VAPID/VAPIDConfiguration.swift | 4 ++++ Sources/WebPush/VAPID/VAPIDKey.swift | 4 ++++ Sources/WebPush/VAPID/VAPIDToken.swift | 4 ++++ Sources/WebPush/WebPushManager.swift | 4 ++++ Sources/WebPushTesting/Subscriber+Testing.swift | 4 ++++ Sources/WebPushTesting/VAPIDConfiguration+Testing.swift | 4 ++++ Tests/WebPushTests/Base64URLCodingTests.swift | 4 ++++ Tests/WebPushTests/BytesTests.swift | 4 ++++ Tests/WebPushTests/ErrorTests.swift | 4 ++++ Tests/WebPushTests/Helpers/VAPIDConfiguration+Testing.swift | 4 ++++ Tests/WebPushTests/SubscriberTests.swift | 4 ++++ Tests/WebPushTests/TopicTests.swift | 4 ++++ Tests/WebPushTests/URLOriginTests.swift | 4 ++++ Tests/WebPushTests/VAPIDConfigurationTests.swift | 4 ++++ Tests/WebPushTests/VAPIDKeyTests.swift | 4 ++++ Tests/WebPushTests/VAPIDTokenTests.swift | 4 ++++ Tests/WebPushTests/WebPushManagerTests.swift | 4 ++++ 29 files changed, 116 insertions(+) diff --git a/Sources/WebPush/Errors/BadSubscriberError.swift b/Sources/WebPush/Errors/BadSubscriberError.swift index 670e65a..a464ca5 100644 --- a/Sources/WebPush/Errors/BadSubscriberError.swift +++ b/Sources/WebPush/Errors/BadSubscriberError.swift @@ -6,7 +6,11 @@ // Copyright © 2024 Mochi Development, Inc. All rights reserved. // +#if canImport(FoundationEssentials) +import FoundationEssentials +#else import Foundation +#endif /// The subscription is no longer valid and should be removed and re-registered. /// diff --git a/Sources/WebPush/Errors/Base64URLDecodingError.swift b/Sources/WebPush/Errors/Base64URLDecodingError.swift index ae78472..ae585d8 100644 --- a/Sources/WebPush/Errors/Base64URLDecodingError.swift +++ b/Sources/WebPush/Errors/Base64URLDecodingError.swift @@ -6,7 +6,11 @@ // Copyright © 2024 Mochi Development, Inc. All rights reserved. // +#if canImport(FoundationEssentials) +import FoundationEssentials +#else import Foundation +#endif /// An error encountered while decoding Base64 data. public struct Base64URLDecodingError: LocalizedError, Hashable, Sendable { diff --git a/Sources/WebPush/Errors/MessageTooLargeError.swift b/Sources/WebPush/Errors/MessageTooLargeError.swift index 41475bf..a161bae 100644 --- a/Sources/WebPush/Errors/MessageTooLargeError.swift +++ b/Sources/WebPush/Errors/MessageTooLargeError.swift @@ -6,7 +6,11 @@ // Copyright © 2024 Mochi Development, Inc. All rights reserved. // +#if canImport(FoundationEssentials) +import FoundationEssentials +#else import Foundation +#endif /// The message was too large, and could not be delivered to the push service. /// diff --git a/Sources/WebPush/Errors/PushServiceError.swift b/Sources/WebPush/Errors/PushServiceError.swift index a4fda6b..0e16587 100644 --- a/Sources/WebPush/Errors/PushServiceError.swift +++ b/Sources/WebPush/Errors/PushServiceError.swift @@ -7,7 +7,11 @@ // import AsyncHTTPClient +#if canImport(FoundationEssentials) +import FoundationEssentials +#else import Foundation +#endif /// An unknown Push Service error was encountered. /// diff --git a/Sources/WebPush/Errors/UserAgentKeyMaterialError.swift b/Sources/WebPush/Errors/UserAgentKeyMaterialError.swift index 92e8e5c..c158a70 100644 --- a/Sources/WebPush/Errors/UserAgentKeyMaterialError.swift +++ b/Sources/WebPush/Errors/UserAgentKeyMaterialError.swift @@ -6,7 +6,11 @@ // Copyright © 2024 Mochi Development, Inc. All rights reserved. // +#if canImport(FoundationEssentials) +import FoundationEssentials +#else import Foundation +#endif /// An error encountered during ``VAPID/Configuration`` initialization or decoding. public struct UserAgentKeyMaterialError: LocalizedError, Sendable { diff --git a/Sources/WebPush/Errors/VAPIDConfigurationError.swift b/Sources/WebPush/Errors/VAPIDConfigurationError.swift index 38f0e6a..6693887 100644 --- a/Sources/WebPush/Errors/VAPIDConfigurationError.swift +++ b/Sources/WebPush/Errors/VAPIDConfigurationError.swift @@ -6,7 +6,11 @@ // Copyright © 2024 Mochi Development, Inc. All rights reserved. // +#if canImport(FoundationEssentials) +import FoundationEssentials +#else import Foundation +#endif extension VAPID { /// An error encountered during ``VAPID/Configuration`` initialization or decoding. diff --git a/Sources/WebPush/Helpers/DataProtocol+Base64URLCoding.swift b/Sources/WebPush/Helpers/DataProtocol+Base64URLCoding.swift index e645bba..fc8ed68 100644 --- a/Sources/WebPush/Helpers/DataProtocol+Base64URLCoding.swift +++ b/Sources/WebPush/Helpers/DataProtocol+Base64URLCoding.swift @@ -6,7 +6,11 @@ // Copyright © 2024 Mochi Development, Inc. All rights reserved. // +#if canImport(FoundationEssentials) +import FoundationEssentials +#else import Foundation +#endif extension DataProtocol { /// The receiver as a Base64 URL encoded string. diff --git a/Sources/WebPush/Helpers/PrintLogHandler.swift b/Sources/WebPush/Helpers/PrintLogHandler.swift index b7f489b..3cce3de 100644 --- a/Sources/WebPush/Helpers/PrintLogHandler.swift +++ b/Sources/WebPush/Helpers/PrintLogHandler.swift @@ -6,7 +6,11 @@ // Copyright © 2024 Mochi Development, Inc. All rights reserved. // +#if canImport(FoundationEssentials) +import FoundationEssentials +#else import Foundation +#endif import Logging /// A simple log handler that uses formatted print statements. diff --git a/Sources/WebPush/Helpers/URL+Origin.swift b/Sources/WebPush/Helpers/URL+Origin.swift index 3a6e645..e85b979 100644 --- a/Sources/WebPush/Helpers/URL+Origin.swift +++ b/Sources/WebPush/Helpers/URL+Origin.swift @@ -6,7 +6,11 @@ // Copyright © 2024 Mochi Development, Inc. All rights reserved. // +#if canImport(FoundationEssentials) +import FoundationEssentials +#else import Foundation +#endif extension URL { /// Returns the origin for the receiving URL, as defined for use in signing headers for VAPID. diff --git a/Sources/WebPush/Subscriber.swift b/Sources/WebPush/Subscriber.swift index 8844608..1c3cfc9 100644 --- a/Sources/WebPush/Subscriber.swift +++ b/Sources/WebPush/Subscriber.swift @@ -7,7 +7,11 @@ // @preconcurrency import Crypto +#if canImport(FoundationEssentials) +import FoundationEssentials +#else import Foundation +#endif /// Represents a subscriber registration from the browser. /// diff --git a/Sources/WebPush/Topic.swift b/Sources/WebPush/Topic.swift index 8ffc959..fc2f6d3 100644 --- a/Sources/WebPush/Topic.swift +++ b/Sources/WebPush/Topic.swift @@ -7,7 +7,11 @@ // @preconcurrency import Crypto +#if canImport(FoundationEssentials) +import FoundationEssentials +#else import Foundation +#endif /// Topics are used to de-duplicate and overwrite messages on push services before they are delivered to a subscriber. /// diff --git a/Sources/WebPush/VAPID/VAPID.swift b/Sources/WebPush/VAPID/VAPID.swift index 47a7ed2..e9cda4a 100644 --- a/Sources/WebPush/VAPID/VAPID.swift +++ b/Sources/WebPush/VAPID/VAPID.swift @@ -6,7 +6,11 @@ // Copyright © 2024 Mochi Development, Inc. All rights reserved. // +#if canImport(FoundationEssentials) +import FoundationEssentials +#else import Foundation +#endif /// The fully qualified name for VAPID. public typealias VoluntaryApplicationServerIdentification = VAPID diff --git a/Sources/WebPush/VAPID/VAPIDConfiguration.swift b/Sources/WebPush/VAPID/VAPIDConfiguration.swift index fa77ff1..a975a89 100644 --- a/Sources/WebPush/VAPID/VAPIDConfiguration.swift +++ b/Sources/WebPush/VAPID/VAPIDConfiguration.swift @@ -6,7 +6,11 @@ // Copyright © 2024 Mochi Development, Inc. All rights reserved. // +#if canImport(FoundationEssentials) +import FoundationEssentials +#else import Foundation +#endif extension VoluntaryApplicationServerIdentification { /// A configuration object specifying the contact information along with the keys that your application server identifies itself with. diff --git a/Sources/WebPush/VAPID/VAPIDKey.swift b/Sources/WebPush/VAPID/VAPIDKey.swift index 29a9f3e..f101d21 100644 --- a/Sources/WebPush/VAPID/VAPIDKey.swift +++ b/Sources/WebPush/VAPID/VAPIDKey.swift @@ -7,7 +7,11 @@ // @preconcurrency import Crypto +#if canImport(FoundationEssentials) +import FoundationEssentials +#else import Foundation +#endif extension VoluntaryApplicationServerIdentification { /// Represents the application server's identification key that is used to confirm to a push service that the server connecting to it is the same one that was subscribed to. diff --git a/Sources/WebPush/VAPID/VAPIDToken.swift b/Sources/WebPush/VAPID/VAPIDToken.swift index 430177b..c53a0cc 100644 --- a/Sources/WebPush/VAPID/VAPIDToken.swift +++ b/Sources/WebPush/VAPID/VAPIDToken.swift @@ -7,7 +7,11 @@ // @preconcurrency import Crypto +#if canImport(FoundationEssentials) +import FoundationEssentials +#else import Foundation +#endif extension VAPID { /// An internal representation the token and authorization headers used self-identification. diff --git a/Sources/WebPush/WebPushManager.swift b/Sources/WebPush/WebPushManager.swift index cb0ada1..e3fcb4e 100644 --- a/Sources/WebPush/WebPushManager.swift +++ b/Sources/WebPush/WebPushManager.swift @@ -8,7 +8,11 @@ import AsyncHTTPClient @preconcurrency import Crypto +#if canImport(FoundationEssentials) +import FoundationEssentials +#else import Foundation +#endif import NIOHTTP1 import Logging import NIOCore diff --git a/Sources/WebPushTesting/Subscriber+Testing.swift b/Sources/WebPushTesting/Subscriber+Testing.swift index b86df66..a756265 100644 --- a/Sources/WebPushTesting/Subscriber+Testing.swift +++ b/Sources/WebPushTesting/Subscriber+Testing.swift @@ -7,7 +7,11 @@ // @preconcurrency import Crypto +#if canImport(FoundationEssentials) +import FoundationEssentials +#else import Foundation +#endif import WebPush extension Subscriber { diff --git a/Sources/WebPushTesting/VAPIDConfiguration+Testing.swift b/Sources/WebPushTesting/VAPIDConfiguration+Testing.swift index ef90663..1b02daf 100644 --- a/Sources/WebPushTesting/VAPIDConfiguration+Testing.swift +++ b/Sources/WebPushTesting/VAPIDConfiguration+Testing.swift @@ -7,7 +7,11 @@ // @preconcurrency import Crypto +#if canImport(FoundationEssentials) +import FoundationEssentials +#else import Foundation +#endif import WebPush extension VAPID.Configuration { diff --git a/Tests/WebPushTests/Base64URLCodingTests.swift b/Tests/WebPushTests/Base64URLCodingTests.swift index e547a87..6361254 100644 --- a/Tests/WebPushTests/Base64URLCodingTests.swift +++ b/Tests/WebPushTests/Base64URLCodingTests.swift @@ -6,7 +6,11 @@ // Copyright © 2024 Mochi Development, Inc. All rights reserved. // +#if canImport(FoundationEssentials) +import FoundationEssentials +#else import Foundation +#endif import Testing @testable import WebPush diff --git a/Tests/WebPushTests/BytesTests.swift b/Tests/WebPushTests/BytesTests.swift index 088ad91..c7514e7 100644 --- a/Tests/WebPushTests/BytesTests.swift +++ b/Tests/WebPushTests/BytesTests.swift @@ -6,7 +6,11 @@ // Copyright © 2024 Mochi Development, Inc. All rights reserved. // +#if canImport(FoundationEssentials) +import FoundationEssentials +#else import Foundation +#endif import Testing @testable import WebPush diff --git a/Tests/WebPushTests/ErrorTests.swift b/Tests/WebPushTests/ErrorTests.swift index 8813e5e..62514b0 100644 --- a/Tests/WebPushTests/ErrorTests.swift +++ b/Tests/WebPushTests/ErrorTests.swift @@ -7,7 +7,11 @@ // import AsyncHTTPClient +#if canImport(FoundationEssentials) +import FoundationEssentials +#else import Foundation +#endif import Testing @testable import WebPush diff --git a/Tests/WebPushTests/Helpers/VAPIDConfiguration+Testing.swift b/Tests/WebPushTests/Helpers/VAPIDConfiguration+Testing.swift index 3426ea4..be786b5 100644 --- a/Tests/WebPushTests/Helpers/VAPIDConfiguration+Testing.swift +++ b/Tests/WebPushTests/Helpers/VAPIDConfiguration+Testing.swift @@ -6,7 +6,11 @@ // Copyright © 2024 Mochi Development, Inc. All rights reserved. // +#if canImport(FoundationEssentials) +import FoundationEssentials +#else import Foundation +#endif import WebPush extension VAPID.Configuration { diff --git a/Tests/WebPushTests/SubscriberTests.swift b/Tests/WebPushTests/SubscriberTests.swift index f6e281e..1508d61 100644 --- a/Tests/WebPushTests/SubscriberTests.swift +++ b/Tests/WebPushTests/SubscriberTests.swift @@ -7,7 +7,11 @@ // import Crypto +#if canImport(FoundationEssentials) +import FoundationEssentials +#else import Foundation +#endif import Testing @testable import WebPush import WebPushTesting diff --git a/Tests/WebPushTests/TopicTests.swift b/Tests/WebPushTests/TopicTests.swift index 568b70f..fbd439e 100644 --- a/Tests/WebPushTests/TopicTests.swift +++ b/Tests/WebPushTests/TopicTests.swift @@ -8,7 +8,11 @@ import Crypto +#if canImport(FoundationEssentials) +import FoundationEssentials +#else import Foundation +#endif import Testing @testable import WebPush diff --git a/Tests/WebPushTests/URLOriginTests.swift b/Tests/WebPushTests/URLOriginTests.swift index bee6b44..472e383 100644 --- a/Tests/WebPushTests/URLOriginTests.swift +++ b/Tests/WebPushTests/URLOriginTests.swift @@ -6,7 +6,11 @@ // Copyright © 2024 Mochi Development, Inc. All rights reserved. // +#if canImport(FoundationEssentials) +import FoundationEssentials +#else import Foundation +#endif import Testing @testable import WebPush diff --git a/Tests/WebPushTests/VAPIDConfigurationTests.swift b/Tests/WebPushTests/VAPIDConfigurationTests.swift index bda875e..bc52739 100644 --- a/Tests/WebPushTests/VAPIDConfigurationTests.swift +++ b/Tests/WebPushTests/VAPIDConfigurationTests.swift @@ -7,7 +7,11 @@ // import Crypto +#if canImport(FoundationEssentials) +import FoundationEssentials +#else import Foundation +#endif import Testing @testable import WebPush import WebPushTesting diff --git a/Tests/WebPushTests/VAPIDKeyTests.swift b/Tests/WebPushTests/VAPIDKeyTests.swift index 9e508fd..0c5650d 100644 --- a/Tests/WebPushTests/VAPIDKeyTests.swift +++ b/Tests/WebPushTests/VAPIDKeyTests.swift @@ -7,7 +7,11 @@ // import Crypto +#if canImport(FoundationEssentials) +import FoundationEssentials +#else import Foundation +#endif import Testing @testable import WebPush import WebPushTesting diff --git a/Tests/WebPushTests/VAPIDTokenTests.swift b/Tests/WebPushTests/VAPIDTokenTests.swift index 08a95c7..921dd5b 100644 --- a/Tests/WebPushTests/VAPIDTokenTests.swift +++ b/Tests/WebPushTests/VAPIDTokenTests.swift @@ -7,7 +7,11 @@ // import Crypto +#if canImport(FoundationEssentials) +import FoundationEssentials +#else import Foundation +#endif import Testing @testable import WebPush diff --git a/Tests/WebPushTests/WebPushManagerTests.swift b/Tests/WebPushTests/WebPushManagerTests.swift index 6dd1353..7d20b63 100644 --- a/Tests/WebPushTests/WebPushManagerTests.swift +++ b/Tests/WebPushTests/WebPushManagerTests.swift @@ -8,7 +8,11 @@ @testable import AsyncHTTPClient @preconcurrency import Crypto +#if canImport(FoundationEssentials) +import FoundationEssentials +#else import Foundation +#endif import Logging import ServiceLifecycle import Testing