Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gemini -(Kumo) Task created in a session that has been invalidated #23

Merged
merged 8 commits into from
Mar 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions Kumo.podspec
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
Pod::Spec.new do |s|
s.name = 'Kumo'
s.version = '2.2.0'
s.version = '3.0.0'
s.summary = 'Simple networking with little boilerplate built with reactive programming.'
s.homepage = 'https://gitlab.duethealth.com/ios-projects/Dependencies/Kumo'
s.license = 'MIT'
s.author = 'ライアン'
s.source = { git: 'https://gitlab.duethealth.com/ios-projects/Dependencies/Kumo.git', tag: "#{s.version}" }
s.swift_version = '5.1'
s.swift_version = '5.5'

s.ios.deployment_target = '13.0'
s.osx.deployment_target = '10.15'
s.tvos.deployment_target = '13.0'
s.osx.deployment_target = '12.0'
s.tvos.deployment_target = '15.0'

s.default_subspecs = 'Kumo', 'KumoCoding'

Expand All @@ -22,7 +22,6 @@ Pod::Spec.new do |s|
s.subspec 'Kumo' do |myLib|
myLib.dependency 'Kumo/KumoCoding'
myLib.source_files = 'Sources/Kumo/**/*.{h,m,swift}'
myLib.dependency 'RxSwift'
end

