Skip to content

Commit

Permalink
Merge pull request #28 from armanbilge/update/sjs-dom-2.0.0
Browse files Browse the repository at this point in the history
Establish series/0.2 against sjs-dom 2.x
  • Loading branch information
armanbilge authored Oct 28, 2021
2 parents 9f21742 + 6a60cb9 commit 306a00d
Show file tree
Hide file tree
Showing 11 changed files with 60 additions and 55 deletions.
16 changes: 13 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ name: Continuous Integration

on:
pull_request:
branches: [series/0.1]
branches: [series/0.2]
push:
branches: [series/0.1]
branches: [series/0.2]
tags: [v*]

env:
Expand All @@ -26,7 +26,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest]
scala: [2.12.15, 2.13.6]
scala: [2.12.15, 3.1.0, 2.13.6]
java: [[email protected]]
runs-on: ${{ matrix.os }}
steps:
Expand Down Expand Up @@ -109,6 +109,16 @@ jobs:
tar xf targets.tar
rm targets.tar
- name: Download target directories (3.1.0)
uses: actions/download-artifact@v2
with:
name: target-${{ matrix.os }}-3.1.0-${{ matrix.java }}

- name: Inflate target directories (3.1.0)
run: |
tar xf targets.tar
rm targets.tar
- name: Download target directories (2.13.6)
uses: actions/download-artifact@v2
with:
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,9 @@ Features:
### Usage

```sbt
// supports http4s 0.23.x and scala-js-dom 2.x
libraryDependencies += "org.http4s" %%% "http4s-dom" % "0.2.0"

// supports http4s 0.23.x and scala-js-dom 1.x
libraryDependencies += "org.http4s" %%% "http4s-dom" % "0.1.0"
```
10 changes: 5 additions & 5 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -23,23 +23,23 @@ import JSEnv._

name := "http4s-dom"

ThisBuild / baseVersion := "0.1"
ThisBuild / baseVersion := "0.2"

ThisBuild / organization := "org.http4s"
ThisBuild / organizationName := "http4s.org"
ThisBuild / publishGithubUser := "armanbilge"
ThisBuild / publishFullName := "Arman Bilge"

enablePlugins(SonatypeCiReleasePlugin)
ThisBuild / githubWorkflowTargetBranches := Seq("series/0.1")
ThisBuild / githubWorkflowTargetBranches := Seq("series/0.2")

ThisBuild / homepage := Some(url("https://github.com/http4s/http4s-dom"))
ThisBuild / scmInfo := Some(
ScmInfo(
url("https://github.com/http4s/http4s-dom"),
"https://github.com/http4s/http4s-dom.git"))

ThisBuild / crossScalaVersions := Seq("2.12.15", "2.13.6")
ThisBuild / crossScalaVersions := Seq("2.12.15", "3.1.0", "2.13.6")

