Skip to content
This repository has been archived by the owner on Jul 29, 2024. It is now read-only.

Commit

Permalink
Upgrade azure library (#4)
Browse files Browse the repository at this point in the history
Co-authored-by: BeniVF <[email protected]>
  • Loading branch information
JesusMtnez and BeniVF authored Aug 26, 2020
1 parent 2d11e68 commit 64a9bff
Show file tree
Hide file tree
Showing 10 changed files with 194 additions and 99 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ on: [push, pull_request]
env:
CI: true
CI_SNAPSHOT_RELEASE: +publishSigned
SCALA_VERSION: 2.12.11
SCALA_VERSION: 2.12.12
jobs:
validate:
name: Scala ${{ matrix.scala }}, Java ${{ matrix.java }}
Expand All @@ -12,7 +12,7 @@ jobs:
fail-fast: false
matrix:
java: [[email protected], [email protected], [email protected]]
scala: [2.12.11, 2.13.1]
scala: [2.12.12, 2.13.3]
env:
SCALA_VERSION: ${{ matrix.scala }}
steps:
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ on:
push:
branches:
- master
tags:
tags:
- '*'
env:
CI: true
SCALA_VERSION: 2.12.11
SCALA_VERSION: 2.12.12
jobs:
release:
name: Release
Expand All @@ -17,7 +17,7 @@ jobs:
with:
fetch-depth: 0
- uses: olafurpg/setup-scala@v5
- uses: olafurpg/setup-gpg@v2
- uses: olafurpg/setup-gpg@v2
- name: Cache Coursier
uses: actions/cache@v1
with:
Expand All @@ -34,7 +34,7 @@ jobs:
PGP_PASSPHRASE: ${{ secrets.PGP_PASSPHRASE }}
PGP_SECRET: ${{ secrets.PGP_SECRET }}
SONATYPE_PASSWORD: ${{ secrets.SONATYPE_PASSWORD }}
SONATYPE_USERNAME: ${{ secrets.SONATYPE_USERNAME }}
SONATYPE_USERNAME: ${{ secrets.SONATYPE_USERNAME }}
- name: Set up Ruby 2.6
uses: actions/setup-ruby@v1
with:
Expand Down
41 changes: 29 additions & 12 deletions .scalafmt.conf
Original file line number Diff line number Diff line change
@@ -1,18 +1,35 @@
version = 2.5.3

style = default
version = "2.5.3"

maxColumn = 100

// Vertical alignment is pretty, but leads to bigger diffs
align.preset = none
continuationIndent.callSite = 2

newlines {
sometimesBeforeColonInMethodReturnType = false
}

align {
preset = none
arrowEnumeratorGenerator = false
ifWhileOpenParen = false
multiline = false
openParenCallSite = false
openParenDefnSite = false

tokens = ["%", "%%"]
}

danglingParentheses.preset = false

rewrite.rules = [
AvoidInfix
RedundantBraces
RedundantParens
AsciiSortImports
PreferCurlyFors
]
docstrings = JavaDoc

rewrite {
rules = [
AvoidInfix
RedundantBraces
RedundantParens
AsciiSortImports
PreferCurlyFors
]
redundantBraces.maxLines = 1
}
35 changes: 16 additions & 19 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
val catsV = "2.1.1"
val catsEffectV = "2.1.3"

val fs2V = "2.4.1"

val circeV = "0.12.3"
val specs2V = "4.9.4"

val catsEffectV = "2.1.4"
val fs2V = "2.4.4"
val circeV = "0.13.0"
val specs2V = "4.10.3"
// compiler plugins
val kindProjectorV = "0.11.0"
val betterMonadicForV = "0.3.1"

// Projects
lazy val `cosmos4s` = project
.in(file("."))
.disablePlugins(MimaPlugin)
Expand Down Expand Up @@ -79,21 +76,21 @@ lazy val site = project

// General Settings
lazy val commonSettings = Seq(
scalaVersion := "2.13.1",
crossScalaVersions := Seq(scalaVersion.value, "2.12.11"),
scalaVersion := "2.13.3",
crossScalaVersions := Seq(scalaVersion.value, "2.12.12"),
addCompilerPlugin(
("org.typelevel" %% "kind-projector" % kindProjectorV).cross(CrossVersion.full)),
addCompilerPlugin("com.olegpy" %% "better-monadic-for" % betterMonadicForV),
libraryDependencies ++= Seq(
"com.azure" % "azure-cosmos" % "4.0.1-beta.2",
"org.typelevel" %% "cats-core" % catsV,
"org.typelevel" %% "cats-effect" % catsEffectV,
"co.fs2" %% "fs2-reactive-streams" % fs2V,
"io.circe" %% "circe-core" % circeV,
"io.circe" %% "circe-parser" % circeV,
"io.circe" %% "circe-jackson210" % "0.13.0",
"org.specs2" %% "specs2-core" % specs2V % Test,
"org.specs2" %% "specs2-scalacheck" % specs2V % Test
"com.azure" % "azure-cosmos" % "4.3.2-beta.2",
"org.typelevel" %% "cats-core" % catsV,
"org.typelevel" %% "cats-effect" % catsEffectV,
"co.fs2" %% "fs2-reactive-streams" % fs2V,
"io.circe" %% "circe-core" % circeV,
"io.circe" %% "circe-parser" % circeV,
"io.circe" %% "circe-jackson210" % "0.13.0",
"org.specs2" %% "specs2-core" % specs2V % Test,
"org.specs2" %% "specs2-scalacheck" % specs2V % Test
)
)

Expand Down
69 changes: 41 additions & 28 deletions core/src/main/scala/com/banno/cosmos4s/IndexedCosmosContainer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,27 +16,26 @@

package com.banno.cosmos4s

import _root_.io.circe._
import cats._
import cats.implicits._
import cats.effect._
import _root_.fs2._

import _root_.io.circe.jackson._
import com.fasterxml.jackson.databind.JsonNode

import cats.implicits._
import com.azure.cosmos._
import com.azure.cosmos.models._
import com.banno.cosmos4s.types._
import com.fasterxml.jackson.databind.JsonNode
import fs2.Stream
import io.circe._
import io.circe.jackson._

trait IndexedCosmosContainer[F[_], K, I, V] {
def query(
partitionKey: K,
query: String,
overrides: FeedOptions => FeedOptions = identity): Stream[F, V]
overrides: QueryOptions => QueryOptions = identity): Stream[F, V]
def queryCustom[A: Decoder](
partitionKey: K,
query: String,
overrides: FeedOptions => FeedOptions = identity): Stream[F, A]
overrides: QueryOptions => QueryOptions = identity): Stream[F, A]
def lookup(partitionKey: K, id: I): F[Option[V]]
def insert(partitionKey: K, value: V): F[Option[V]]
def replace(partitionKey: K, id: I, value: V): F[Option[V]]
Expand All @@ -61,26 +60,33 @@ object IndexedCosmosContainer {

def impl[F[_]: ConcurrentEffect: ContextShift](
container: CosmosAsyncContainer,
createFeedOptions: Option[F[FeedOptions]] = None)
: IndexedCosmosContainer[F, String, String, Json] =
createFeedOptions: Option[F[QueryOptions]] = None): IndexedCosmosContainer[
F,
String,
String,
Json] =
new BaseImpl[F](container, createFeedOptions)

