-
Notifications
You must be signed in to change notification settings - Fork 55
add DSL overloads, paginators, and better builder integration for DDB Mapper ops codegen #1409
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
234c209
add DSL overloads, paginators, and better builder integration for DDB…
ianbotsf f906f22
addressing PR feedback: move DDB-specific packages back to DDB module…
ianbotsf 0318aa5
addressing PR feedback: abstract stdout replacement and double-invoca…
ianbotsf 59da95d
Merge branch 'feat-ddb-mapper' into ddbmapper-dsls-and-paginators
ianbotsf File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,6 +4,8 @@ | |
| */ | ||
| package aws.sdk.kotlin.hll.dynamodbmapper.codegen.operations.model | ||
|
|
||
| import aws.sdk.kotlin.hll.codegen.model.Operation | ||
| import aws.sdk.kotlin.hll.codegen.model.Structure | ||
| import aws.smithy.kotlin.runtime.collections.AttributeKey | ||
|
|
||
| /** | ||
|
|
@@ -19,4 +21,6 @@ internal object ModelAttributes { | |
| * For a given high-level [Structure], this attribute key identifies the associated low-level [Structure] | ||
| */ | ||
| val LowLevelStructure: AttributeKey<Structure> = AttributeKey("aws.sdk.kotlin.ddbmapper#LowLevelStructure") | ||
|
|
||
| val PaginationInfo: AttributeKey<PaginationMembers> = AttributeKey("aws.sdk.kotlin.ddbmapper#PaginationInfo") | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: missing kdocs |
||
| } | ||
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
53 changes: 53 additions & 0 deletions
53
.../src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/operations/model/Pagination.kt
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| /* | ||
| * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
| package aws.sdk.kotlin.hll.dynamodbmapper.codegen.operations.model | ||
|
|
||
| import aws.sdk.kotlin.hll.codegen.model.Member | ||
| import aws.sdk.kotlin.hll.codegen.model.ModelParsingPlugin | ||
| import aws.sdk.kotlin.hll.codegen.model.Operation | ||
| import aws.sdk.kotlin.hll.codegen.util.plus | ||
|
|
||
| /** | ||
| * Identifies the [Member] instances of an operation's request and response which control pagination | ||
| * @param inputToken The field for passing a pagination token into a request | ||
| * @param outputToken The field for receiving a pagination token from a request | ||
| * @param limit The field for limiting the number of returned results | ||
| * @param items The field for getting the low-level items from each page of results | ||
| */ | ||
| internal data class PaginationMembers( | ||
| val inputToken: Member, | ||
| val outputToken: Member, | ||
| val limit: Member, | ||
| val items: Member, | ||
| ) { | ||
| internal companion object { | ||
| fun forOperationOrNull(operation: Operation): PaginationMembers? { | ||
| val inputToken = operation.request.members.find { it.name == "exclusiveStartKey" } ?: return null | ||
| val outputToken = operation.response.members.find { it.name == "lastEvaluatedKey" } ?: return null | ||
| val limit = operation.request.members.find { it.name == "limit" } ?: return null | ||
| val items = operation.response.members.find { it.name == "items" } ?: return null | ||
|
|
||
| return PaginationMembers(inputToken, outputToken, limit, items) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Gets the [PaginationMembers] for an operation, if applicable. If the operation does not support pagination, this | ||
| * property returns `null`. | ||
| */ | ||
| internal val Operation.paginationInfo: PaginationMembers? | ||
| get() = attributes.getOrNull(ModelAttributes.PaginationInfo) | ||
|
|
||
| /** | ||
| * A codegen plugin that adds DDB-specific pagination info to operations | ||
| */ | ||
| internal class DdbPaginationPlugin : ModelParsingPlugin { | ||
| override fun postProcessOperation(operation: Operation): Operation { | ||
| val paginationMembers = PaginationMembers.forOperationOrNull(operation) ?: return operation | ||
| val newAttributes = operation.attributes + (ModelAttributes.PaginationInfo to paginationMembers) | ||
| return operation.copy(attributes = newAttributes) | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is this change used for?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was really useful in debugging deep codegen stacks where the KSP logger wasn't passed through. Regular
printlnto stdout appear to be swallowed by KSP (or possibly Gradle?) so I needed a way to access the logger despite not having it in scope. I thought it could be useful in future debug scenarios but if we feel this doesn't merit permanent inclusion (or perhaps warrants a better solution) I can remove/update as requested.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok that's what I thought. I've also ran into this issue in the past, so I'm happy to have this feature, as long as we remove the println's before merging. Could you add the same thing in the high level class of the annotations processor?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about a base class from which all of our symbol processors inherit? 😃