Skip to content

Commit

Permalink
Remove deprecations since 0.16
Browse files Browse the repository at this point in the history
  • Loading branch information
vkostyukov committed Jan 3, 2018
1 parent da33ff0 commit 322e7cb
Show file tree
Hide file tree
Showing 13 changed files with 23 additions and 323 deletions.
123 changes: 1 addition & 122 deletions core/src/main/scala/io/finch/Endpoint.scala
@@ -1,12 +1,9 @@
package io.finch

import java.nio.charset.Charset
import scala.reflect.ClassTag

import cats.Alternative
import cats.data.NonEmptyList
import com.twitter.finagle.Service
import com.twitter.finagle.http.{Cookie, Request, Response}
import com.twitter.finagle.http.{Request, Response}
import com.twitter.util.{Future, Return, Throw, Try}
import io.catbird.util.Rerunnable
import io.finch.internal._
Expand Down Expand Up @@ -232,18 +229,6 @@ trait Endpoint[A] { self =>
left.coproduct(right)
}

@deprecated("Use transform instead", "0.16")
final def withHeader(header: (String, String)): Endpoint[A] =
withOutput(o => o.withHeader(header))

@deprecated("Use transform instead", "0.16")
final def withCookie(cookie: Cookie): Endpoint[A] =
withOutput(o => o.withCookie(cookie))

@deprecated("Use transform instead", "0.16")
final def withCharset(charset: Charset): Endpoint[A] =
withOutput(o => o.withCharset(charset))

/**
* Converts this endpoint to a Finagle service `Request => Future[Response]` that serves JSON.
*
Expand Down Expand Up @@ -358,9 +343,6 @@ trait Endpoint[A] { self =>
final def apply(input: Input): Endpoint.Result[A] = self(input)
final override def toString: String = ts
}

private[this] def withOutput[B](fn: Output[A] => Output[B]): Endpoint[B] =
transform(foa => foa.map(oa => fn(oa)))
}

/**
Expand Down Expand Up @@ -410,12 +392,6 @@ object Endpoint {
EndpointResult.Matched(input, Rerunnable.fromFuture(fa).map(a => Output.payload(a)))
}

/**
* Creates an [[Endpoint]] that always matches and returns a given `Future` (evaluated lazily).
*/
@deprecated("Use liftAsync instead", "0.16")
def liftFuture[A](fa: => Future[A]): Endpoint[A] = liftAsync(fa)

/**
* Creates an [[Endpoint]] that always matches and returns a given `Output` (evaluated lazily).
*/
Expand All @@ -433,13 +409,6 @@ object Endpoint {
EndpointResult.Matched(input, Rerunnable.fromFuture(foa))
}

/**
* Creates an [[Endpoint]] that always matches and returns a given `Future[Output]`
* (evaluated lazily).
*/
@deprecated("Use liftOutputAsync instead", "0.16")
def liftFutureOutput[A](foa: => Future[Output[A]]): Endpoint[A] = liftOutputAsync(foa)

