mirror of
https://github.com/TheAnachronism/docspell.git
synced 2025-06-21 18:08:25 +00:00
Serving scalajs artifacts and provide errors to js
This commit is contained in:
@ -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])
|
||||
|
||||
}
|
@ -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)
|
||||
|
||||
}
|
Reference in New Issue
Block a user