end
4 changes: 2 additions & 2 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ let package = Package(
name: "Kumo",
platforms: [
.iOS(.v13),
.tvOS(.v13),
.macOS(.v10_15),
.tvOS(.v15),
.macOS(.v12),
],
products: [
.library(name: "Kumo", targets: ["Kumo"]),
Expand Down
16 changes: 15 additions & 1 deletion Sources/Kumo/Blobs/BlobCache.swift
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ public class BlobCache {
/// - Returns: A publisher for an object representing the data for the
/// blob resource at the `url`.
public func fetch<D: _DataConvertible & _DataRepresentable>(from url: URL, convertWith conversionArguments: D._ConversionArguments, representWith representationArguments: D._RepresentationArguments) -> AnyPublisher<D, Error> {
let downloadTask = service.perform(HTTP.Request.download(url))
let downloadTask = fetch(from: url)
.flatMap { [self] downloadPath -> AnyPublisher<D, Error> in
do {
if let data: D = try self.ephemeralStorage.acquire(fromPath: downloadPath, origin: url, convertWith: conversionArguments, representWith: representationArguments) {
Expand Down Expand Up @@ -195,4 +195,18 @@ public class BlobCache {
persistentStorage.clean()
}

private func fetch(from url: URL) -> AnyPublisher<URL, Error> {
Deferred<AnyPublisher<URL, Error>> {
Future<URL, Error> { [self] promise in
Task {
do {
let downloadPath = try await service.perform(HTTP.Request.download(url))
promise(.success(downloadPath))
} catch {
promise(.failure(error))
}
}
}.eraseToAnyPublisher()
}.eraseToAnyPublisher()
}
}
32 changes: 11 additions & 21 deletions Sources/Kumo/Logger/KumoLogger.swift
Original file line number Diff line number Diff line change
Expand Up @@ -73,27 +73,17 @@ extension KumoLogger {
}
}

}

extension Publisher {

func logPublisher(_ logger: KumoLogger?) -> Publishers.HandleEvents<Self> {
handleEvents(receiveOutput: { output in
guard let logger = logger, logger.levels.contains(.responseDecoding) else {
return
}
logger.log(message: "Decoded Response: \(output)", error: nil)
}, receiveCompletion: { completion in
switch completion {
case .failure(let error):
guard let logger = logger, logger.levels.contains(.responseDecoding) || logger.levels.contains(.error) else {
return
}
logger.log(message: "Error with request or response", error: error)
case .finished:
()
}
})
func logDecodedResponse(output: Any) {
guard levels.contains(.responseDecoding) else {
return
}
log(message: "Decoded Response: \(output)", error: nil)
}

func logRequestOrResponseError(error: Error) {
guard levels.contains(.responseDecoding) || levels.contains(.error) else {
return
}
log(message: "Error with request or response", error: error)
}
}
4 changes: 2 additions & 2 deletions Sources/Kumo/Services/Functions/Service+Download.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ public extension Service {
/// - Returns: An [`AnyPublisher`](https://developer.apple.com/documentation/combine/anypublisher)
/// which publishes a URL to the downloaded file upon success.
@available(*, deprecated, message: "Construct a request with HTTP.Request.download(_:) and use Service/perform(_:) instead.")
func download(_ endpoint: String, parameters: [String: Any] = [:]) -> AnyPublisher<URL, Error> {
perform(HTTP.Request.download(endpoint).parameters(parameters))
func download(_ endpoint: String, parameters: [String: Any] = [:]) async throws -> URL {
try await perform(HTTP.Request.download(endpoint).parameters(parameters))
}

}
7 changes: 3 additions & 4 deletions Sources/Kumo/Services/Functions/Service+SideEffects.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,9 @@ public extension Service {
/// will be cancelled if the ``Service`` is deallocated.
/// - Parameters:
/// - request: the request to be performed.
public func perform<Method: _RequestMethod, Resource: _RequestResource, Body: _RequestBody, Parameters: _RequestParameters, Key: _ResponseNestedKey>(_ request: HTTP._Request<Method, Resource, Body, Parameters, Key>) {
(base.perform(request) as AnyPublisher<Void, Error>)
.sink(receiveCompletion: { _ in }, receiveValue: { })
.withLifetime(of: base)
public func perform<Method: _RequestMethod, Resource: _RequestResource, Body: _RequestBody, Parameters: _RequestParameters, Key: _ResponseNestedKey>(_ request: HTTP._Request<Method, Resource, Body, Parameters, Key>) async throws -> Void {
let result: Void = try await base.perform(request)
return result
}

}
Expand Down
12 changes: 6 additions & 6 deletions Sources/Kumo/Services/Functions/Service+Upload.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ public extension Service {
/// - Returns: An [`AnyPublisher`](https://developer.apple.com/documentation/combine/anypublisher)
/// which publishes upon success.
@available(*, deprecated, message: "Construct an HTTP.Request with `.upload(_:)` and use `perform` instead.")
func upload<Response: Decodable>(_ endpoint: String, file: URL, under key: String) -> AnyPublisher<Response, Error> {
perform(HTTP.Request.upload(endpoint).file(file).keyed(under: key))
func upload<Response: Decodable>(_ endpoint: String, file: URL, under key: String) async throws -> Response? {
try await perform(HTTP.Request.upload(endpoint).file(file).keyed(under: key))
}

/// Uploads to an endpoint the provided file. The file is uploaded as form data
Expand All @@ -29,8 +29,8 @@ public extension Service {
/// - Returns: An [`AnyPublisher`](https://developer.apple.com/documentation/combine/anypublisher)
/// which publishes a single empty element upon success.
@available(*, deprecated, message: "Construct an HTTP.Request with `.upload(_:)` and use `perform` instead.")
func upload(_ endpoint: String, parameters: [String: Any] = [:], file: URL, under key: String) -> AnyPublisher<Void, Error> {
perform(HTTP.Request.upload(endpoint).parameters(parameters).file(file).keyed(under: key))
func upload(_ endpoint: String, parameters: [String: Any] = [:], file: URL, under key: String) async throws {
try await perform(HTTP.Request.upload(endpoint).parameters(parameters).file(file).keyed(under: key))
}

/// Uploads to an endpoint the provided file. The file is uploaded as form data
Expand All @@ -45,8 +45,8 @@ public extension Service {
/// - Returns: An [`AnyPublisher`](https://developer.apple.com/documentation/combine/anypublisher)
/// which publishes the progress of the upload.
@available(*, deprecated, message: "Construct an HTTP.Request with `.upload(_:)` and use `perform` with `.progress()` instead.")
func upload(_ endpoint: String, parameters: [String: Any] = [:], file: URL, under key: String) -> AnyPublisher<Double, Error> {
perform(HTTP.Request.upload(endpoint).parameters(parameters).file(file).keyed(under: key).progress())
func uploads(_ endpoint: String, parameters: [String: Any] = [:], file: URL, under key: String) async throws -> Double {
try await perform(HTTP.Request.upload(endpoint).parameters(parameters).file(file).keyed(under: key).progress())
}

}
Loading