private class BaseImpl[F[_]: ConcurrentEffect: ContextShift](
container: CosmosAsyncContainer,
createFeedOptions: Option[F[FeedOptions]] = None)
createFeedOptions: Option[F[QueryOptions]] = None)
extends IndexedCosmosContainer[F, String, String, Json] {

def createFeedOptionsAlways = createFeedOptions.getOrElse(Sync[F].delay(new FeedOptions()))
private def createFeedOptionsAlways: F[QueryOptions] =
createFeedOptions.getOrElse(Sync[F].delay(QueryOptions.default))

import scala.collection.JavaConverters._

def query(
partitionKey: String,
query: String,
overrides: FeedOptions => FeedOptions = identity): Stream[F, Json] =
overrides: QueryOptions => QueryOptions = identity): Stream[F, Json] =
queryCustom[Json](partitionKey, query, overrides)

def queryCustom[A: Decoder](
partitionKey: String,
query: String,
overrides: FeedOptions => FeedOptions = identity): Stream[F, A] =
overrides: QueryOptions => QueryOptions = identity): Stream[F, A] =
Stream
.eval(createFeedOptionsAlways)
.map(overrides)
Expand All @@ -90,15 +96,16 @@ object IndexedCosmosContainer {
container
.queryItems(
query,
options.setPartitionKey(new PartitionKey(partitionKey)),
options.build().setPartitionKey(new PartitionKey(partitionKey)),
classOf[JsonNode])
.byPage()
)
)
}
.flatMap(page => Stream.fromIterator(page.getElements().iterator().asScala))
.map(jacksonToCirce)
.map(jacksonToCirce(_))
.evalMap(_.as[A].liftTo[F])

def lookup(partitionKey: String, id: String): F[Option[Json]] =
cats.data
.OptionT(
Expand All @@ -112,8 +119,9 @@ object IndexedCosmosContainer {
))
)
.subflatMap(response => Option(response.getItem()))
.map(jacksonToCirce)
.map(jacksonToCirce(_))
.value

