scala-js / scala-js-dom

Statically typed DOM API for Scala.js
Other
317 stars 162 forks source link

`crypto` and it's deprecated package #597

Closed japgolly closed 2 years ago

japgolly commented 2 years ago

I'd really love to have dom.crypto be of type js.UndefOr[Crypto]. It seems the impediment is the old deprecated package with the same name.

These are my ideas:

  1. change dom.crypto to be of type js.UndefOr[Crypto with DeprecatedCryptoPackage] so that at least in userland we can use it Crypto -- actually this won't work - deprecated crypto imports wouldn't be stable, not to mention that there's a js.UndefOr there

  2. Building on @sjrd's suggestion we could keep #588 as it but also add a webCrypto: js.UndefOr[Crypto] which we could deprecate in 3.x to be replaced by crypto

  3. just nuke the deprecated package, 2.0 is a new world

Any more ideas? I'm kinda happy with 3, but 2 would definitely be acceptable.

armanbilge commented 2 years ago

It's a bit ugly, but what if we add an implicit conversion to Crypto that brings in all the deprecated aliases? So that dom.crypto can still be used as if it is the old package. Would this work?

japgolly commented 2 years ago

I don't think so. Cos source-compat is the concern the direct import statements would stop working. Plus maybe it wouldn't be worth it if the cost is an implicit anyway :)

armanbilge commented 2 years ago

Right, imports 😕

Regarding your idea 2, we already have a deprecated GlobalCrypto object or similar that could be used like that I think. Otherwise I'm 👍 with it, I think I suggested something similar as well.

japgolly commented 2 years ago

Oh another idea, we could add

object Crypto {
  def ifAvailable: js.UndefOr[Cypto]
}

It would be the same as option 2 above except instead of webCrypto it would be Crypto.ifAvailable. More of a 2b

japgolly commented 2 years ago

GlobalCrypto has the wrong type for crypto and it's deprecated anyway.

Regarding your idea 2, we already have a deprecated GlobalCrypto object or similar that could be used like that I think. Otherwise I'm +1 with it, I think I suggested something similar as well.

Nice, so we'll go with a 2x option? Do you have a preference between webCrypto or Crypto.ifAvailable or something else?

armanbilge commented 2 years ago

IMO dom.webCrypto is best since it's very close to our eventual target of dom.crypto.

japgolly commented 2 years ago

ok np, I'll do PR that after #588 is in :+1: