Skip to content

Commit

Permalink
DOPE-239: implement pr feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
jansigi committed Jan 24, 2025
1 parent a5ee465 commit a3b24dc
Show file tree
Hide file tree
Showing 8 changed files with 97 additions and 81 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,28 +23,28 @@ class UpdateIntegrationTest : BaseIntegrationTest() {

@Test
fun `update to set and unset single attribute`() {
val newField = Field<StringType>("newField", testBucket.name)
val newFieldName = Field<StringType>("newFieldName", testBucket.name)
val dopeQuery = QueryBuilder()
.update(
testBucket.useKeys("client:1"),
)
.set(
newField,
newFieldName,
"newName",
)
.unset(
nameField,
)
.returning(
newField,
newFieldName,
nameField,
).build()

tryUntil {
val queryResult = queryWithoutParameters(dopeQuery)
val result = queryResult.toMapValues()

assertEquals("newName", result["newField"])
assertEquals("newName", result["newFieldName"])
assertNull(result["nameField"])
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ class ObjectPrimitive(
)

class ObjectEntryPrimitive<T : ValidType>(
private val key: TypeExpression<StringType>,
private val value: TypeExpression<T>,
val key: TypeExpression<StringType>,
val value: TypeExpression<T>,
) : Resolvable {
override fun toDopeQuery(manager: DopeQueryManager): DopeQuery {
val keyQuery = key.toDopeQuery(manager)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,24 @@
package ch.ergon.dope.resolvable.expression.unaliased.type.function.`object`

import ch.ergon.dope.resolvable.expression.TypeExpression
import ch.ergon.dope.resolvable.expression.unaliased.type.ObjectEntryPrimitive
import ch.ergon.dope.resolvable.expression.unaliased.type.function.FunctionExpression
import ch.ergon.dope.resolvable.expression.unaliased.type.toDopeType
import ch.ergon.dope.resolvable.expression.unaliased.type.toObjectEntry
import ch.ergon.dope.validtype.ObjectType
import ch.ergon.dope.validtype.StringType
import ch.ergon.dope.validtype.ValidType

class ObjectAddExpression(
objectExpression: TypeExpression<ObjectType>,
newAttributeKey: TypeExpression<StringType>,
newAttributeValue: TypeExpression<out ValidType>,
) : FunctionExpression<ObjectType>("OBJECT_ADD", objectExpression, newAttributeKey, newAttributeValue)
objectEntryPrimitive: ObjectEntryPrimitive<out ValidType>,
) : FunctionExpression<ObjectType>("OBJECT_ADD", objectExpression, objectEntryPrimitive.key, objectEntryPrimitive.value)

fun TypeExpression<ObjectType>.addAttribute(objectEntryPrimitive: ObjectEntryPrimitive<out ValidType>) =
ObjectAddExpression(this, objectEntryPrimitive)

fun TypeExpression<ObjectType>.addAttribute(key: TypeExpression<StringType>, value: TypeExpression<out ValidType>) =
ObjectAddExpression(this, key, value)
addAttribute(key.toObjectEntry(value))

fun TypeExpression<ObjectType>.addAttribute(key: String, value: TypeExpression<out ValidType>) = addAttribute(key.toDopeType(), value)
fun TypeExpression<ObjectType>.addAttribute(key: String, value: TypeExpression<out ValidType>) =
addAttribute(key.toDopeType(), value)
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,26 @@ import ch.ergon.dope.validtype.StringType

class ObjectRenameExpression(
objectExpression: TypeExpression<ObjectType>,
oldField: TypeExpression<StringType>,
newField: TypeExpression<StringType>,
) : FunctionExpression<ObjectType>("OBJECT_RENAME", objectExpression, oldField, newField)
oldFieldName: TypeExpression<StringType>,
newFieldName: TypeExpression<StringType>,
) : FunctionExpression<ObjectType>("OBJECT_RENAME", objectExpression, oldFieldName, newFieldName)

fun TypeExpression<ObjectType>.renameAttribute(
oldField: TypeExpression<StringType>,
newField: TypeExpression<StringType>,
) = ObjectRenameExpression(this, oldField, newField)
oldFieldName: TypeExpression<StringType>,
newFieldName: TypeExpression<StringType>,
) = ObjectRenameExpression(this, oldFieldName, newFieldName)

fun TypeExpression<ObjectType>.renameAttribute(
oldField: String,
newField: String,
) = renameAttribute(oldField.toDopeType(), newField.toDopeType())
oldFieldName: String,
newFieldName: String,
) = renameAttribute(oldFieldName.toDopeType(), newFieldName.toDopeType())

fun TypeExpression<ObjectType>.renameAttribute(
oldField: TypeExpression<StringType>,
newField: String,
) = renameAttribute(oldField, newField.toDopeType())
oldFieldName: TypeExpression<StringType>,
newFieldName: String,
) = renameAttribute(oldFieldName, newFieldName.toDopeType())

