-
Notifications
You must be signed in to change notification settings - Fork 105
support eventstream traits #110
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
AllanZhengYP
merged 12 commits into
smithy-lang:master
from
AllanZhengYP:event-stream-utils-dev
Feb 17, 2020
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
a5eb480
add eventstream serde generator
AllanZhengYP 5ae94a0
generate special serde for events and event unions
AllanZhengYP 60f6dc6
complete event deserializer and event union deserializer
AllanZhengYP d5d34c9
Add event stream and events unions serializer
AllanZhengYP 4eb3e87
Add event-stream middleware if operation has eventstream input
AllanZhengYP 7495fab
formatting code and add necessary docs
AllanZhengYP 21125ca
add eventstream-serde-browser dependency
AllanZhengYP e58e281
address PR feedbacks
AllanZhengYP 0009f5e
re-organize the functions
AllanZhengYP e9da31a
format java code
AllanZhengYP 42751c8
use normal error deserializer to deserialize error event in event stream
AllanZhengYP 3eed021
fix readEventPayload()
AllanZhengYP 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
121 changes: 121 additions & 0 deletions
121
.../java/software/amazon/smithy/typescript/codegen/integration/AddEventStreamDependency.java
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,121 @@ | ||
/* | ||
* Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"). | ||
* You may not use this file except in compliance with the License. | ||
* A copy of the License is located at | ||
* | ||
* http://aws.amazon.com/apache2.0 | ||
* | ||
* or in the "license" file accompanying this file. This file is distributed | ||
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either | ||
* express or implied. See the License for the specific language governing | ||
* permissions and limitations under the License. | ||
*/ | ||
|
||
package software.amazon.smithy.typescript.codegen.integration; | ||
|
||
import java.util.List; | ||
import java.util.Set; | ||
|
||
import software.amazon.smithy.codegen.core.SymbolProvider; | ||
import software.amazon.smithy.model.Model; | ||
import software.amazon.smithy.model.knowledge.EventStreamIndex; | ||
import software.amazon.smithy.model.knowledge.TopDownIndex; | ||
import software.amazon.smithy.model.shapes.OperationShape; | ||
import software.amazon.smithy.model.shapes.ServiceShape; | ||
import software.amazon.smithy.typescript.codegen.LanguageTarget; | ||
import software.amazon.smithy.typescript.codegen.TypeScriptDependency; | ||
import software.amazon.smithy.typescript.codegen.TypeScriptSettings; | ||
import software.amazon.smithy.typescript.codegen.TypeScriptWriter; | ||
import software.amazon.smithy.utils.ListUtils; | ||
|
||
/** | ||
* Adds event streams if needed. | ||
*/ | ||
public final class AddEventStreamDependency implements TypeScriptIntegration { | ||
|
||
@Override | ||
public List<RuntimeClientPlugin> getClientPlugins() { | ||
return ListUtils.of( | ||
RuntimeClientPlugin.builder() | ||
.withConventions(TypeScriptDependency.AWS_SDK_EVENTSTREAM_SERDE_CONFIG_RESOLVER.dependency, | ||
"EventStreamSerde", RuntimeClientPlugin.Convention.HAS_CONFIG) | ||
.servicePredicate(AddEventStreamDependency::hasEventStream) | ||
.build() | ||
); | ||
} | ||
|
||
@Override | ||
public void addConfigInterfaceFields( | ||
TypeScriptSettings settings, | ||
Model model, | ||
SymbolProvider symbolProvider, | ||
TypeScriptWriter writer | ||
) { | ||
if (!hasEventStream(model, settings.getService(model))) { | ||
return; | ||
} | ||
|
||
writer.addDependency(TypeScriptDependency.AWS_SDK_EVENTSTREAM_SERDE_CONFIG_RESOLVER); | ||
writer.addImport("EventStreamSerdeProvider", "__EventStreamSerdeProvider", | ||
TypeScriptDependency.AWS_SDK_TYPES.packageName); | ||
writer.writeDocs("The function that provides necessary utilities for generating and signing event stream"); | ||
writer.write("eventStreamSerdeProvider?: __EventStreamSerdeProvider;\n"); | ||
} | ||
|
||
@Override | ||
public void addRuntimeConfigValues( | ||
TypeScriptSettings settings, | ||
Model model, | ||
SymbolProvider symbolProvider, | ||
TypeScriptWriter writer, | ||
LanguageTarget target | ||
) { | ||
if (!hasEventStream(model, settings.getService(model))) { | ||
return; | ||
} | ||
|
||
switch (target) { | ||
case NODE: | ||
writer.addDependency(TypeScriptDependency.AWS_SDK_EVENTSTREAM_SERDE_NODE); | ||
writer.addImport("eventStreamSerdeProvider", "eventStreamSerdeProvider", | ||
TypeScriptDependency.AWS_SDK_EVENTSTREAM_SERDE_NODE.packageName); | ||
writer.write("eventStreamSerdeProvider"); | ||
break; | ||
case BROWSER: | ||
writer.addDependency(TypeScriptDependency.AWS_SDK_EVENTSTREAM_SERDE_BROWSER); | ||
writer.addImport("eventStreamSerdeProvider", "eventStreamSerdeProvider", | ||
TypeScriptDependency.AWS_SDK_EVENTSTREAM_SERDE_BROWSER.packageName); | ||
writer.write("eventStreamSerdeProvider"); | ||
break; | ||
case REACT_NATIVE: | ||
// TODO: add ReactNative eventstream support | ||
writer.addDependency(TypeScriptDependency.INVALID_DEPENDENCY); | ||
writer.addImport("invalidFunction", "invalidFunction", | ||
TypeScriptDependency.INVALID_DEPENDENCY.packageName); | ||
writer.write("eventStreamSerdeProvider: invalidFunction(\"event stream is not supported in " | ||
+ "ReactNative\") as any,"); | ||
break; | ||
default: | ||
// do nothing | ||
} | ||
} | ||
|
||
private static boolean hasEventStream( | ||
Model model, | ||
ServiceShape service | ||
) { | ||
TopDownIndex topDownIndex = model.getKnowledge(TopDownIndex.class); | ||
Set<OperationShape> operations = topDownIndex.getContainedOperations(service); | ||
EventStreamIndex eventStreamIndex = model.getKnowledge(EventStreamIndex.class); | ||
for (OperationShape operation : operations) { | ||
if (eventStreamIndex.getInputInfo(operation).isPresent() | ||
|| eventStreamIndex.getOutputInfo(operation).isPresent() | ||
) { | ||
return true; | ||
} | ||
} | ||
return false; | ||
} | ||
} |
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.
Uh oh!
There was an error while loading. Please reload this page.