-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: add EventStorage * refactor: make getFolderURL() static * fix: initialize URLs in init() * feat: extend EventStorage API * refactor: add error handling * fix: handle continuing writing to batch from disk * fix: handle continuing writing to batch from disk, remove force unwrapping * fix: simplify batching * refactor: change handling of file creation * refactor: create a new file if no file left after previous session * fix creating file, folder and use file handler, fix appending events to the storage. fix tests * always seek to the end of the file to append * close file handler before moving it to ready * move private funcs down * cache folder url * test appending events * tear down test * fix: update .gitignore * refactor: refactor EventStorage * test: test EventStorage * fix: unalignment with main * fix: fix lint issues * fix: align links and add comments * Add RemoteClient to Confidence * Make NetworkClient endpoint independent * Generalie and reuse HTTP module * Add Common target for shared internal code * Finalize the network layer for events * Smaller refactoring * Move StructValue to Common * [WIP] One struct for all network * [WIP] Rename Struct * [WIP] Finish implementing NetworkTypeMapper * Remove generic number type * NetworkValue works with number * Network model better represents JSON types * Fix file name * Fix CI build * Rename NetworkValue * Create testbed with URLProtocol mock * Add ConfidenceClient tests * ConfidenceClient error handling/testing * Rebase on top of EventSenderEngine * Formatting * Name alignments and visibility tweaks * Main rebase * Send context in events and align naming * Fix demo app and def policy * Test more types in demo app --------- Co-authored-by: Nicky Bondarenko <[email protected]> Co-authored-by: Nicklas Lundin <[email protected]> Co-authored-by: vahid torkaman <[email protected]>
- Loading branch information
1 parent
fdc7543
commit b5ba3e0
Showing
52 changed files
with
1,049 additions
and
410 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,29 +21,40 @@ let package = Package( | |
.package(url: "[email protected]:open-feature/swift-sdk.git", from: "0.1.0"), | ||
], | ||
targets: [ | ||
// Internal definitions shared between Confidence and ConfidenceProvider | ||
// These are not exposed to the consumers of Confidence or ConfidenceProvider | ||
.target( | ||
name: "Confidence", | ||
name: "Common", | ||
dependencies: [], | ||
plugins: [] | ||
), | ||
.target( | ||
name: "Confidence", | ||
dependencies: [ | ||
"Common" | ||
], | ||
plugins: [] | ||
), | ||
.target( | ||
name: "ConfidenceProvider", | ||
dependencies: [ | ||
.product(name: "OpenFeature", package: "swift-sdk"), | ||
"Confidence" | ||
"Confidence", | ||
"Common" | ||
], | ||
plugins: [] | ||
), | ||
.testTarget( | ||
name: "ConfidenceProviderTests", | ||
dependencies: [ | ||
"ConfidenceProvider", | ||
"Common", | ||
] | ||
), | ||
.testTarget( | ||
name: "ConfidenceTests", | ||
dependencies: [ | ||
"Confidence" | ||
"Confidence", | ||
] | ||
), | ||
] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import Foundation | ||
|
||
/// Used to default an enum to the last value if none matches, this should respresent unknown | ||
public protocol CaseIterableDefaultsLast: Decodable & CaseIterable & RawRepresentable | ||
where RawValue: Decodable, AllCases: BidirectionalCollection {} | ||
|
||
extension CaseIterableDefaultsLast { | ||
public init(from decoder: Decoder) throws { | ||
// All enums should contain at least one item so we allow force unwrap | ||
// swiftlint:disable:next force_unwrapping | ||
self = try Self(rawValue: decoder.singleValueContainer().decode(RawValue.self)) ?? Self.allCases.last! | ||
} | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import Foundation | ||
|
||
public typealias HttpClientResult<T> = Result<HttpClientResponse<T>, Error> | ||
|
||
public protocol HttpClient { | ||
func post<T: Decodable>(path: String, data: Encodable) async throws -> HttpClientResult<T> | ||
} | ||
|
||
public struct HttpClientResponse<T> { | ||
public init(decodedData: T? = nil, decodedError: HttpError? = nil, response: HTTPURLResponse) { | ||
self.decodedData = decodedData | ||
self.decodedError = decodedError | ||
self.response = response | ||
} | ||
public var decodedData: T? | ||
public var decodedError: HttpError? | ||
public var response: HTTPURLResponse | ||
} | ||
|
||
public struct HttpError: Codable { | ||
public init(code: Int, message: String, details: [String]) { | ||
self.code = code | ||
self.message = message | ||
self.details = details | ||
} | ||
public var code: Int | ||
public var message: String | ||
public var details: [String] | ||
} | ||
|
||
public enum HttpClientError: Error { | ||
case invalidResponse | ||
case internalError | ||
} | ||
|
||
extension HTTPURLResponse { | ||
public func mapStatusToError(error: HttpError?) -> ConfidenceError { | ||
let defaultError = ConfidenceError.internalError( | ||
message: "General error: \(error?.message ?? "Unknown error")") | ||
|
||
switch self.status { | ||
case .notFound, .badRequest: | ||
return ConfidenceError.badRequest(message: error?.message ?? "") | ||
default: | ||
return defaultError | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.