fun TypeExpression<ObjectType>.renameAttribute(
oldField: String,
newField: TypeExpression<StringType>,
) = renameAttribute(oldField.toDopeType(), newField)
oldFieldName: String,
newFieldName: TypeExpression<StringType>,
) = renameAttribute(oldFieldName.toDopeType(), newFieldName)
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import ch.ergon.dope.resolvable.expression.TypeExpression
import ch.ergon.dope.resolvable.expression.unaliased.type.function.FunctionExpression
import ch.ergon.dope.validtype.ArrayType
import ch.ergon.dope.validtype.ObjectType
import ch.ergon.dope.validtype.StringType
import ch.ergon.dope.validtype.ValidType

class ObjectValuesExpression(
objectExpression: TypeExpression<ObjectType>,
) : FunctionExpression<ArrayType<StringType>>("OBJECT_VALUES", objectExpression)
) : FunctionExpression<ArrayType<out ValidType>>("OBJECT_VALUES", objectExpression)

fun TypeExpression<ObjectType>.values() = ObjectValuesExpression(this)
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import ch.ergon.dope.DopeQuery
import ch.ergon.dope.DopeQueryManager
import ch.ergon.dope.helper.ManagerDependentTest
import ch.ergon.dope.helper.someObjectField
import ch.ergon.dope.resolvable.expression.unaliased.type.ObjectEntryPrimitive
import ch.ergon.dope.resolvable.expression.unaliased.type.toDopeType
import kotlin.test.Test
import kotlin.test.assertEquals
Expand All @@ -16,7 +17,7 @@ class ObjectAddExpressionTest : ManagerDependentTest {
val expected = DopeQuery(
queryString = "OBJECT_ADD(`objectField`, \"key\", \"value\")",
)
val underTest = ObjectAddExpression(someObjectField(), "key".toDopeType(), "value".toDopeType())
val underTest = ObjectAddExpression(someObjectField(), ObjectEntryPrimitive("key".toDopeType(), "value".toDopeType()))

val actual = underTest.toDopeQuery(manager)

Expand All @@ -28,7 +29,7 @@ class ObjectAddExpressionTest : ManagerDependentTest {
val objectExpression = someObjectField()
val newAttributeKey = "key".toDopeType()
val newAttributeValue = "value".toDopeType()
val expected = ObjectAddExpression(objectExpression, newAttributeKey, newAttributeValue)
val expected = ObjectAddExpression(objectExpression, ObjectEntryPrimitive(newAttributeKey, newAttributeValue))

val actual = objectExpression.addAttribute(newAttributeKey, newAttributeValue)

Expand All @@ -40,7 +41,7 @@ class ObjectAddExpressionTest : ManagerDependentTest {
val objectExpression = someObjectField()
val newAttributeKey = "key"
val newAttributeValue = "value".toDopeType()
val expected = ObjectAddExpression(objectExpression, newAttributeKey.toDopeType(), newAttributeValue)
val expected = ObjectAddExpression(objectExpression, ObjectEntryPrimitive(newAttributeKey.toDopeType(), newAttributeValue))

val actual = objectExpression.addAttribute(newAttributeKey, newAttributeValue)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,74 +106,74 @@ fun CMObjectField<Schema>.removeAttribute(key: String) = toDopeType().removeAttr
fun CMObjectField<Schema>.removeAttribute(key: CMJsonField<String>) = toDopeType().removeAttribute(key.toDopeType())

fun CMObjectField<Schema>.renameAttribute(
oldField: TypeExpression<StringType>,
newField: TypeExpression<StringType>,
) = toDopeType().renameAttribute(oldField, newField)
oldFieldName: TypeExpression<StringType>,
newFieldName: TypeExpression<StringType>,
) = toDopeType().renameAttribute(oldFieldName, newFieldName)

fun CMObjectField<Schema>.renameAttribute(
oldField: String,
newField: String,
) = toDopeType().renameAttribute(oldField.toDopeType(), newField.toDopeType())
oldFieldName: String,
newFieldName: String,
) = toDopeType().renameAttribute(oldFieldName.toDopeType(), newFieldName.toDopeType())

fun CMObjectField<Schema>.renameAttribute(
oldField: TypeExpression<StringType>,
newField: String,
) = toDopeType().renameAttribute(oldField, newField.toDopeType())
oldFieldName: TypeExpression<StringType>,
newFieldName: String,
) = toDopeType().renameAttribute(oldFieldName, newFieldName.toDopeType())

fun CMObjectField<Schema>.renameAttribute(
oldField: String,
newField: TypeExpression<StringType>,
) = toDopeType().renameAttribute(oldField.toDopeType(), newField)
oldFieldName: String,
newFieldName: TypeExpression<StringType>,
) = toDopeType().renameAttribute(oldFieldName.toDopeType(), newFieldName)

