All Downloads are FREE. Search and download functionalities are using the official Maven repository.

commonMain.aws.sdk.kotlin.hll.dynamodbmapper.operations.PutItem.kt Maven / Gradle / Ivy

There is a newer version: 1.3.73-beta
Show newest version
// Code generated by dynamodb-mapper-ops-codegen. DO NOT EDIT!

package aws.sdk.kotlin.hll.dynamodbmapper.operations

import aws.sdk.kotlin.hll.dynamodbmapper.expressions.internal.ParameterizingExpressionVisitor
import aws.sdk.kotlin.hll.dynamodbmapper.internal.withWrappedClient
import aws.sdk.kotlin.hll.dynamodbmapper.items.ItemSchema
import aws.sdk.kotlin.hll.dynamodbmapper.model.TableSpec
import aws.sdk.kotlin.hll.dynamodbmapper.model.toItem
import aws.sdk.kotlin.hll.dynamodbmapper.pipeline.internal.HReqContextImpl
import aws.sdk.kotlin.hll.dynamodbmapper.pipeline.internal.MapperContextImpl
import aws.sdk.kotlin.hll.dynamodbmapper.pipeline.internal.Operation
import aws.sdk.kotlin.services.dynamodb.model.ConsumedCapacity
import aws.sdk.kotlin.services.dynamodb.model.ItemCollectionMetrics
import aws.sdk.kotlin.services.dynamodb.model.ReturnConsumedCapacity
import aws.sdk.kotlin.services.dynamodb.model.ReturnItemCollectionMetrics
import aws.sdk.kotlin.services.dynamodb.model.ReturnValue
import aws.sdk.kotlin.services.dynamodb.model.ReturnValuesOnConditionCheckFailure
import aws.smithy.kotlin.runtime.ExperimentalApi
import aws.sdk.kotlin.services.dynamodb.model.PutItemRequest as LowLevelPutItemRequest
import aws.sdk.kotlin.services.dynamodb.model.PutItemResponse as LowLevelPutItemResponse

@ExperimentalApi
public interface PutItemRequest {
    @ExperimentalApi
    public companion object { }

    public val item: T?
    public val returnConsumedCapacity: ReturnConsumedCapacity?
    public val returnItemCollectionMetrics: ReturnItemCollectionMetrics?
    public val returnValues: ReturnValue?
    public val returnValuesOnConditionCheckFailure: ReturnValuesOnConditionCheckFailure?
}

private data class PutItemRequestImpl(
    override val item: T?,
    override val returnConsumedCapacity: ReturnConsumedCapacity?,
    override val returnItemCollectionMetrics: ReturnItemCollectionMetrics?,
    override val returnValues: ReturnValue?,
    override val returnValuesOnConditionCheckFailure: ReturnValuesOnConditionCheckFailure?,
): PutItemRequest

/**
 * A DSL-style builder for instances of [PutItemRequest]
 */
@ExperimentalApi
public class PutItemRequestBuilder {
    public var item: T? = null
    public var returnConsumedCapacity: ReturnConsumedCapacity? = null
    public var returnItemCollectionMetrics: ReturnItemCollectionMetrics? = null
    public var returnValues: ReturnValue? = null
    public var returnValuesOnConditionCheckFailure: ReturnValuesOnConditionCheckFailure? = null

    public fun build(): PutItemRequest {
        val item = item
        val returnConsumedCapacity = returnConsumedCapacity
        val returnItemCollectionMetrics = returnItemCollectionMetrics
        val returnValues = returnValues
        val returnValuesOnConditionCheckFailure = returnValuesOnConditionCheckFailure

        return PutItemRequestImpl(
            item,
            returnConsumedCapacity,
            returnItemCollectionMetrics,
            returnValues,
            returnValuesOnConditionCheckFailure,
        )
    }
}