def insert(partitionKey: String, value: Json): F[Option[Json]] =
cats.data.OptionT
.liftF(Sync[F].delay(new CosmosItemRequestOptions()))
Expand All @@ -123,6 +131,7 @@ object IndexedCosmosContainer {
.subflatMap(response => Option(response.getItem()))
.map(jacksonToCirce)
.value

def replace(partitionKey: String, id: String, value: Json): F[Option[Json]] =
cats.data
.OptionT(
Expand All @@ -134,6 +143,7 @@ object IndexedCosmosContainer {
.subflatMap(response => Option(response.getItem()))
.map(jacksonToCirce)
.value

def upsert(partitionKey: String, value: Json): F[Option[Json]] =
cats.data
.OptionT(
Expand Down Expand Up @@ -162,12 +172,12 @@ object IndexedCosmosContainer {
def query(
partitionKey: K,
query: String,
overrides: FeedOptions => FeedOptions = identity): Stream[G, V] =
overrides: QueryOptions => QueryOptions = identity): Stream[G, V] =
base.query(partitionKey, query, overrides).translate(fk)
def queryCustom[A: Decoder](
partitionKey: K,
query: String,
overrides: FeedOptions => FeedOptions = identity): Stream[G, A] =
overrides: QueryOptions => QueryOptions = identity): Stream[G, A] =
base.queryCustom[A](partitionKey, query, overrides).translate(fk)
def lookup(partitionKey: K, id: I): G[Option[V]] =
fk(base.lookup(partitionKey, id))
Expand All @@ -188,12 +198,12 @@ object IndexedCosmosContainer {
def query(
partitionKey: K2,
query: String,
overrides: FeedOptions => FeedOptions): Stream[F, V] =
overrides: QueryOptions => QueryOptions): Stream[F, V] =
base.query(contra(partitionKey), query, overrides)
def queryCustom[A: Decoder](
partitionKey: K2,
query: String,
overrides: FeedOptions => FeedOptions): Stream[F, A] =
overrides: QueryOptions => QueryOptions): Stream[F, A] =
base.queryCustom(contra(partitionKey), query, overrides)
def lookup(partitionKey: K2, id: I): F[Option[V]] =
base.lookup(contra(partitionKey), id)
Expand All @@ -211,12 +221,15 @@ object IndexedCosmosContainer {
base: IndexedCosmosContainer[F, K, I, V],
contra: I2 => I
) extends IndexedCosmosContainer[F, K, I2, V] {
def query(partitionKey: K, query: String, overrides: FeedOptions => FeedOptions): Stream[F, V] =
def query(
partitionKey: K,
query: String,
overrides: QueryOptions => QueryOptions): Stream[F, V] =
base.query(partitionKey, query, overrides)
def queryCustom[A: Decoder](
partitionKey: K,
query: String,
overrides: FeedOptions => FeedOptions): Stream[F, A] =
overrides: QueryOptions => QueryOptions): Stream[F, A] =
base.queryCustom(partitionKey, query, overrides)
def lookup(partitionKey: K, id: I2): F[Option[V]] =
base.lookup(partitionKey, contra(id))
Expand All @@ -238,14 +251,14 @@ object IndexedCosmosContainer {
def query(
partitionKey: K,
query: String,
overrides: FeedOptions => FeedOptions): Stream[F, V2] =
overrides: QueryOptions => QueryOptions): Stream[F, V2] =
base
.query(partitionKey, query, overrides)
.evalMap(f)
def queryCustom[A: Decoder](
partitionKey: K,
query: String,
overrides: FeedOptions => FeedOptions): Stream[F, A] =
overrides: QueryOptions => QueryOptions): Stream[F, A] =
base.queryCustom(partitionKey, query, overrides)
def lookup(partitionKey: K, id: I): F[Option[V2]] =
base.lookup(partitionKey, id).flatMap(_.traverse(f))
Expand All @@ -267,14 +280,14 @@ object IndexedCosmosContainer {
def query(
partitionKey: K,
query: String,
overrides: FeedOptions => FeedOptions): Stream[F, V2] =
overrides: QueryOptions => QueryOptions): Stream[F, V2] =
base
.query(partitionKey, query, overrides)
.map(f)
def queryCustom[A: Decoder](
partitionKey: K,
query: String,
overrides: FeedOptions => FeedOptions): Stream[F, A] =
overrides: QueryOptions => QueryOptions): Stream[F, A] =
base.queryCustom(partitionKey, query, overrides)
def lookup(partitionKey: K, id: I): F[Option[V2]] =
base.lookup(partitionKey, id).map(_.map(f))
Expand Down
Loading

0 comments on commit 64a9bff

Please sign in to comment.