fun CMObjectField<Schema>.renameAttribute(
oldField: CMJsonField<String>,
newField: CMJsonField<String>,
) = toDopeType().renameAttribute(oldField.toDopeType(), newField.toDopeType())
oldFieldName: CMJsonField<String>,
newFieldName: CMJsonField<String>,
) = toDopeType().renameAttribute(oldFieldName.toDopeType(), newFieldName.toDopeType())

fun CMObjectField<Schema>.renameAttribute(
oldField: CMJsonField<String>,
newField: String,
) = toDopeType().renameAttribute(oldField.toDopeType(), newField.toDopeType())
oldFieldName: CMJsonField<String>,
newFieldName: String,
) = toDopeType().renameAttribute(oldFieldName.toDopeType(), newFieldName.toDopeType())

fun CMObjectField<Schema>.renameAttribute(
oldField: String,
newField: CMJsonField<String>,
) = toDopeType().renameAttribute(oldField.toDopeType(), newField.toDopeType())
oldFieldName: String,
newFieldName: CMJsonField<String>,
) = toDopeType().renameAttribute(oldFieldName.toDopeType(), newFieldName.toDopeType())

fun CMObjectField<Schema>.renameAttribute(
oldField: CMJsonField<String>,
newField: TypeExpression<StringType>,
) = toDopeType().renameAttribute(oldField.toDopeType(), newField)
oldFieldName: CMJsonField<String>,
newFieldName: TypeExpression<StringType>,
) = toDopeType().renameAttribute(oldFieldName.toDopeType(), newFieldName)

fun CMObjectField<Schema>.renameAttribute(
oldField: TypeExpression<StringType>,
newField: CMJsonField<String>,
) = toDopeType().renameAttribute(oldField, newField.toDopeType())
oldFieldName: TypeExpression<StringType>,
newFieldName: CMJsonField<String>,
) = toDopeType().renameAttribute(oldFieldName, newFieldName.toDopeType())

fun TypeExpression<ObjectType>.renameAttribute(
oldField: CMJsonField<String>,
newField: CMJsonField<String>,
) = renameAttribute(oldField.toDopeType(), newField.toDopeType())
oldFieldName: CMJsonField<String>,
newFieldName: CMJsonField<String>,
) = renameAttribute(oldFieldName.toDopeType(), newFieldName.toDopeType())

fun TypeExpression<ObjectType>.renameAttribute(
oldField: CMJsonField<String>,
newField: String,
) = renameAttribute(oldField.toDopeType(), newField.toDopeType())
oldFieldName: CMJsonField<String>,
newFieldName: String,
) = renameAttribute(oldFieldName.toDopeType(), newFieldName.toDopeType())

fun TypeExpression<ObjectType>.renameAttribute(
oldField: String,
newField: CMJsonField<String>,
) = renameAttribute(oldField.toDopeType(), newField.toDopeType())
oldFieldName: String,
newFieldName: CMJsonField<String>,
) = renameAttribute(oldFieldName.toDopeType(), newFieldName.toDopeType())

fun TypeExpression<ObjectType>.renameAttribute(
oldField: CMJsonField<String>,
newField: TypeExpression<StringType>,
) = renameAttribute(oldField.toDopeType(), newField)
oldFieldName: CMJsonField<String>,
newFieldName: TypeExpression<StringType>,
) = renameAttribute(oldFieldName.toDopeType(), newFieldName)

fun TypeExpression<ObjectType>.renameAttribute(
oldField: TypeExpression<StringType>,
newField: CMJsonField<String>,
) = renameAttribute(oldField, newField.toDopeType())
oldFieldName: TypeExpression<StringType>,
newFieldName: CMJsonField<String>,
) = renameAttribute(oldFieldName, newFieldName.toDopeType())

