Skip to content

Commit

Permalink
sync with monorepo
Browse files Browse the repository at this point in the history
  • Loading branch information
joshmossas committed Aug 18, 2024
1 parent 87e23d0 commit 30096fd
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
8 changes: 8 additions & 0 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@ import PackageDescription

let package = Package(
name: "ArriClient",
// platforms: [
// .iOS("13.0"),
// .macCatalyst("13.0"),
// .macOS("10.15"),
// .tvOS("13.0"),
// .visionOS("1.0"),
// .watchOS("6.0")
// ],
products: [
// Products define the executables and libraries a package produces, making them visible to other packages.
.library(
Expand Down
11 changes: 9 additions & 2 deletions Sources/ArriClient/ArriClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import NIOFoundationCompat
let jsonEncoder = JSONEncoder()
let jsonDecoder = JSONDecoder()

@available(macOS 10.15, iOS 13, tvOS 13, macCatalyst 13, *)
public func parsedArriHttpRequest<TParams: ArriClientModel, TResponse: ArriClientModel>(
delegate: ArriRequestDelegate,
url: String,
Expand Down Expand Up @@ -238,12 +239,12 @@ public func serializeAny(input: JSON) -> String {


//// Request Delegate ////

@available(macOS 10.15, iOS 13, tvOS 13, macCatalyst 13, *)
public protocol ArriRequestDelegate {
func handleHTTPRequest(request: ArriHTTPRequest) async throws -> ArriHTTPResponse<Data>
func handleHTTPEventStreamRequest(request: ArriHTTPRequest) async throws -> ArriSSEResponse
}

@available(macOS 10.15, iOS 13, tvOS 13, macCatalyst 13, *)
public struct DefaultRequestDelegate: ArriRequestDelegate {
var maxBodyBytes: Int = 1024 * 1024
public init() {}
Expand Down Expand Up @@ -307,6 +308,7 @@ public struct DefaultRequestDelegate: ArriRequestDelegate {
}
}

@available(macOS 10.15, iOS 13, tvOS 13, macCatalyst 13, *)
public enum ArriSSEResponse {
case ok(ArriHTTPResponse<HTTPClientResponse.Body>)
case error(ArriHTTPResponse<Data>)
Expand Down Expand Up @@ -386,6 +388,7 @@ public enum ArriResponseErrors: Error {
}

extension URLSession {
@available(macOS 10.15, iOS 13, tvOS 13, macCatalyst 13, *)
func asyncData(with: URLRequest) async throws -> (Data?, HTTPURLResponse) {
return try await withCheckedThrowingContinuation { continuation in
URLSession.shared.dataTask(with: with) {data, response, error in
Expand Down Expand Up @@ -596,10 +599,12 @@ public func sseEventListFromString(input: String, debug: Bool) -> ([RawSSEEvent]
return (events, String(leftover))
}

@available(macOS 10.15, iOS 13, tvOS 13, macCatalyst 13, *)
public protocol ArriCancellable {
mutating func cancel() -> ()
}

@available(macOS 10.15, iOS 13, tvOS 13, macCatalyst 13, *)
public struct EventSourceOptions<T: ArriClientModel> {
public var onMessage: (T, inout EventSource<T>) -> ()
public var onRequest: ((ArriHTTPRequest, inout EventSource<T>) -> ()) = { _, __ in }
Expand Down Expand Up @@ -666,6 +671,7 @@ public struct EventSourceOptions<T: ArriClientModel> {
}
}

@available(macOS 10.15, iOS 13, tvOS 13, macCatalyst 13, *)
public struct EventSource<T: ArriClientModel>: ArriCancellable {
var url: String
var method: String
Expand Down Expand Up @@ -701,6 +707,7 @@ public struct EventSource<T: ArriClientModel>: ArriCancellable {
self.cancelled = true
}

@available(macOS 10.15, iOS 13, tvOS 13, macCatalyst 13, *)
public mutating func sendRequest() async {
var urlComponents = URLComponents(string: self.url)
if urlComponents == nil {
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,6 @@
"fs-extra": "^11.2.0",
"jiti": "^1.21.6",
"prettier": "^3.3.3"
}
},
"packageManager": "[email protected]"
}

0 comments on commit 30096fd

Please sign in to comment.