This repository has been archived by the owner on Jun 3, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Fixes problem where sending data in a POST or PUT request would cause a serialization error. Plus: makes the deserialziation of action properties better by using AnyServerDrivenData. * better error handling * self review * Makes nimbus core aware of NSNull + correctly handles potential errors on operations * self review
- Loading branch information
1 parent
8e6a50e
commit 62231af
Showing
13 changed files
with
178 additions
and
44 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
24 changes: 17 additions & 7 deletions
24
src/commonMain/kotlin/com/zup/nimbus/core/ui/operations/array.kt
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
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
33 changes: 23 additions & 10 deletions
33
src/commonMain/kotlin/com/zup/nimbus/core/ui/operations/string.kt
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,37 +1,50 @@ | ||
package com.zup.nimbus.core.ui.operations | ||
|
||
import com.zup.nimbus.core.deserialization.AnyServerDrivenData | ||
import com.zup.nimbus.core.ui.UILibrary | ||
import com.zup.nimbus.core.regex.replace | ||
import com.zup.nimbus.core.regex.matches | ||
import com.zup.nimbus.core.regex.toFastRegex | ||
|
||
private fun toStringList(values: List<Any?>): List<String> { | ||
return values.filterIsInstance<String>() | ||
private fun getSingleArgument(argumentList: List<Any?>): String { | ||
val arguments = AnyServerDrivenData(argumentList) | ||
val str = arguments.at(0).asString() | ||
if (arguments.hasError()) throw IllegalArgumentException(arguments.errorsAsString()) | ||
return str | ||
} | ||
|
||
internal fun registerStringOperations(library: UILibrary) { | ||
library | ||
.addOperation("capitalize"){ | ||
(it[0] as String).replaceFirstChar { char -> char.uppercaseChar() } | ||
getSingleArgument(it).replaceFirstChar { char -> char.uppercaseChar() } | ||
} | ||
.addOperation("lowercase"){ | ||
(it[0] as String).lowercase() | ||
getSingleArgument(it).lowercase() | ||
} | ||
.addOperation("uppercase"){ | ||
(it[0] as String).uppercase() | ||
getSingleArgument(it).uppercase() | ||
} | ||
.addOperation("match"){ | ||
val (value, regex) = toStringList(it) | ||
val arguments = AnyServerDrivenData(it) | ||
val value = arguments.at(0).asString() | ||
val regex = arguments.at(1).asString() | ||
if (arguments.hasError()) throw IllegalArgumentException(arguments.errorsAsString()) | ||
value.matches(regex.toFastRegex()) | ||
} | ||
.addOperation("replace"){ | ||
val (value, regex, replace) = toStringList(it) | ||
val arguments = AnyServerDrivenData(it) | ||
val value = arguments.at(0).asString() | ||
val regex = arguments.at(1).asString() | ||
val replace = arguments.at(2).asString() | ||
if (arguments.hasError()) throw IllegalArgumentException(arguments.errorsAsString()) | ||
value.replace(regex.toFastRegex(), replace) | ||
} | ||
.addOperation("substr"){ | ||
val value = it[0] as String | ||
val start = it[1] as Int | ||
val end = it.getOrNull(2) as Int? | ||
val arguments = AnyServerDrivenData(it) | ||
val value = arguments.at(0).asString() | ||
val start = arguments.at(1).asInt() | ||
val end = arguments.at(2).asIntOrNull() | ||
if (arguments.hasError()) throw IllegalArgumentException(arguments.errorsAsString()) | ||
if (end == null) value.substring(start) else value.substring(start, end) | ||
} | ||
} |
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,16 @@ | ||
package com.zup.nimbus.core.utils | ||
|
||
expect object Null { | ||
/** | ||
* Verifies if the value is null considering all the null values of the platform. | ||
* | ||
* Example: NSNull on iOS. | ||
*/ | ||
fun isNull(value: Any?): Boolean | ||
|
||
/** | ||
* If the value passed as parameter corresponds to null in the current platform, this function returns the Kotlin | ||
* Null (`null`). Otherwise, it returns the value. | ||
*/ | ||
fun <T>sanitize(value: T): T? | ||
} |
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
Oops, something went wrong.