-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
40 additions
and
11 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
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
38 changes: 33 additions & 5 deletions
38
modules/library/src/main/scala/zio/elasticsearch/package.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,20 +1,48 @@ | ||
package zio | ||
|
||
import zio.prelude.Assertion._ | ||
import zio.prelude.{Newtype, Subtype} | ||
import zio.prelude.{AssertionError, Newtype} | ||
import zio.prelude.QuotedAssertion | ||
|
||
package object elasticsearch { | ||
object Routing extends Subtype[String] { | ||
override def assertion = assert { | ||
object Routing extends Newtype[String] { | ||
override def assertion: QuotedAssertion[String] = assert { | ||
!isEmptyString | ||
} | ||
} | ||
type Routing = Routing.Type | ||
|
||
object DocumentId extends Newtype[String] | ||
object DocumentId extends Newtype[String] {} | ||
type DocumentId = DocumentId.Type | ||
|
||
object IndexName extends Newtype[String] | ||
object IndexName extends Newtype[String] { | ||
override def assertion: QuotedAssertion[String] = assertCustom { (x: String) => | ||
if (x.toLowerCase != x) Left(AssertionError.Failure("IndexName must be lower case only.")) | ||
else if (x.startsWith("-") || x.startsWith("+") || x.startsWith("_")) | ||
Left(AssertionError.Failure("IndexName cannot start with -, _, +.")) | ||
else if (x.exists(char => raw"""\/*?"<>|,#""".contains(char)) || x.contains(' ')) | ||
Left( | ||
AssertionError.Failure( | ||
"IndexName cannot include \\, /, *, ?, \", <, >, |, ` ` (space character), ,(comma), #" | ||
) | ||
) | ||
else if (x.contains(':')) | ||
Left(AssertionError.Failure("""IndexName cannot include ":"(since 7.0).""")) | ||
else if (x == "." || x == "..") | ||
Left(AssertionError.Failure("""IndexName cannot be . or ..""")) | ||
else if (x.getBytes().length > 255) | ||
Left( | ||
AssertionError.Failure( | ||
"""IndexName cannot be longer than 255 bytes (note it is bytes, so multi-byte characters will count towards the 255 limit faster)""" | ||
) | ||
) | ||
else if (x.startsWith(".")) { | ||
// todo: Warning should be that IndexNames starting with . are deprecated? | ||
Right(()) | ||
} else | ||
Right(()) | ||
} | ||
} | ||
type IndexName = IndexName.Type | ||
|
||
} |