Skip to content
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

✨ New EmailAddress type in org.kotools.types package #635

Closed
16 tasks done
LVMVRQUXL opened this issue Mar 31, 2024 · 3 comments
Closed
16 tasks done

✨ New EmailAddress type in org.kotools.types package #635

LVMVRQUXL opened this issue Mar 31, 2024 · 3 comments
Assignees
Labels
common Item related to all platforms. feature New feature or request.
Milestone

Comments

@LVMVRQUXL
Copy link
Contributor

LVMVRQUXL commented Mar 31, 2024

📝 Description

We want to introduce an EmailAddress experimental type, in the org.kotools.types package of the types Gradle subproject, with an improved API for deprecating the same type from the kotools.types.web package.

interface EmailAddress {
    override fun equals(other: Any?): Boolean
    override fun hashCode(): Int
    override fun toString(): String
    
    companion object {
        const val PATTERN: String

        fun fromString(value: Any): EmailAddress
        fun fromString(value: Any, pattern: Any): EmailAddress

        fun fromStringOrNull(value: Any): EmailAddress?
        fun fromStringOrNull(value: Any, pattern: Any): EmailAddress?
    }
}

Like the type from the kotools.types.web package, this new one should be serializable as String.
Finally, we want to deprecate the type from the kotools.types.web with a warning level, and its factory functions with an error level and replacement suggestions, for removal in v4.7.

✅ Checklist

  • ✨ Add the type in the org.kotools.types package and dump the Application Binary Interface (ABI).
  • ✨ Add the PATTERN constant, test this constant, add Kotlin and Java code samples for this constant, and dump the ABI.
  • ✨ Add the fromStringOrNull(Any) function with tests, code samples for Kotlin and Java, reference it in the type's documentation and dump the ABI.
  • ✨ Add the fromString(Any) function with tests, code samples for Kotlin and Java, reference it in the type's documentation and dump the ABI.
  • ✨ Add the fromStringOrNull(Any, Any) function with tests, code samples for Kotlin and Java, and dump the ABI.
  • ✨ Add the fromString(Any, Any) function with tests, code samples for Kotlin and Java, and dump the ABI.
  • ✨ Add the toString function with tests, code samples for Kotlin and Java, and dump the ABI.
  • ✨ Add structural equality operations (equals and hashCode) with tests, code samples for Kotlin and Java, and dump the ABI.
  • ✨ Make the type serializable as String with tests, Kotlin code sample and dump the ABI.
  • 🗑️ Deprecate the EmailAddress type from the kotools.types.web package with a warning level, and its factory functions with an error level and replacement suggestions, for removal in v4.7. This is a source incompatible change.
  • 📝 Add an entry for this issue in the unreleased changelog.
  • 🔥 Remove outdated entries from the unreleased changelog.
  • 📝 Create an issue for removing the EmailAddress type from the kotools.types.web package in v4.7.
  • ✨ Add the KotoolsTypesSerializers.emailAddress property for serializing this type as String, with documentation, tests, samples, then dump the corresponding ABI.
  • 🔥 Remove the @Serializable annotation from this type, its serialization tests and documentation, then dump the ABI.
  • ✨ Include the KotoolsTypesSerializers.emailAddress module in the KotoolsTypesSerializers.all one with tests.
@LVMVRQUXL LVMVRQUXL added feature New feature or request. common Item related to all platforms. labels Mar 31, 2024
@LVMVRQUXL LVMVRQUXL added this to the 4.6.0 milestone Mar 31, 2024
@LVMVRQUXL LVMVRQUXL self-assigned this Mar 31, 2024
LVMVRQUXL added a commit that referenced this issue Mar 31, 2024
Adds the constant property with tests, tested Kotlin and Java code samples, and dumps the Application Binary Interface (ABI).
LVMVRQUXL added a commit that referenced this issue Mar 31, 2024
Adds this function to the type in the `org.kotools.types` package, with tests, tested Kotlin and Java code samples, and documentation.
Also dumps the Application Binary Interface (ABI).
LVMVRQUXL added a commit that referenced this issue Mar 31, 2024
Updates code samples tests of this function.
LVMVRQUXL added a commit that referenced this issue Mar 31, 2024
Adds this function in the `org.kotools.types` package with tests, tested code samples for Kotlin and Java, and documentation.
Also dumps the Application Binary Interface (ABI).
@LVMVRQUXL LVMVRQUXL assigned LVMVRQUXL and unassigned LVMVRQUXL Mar 31, 2024
LVMVRQUXL added a commit that referenced this issue Apr 1, 2024
Adds the `equals(Any?)` and the `hashCode()` functions to the `EmailAddress` type in the `org.kotools.types` package.
@LVMVRQUXL

