From a5e17552121e0a7bc93b1292f501d187d962d0bf Mon Sep 17 00:00:00 2001 From: Trivikram Kamat <16024985+trivikr@users.noreply.github.com> Date: Thu, 2 Jun 2022 22:00:29 -0700 Subject: [PATCH] Use Record type in place of Object (#557) * Use Record type instead Object type * Update protocol-test-form-urlencoded-stub.ts * Change Object -> Record in doc --- .../smithy/typescript/codegen/StructuredMemberWriter.java | 2 +- .../amazon/smithy/typescript/codegen/SymbolVisitor.java | 4 ++-- .../codegen/integration/DocumentShapeDeserVisitor.java | 4 ++-- .../codegen/integration/DocumentShapeSerVisitor.java | 4 ++-- .../codegen/integration/HttpBindingProtocolGenerator.java | 6 +++--- .../codegen/protocol-test-form-urlencoded-stub.ts | 4 ++-- 6 files changed, 12 insertions(+), 12 deletions(-) diff --git a/smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/StructuredMemberWriter.java b/smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/StructuredMemberWriter.java index 2d0823b20f4..4be869945cf 100644 --- a/smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/StructuredMemberWriter.java +++ b/smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/StructuredMemberWriter.java @@ -530,7 +530,7 @@ private void writeConstraintValidatorType(TypeScriptWriter writer, Shape shape) Shape collectionMemberTargetShape = model.expectShape(collectionMemberShape.getTarget()); writer.writeInline("Iterable<$T>", getSymbolForValidatedType(collectionMemberTargetShape)); } else if (shape.isMapShape()) { - writer.writeInline("{ [key: string]: $T }", getSymbolForValidatedType(((MapShape) shape).getValue())); + writer.writeInline("Record", getSymbolForValidatedType(((MapShape) shape).getValue())); } else if (shape instanceof SimpleShape) { writer.writeInline("$T", getSymbolForValidatedType(shape)); } else { diff --git a/smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/SymbolVisitor.java b/smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/SymbolVisitor.java index 40cbe3feef7..5d744d04e14 100644 --- a/smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/SymbolVisitor.java +++ b/smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/SymbolVisitor.java @@ -175,7 +175,7 @@ public Symbol setShape(SetShape shape) { * *
{@code
      * interface MyStructureShape {
-     *   memberPointingToMap: {[key: string]: string};
+     *   memberPointingToMap: Record;
      * }
      * }
* @@ -184,7 +184,7 @@ public Symbol setShape(SetShape shape) { @Override public Symbol mapShape(MapShape shape) { Symbol reference = toSymbol(shape.getValue()); - return createSymbolBuilder(shape, format("{ [key: string]: %s }", reference.getName()), null) + return createSymbolBuilder(shape, format("Record", reference.getName()), null) .addReference(reference) .build(); } diff --git a/smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/integration/DocumentShapeDeserVisitor.java b/smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/integration/DocumentShapeDeserVisitor.java index 999c2f02d2d..90bbccb5e63 100644 --- a/smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/integration/DocumentShapeDeserVisitor.java +++ b/smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/integration/DocumentShapeDeserVisitor.java @@ -177,7 +177,7 @@ protected Void getDefault(Shape shape) { *
  • {@code context: SerdeContext}: a TypeScript type containing context and tools for type serde.
  • * * - *

    The function signature specifies a {@code { [key: string]: Field }} return type. + *

    The function signature specifies a {@code Record} return type. * *

    This function would generate the following: * @@ -408,7 +408,7 @@ public final Void listShape(ListShape shape) { * const deserializeAws_restJson1_1FieldMap = ( * output: any, * context: SerdeContext - * ): { [key: string]: Field } => { + * ): Record => { * let mapParams: any = {}; * Object.keys(output).forEach(key => { * mapParams[key] = deserializeAws_restJson1_1Field(output[key], context); diff --git a/smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/integration/DocumentShapeSerVisitor.java b/smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/integration/DocumentShapeSerVisitor.java index e4e5ed9a8c8..814058f8193 100644 --- a/smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/integration/DocumentShapeSerVisitor.java +++ b/smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/integration/DocumentShapeSerVisitor.java @@ -175,7 +175,7 @@ protected Void getDefault(Shape shape) { * *

    The function signature for this body will have two parameters available in scope: *

    * @@ -403,7 +403,7 @@ public final Void listShape(ListShape shape) { * *
    {@code
          * const serializeAws_restJson1_1FieldMap = (
    -     *   input: { [key: string]: Field },
    +     *   input: Record,
          *   context: SerdeContext
          * ): any => {
          *   let mapParams: any = {};
    diff --git a/smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/integration/HttpBindingProtocolGenerator.java b/smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/integration/HttpBindingProtocolGenerator.java
    index 6c217ddad96..6483c725d3c 100644
    --- a/smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/integration/HttpBindingProtocolGenerator.java
    +++ b/smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/integration/HttpBindingProtocolGenerator.java
    @@ -1867,7 +1867,7 @@ private void readMappedQueryBindings(GenerationContext context, HttpBinding mapp
             if (valueShape instanceof CollectionShape) {
                 valueType = "string[]";
             }
    -        writer.write("let parsedQuery: { [key: string]: $L } = {}", valueType);
    +        writer.write("let parsedQuery: Record = {}", valueType);
             writer.openBlock("for (const [key, value] of Object.entries(query)) {", "}", () -> {
                 writer.write("let queryValue: string;");
                 final String parsedValue;
    @@ -2315,12 +2315,12 @@ private HttpBinding readPayload(
             } else if (target instanceof StructureShape) {
                 // If payload is a Structure, then we need to parse the string into JavaScript object.
                 writer.addImport("expectObject", "__expectObject", "@aws-sdk/smithy-client");
    -            writer.write("const data: { [key: string]: any } | undefined "
    +            writer.write("const data: Record | undefined "
                         + "= __expectObject(await parseBody(output.body, context));");
             } else if (target instanceof UnionShape) {
                 // If payload is a Union, then we need to parse the string into JavaScript object.
                 writer.addImport("expectUnion", "__expectUnion", "@aws-sdk/smithy-client");
    -            writer.write("const data: { [key: string]: any } | undefined "
    +            writer.write("const data: Record | undefined "
                         + "= __expectUnion(await parseBody(output.body, context));");
             } else if (target instanceof StringShape || target instanceof DocumentShape) {
                 // If payload is String or Document, we need to collect body and convert binary to string.
    diff --git a/smithy-typescript-codegen/src/main/resources/software/amazon/smithy/typescript/codegen/protocol-test-form-urlencoded-stub.ts b/smithy-typescript-codegen/src/main/resources/software/amazon/smithy/typescript/codegen/protocol-test-form-urlencoded-stub.ts
    index ef67aff33a8..9b6bc574cc7 100644
    --- a/smithy-typescript-codegen/src/main/resources/software/amazon/smithy/typescript/codegen/protocol-test-form-urlencoded-stub.ts
    +++ b/smithy-typescript-codegen/src/main/resources/software/amazon/smithy/typescript/codegen/protocol-test-form-urlencoded-stub.ts
    @@ -3,8 +3,8 @@
      * discrepancies between the components.
      */
     const compareEquivalentFormUrlencodedBodies = (expectedBody: string, generatedBody: string): Object => {
    -  const fromEntries = (components: string[][]): { [key: string]: string } => {
    -    const parts: { [key: string]: string } = {};
    +  const fromEntries = (components: string[][]): Record => {
    +    const parts: Record = {};
     
         components.forEach(component => {
           parts[component[0]] = component[1];