final implicit class ValueEndpointOps[B](val self: Endpoint[B]) extends AnyVal {
/**
* Converts this endpoint to one that returns any type with `B :: HNil` as its representation.
Expand All @@ -465,33 +434,10 @@ object Endpoint {
def asTuple(implicit t: Tupler[L]): Endpoint[t.Out] = self.map(t(_))
}

private[this] def notParsed[A](
e: Endpoint[_], tag: ClassTag[_]
): PartialFunction[Throwable, Try[A]] = {
case exc => Throw[A](Error.NotParsed(e.item, tag, exc))
}

/**
* Implicit conversion that allows to call `as[A]` on any `Endpoint[String]` to perform a type
* conversion based on an implicit `DecodeEntity[A]` which must be in scope.
*
* The resulting endpoint will fail when type conversion fails.
*/
implicit class StringEndpointOps(val self: Endpoint[String]) extends AnyVal {
@deprecated(s"Use type parameter instead for a corresponding endpoint (param[A], header[A], ...)", "0.16")
def as[A](implicit d: DecodeEntity[A], tag: ClassTag[A]): Endpoint[A] =
self.mapAsync(value => Future.const(d(value).rescue(notParsed[A](self, tag))))
}

/**
* Implicit conversion that adds convenience methods to endpoint for optional values.
*/
implicit class OptionEndpointOps[A](val self: Endpoint[Option[A]]) extends AnyVal {
private[finch] def failIfNone: Endpoint[A] = self.mapAsync {
case Some(value) => Future.value(value)
case None => Future.exception(Error.NotPresent(self.item))
}

/**
* If endpoint is empty it will return provided default value.
*/
Expand All @@ -504,73 +450,6 @@ object Endpoint {
self.map(_.orElse(alternative))
}

/**
* Implicit conversion that allows to call `as[A]` on any `Endpoint[NonEmptyList[String]]` to perform a
* type conversion based on an implicit `Decode[A]` which must be in scope.
*
* The resulting endpoint will fail when type conversion fails on one
* or more of the elements in the `NonEmptyList`. It will succeed if type conversion succeeds for all elements.
*/
implicit class StringNelEndpointOps(val self: Endpoint[NonEmptyList[String]]) extends AnyVal {
@deprecated(s"Use type parameter instead for a corresponding endpoint (param[A], header[A], ...)", "0.16")
def as[A](implicit d: DecodeEntity[A], tag: ClassTag[A]): Endpoint[NonEmptyList[A]] =
self.mapAsync { items =>
val decoded = items.toList.map(d.apply)
val errors = decoded.collect {
case Throw(e) => Error.NotParsed(self.item, tag, e)
}

NonEmptyList.fromList(errors) match {
case None =>
Future.const(Try.collect(decoded).map(seq => NonEmptyList(seq.head, seq.tail.toList)))
case Some(err) =>
Future.exception(Errors(err))
}
}
}

/**
* Implicit conversion that allows to call `as[A]` on any `Endpoint[Seq[String]]` to perform a
* type conversion based on an implicit `DecodeRequest[A]` which must be in scope.
*
* The resulting endpoint will fail when the result is non-empty and type conversion fails on one
* or more of the elements in the `Seq`. It will succeed if the result is empty or type conversion
* succeeds for all elements.
*/
implicit class StringSeqEndpointOps(val self: Endpoint[Seq[String]]) extends AnyVal {
@deprecated(s"Use type parameter instead for a corresponding endpoint (param[A], header[A], ...)", "0.16")
def as[A](implicit d: DecodeEntity[A], tag: ClassTag[A]): Endpoint[Seq[A]] =
self.mapAsync { items =>
val decoded = items.map(d.apply)
val errors = decoded.collect {
case Throw(e) => Error.NotParsed(self.item, tag, e)
}

NonEmptyList.fromList(errors.toList) match {
case None => Future.const(Try.collect(decoded))
case Some(err) => Future.exception(Errors(err))
}
}
}

/**
* Implicit conversion that allows to call `as[A]` on any `Endpoint[Option[String]]` to perform a
* type conversion based on an implicit `DecodeRequest[A]` which must be in scope.
*
* The resulting endpoint will fail when the result is non-empty and type conversion fails. It
* will succeed if the result is empty or type conversion succeeds.
*/
implicit class StringOptionEndpointOps(val self: Endpoint[Option[String]]) extends AnyVal {
@deprecated(s"Use type parameter instead for a corresponding endpoint (param[A], header[A], ...)", "0.16")
def as[A](implicit d: DecodeEntity[A], tag: ClassTag[A]): Endpoint[Option[A]] =
self.mapAsync {
case Some(value) =>
Future.const(d(value).rescue(notParsed[A](self, tag))).map(Some.apply)
case None =>
Future.None
}
}

implicit val endpointInstance: Alternative[Endpoint] = new Alternative[Endpoint] {
final override def ap[A, B](ff: Endpoint[A => B])(fa: Endpoint[A]): Endpoint[B] =
ff.productWith(fa)((f, a) => f(a))
Expand Down
15 changes: 0 additions & 15 deletions core/src/main/scala/io/finch/endpoint/multipart.scala
Expand Up @@ -209,19 +209,4 @@ private[finch] trait FileUploadsAndAttributes {
*/
def multipartAttributesNel[A](name: String)(implicit d: DecodeEntity[A], t: ClassTag[A]): Endpoint[NonEmptyList[A]] =
new Attribute[NonEmptyList, A](name, d, t) with Attribute.NonEmpty[A] with Attribute.MultipleErrors[NonEmptyList, A]

/**
* An evaluating [[Endpoint]] that reads an optional file upload from a `multipart/form-data`
* request into an `Option`.
*/
@deprecated("Use multipartFileUploadOption instead", "0.16")
def fileUploadOption(name: String): Endpoint[Option[FinagleMultipart.FileUpload]] =
multipartFileUploadOption(name)

/**
* An evaluating [[Endpoint]] that reads a required file upload from a `multipart/form-data`
* request.
*/
@deprecated("Use multipartFileUpload instead", "0.16")
def fileUpload(name: String): Endpoint[FinagleMultipart.FileUpload] = multipartFileUpload(name)
}
91 changes: 0 additions & 91 deletions core/src/main/scala/io/finch/endpoint/path.scala
Expand Up @@ -3,7 +3,6 @@ package io.finch.endpoint
import io.catbird.util.Rerunnable
import io.finch._
import io.finch.internal.Rs
import java.util.UUID
import scala.reflect.ClassTag
import shapeless.HNil

Expand Down Expand Up @@ -62,94 +61,4 @@ private[finch] trait Paths {
* An [[Endpoint]] that matches a given string.
*/
def path(s: String): Endpoint[HNil] = new MatchPath(s)

/**
* A matching [[Endpoint]] that reads an integer value from the current path segment.
*/
@deprecated("Use path[Int] instead", "0.16")
val int: Endpoint[Int] = path[Int]

/**
* A matching [[Endpoint]] that reads a long value from the current path segment.
*/
@deprecated("Use path[Long] instead", "0.16")
val long: Endpoint[Long] = path[Long]

/**
* A matching [[Endpoint]] that reads a string value from the current path segment.
*/
@deprecated("Use path[String] instead", "0.16")
val string: Endpoint[String] = path[String]

/**
* A matching [[Endpoint]] that reads a boolean value from the current path segment.
*/
@deprecated("Use path[Boolean] instead", "0.16")
val boolean: Endpoint[Boolean] = path[Boolean]

/**
* A matching [[Endpoint]] that reads an UUID value from the current path segment.
*/
@deprecated("Use path[UUID] instead", "0.16")
val uuid: Endpoint[UUID] = path[UUID]

/**
* A matching [[Endpoint]] that reads a string tail from the current path segment.
*/
@deprecated("Use paths[Int] instead", "0.16")
val ints: Endpoint[Seq[Int]] = paths[Int]

/**
* A matching [[Endpoint]] that reads a long tail from the current path segment.
*/
@deprecated("Use paths[Long] instead", "0.16")
val longs: Endpoint[Seq[Long]] = paths[Long]

/**
* A matching [[Endpoint]] that reads a string tail from the current path segment.
*/
@deprecated("Use paths[String] instead", "0.16")
val strings: Endpoint[Seq[String]] = paths[String]

/**
* A matching [[Endpoint]] that reads a boolean tail from the current path segment.
*/
@deprecated("Use paths[Boolean] instead", "0.16")
val booleans: Endpoint[Seq[Boolean]] = paths[Boolean]

/**
* A matching [[Endpoint]] that reads a UUID tail from the current path segment.
*/
@deprecated("Use paths[UUID] instead", "0.16")
val uuids: Endpoint[Seq[UUID]] = paths[UUID]

/**
* A matching [[Endpoint]] that reads an integer value from the current path segment.
*/
@deprecated("Use path[Int].withToString(String) instead", "0.16")
def int(name: String): Endpoint[Int] = int.withToString(name)

/**
* A matching [[Endpoint]] that reads a long value from the current path segment.
*/
@deprecated("Use path[Long].withToString(String) instead", "0.16")
def long(name: String): Endpoint[Long] = long.withToString(name)

/**
* A matching [[Endpoint]] that reads a string value from the current path segment.
*/
@deprecated("Use path[String].withToString(String) instead", "0.16")
def string(name: String): Endpoint[String] = string.withToString(name)

/**
* A matching [[Endpoint]] that reads a boolean value from the current path segment.
*/
@deprecated("Use path[Boolean].withToString(String) instead", "0.16")
def boolean(name: String): Endpoint[Boolean] = boolean.withToString(name)

/**
* A matching [[Endpoint]] that reads a UUID value from the current path segment.
*/
@deprecated("Use path[UUID].withToString(String) instead", "0.16")
def uuid(name: String): Endpoint[UUID] = uuid.withToString(name)
}
3 changes: 1 addition & 2 deletions core/src/main/scala/io/finch/package.scala
Expand Up @@ -8,8 +8,7 @@ import shapeless.Witness
*/
package object finch extends Endpoints
with Outputs
with ValidationRules
with io.finch.syntax.DeprecatedEndpointMappers {
with ValidationRules {

object items {
sealed abstract class RequestItem(val kind: String, val nameOption:Option[String] = None) {
Expand Down

This file was deleted.

2 changes: 1 addition & 1 deletion core/src/test/scala/io/finch/BootstrapSpec.scala
Expand Up @@ -14,7 +14,7 @@ class BootstrapSpec extends FinchSpec {
check { e: Either[Error, Errors] =>
val exception = e.fold[Exception](identity, identity)

val ee = Endpoint.liftFuture[Unit](Future.exception(exception))
val ee = Endpoint.liftAsync[Unit](Future.exception(exception))
val rep = Await.result(ee.toServiceAs[Text.Plain].apply(Request()))
rep.status === Status.BadRequest
}
Expand Down

0 comments on commit 322e7cb

Please sign in to comment.