From 543c3808a73ca03be0ff37b210da63d86a08d8ad Mon Sep 17 00:00:00 2001 From: Fabrizio Demaria Date: Tue, 2 Jul 2024 15:30:25 +0200 Subject: [PATCH] fix: Removes flag resolving from Confidence child instances (#149) --- .../ConfidenceDemoApp/ConfidenceDemoApp.swift | 1 - Sources/Confidence/Confidence.swift | 5 +---- .../ConfidenceContextProvider.swift | 3 +++ .../Confidence/ConfidenceEventSender.swift | 15 ++++++++++++- Sources/Confidence/Contextual.swift | 22 ------------------- 5 files changed, 18 insertions(+), 28 deletions(-) delete mode 100644 Sources/Confidence/Contextual.swift diff --git a/ConfidenceDemoApp/ConfidenceDemoApp/ConfidenceDemoApp.swift b/ConfidenceDemoApp/ConfidenceDemoApp/ConfidenceDemoApp.swift index 1dc1cf13..38769765 100644 --- a/ConfidenceDemoApp/ConfidenceDemoApp/ConfidenceDemoApp.swift +++ b/ConfidenceDemoApp/ConfidenceDemoApp/ConfidenceDemoApp.swift @@ -21,7 +21,6 @@ struct ConfidenceDemoApp: App { let secret = ProcessInfo.processInfo.environment["CLIENT_SECRET"] ?? "" let confidence = Confidence.Builder(clientSecret: secret, loggerLevel: .TRACE) .withContext(initialContext: ["targeting_key": ConfidenceValue(string: UUID.init().uuidString)]) - .withRegion(region: .europe) .build() let status = Status() diff --git a/Sources/Confidence/Confidence.swift b/Sources/Confidence/Confidence.swift index 67c6f103..22ff1320 100644 --- a/Sources/Confidence/Confidence.swift +++ b/Sources/Confidence/Confidence.swift @@ -262,10 +262,7 @@ public class Confidence: ConfidenceEventSender { } } - /** - Sets the initial Context. - */ - public func withContext(_ context: ConfidenceStruct) -> Self { + public func withContext(_ context: ConfidenceStruct) -> ConfidenceEventSender { return Self.init( clientSecret: clientSecret, region: region, diff --git a/Sources/Confidence/ConfidenceContextProvider.swift b/Sources/Confidence/ConfidenceContextProvider.swift index 33366dcc..57516d11 100644 --- a/Sources/Confidence/ConfidenceContextProvider.swift +++ b/Sources/Confidence/ConfidenceContextProvider.swift @@ -4,5 +4,8 @@ import Foundation A Contextual implementer returns the current context */ public protocol ConfidenceContextProvider { + /** + Returns the current context, including the ancestors' context data + */ func getContext() -> ConfidenceStruct } diff --git a/Sources/Confidence/ConfidenceEventSender.swift b/Sources/Confidence/ConfidenceEventSender.swift index f1af53b4..18e7b829 100644 --- a/Sources/Confidence/ConfidenceEventSender.swift +++ b/Sources/Confidence/ConfidenceEventSender.swift @@ -3,7 +3,7 @@ import Foundation /** Sends events to Confidence. Contextual data is appended to each event */ -public protocol ConfidenceEventSender: Contextual { +public protocol ConfidenceEventSender: ConfidenceContextProvider { /** Upon return, the event has been correctly stored and will be emitted to the backend according to the configured flushing logic @@ -18,4 +18,17 @@ public protocol ConfidenceEventSender: Contextual { Schedule a manual flush of the event data currently stored on disk */ func flush() + /** + Adds/override entry to local context data + */ + func putContext(key: String, value: ConfidenceValue) + /** + Removes entry from localcontext data + It hides entries with this key from parents' data (without modifying parents' data) + */ + func removeKey(key: String) + /** + Creates a child event sender instance that maintains access to its parent's data + */ + func withContext(_ context: ConfidenceStruct) -> ConfidenceEventSender } diff --git a/Sources/Confidence/Contextual.swift b/Sources/Confidence/Contextual.swift deleted file mode 100644 index 1172c2fb..00000000 --- a/Sources/Confidence/Contextual.swift +++ /dev/null @@ -1,22 +0,0 @@ -import Foundation - -/** -A Contextual implementer maintains local context data and can create child instances -that can still access their parent's data -Each ConfidenceContextProvider returns local data reconciled with parents' data. Local data has precedence -*/ -public protocol Contextual: ConfidenceContextProvider { - /** - Adds/override entry to local data - */ - func putContext(key: String, value: ConfidenceValue) - /** - Removes entry from local data - It hides entries with this key from parents' data (without modifying parents' data) - */ - func removeKey(key: String) - /** - Creates a child Contextual instance that maintains access to its parent's data - */ - func withContext(_ context: ConfidenceStruct) -> Self -}