This comment was marked as resolved.

@LVMVRQUXL LVMVRQUXL reopened this Apr 4, 2024
@LVMVRQUXL LVMVRQUXL assigned LVMVRQUXL and unassigned LVMVRQUXL Apr 13, 2024
LVMVRQUXL added a commit that referenced this issue Apr 17, 2024
Adds module for serializing the `EmailAddress` type.
LVMVRQUXL added a commit that referenced this issue Apr 17, 2024
Consumers should use the `KotoolsTypesSerializers` type instead for serializing the `org.kotools.types.EmailAddress` type.
LVMVRQUXL added a commit that referenced this issue Apr 17, 2024
Includes the serializer of `org.kotools.types.EmailAddress` in this serializers module.
LVMVRQUXL added a commit that referenced this issue Apr 17, 2024
Moves these errors to the `types-internal` Gradle subproject and suffixes their name with `Error`.
Also introduces an `Error` interface in the same subproject for conventioning the Application Programming Interface (API) of errors.
LVMVRQUXL added a commit that referenced this issue Apr 17, 2024
This function now uses the `hashCodeOf(Any, vararg Any)` function from the `types-internal` Gradle subproject.
This commit also removes the `hashCodeOf` function from the `types` subproject.
@LVMVRQUXL
Copy link
Contributor Author

A better design for creating instances of the EmailAddress type is to provide constructors that should throw exceptions in case of invalid arguments, and orNull factory functions that should return null in case of invalid arguments.
Also, arguments should be of type String instead of Any for avoiding confusions.

fun EmailAddress(value: String): EmailAddress
fun EmailAddress(value: String, pattern: String): EmailAddress

fun EmailAddress.Companion.orNull(value: String): EmailAddress?
fun EmailAddress.Companion.orNull(value: String, pattern: String): EmailAddress?

Here are some examples for calling these functions from Kotlin code:

EmailAddress("[email protected]")
EmailAddress(" @kotools.org") // throws an exception

EmailAddress(value = "[email protected]", pattern = "^[a-z]+@[a-z]+\\.[a-z]+\$")
EmailAddress(value = " @kotools.org", pattern = "^[a-z]+@[a-z]+\\.[a-z]+\$") // throws an exception
EmailAddress(value = "[email protected]", pattern = "^[a-z]+\$") // throws an exception

EmailAddress.orNull("[email protected]")
EmailAddress.orNull(" @kotools.org") // returns null

EmailAddress.orNull(value = "[email protected]", pattern = "^[a-z]+@[a-z]+\\.[a-z]+\$")
EmailAddress.orNull(value = " @kotools.org", pattern = "^[a-z]+@[a-z]+\\.[a-z]+\$") // returns null
EmailAddress.orNull(value = "[email protected]", pattern = "^[a-z]+\$") // returns null

Finally, the EmailAddress(String) function should be the primary constructor.

@LVMVRQUXL
Copy link
Contributor Author

It is not possible to define another constructor without directly calling the primary one, including the check of the value against the default pattern, which is not the intended behavior when calling the factory function of EmailAddress with a custom pattern. So we will go back to the original factory functions.

LVMVRQUXL added a commit that referenced this issue Apr 18, 2024
LVMVRQUXL added a commit that referenced this issue Apr 18, 2024
Replaces `runCatching` function by `try catch` blocks in these samples.

Ref: #635
@LVMVRQUXL LVMVRQUXL reopened this Apr 20, 2024
LVMVRQUXL added a commit that referenced this issue Apr 22, 2024
Updates the message of the exception thrown when deserializing an `EmailAddress` from a value fails.

Ref: #635
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
common Item related to all platforms. feature New feature or request.
Projects
None yet
Development

No branches or pull requests

1 participant