diff --git a/.swiftlint.yml b/.swiftlint.yml index 26fc0ce8..4438158e 100644 --- a/.swiftlint.yml +++ b/.swiftlint.yml @@ -4,6 +4,7 @@ only_rules: - force_unwrapping - force_try - force_cast + - custom_rules included: - REES46/Classes/Core @@ -33,3 +34,16 @@ excluded: force_unwrapping: error force_try: error force_cast: error + +custom_rules: + # A synchronized copy of the SDK renames the module and the `Rees46` facade to the same word, so + # `REES46.X` there means the facade's nested type, not the module's: the copy stops compiling. + module_qualified_name: + name: "Module-qualified name" + regex: '\bREES46\.[A-Z]' + excluded_match_kinds: + - comment + - doccomment + - string + message: "A synchronized copy renames the module and Rees46 to the same word: use a plain name or LegacySdkError / LegacyPushEvent" + severity: error diff --git a/REES46/Classes/Sdk/Facade/LegacyTypes.swift b/REES46/Classes/Sdk/Facade/LegacyTypes.swift new file mode 100644 index 00000000..d42baf0f --- /dev/null +++ b/REES46/Classes/Sdk/Facade/LegacyTypes.swift @@ -0,0 +1,14 @@ +import Foundation + +/** + The SDK's first error type, under a name of its own. + + `Rees46` nests a `SdkError` of its own, so inside it a plain `SdkError` is the nested one. The + module's name cannot point at this one either: a synchronized copy of the SDK renames the module + and `Rees46` to the same word, where the module-qualified name would mean the nested type. This + name stays the same in every copy. + */ +public typealias LegacySdkError = SdkError + +/// The push events of earlier versions, under a name of its own for the same reason as `LegacySdkError`. +public typealias LegacyPushEvent = PushEvent diff --git a/REES46/Classes/Sdk/Facade/Rees46+Bridge.swift b/REES46/Classes/Sdk/Facade/Rees46+Bridge.swift index 8952359e..4bdce3e1 100644 --- a/REES46/Classes/Sdk/Facade/Rees46+Bridge.swift +++ b/REES46/Classes/Sdk/Facade/Rees46+Bridge.swift @@ -62,13 +62,13 @@ extension Rees46 { /// otherwise one made from `legacy` — `network` offline, `decoding` for an answer the SDK could /// not take, `notInitialized`, `shopBlocked` for a refused shop, `invalidArgument` with the /// message of another `.custom`, `timeout` otherwise. - public static func error(of legacy: REES46.SdkError) -> Rees46.SdkError { + public static func error(of legacy: LegacySdkError) -> Rees46.SdkError { currentError() ?? SimplePersonalizationSDK.newCoreError(legacy) } /// A completion for any old method that reports the whole result to `onResult`, once, on the /// thread the SDK answers on. - public static func completion(_ onResult: @escaping (Result) -> Void) -> (Result) -> Void { + public static func completion(_ onResult: @escaping (Result) -> Void) -> (Result) -> Void { { result in onResult(result.mapError { error(of: $0) }) } @@ -76,7 +76,7 @@ extension Rees46 { /// A completion for an old method that reports only an error — `Rees46.initialize` — that hands /// `onError` the whole error, or `nil` for none, once, on the thread the SDK answers on. - public static func completion(_ onError: @escaping (Rees46.SdkError?) -> Void) -> (REES46.SdkError?) -> Void { + public static func completion(_ onError: @escaping (Rees46.SdkError?) -> Void) -> (LegacySdkError?) -> Void { { legacy in onError(legacy.map { error(of: $0) }) } @@ -118,7 +118,7 @@ extension PersonalizationSDK { device id, as it always has; on `Rees46Config.coreV2` it, too, hears the answer once it went. */ public func setPushToken(_ token: Rees46.PushToken, completion: @escaping (Result) -> Void) { - let finish: (Result) -> Void = { result in + let finish: (Result) -> Void = { result in let mapped = result.mapError { Rees46.BridgeErrors.error(of: $0) } DispatchQueue.main.async { completion(mapped) } } diff --git a/REES46/Classes/Sdk/Facade/Rees46.swift b/REES46/Classes/Sdk/Facade/Rees46.swift index 3e9f981f..2701eeac 100644 --- a/REES46/Classes/Sdk/Facade/Rees46.swift +++ b/REES46/Classes/Sdk/Facade/Rees46.swift @@ -84,7 +84,7 @@ public enum Rees46 { @discardableResult public static func initialize( _ config: Rees46Config, - completion: ((REES46.SdkError?) -> Void)? = nil + completion: ((LegacySdkError?) -> Void)? = nil ) -> PersonalizationSDK { withCreationLock { lock.lock() @@ -125,7 +125,7 @@ public enum Rees46 { private static func joinExisting( _ existing: PersonalizationSDK, config: Rees46Config, - completion: ((REES46.SdkError?) -> Void)? + completion: ((LegacySdkError?) -> Void)? ) -> () -> Void { guard let instance = existing as? SimplePersonalizationSDK else { // Another conformer the app registered: it has no outcome to tell. @@ -349,7 +349,7 @@ public enum Rees46 { `track/received` as before. */ @_disfavoredOverload - public static func handlePush(_ payload: [AnyHashable: Any], event: REES46.PushEvent) { + public static func handlePush(_ payload: [AnyHashable: Any], event: LegacyPushEvent) { route(payload, PushRoute(event)) }