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

Add Vapor 3 API shims #2373

Merged
merged 5 commits into from Jun 26, 2020
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 8 additions & 1 deletion Package.swift
Expand Up @@ -8,7 +8,8 @@ let package = Package(
],
products: [
.library(name: "Vapor", targets: ["Vapor"]),
.library(name: "XCTVapor", targets: ["XCTVapor"])
.library(name: "XCTVapor", targets: ["XCTVapor"]),
.library(name: "_Vapor3", targets: ["_Vapor3"]),
],
dependencies: [
// HTTP client library built on SwiftNIO
Expand Down Expand Up @@ -83,10 +84,16 @@ let package = Package(
.product(name: "RoutingKit", package: "routing-kit"),
.product(name: "WebSocketKit", package: "websocket-kit"),
]),
// Vapor 3 API shim
.target(name: "_Vapor3", dependencies: [
.target(name: "Vapor"),
.product(name: "_NIO1APIShims", package: "swift-nio")
]),

// Development
.target(name: "Development", dependencies: [
.target(name: "Vapor"),
.target(name: "_Vapor3"),
]),

// Testing
Expand Down
3 changes: 2 additions & 1 deletion Sources/Development/routes.swift
@@ -1,4 +1,5 @@
import Vapor
import _Vapor3

struct Creds: Content {
var email: String
Expand All @@ -12,7 +13,7 @@ public func routes(_ app: Application) throws {


// ( echo -e 'POST /slow-stream HTTP/1.1\r\nContent-Length: 1000000000\r\n\r\n'; dd if=/dev/zero; ) | nc localhost 8080
app.on(.POST, "slow-stream", body: .stream) { req -> EventLoopFuture<String> in
app.on(.POST, "slow-stream", body: .stream) { req -> Future<String> in
let done = req.eventLoop.makePromise(of: String.self)

var total = 0
Expand Down
2 changes: 2 additions & 0 deletions Sources/_Vapor3/Config.swift
@@ -0,0 +1,2 @@
@available(*, unavailable, message: "Use `Application` instead.")
public typealias Config = Void
1 change: 1 addition & 0 deletions Sources/_Vapor3/Exports.swift
@@ -0,0 +1 @@
@_exported import _NIO1APIShims
43 changes: 43 additions & 0 deletions Sources/_Vapor3/Future.swift
@@ -0,0 +1,43 @@
import Vapor

@available(*, deprecated, renamed: "EventLoopFuture")
public typealias Future = EventLoopFuture

extension EventLoopFuture {
@available(*, deprecated, renamed: "Value")
public typealias Expectation = Value

@available(*, deprecated, message: "The `to` parameter has been removed and this method can no longer throw.")
public func map<T>(to type: T.Type, _ callback: @escaping (Value) throws -> T) -> EventLoopFuture<T> {
return self.flatMapThrowing(callback)
}


@available(*, deprecated, message: "The `to` parameter has been removed and this method can no longer throw.")
public func flatMap<T>(to type: T.Type, _ callback: @escaping (Value) throws -> EventLoopFuture<T>) -> EventLoopFuture<T> {
return self.flatMap { input in
do {
return try callback(input)
} catch {
return self.eventLoop.makeFailedFuture(error)
}
}
}

@available(*, deprecated, renamed: "flatMapErrorThrowing")
public func catchMap(_ callback: @escaping (Error) throws -> (Value)) -> EventLoopFuture<Value> {
return self.flatMapErrorThrowing(callback)
}


@available(*, deprecated, message: "Use `flatMapError` with internal do / catch that returns a failed future.")
public func catchFlatMap(_ callback: @escaping (Error) throws -> (EventLoopFuture<Value>)) -> EventLoopFuture<Value> {
return self.flatMapError { inputError in
do {
return try callback(inputError)
} catch {
return self.eventLoop.makeFailedFuture(error)
}
}
}
}
2 changes: 2 additions & 0 deletions Sources/_Vapor3/NIOServerConfig.swift
@@ -0,0 +1,2 @@
@available(*, unavailable, message: "Use `app.http.server.configuration` instead.")
public typealias NIOServerConfig = Void
4 changes: 4 additions & 0 deletions Sources/_Vapor3/Promise.swift
@@ -0,0 +1,4 @@
import Vapor

@available(*, deprecated, renamed: "EventLoopPromise")
public typealias Promise = EventLoopPromise
2 changes: 2 additions & 0 deletions Sources/_Vapor3/Services.swift
@@ -0,0 +1,2 @@
@available(*, unavailable, message: "Use `Application` instead.")
public typealias Services = Void