A small collection of custom scalars for EdgeDB, ensuring valid values going into the database.
Last active
April 1, 2023 03:06
-
-
Save tdolsen/cac959ae70e91c841ae8d24ec4129360 to your computer and use it in GitHub Desktop.
EdgeDB custom scalars
This file contains hidden or 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
scalar type bcrypt_hash_str extending str { | |
annotation description := "A valid bcrypt hash string."; | |
constraint regexp(r"^\$2[ayb]?\$[0-9]{2}\$.{53}$"); | |
} |
This file contains hidden or 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
scalar type email_str extending str { | |
annotation description := "Valid email address according to the W3C specification for input[type=email]."; | |
constraint regexp(r"^[a-zA-Z0-9.!#$%&'*+\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$"); | |
} |
This file contains hidden or 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
scalar type locale_str extending str { | |
annotation description := "Locale identifier string, formatted as xx_YY. (xx = country, YY = dialect)"; | |
constraint regexp(r"^[a-z]{2}_[A-Z]{2}$"); | |
} |
This file contains hidden or 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
scalar type phone_number_str extending str { | |
annotation description := "String representing a phone number, formatted according to E.164."; | |
constraint regexp(r"^\+?[1-9]\d{1,14}$"); | |
} |
This file contains hidden or 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
scalar type trimmed_str extending str { | |
annotation description := "A string with no leading or trailing whitespace."; | |
constraint expression on ( __subject__ = str_trim(__subject__) ); | |
} |
This file contains hidden or 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
scalar type uuid_str extending str { | |
annotation description := "A valid UUID string."; | |
constraint regexp(r"^[0-9a-fA-F]{8}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{12}$"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment