Serving scalajs artifacts and provide errors to js

This commit is contained in:
Eike Kettner
2021-03-02 00:51:13 +01:00
parent 71985244f1
commit d4006461f6
25 changed files with 45 additions and 9 deletions

View File

@ -0,0 +1,29 @@
package docspell.query.js
import scala.scalajs.js
import scala.scalajs.js.annotation._
import docspell.query.ItemQueryParser
@JSExportTopLevel("DsItemQueryParser")
object JSItemQueryParser {
@JSExport
def parseToFailure(input: String): Failure =
ItemQueryParser
.parse(input)
.swap
.toOption
.map(fr =>
new Failure(
fr.input,
fr.failedAt,
js.Array(fr.messages.toList.toSeq.map(_.msg): _*)
)
)
.orNull
@JSExportAll
case class Failure(input: String, failedAt: Int, messages: js.Array[String])
}

View File

@ -1,14 +1,10 @@
package docspell.query
import scala.scalajs.js.annotation._
import docspell.query.internal.ExprParser
import docspell.query.internal.ExprUtil
@JSExportTopLevel("DsItemQueryParser")
object ItemQueryParser {
@JSExport
def parse(input: String): Either[ParseFailure, ItemQuery] =
if (input.isEmpty) Right(ItemQuery.all)
else {
@ -22,5 +18,4 @@ object ItemQueryParser {
def parseUnsafe(input: String): ItemQuery =
parse(input).fold(m => sys.error(m.render), identity)
}