-
Notifications
You must be signed in to change notification settings - Fork 105
feat: codegen for waitUntil[State] #318
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 10 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
42cb361
feat: creating codegen for WaitUntilState
alexforsyth 63aee1e
fix: spacing
alexforsyth 90a3ec5
Update smithy-typescript-codegen/src/main/java/software/amazon/smithy…
alexforsyth 4d091b3
feat: throw a new error object
alexforsyth 37d21b6
feat: throw a new object on error
alexforsyth 958e444
fix: minor updates
alexforsyth 92299f8
Merge branch 'main' into waitUntilState
alexforsyth ab571ce
Merge branch 'main' into waitUntilState
alexforsyth 22493e4
fix: param annotation in doc generator
alexforsyth 8367b3b
fix: capitalization
alexforsyth 796e20f
fix: remove old documentation
alexforsyth d68d6ec
fix: documentation spacing
alexforsyth 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
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
|
@@ -70,27 +70,45 @@ private void generateWaiter() { | |||||||
writer.addImport("createWaiter", "createWaiter", WAITABLE_UTIL_PACKAGE); | ||||||||
writer.addImport("WaiterResult", "WaiterResult", WAITABLE_UTIL_PACKAGE); | ||||||||
writer.addImport("WaiterState", "WaiterState", WAITABLE_UTIL_PACKAGE); | ||||||||
writer.addImport("checkExceptions", "checkExceptions", WAITABLE_UTIL_PACKAGE); | ||||||||
writer.addImport("WaiterConfiguration", "WaiterConfiguration", WAITABLE_UTIL_PACKAGE); | ||||||||
|
||||||||
// generates the now deprecated WaitFor.... | ||||||||
writer.writeDocs(waiter.getDocumentation().orElse("") + " \n" | ||||||||
+ " @param params : Waiter configuration options.\n" | ||||||||
+ " @param input : the input to " + operationSymbol.getName() + " for polling."); | ||||||||
+ " @deprecated In favor of waitUntil" + waiterName + ". This does not throw on failure.\n" | ||||||||
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.
Suggested change
|
||||||||
+ " @param params - Waiter configuration options.\n" | ||||||||
+ " @param input - The input to " + operationSymbol.getName() + " for polling."); | ||||||||
writer.openBlock("export const waitFor$L = async (params: WaiterConfiguration<$T>, input: $T): " | ||||||||
+ "Promise<WaiterResult> => {", "}", waiterName, serviceSymbol, inputSymbol, () -> { | ||||||||
writer.write("const serviceDefaults = { minDelay: $L, maxDelay: $L };", waiter.getMinDelay(), | ||||||||
waiter.getMaxDelay()); | ||||||||
writer.write("return createWaiter({...serviceDefaults, ...params}, input, checkState);"); | ||||||||
}); | ||||||||
|
||||||||
// generates WaitUtil.... | ||||||||
writer.writeDocs(waiter.getDocumentation().orElse("") + " \n" | ||||||||
+ " @param params - Waiter configuration options.\n" | ||||||||
+ " @param input - The input to " + operationSymbol.getName() + " for polling."); | ||||||||
writer.openBlock("export const waitUntil$L = async (params: WaiterConfiguration<$T>, input: $T): " | ||||||||
+ "Promise<WaiterResult> => {", "}", waiterName, serviceSymbol, inputSymbol, () -> { | ||||||||
writer.write("const serviceDefaults = { minDelay: $L, maxDelay: $L };", waiter.getMinDelay(), | ||||||||
waiter.getMaxDelay()); | ||||||||
writer.write("const result = await createWaiter({...serviceDefaults, ...params}, input, checkState);"); | ||||||||
trivikr marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||
writer.write("return checkExceptions(result);"); | ||||||||
}); | ||||||||
} | ||||||||
|
||||||||
private void generateAcceptors() { | ||||||||
writer.openBlock("const checkState = async (client: $T, input: $T): Promise<WaiterResult> => {", "}", | ||||||||
serviceSymbol, inputSymbol, () -> { | ||||||||
writer.write("let reason;"); | ||||||||
writer.openBlock("try {", "}", () -> { | ||||||||
writer.write("let result: any = await client.send(new $T(input))", operationSymbol); | ||||||||
writer.write("reason = result;"); | ||||||||
writeAcceptors("result", false); | ||||||||
}); | ||||||||
writer.openBlock("catch (exception) {", "}", () -> { | ||||||||
writer.write("reason = exception;"); | ||||||||
writeAcceptors("exception", true); | ||||||||
}); | ||||||||
writer.write("return $L;", makeWaiterResult(AcceptorState.RETRY)); | ||||||||
|
@@ -165,11 +183,11 @@ private void generatePathMatcher(String accessor, PathMatcher pathMatcher, Accep | |||||||
|
||||||||
private String makeWaiterResult(AcceptorState resultantState) { | ||||||||
if (resultantState == AcceptorState.SUCCESS) { | ||||||||
return "{ state: WaiterState.SUCCESS }"; | ||||||||
return "{ state: WaiterState.SUCCESS, reason }"; | ||||||||
} else if (resultantState == AcceptorState.FAILURE) { | ||||||||
return "{ state: WaiterState.FAILURE }"; | ||||||||
return "{ state: WaiterState.FAILURE, reason }"; | ||||||||
} else if (resultantState == AcceptorState.RETRY) { | ||||||||
return "{ state: WaiterState.RETRY }"; | ||||||||
return "{ state: WaiterState.RETRY, reason }"; | ||||||||
} | ||||||||
throw new CodegenException("Hit an invalid acceptor state to codegen " + resultantState.toString()); | ||||||||
} | ||||||||
|
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.
Remove waiter documentation, as
waitFor
is deprecated. Users should read documentation forwaitUntil
instead.