-
Notifications
You must be signed in to change notification settings - Fork 17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Introduce Newtype instead of AnyVal #14
Changes from all commits
b8e45ec
5122cc7
8d94cb3
3b70d55
ffc6b9f
63c38c3
3d190fe
755a1a6
e0bffd4
0bda4bc
b62728f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
This file was deleted.
This file was deleted.
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(()) | ||
} | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does it make sense to add a new line? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes. |
||
type IndexName = IndexName.Type | ||
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I prefer sorting those by alphabet. So, you can order all of those that way.