-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
No longer automatically rewrite types to
js.Promise
and `js.Thenabl…
…e`. Instead provide `toPromise` and `toFuture` operations implicitly. It's just too complicated and it currently breaks a bunch of libs. This fixes #404, see that for some details
- Loading branch information
1 parent
3598592
commit f514ce0
Showing
43 changed files
with
579 additions
and
203 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
122 changes: 122 additions & 0 deletions
122
.../src/main/scala/org/scalablytyped/converter/internal/scalajs/flavours/GenPromiseOps.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
package org.scalablytyped.converter.internal | ||
package scalajs | ||
package flavours | ||
|
||
object GenPromiseOps extends TreeTransformation { | ||
override def leaveContainerTree(scope: TreeScope)(s: ContainerTree): ContainerTree = | ||
if (scope.libName == Name.std && s.name == Name.std) { | ||
val newCompanions = IArray | ||
.fromOptions( | ||
flaff(s, Name("Promise")), | ||
flaff(s, Name("PromiseLike")), | ||
) | ||
.toMap | ||
|
||
val filteredMembers = s.members.filter { | ||
case x: ModuleTree if newCompanions.contains(x.name) => false | ||
case _ => true | ||
} | ||
s.withMembers(filteredMembers ++ IArray.fromTraversable(newCompanions.values)) | ||
} else s | ||
|
||
def flaff(s: ContainerTree, name: Name): Option[(Name, ModuleTree)] = { | ||
val (existingClass, existingModule, _) = s.index | ||
.getOrElse(name, IArray.Empty) | ||
.partitionCollect2({ case x: ClassTree => x }, { case x: ModuleTree => x }) | ||
|
||
existingClass match { | ||
case IArray.first(cls) => | ||
val mod = existingModule.headOption.getOrElse( | ||
ModuleTree( | ||
Empty, | ||
level = ProtectionLevel.Public, | ||
name = cls.name, | ||
parents = Empty, | ||
members = Empty, | ||
comments = NoComments, | ||
codePath = cls.codePath, | ||
isOverride = false, | ||
), | ||
) | ||
val ops = genPromiseOps(cls, mod) | ||
val mod1 = mod.copy(members = mod.members :+ ops) | ||
Some((name, mod1)) | ||
case _ => None | ||
} | ||
} | ||
|
||
def genPromiseOps(cls: ClassTree, mod: ModuleTree) = { | ||
val paramName = Name("promise") | ||
val Ops = Name(cls.name.unescaped + "Ops") | ||
val OpsCP = mod.codePath + Ops | ||
|
||
val toPromise = { | ||
val name = Name("toPromise") | ||
val tpe = TypeRef(QualifiedName.JsPromise, TypeParamTree.asTypeArgs(cls.tparams), NoComments) | ||
MethodTree( | ||
annotations = Empty, | ||
level = ProtectionLevel.Public, | ||
name = name, | ||
tparams = Empty, | ||
params = Empty, | ||
impl = ExprTree.Cast(ExprTree.Ref(paramName), tpe), | ||
resultType = tpe, | ||
isOverride = false, | ||
comments = NoComments, | ||
codePath = OpsCP + name, | ||
isImplicit = false, | ||
) | ||
} | ||
|
||
val toFuture = { | ||
val name = Name("toFuture") | ||
val tpe = TypeRef( | ||
QualifiedName(IArray(Name.scala, Name("concurrent"), Name("Future"))), | ||
TypeParamTree.asTypeArgs(cls.tparams), | ||
NoComments, | ||
) | ||
MethodTree( | ||
annotations = Empty, | ||
level = ProtectionLevel.Public, | ||
name = name, | ||
tparams = Empty, | ||
params = Empty, | ||
impl = ExprTree.Select(ExprTree.Ref(toPromise.name), Name("toFuture")), | ||
resultType = tpe, | ||
isOverride = false, | ||
comments = NoComments, | ||
codePath = OpsCP + name, | ||
isImplicit = false, | ||
) | ||
} | ||
ClassTree( | ||
isImplicit = true, | ||
annotations = IArray(Annotation.Inline), | ||
level = ProtectionLevel.Public, | ||
name = Ops, | ||
tparams = cls.tparams, | ||
parents = IArray(TypeRef.AnyVal), | ||
ctors = IArray( | ||
CtorTree( | ||
ProtectionLevel.Public, | ||
IArray( | ||
ParamTree( | ||
name = paramName, | ||
isImplicit = false, | ||
isVal = true, | ||
tpe = TypeRef(cls.codePath, TypeParamTree.asTypeArgs(cls.tparams), NoComments), | ||
default = NotImplemented, | ||
comments = NoComments, | ||
), | ||
), | ||
NoComments, | ||
), | ||
), | ||
members = IArray(toPromise, toFuture), | ||
classType = ClassType.Class, | ||
isSealed = false, | ||
comments = NoComments, | ||
codePath = OpsCP, | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,11 @@ | ||
organization := "org.scalablytyped" | ||
name := "elasticsearch-js" | ||
version := "0.0-unknown-e3106b" | ||
version := "0.0-unknown-d0fe82" | ||
scalaVersion := "3.1.2" | ||
enablePlugins(ScalaJSPlugin) | ||
libraryDependencies ++= Seq( | ||
"com.olvind" %%% "scalablytyped-runtime" % "2.4.2", | ||
"org.scalablytyped" %%% "std" % "0.0-unknown-befc3c") | ||
"org.scalablytyped" %%% "std" % "0.0-unknown-184a14") | ||
publishArtifact in packageDoc := false | ||
scalacOptions ++= List("-encoding", "utf-8", "-feature", "-language:implicitConversions", "-language:higherKinds", "-language:existentials", "-no-indent", "-source:future") | ||
licenses += ("MIT", url("http://opensource.org/licenses/MIT")) |
15 changes: 5 additions & 10 deletions
15
...sticsearch-js/check-3/e/elasticsearch-js/src/main/scala/typings/elasticsearchJs/mod.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
tests/elasticsearch-js/check-3/s/std/src/main/scala/typings/std/Promise.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,17 @@ | ||
package typings.std | ||
|
||
import scala.concurrent.Future | ||
import org.scalablytyped.runtime.StObject | ||
import scala.scalajs.js | ||
import scala.scalajs.js.annotation.{JSGlobalScope, JSGlobal, JSImport, JSName, JSBracketAccess} | ||
|
||
trait Promise[T] extends StObject | ||
object Promise { | ||
|
||
extension [T](promise: Promise[T]) { | ||
|
||
def toFuture: Future[T] = toPromise.toFuture | ||
|
||
def toPromise: js.Promise[T] = promise.asInstanceOf[js.Promise[T]] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
organization := "org.scalablytyped" | ||
name := "prisma" | ||
version := "0.0-unknown-7a849c" | ||
scalaVersion := "3.1.2" | ||
enablePlugins(ScalaJSPlugin) | ||
libraryDependencies ++= Seq( | ||
"com.olvind" %%% "scalablytyped-runtime" % "2.4.2", | ||
"org.scalablytyped" %%% "std" % "0.0-unknown-ba7c78") | ||
publishArtifact in packageDoc := false | ||
scalacOptions ++= List("-encoding", "utf-8", "-feature", "-language:implicitConversions", "-language:higherKinds", "-language:existentials", "-no-indent", "-source:future") | ||
licenses += ("MIT", url("http://opensource.org/licenses/MIT")) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
sbt.version=1.7.1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
addSbtPlugin("org.scala-js" %% "sbt-scalajs" % "1.10.0") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
|
||
# Scala.js typings for prisma | ||
|
||
|
||
|
||
|
||
## Note | ||
This library has been generated from typescript code from first party type definitions. | ||
|
||
Provided with :purple_heart: from [ScalablyTyped](https://github.com/oyvindberg/ScalablyTyped) | ||
|
||
## Usage | ||
See [the main readme](../../readme.md) for instructions. | ||
|
||
|
41 changes: 41 additions & 0 deletions
41
tests/prisma/check-3/p/prisma/src/main/scala/typings/prisma/mod.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package typings.prisma | ||
|
||
import typings.prisma.prismaStrings.PrismaClientPromise | ||
import typings.std.Promise | ||
import typings.std.PromiseLike | ||
import org.scalablytyped.runtime.StObject | ||
import scala.scalajs.js | ||
import scala.scalajs.js.annotation.{JSGlobalScope, JSGlobal, JSImport, JSName, JSBracketAccess} | ||
|
||
object mod { | ||
|
||
@JSImport("prisma", "Prisma__ColumnClient") | ||
@js.native | ||
open class PrismaColumnClient[T] () | ||
extends StObject | ||
with PrismaPromise[T] { | ||
|
||
def `catch`[TResult](): js.Promise[T | TResult] = js.native | ||
def `catch`[TResult](onrejected: js.Function1[/* reason */ Any, TResult | PromiseLike[TResult]]): js.Promise[T | TResult] = js.native | ||
|
||
def `finally`(): js.Promise[T] = js.native | ||
def `finally`(onfinally: js.Function0[Unit]): js.Promise[T] = js.native | ||
|
||
def `then`[TResult1, TResult2](): js.Promise[TResult1 | TResult2] = js.native | ||
def `then`[TResult1, TResult2](onfulfilled: js.Function1[/* value */ T, TResult1 | PromiseLike[TResult1]]): js.Promise[TResult1 | TResult2] = js.native | ||
def `then`[TResult1, TResult2]( | ||
onfulfilled: js.Function1[/* value */ T, TResult1 | PromiseLike[TResult1]], | ||
onrejected: js.Function1[/* reason */ Any, TResult2 | PromiseLike[TResult2]] | ||
): js.Promise[TResult1 | TResult2] = js.native | ||
def `then`[TResult1, TResult2](onfulfilled: Null, onrejected: js.Function1[/* reason */ Any, TResult2 | PromiseLike[TResult2]]): js.Promise[TResult1 | TResult2] = js.native | ||
def `then`[TResult1, TResult2](onfulfilled: Unit, onrejected: js.Function1[/* reason */ Any, TResult2 | PromiseLike[TResult2]]): js.Promise[TResult1 | TResult2] = js.native | ||
|
||
@JSName(js.Symbol.toStringTag) | ||
val toStringTag: PrismaClientPromise = js.native | ||
} | ||
|
||
@js.native | ||
trait PrismaPromise[A] | ||
extends StObject | ||
with Promise[A] | ||
} |
11 changes: 11 additions & 0 deletions
11
tests/prisma/check-3/p/prisma/src/main/scala/typings/prisma/prismaRequire.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package typings.prisma | ||
|
||
import org.scalablytyped.runtime.StObject | ||
import scala.scalajs.js | ||
import scala.scalajs.js.annotation.{JSGlobalScope, JSGlobal, JSImport, JSName, JSBracketAccess} | ||
|
||
/* This can be used to `require` the library as a side effect. | ||
If it is a global library this will make scalajs-bundler include it */ | ||
@JSImport("prisma", JSImport.Namespace) | ||
@js.native | ||
object prismaRequire extends StObject |
12 changes: 12 additions & 0 deletions
12
tests/prisma/check-3/p/prisma/src/main/scala/typings/prisma/prismaStrings.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package typings.prisma | ||
|
||
import org.scalablytyped.runtime.StObject | ||
import scala.scalajs.js | ||
import scala.scalajs.js.annotation.{JSGlobalScope, JSGlobal, JSImport, JSName, JSBracketAccess} | ||
|
||
object prismaStrings { | ||
|
||
@js.native | ||
sealed trait PrismaClientPromise extends StObject | ||
inline def PrismaClientPromise: PrismaClientPromise = "PrismaClientPromise".asInstanceOf[PrismaClientPromise] | ||
} |
Oops, something went wrong.