replaceCommandAlias("ci", CI.AllCIs.map(_.toString).mkString)
addCommandAlias("ciFirefox", CI.Firefox.toString)
Expand Down Expand Up @@ -108,7 +108,7 @@ ThisBuild / Test / jsEnv := {
val catsEffectVersion = "3.2.9"
val fs2Version = "3.2.2"
val http4sVersion = "0.23.6"
val scalaJSDomVersion = "1.2.0"
val scalaJSDomVersion = "2.0.0"
val munitVersion = "0.7.29"
val munitCEVersion = "1.0.6"

Expand All @@ -122,7 +122,7 @@ lazy val dom = project
description := "http4s browser integrations",
libraryDependencies ++= Seq(
"org.typelevel" %%% "cats-effect" % catsEffectVersion,
"co.fs2" %%% "fs2-core" % fs2Version,
"co.fs2" %%% "fs2-io" % fs2Version,
"org.http4s" %%% "http4s-client" % http4sVersion,
"org.scala-js" %%% "scalajs-dom" % scalaJSDomVersion
)
Expand Down
15 changes: 7 additions & 8 deletions dom/src/main/scala/org/http4s/dom/FetchClient.scala
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,12 @@ import cats.effect.syntax.all._
import cats.syntax.all._
import org.http4s.client.Client
import org.http4s.headers.Referer
import org.scalajs.dom.crypto._
import org.scalajs.dom.experimental.AbortController
import org.scalajs.dom.experimental.Fetch
import org.scalajs.dom.experimental.Headers
import org.scalajs.dom.experimental.HttpMethod
import org.scalajs.dom.experimental.RequestInit
import org.scalajs.dom.experimental.{Response => FetchResponse}
import org.scalajs.dom.AbortController
import org.scalajs.dom.Fetch
import org.scalajs.dom.Headers
import org.scalajs.dom.HttpMethod
import org.scalajs.dom.RequestInit
import org.scalajs.dom.{Response => FetchResponse}

import java.util.concurrent.TimeoutException
import scala.concurrent.duration._
Expand All @@ -52,7 +51,7 @@ private[dom] object FetchClient {

init.method = req.method.name.asInstanceOf[HttpMethod]
init.headers = new Headers(toDomHeaders(req.headers))
body.foreach { body => init.body = arrayBuffer2BufferSource(body.toJSArrayBuffer) }
body.foreach { body => init.body = body.toJSArrayBuffer }
init.signal = abortController.signal
mergedOptions.cache.foreach(init.cache = _)
mergedOptions.credentials.foreach(init.credentials = _)
Expand Down
10 changes: 5 additions & 5 deletions dom/src/main/scala/org/http4s/dom/FetchClientBuilder.scala
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ import cats.effect.Resource
import org.http4s.client.Client
import org.http4s.client.defaults
import org.http4s.internal.BackendBuilder
import org.scalajs.dom.experimental.ReferrerPolicy
import org.scalajs.dom.experimental.RequestCache
import org.scalajs.dom.experimental.RequestCredentials
import org.scalajs.dom.experimental.RequestMode
import org.scalajs.dom.experimental.RequestRedirect
import org.scalajs.dom.ReferrerPolicy
import org.scalajs.dom.RequestCache
import org.scalajs.dom.RequestCredentials
import org.scalajs.dom.RequestMode
import org.scalajs.dom.RequestRedirect

import scala.concurrent.duration._

Expand Down
2 changes: 1 addition & 1 deletion dom/src/main/scala/org/http4s/dom/FetchEventContext.scala
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import cats.effect.SyncIO
import cats.effect.kernel.Async
import cats.effect.std.Supervisor
import cats.syntax.all._
import org.scalajs.dom.experimental.serviceworkers.FetchEvent
import org.scalajs.dom.FetchEvent
import org.typelevel.vault.Key

final class FetchEventContext[F[_]] private (
Expand Down
10 changes: 5 additions & 5 deletions dom/src/main/scala/org/http4s/dom/FetchOptions.scala
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@
package org.http4s.dom

import cats.effect.SyncIO
import org.scalajs.dom.experimental.ReferrerPolicy
import org.scalajs.dom.experimental.RequestCache
import org.scalajs.dom.experimental.RequestCredentials
import org.scalajs.dom.experimental.RequestMode
import org.scalajs.dom.experimental.RequestRedirect
import org.scalajs.dom.ReferrerPolicy
import org.scalajs.dom.RequestCache
import org.scalajs.dom.RequestCredentials
import org.scalajs.dom.RequestMode
import org.scalajs.dom.RequestRedirect
import org.typelevel.vault

/**
Expand Down
32 changes: 13 additions & 19 deletions dom/src/main/scala/org/http4s/dom/ServiceWorker.scala
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,11 @@ import cats.effect.unsafe.IORuntime
import cats.syntax.all._
import fs2.Chunk
import fs2.Stream
import org.scalajs.dom.crypto._
import org.scalajs.dom.experimental.Body
import org.scalajs.dom.experimental.Fetch
import org.scalajs.dom.experimental.ResponseInit
import org.scalajs.dom.experimental.serviceworkers.FetchEvent
import org.scalajs.dom.experimental.serviceworkers.ServiceWorkerGlobalScope
import org.scalajs.dom.experimental.{Response => DomResponse}
import org.scalajs.dom.Fetch
import org.scalajs.dom.ResponseInit
import org.scalajs.dom.FetchEvent
import org.scalajs.dom.ServiceWorkerGlobalScope
import org.scalajs.dom.{Response => DomResponse}
import org.typelevel.vault.Key

object ServiceWorker {
Expand Down Expand Up @@ -81,25 +79,21 @@ object ServiceWorker {
uri <- OptionF.fromEither(Uri.fromString(req.url))
headers = fromDomHeaders(req.headers)
body = Stream
.evalUnChunk(
// TODO remove cast after next scala-js-dom release
F.fromPromise(F.delay(req.asInstanceOf[Body].arrayBuffer()))
.map(Chunk.jsArrayBuffer))
.evalUnChunk(F.fromPromise(F.delay(req.arrayBuffer())).map(Chunk.jsArrayBuffer))
.covary[F]
request = Request(method, uri, headers = headers, body = body)
.withAttribute(key, FetchEventContext(event, supervisor))
response <- routes(request)
body <- OptionT.liftF(
OptionT(response.body.chunkAll.filter(_.nonEmpty).compile.last).map { chunk =>
arrayBuffer2BufferSource(chunk.toJSArrayBuffer)
}.value)
response.body.chunkAll.filter(_.nonEmpty).map(_.toJSArrayBuffer).compile.last
)
} yield new DomResponse(
body.getOrElse(null),
ResponseInit(
response.status.code,
response.status.reason,
toDomHeaders(response.headers)
)
new ResponseInit {
var status = response.status.code
var statusText = response.status.reason
var headers = toDomHeaders(response.headers)
}
)
}

Expand Down
9 changes: 4 additions & 5 deletions dom/src/main/scala/org/http4s/dom/package.scala
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ import cats.syntax.all._
import fs2.Stream
import org.scalajs.dom.Blob
import org.scalajs.dom.File
import org.scalajs.dom.experimental.ReadableStream
import org.scalajs.dom.experimental.{Headers => DomHeaders}
import org.scalajs.dom.experimental.{Response => DomResponse}
import org.scalajs.dom.ReadableStream
import org.scalajs.dom.{Headers => DomHeaders}
import org.scalajs.dom.{Response => DomResponse}

import scala.scalajs.js
import scala.scalajs.js.JSConverters._
Expand All @@ -39,8 +39,7 @@ package object dom {
EntityEncoder.entityBodyEncoder.contramap { blob =>
Stream
.bracketCase {
// lol, the facade is still broken. next time
F.delay(blob.stream().asInstanceOf[ReadableStream[Uint8Array]])
F.delay(blob.stream())
} { case (rs, exitCase) => closeReadableStream(rs, exitCase) }
.flatMap(fromReadableStream[F])
}
Expand Down
4 changes: 2 additions & 2 deletions tests/src/main/scala/org/http4s/dom/TestServiceWorker.scala
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ package org.http4s.dom

import cats.effect.IO
import cats.effect.unsafe.implicits._
import org.scalajs.dom.experimental.serviceworkers.ExtendableEvent
import org.scalajs.dom.experimental.serviceworkers.ServiceWorkerGlobalScope
import org.scalajs.dom.ExtendableEvent
import org.scalajs.dom.ServiceWorkerGlobalScope

object TestServiceWorker {

Expand Down
3 changes: 1 addition & 2 deletions tests/src/test/scala/org/http4s/dom/DomSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ import org.http4s.client.dsl.io._
import org.http4s.multipart.Multipart
import org.http4s.multipart.Part
import org.http4s.syntax.all._
import org.scalajs.dom.experimental.serviceworkers._
import org.scalajs.dom.raw.Event
import org.scalajs.dom.Event
import org.scalajs.dom.window

import scala.concurrent.duration._
Expand Down

0 comments on commit 306a00d

Please sign in to comment.