fun CMObjectField<Schema>.replace(oldValue: TypeExpression<out ValidType>, newValue: TypeExpression<out ValidType>) =
toDopeType().replace(oldValue, newValue)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import ch.ergon.dope.helper.someCMObjectField
import ch.ergon.dope.helper.someCMStringField
import ch.ergon.dope.helper.someNumberFieldList
import ch.ergon.dope.helper.someObjectField
import ch.ergon.dope.resolvable.expression.unaliased.type.ObjectEntryPrimitive
import ch.ergon.dope.resolvable.expression.unaliased.type.function.`object`.ObjectAddExpression
import ch.ergon.dope.resolvable.expression.unaliased.type.function.`object`.ObjectConcatExpression
import ch.ergon.dope.resolvable.expression.unaliased.type.function.`object`.ObjectFieldExpression
Expand Down Expand Up @@ -50,7 +51,7 @@ class ObjectFunctionTest : ManagerDependentTest {
val objectExpression = someCMObjectField()
val newAttributeKey = "key".toDopeType()
val newAttributeValue = "value".toDopeType()
val expected = ObjectAddExpression(objectExpression.toDopeType(), newAttributeKey, newAttributeValue)
val expected = ObjectAddExpression(objectExpression.toDopeType(), ObjectEntryPrimitive(newAttributeKey, newAttributeValue))

val actual = objectExpression.addAttribute(newAttributeKey, newAttributeValue)

Expand All @@ -62,7 +63,7 @@ class ObjectFunctionTest : ManagerDependentTest {
val objectExpression = someCMObjectField()
val newAttributeKey = "key"
val newAttributeValue = "value".toDopeType()
val expected = ObjectAddExpression(objectExpression.toDopeType(), newAttributeKey.toDopeType(), newAttributeValue)
val expected = ObjectAddExpression(objectExpression.toDopeType(), ObjectEntryPrimitive(newAttributeKey.toDopeType(), newAttributeValue))

val actual = objectExpression.addAttribute(newAttributeKey, newAttributeValue)

Expand All @@ -74,7 +75,7 @@ class ObjectFunctionTest : ManagerDependentTest {
val objectExpression = someCMObjectField()
val newAttributeKey = someCMStringField()
val newAttributeValue = someNumberFieldList()
val expected = ObjectAddExpression(objectExpression.toDopeType(), newAttributeKey.toDopeType(), newAttributeValue)
val expected = ObjectAddExpression(objectExpression.toDopeType(), ObjectEntryPrimitive(newAttributeKey.toDopeType(), newAttributeValue))

val actual = objectExpression.addAttribute(newAttributeKey, newAttributeValue)

Expand All @@ -86,7 +87,10 @@ class ObjectFunctionTest : ManagerDependentTest {
val objectExpression = someCMObjectField()
val newAttributeKey = someCMStringField()
val newAttributeValue = someCMNumberList()
val expected = ObjectAddExpression(objectExpression.toDopeType(), newAttributeKey.toDopeType(), newAttributeValue.toDopeType())
val expected = ObjectAddExpression(
objectExpression.toDopeType(),
ObjectEntryPrimitive(newAttributeKey.toDopeType(), newAttributeValue.toDopeType()),
)

val actual = objectExpression.addAttribute(newAttributeKey, newAttributeValue)

Expand All @@ -98,7 +102,10 @@ class ObjectFunctionTest : ManagerDependentTest {
val objectExpression = someObjectField()
val newAttributeKey = someCMStringField()
val newAttributeValue = someCMNumberList()
val expected = ObjectAddExpression(objectExpression, newAttributeKey.toDopeType(), newAttributeValue.toDopeType())
val expected = ObjectAddExpression(
objectExpression,
ObjectEntryPrimitive(newAttributeKey.toDopeType(), newAttributeValue.toDopeType()),
)

val actual = objectExpression.addAttribute(newAttributeKey, newAttributeValue)

Expand All @@ -110,7 +117,10 @@ class ObjectFunctionTest : ManagerDependentTest {
val objectExpression = someCMObjectField()
val newAttributeKey = "key"
val newAttributeValue = someCMNumberList()
val expected = ObjectAddExpression(objectExpression.toDopeType(), newAttributeKey.toDopeType(), newAttributeValue.toDopeType())
val expected = ObjectAddExpression(
objectExpression.toDopeType(),
ObjectEntryPrimitive(newAttributeKey.toDopeType(), newAttributeValue.toDopeType()),
)

val actual = objectExpression.addAttribute(newAttributeKey, newAttributeValue)

Expand All @@ -122,7 +132,7 @@ class ObjectFunctionTest : ManagerDependentTest {
val objectExpression = someObjectField()
val newAttributeKey = "key".toDopeType()
val newAttributeValue = someCMNumberList()
val expected = ObjectAddExpression(objectExpression, newAttributeKey, newAttributeValue.toDopeType())
val expected = ObjectAddExpression(objectExpression, ObjectEntryPrimitive(newAttributeKey, newAttributeValue.toDopeType()))

val actual = objectExpression.addAttribute(newAttributeKey, newAttributeValue)

Expand All @@ -134,7 +144,7 @@ class ObjectFunctionTest : ManagerDependentTest {
val objectExpression = someCMObjectField()
val newAttributeKey = "key".toDopeType()
val newAttributeValue = someCMNumberList()
val expected = ObjectAddExpression(objectExpression.toDopeType(), newAttributeKey, newAttributeValue.toDopeType())
val expected = ObjectAddExpression(objectExpression.toDopeType(), ObjectEntryPrimitive(newAttributeKey, newAttributeValue.toDopeType()))

val actual = objectExpression.addAttribute(newAttributeKey, newAttributeValue)

Expand Down

0 comments on commit a3b24dc

Please sign in to comment.