@ExperimentalApi
public fun  PutItemRequest.toBuilder(): PutItemRequestBuilder = PutItemRequestBuilder().apply {
    item = [email protected]
    returnConsumedCapacity = [email protected]
    returnItemCollectionMetrics = [email protected]
    returnValues = [email protected]
    returnValuesOnConditionCheckFailure = [email protected]
}

@ExperimentalApi
public fun  PutItemRequest.copy(block: PutItemRequestBuilder.() -> Unit): PutItemRequest =
    toBuilder().apply(block).build()

@ExperimentalApi
public fun  PutItemRequest(block: PutItemRequestBuilder.() -> Unit): PutItemRequest =
    PutItemRequestBuilder().apply(block).build()

private fun  PutItemRequest.convert(
    tableName: String?, 
    schema: ItemSchema,
) = LowLevelPutItemRequest {
    returnConsumedCapacity = [email protected]
    returnItemCollectionMetrics = [email protected]
    returnValues = [email protected]
    returnValuesOnConditionCheckFailure = [email protected]
    [email protected]?.let { item = schema.converter.convertTo(it) }
    this.tableName = tableName

    val expressionVisitor = ParameterizingExpressionVisitor()
    expressionAttributeNames = expressionVisitor.expressionAttributeNames()
    expressionAttributeValues = expressionVisitor.expressionAttributeValues()
}

@ExperimentalApi
public interface PutItemResponse {
    @ExperimentalApi
    public companion object { }

    public val attributes: T?
    public val consumedCapacity: ConsumedCapacity?
    public val itemCollectionMetrics: ItemCollectionMetrics?
}

private data class PutItemResponseImpl(
    override val attributes: T?,
    override val consumedCapacity: ConsumedCapacity?,
    override val itemCollectionMetrics: ItemCollectionMetrics?,
): PutItemResponse

/**
 * A DSL-style builder for instances of [PutItemResponse]
 */
@ExperimentalApi
public class PutItemResponseBuilder {
    public var attributes: T? = null
    public var consumedCapacity: ConsumedCapacity? = null
    public var itemCollectionMetrics: ItemCollectionMetrics? = null

    public fun build(): PutItemResponse {
        val attributes = attributes
        val consumedCapacity = consumedCapacity
        val itemCollectionMetrics = itemCollectionMetrics

        return PutItemResponseImpl(
            attributes,
            consumedCapacity,
            itemCollectionMetrics,
        )
    }
}

@ExperimentalApi
public fun  PutItemResponse.toBuilder(): PutItemResponseBuilder = PutItemResponseBuilder().apply {
    attributes = [email protected]
    consumedCapacity = [email protected]
    itemCollectionMetrics = [email protected]
}

@ExperimentalApi
public fun  PutItemResponse.copy(block: PutItemResponseBuilder.() -> Unit): PutItemResponse =
    toBuilder().apply(block).build()

@ExperimentalApi
public fun  PutItemResponse(block: PutItemResponseBuilder.() -> Unit): PutItemResponse =
    PutItemResponseBuilder().apply(block).build()

private fun  LowLevelPutItemResponse.convert(schema: ItemSchema) = PutItemResponse {
    consumedCapacity = [email protected]
    itemCollectionMetrics = [email protected]
    attributes = [email protected]?.toItem()?.let(schema.converter::convertFrom)
}

internal fun  putItemOperation(spec: TableSpec) = Operation(
    initialize = { highLevelReq: PutItemRequest -> HReqContextImpl(highLevelReq, spec.schema, MapperContextImpl(spec, "PutItem")) },
    serialize = { highLevelReq, schema -> highLevelReq.convert(spec.tableName, schema) },
    lowLevelInvoke = { lowLevelReq ->
        spec.mapper.client.withWrappedClient { client ->
            client.putItem(lowLevelReq)
        }
    },
    deserialize = LowLevelPutItemResponse::convert,
    interceptors = spec.mapper.config.interceptors,
)




© 2015 - 2024 Weber Informatics LLC | Privacy Policy