-
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.
Introduce Newtype instead of AnyVal (#14)
- Loading branch information
Showing
7 changed files
with
63 additions
and
30 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
5 changes: 0 additions & 5 deletions
5
modules/library/src/main/scala/zio/elasticsearch/DocumentId.scala
This file was deleted.
Oops, something went wrong.
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
5 changes: 0 additions & 5 deletions
5
modules/library/src/main/scala/zio/elasticsearch/IndexName.scala
This file was deleted.
Oops, something went wrong.
3 changes: 0 additions & 3 deletions
3
modules/library/src/main/scala/zio/elasticsearch/Routing.scala
This file was deleted.
Oops, something went wrong.
45 changes: 45 additions & 0 deletions
45
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 |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package zio | ||
|
||
import org.apache.commons.lang3.StringUtils._ | ||
import zio.prelude.Assertion._ | ||
import zio.prelude.AssertionError.failure | ||
import zio.prelude.Newtype | ||
|
||
package object elasticsearch { | ||
object Routing extends Newtype[String] { | ||
override def assertion = assert(!isEmptyString) // scalafix:ok | ||
} | ||
type Routing = Routing.Type | ||
|
||
object DocumentId extends Newtype[String] | ||
type DocumentId = DocumentId.Type | ||
|
||
object IndexName extends Newtype[String] { | ||
override def assertion = assertCustom { (name: String) => // scalafix:ok | ||
if ( | ||
name.toLowerCase != name || | ||
startsWithAny(name, "+", "-", "_") || | ||
containsAny(name, '\\', '/', '*', '?', '"', '/', '<', '>', '|', ' ', ',', '#', ':') || | ||
equalsAny(name, ".", "..") || | ||
name.getBytes().length > 255 | ||
) | ||
Left( | ||
failure( | ||
"""Index names must meet the following criteria: | ||
| - Must be lower case only | ||
| - Cannot include \\, /, *, ?, ", <, >, |, ` `(space character), `,`(comma), #. | ||
| - Cannot include ":"(since 7.0). | ||
| - Cannot start with -, _, +. | ||
| - Cannot be `.` or `..`. | ||
| - Cannot be longer than 255 bytes (note it is bytes, so multi-byte characters will count towards the 255 limit faster). | ||
| - Names starting with . are deprecated, except for hidden indices and internal indices managed by plugins. | ||
|""".stripMargin | ||
) | ||
) | ||
else | ||
Right(()) | ||
} | ||
} | ||
type IndexName = IndexName.Type | ||
|
||
} |