From 7aa0a58c7b7731b172cf9a918c618b9058825d75 Mon Sep 17 00:00:00 2001 From: "Kamat, Trivikram" <16024985+trivikr@users.noreply.github.com> Date: Wed, 19 Oct 2022 22:46:03 +0000 Subject: [PATCH] Add @aws-sdk/util-endpoints dependency in package.json --- .../codegen/DirectedTypeScriptCodegen.java | 2 +- .../codegen/TypeScriptDependency.java | 1 + .../endpointsV2/EndpointsV2Generator.java | 218 +++++++++--------- 3 files changed, 112 insertions(+), 109 deletions(-) diff --git a/smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/DirectedTypeScriptCodegen.java b/smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/DirectedTypeScriptCodegen.java index 68da5fefca6..a1bcb57e1b1 100644 --- a/smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/DirectedTypeScriptCodegen.java +++ b/smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/DirectedTypeScriptCodegen.java @@ -307,7 +307,7 @@ private void generateEndpointV2(GenerateServiceDirective new RuntimeException("service missing EndpointRuleSetTrait")); @@ -63,140 +66,139 @@ public void run() { * Generate the EndpointParameters interface file specific to this service. */ private void generateEndpointParameters() { - TypeScriptWriter writer = new TypeScriptWriter(""); + this.delegator.useFileWriter( + Paths.get(CodegenUtils.SOURCE_FOLDER, ENDPOINT_FOLDER, ENDPOINT_PARAMETERS_FILE).toString(), + writer -> { + writer.addImport("EndpointParameters", "__EndpointParameters", "@aws-sdk/types"); + writer.addImport("Provider", null, "@aws-sdk/types"); - writer.addImport("EndpointParameters", "__EndpointParameters", "@aws-sdk/types"); - writer.addImport("Provider", null, "@aws-sdk/types"); + writer.openBlock( + "export interface ClientInputEndpointParameters {", + "}", + () -> { + RuleSetParameterFinder ruleSetParameterFinder = new RuleSetParameterFinder(service); - writer.openBlock( - "export interface ClientInputEndpointParameters {", - "}", - () -> { - RuleSetParameterFinder ruleSetParameterFinder = new RuleSetParameterFinder(service); + Map clientInputParams = ruleSetParameterFinder.getClientContextParams(); + clientInputParams.putAll(ruleSetParameterFinder.getBuiltInParams()); - Map clientInputParams = ruleSetParameterFinder.getClientContextParams(); - clientInputParams.putAll(ruleSetParameterFinder.getBuiltInParams()); + ObjectNode ruleSet = endpointRuleSetTrait.getRuleSet().expectObjectNode(); + ruleSet.getObjectMember("parameters").ifPresent(parameters -> { + parameters.accept(new RuleSetParametersVisitor(writer, clientInputParams, true)); + }); + } + ); - ObjectNode ruleSet = endpointRuleSetTrait.getRuleSet().expectObjectNode(); - ruleSet.getObjectMember("parameters").ifPresent(parameters -> { - parameters.accept(new RuleSetParametersVisitor(writer, clientInputParams, true)); - }); - } - ); + writer.write(""); + writer.openBlock( + "export type ClientResolvedEndpointParameters = ClientInputEndpointParameters & {", + "};", + () -> { + writer.write("defaultSigningName: string;"); + } + ); + writer.write(""); - writer.write(""); - writer.openBlock( - "export type ClientResolvedEndpointParameters = ClientInputEndpointParameters & {", - "};", - () -> { - writer.write("defaultSigningName: string;"); - } - ); - writer.write(""); - - writer.openBlock( - "export const resolveClientEndpointParameters = " - + "(options: T & ClientInputEndpointParameters" - + "): T & ClientResolvedEndpointParameters => {", - "}", - () -> { - writer.openBlock("return {", "}", () -> { - writer.write("...options,"); - ObjectNode ruleSet = endpointRuleSetTrait.getRuleSet().expectObjectNode(); - ruleSet.getObjectMember("parameters").ifPresent(parameters -> { - parameters.accept(new RuleSetParametersVisitor(writer, true)); - }); - ServiceTrait serviceTrait = service.getTrait(ServiceTrait.class).get(); - writer.write( - "defaultSigningName: \"$L\",", - service.getTrait(SigV4Trait.class).map(SigV4Trait::getName) - .orElse(serviceTrait.getArnNamespace()) - ); - }); - } - ); + writer.openBlock( + "export const resolveClientEndpointParameters = " + + "(options: T & ClientInputEndpointParameters" + + "): T & ClientResolvedEndpointParameters => {", + "}", + () -> { + writer.openBlock("return {", "}", () -> { + writer.write("...options,"); + ObjectNode ruleSet = endpointRuleSetTrait.getRuleSet().expectObjectNode(); + ruleSet.getObjectMember("parameters").ifPresent(parameters -> { + parameters.accept(new RuleSetParametersVisitor(writer, true)); + }); + ServiceTrait serviceTrait = service.getTrait(ServiceTrait.class).get(); + writer.write( + "defaultSigningName: \"$L\",", + service.getTrait(SigV4Trait.class).map(SigV4Trait::getName) + .orElse(serviceTrait.getArnNamespace()) + ); + }); + } + ); - writer.write(""); - writer.openBlock( - "export interface EndpointParameters extends __EndpointParameters {", - "}", - () -> { - ObjectNode ruleSet = endpointRuleSetTrait.getRuleSet().expectObjectNode(); - ruleSet.getObjectMember("parameters").ifPresent(parameters -> { - parameters.accept(new RuleSetParametersVisitor(writer)); - }); + writer.write(""); + writer.openBlock( + "export interface EndpointParameters extends __EndpointParameters {", + "}", + () -> { + ObjectNode ruleSet = endpointRuleSetTrait.getRuleSet().expectObjectNode(); + ruleSet.getObjectMember("parameters").ifPresent(parameters -> { + parameters.accept(new RuleSetParametersVisitor(writer)); + }); + } + ); } ); - - fileManifest.writeFile( - Paths.get(CodegenUtils.SOURCE_FOLDER, ENDPOINT_FOLDER, "EndpointParameters.ts").toString(), - writer.toString() - ); } /** * Generate the resolver function for this service. */ private void generateEndpointResolver() { - TypeScriptWriter writer = new TypeScriptWriter(""); - - writer.addImport("EndpointV2", null, "@aws-sdk/types"); - writer.addImport("Logger", null, "@aws-sdk/types"); + this.delegator.useFileWriter( + Paths.get(CodegenUtils.SOURCE_FOLDER, ENDPOINT_FOLDER, ENDPOINT_RESOLVER_FILE).toString(), + writer -> { + writer.addImport("EndpointV2", null, "@aws-sdk/types"); + writer.addImport("Logger", null, "@aws-sdk/types"); + + writer.addDependency(TypeScriptDependency.AWS_SDK_UTIL_ENDPOINTS); + writer.addImport("EndpointParams", null, TypeScriptDependency.AWS_SDK_UTIL_ENDPOINTS.packageName); + writer.addImport("resolveEndpoint", null, TypeScriptDependency.AWS_SDK_UTIL_ENDPOINTS.packageName); + writer.addImport("EndpointParameters", null, + Paths.get(".", CodegenUtils.SOURCE_FOLDER, ENDPOINT_FOLDER, + ENDPOINT_PARAMETERS_FILE.replace(".ts", "")).toString()); + writer.addImport("ruleSet", null, + Paths.get(".", CodegenUtils.SOURCE_FOLDER, ENDPOINT_FOLDER, + ENDPOINT_RULESET_FILE.replace(".ts", "")).toString()); - writer.addImport("EndpointParams", null, "@aws-sdk/util-endpoints"); - writer.addImport("resolveEndpoint", null, "@aws-sdk/util-endpoints"); - writer.addImport("EndpointParameters", null, "../endpoint/EndpointParameters"); - writer.addImport("ruleSet", null, "../endpoint/ruleset"); - - writer.openBlock( - "export const defaultEndpointResolver = ", - "", - () -> { writer.openBlock( - "(endpointParams: EndpointParameters, context: { logger?: Logger } = {}): EndpointV2 => {", - "};", + "export const defaultEndpointResolver = ", + "", () -> { writer.openBlock( - "return resolveEndpoint(ruleSet, {", - "});", + "(endpointParams: EndpointParameters, context: { logger?: Logger } = {}): EndpointV2 => {", + "};", () -> { - writer.write("endpointParams: endpointParams as EndpointParams,"); - writer.write("logger: context.logger,"); + writer.openBlock( + "return resolveEndpoint(ruleSet, {", + "});", + () -> { + writer.write("endpointParams: endpointParams as EndpointParams,"); + writer.write("logger: context.logger,"); + } + ); } ); } ); } ); - - fileManifest.writeFile( - Paths.get(CodegenUtils.SOURCE_FOLDER, ENDPOINT_FOLDER, "endpointResolver.ts").toString(), - writer.toString() - ); } /** * Generate the ruleset (dynamic resolution only). */ private void generateEndpointRuleset() { - TypeScriptWriter writer = new TypeScriptWriter(""); - - writer.addImport("RuleSetObject", null, "@aws-sdk/util-endpoints"); - - writer.openBlock( - "export const ruleSet: RuleSetObject = ", - "", - () -> { - new RuleSetSerializer( - endpointRuleSetTrait.getRuleSet(), - writer - ).generate(); - } - ); + this.delegator.useFileWriter( + Paths.get(CodegenUtils.SOURCE_FOLDER, ENDPOINT_FOLDER, ENDPOINT_RULESET_FILE).toString(), + writer -> { + writer.addImport("RuleSetObject", null, "@aws-sdk/util-endpoints"); + writer.openBlock( + "export const ruleSet: RuleSetObject = ", + "", + () -> { + new RuleSetSerializer( + endpointRuleSetTrait.getRuleSet(), + writer + ).generate(); + } + ); - fileManifest.writeFile( - Paths.get(CodegenUtils.SOURCE_FOLDER, ENDPOINT_FOLDER, "ruleset.ts").toString(), - writer.toString() + } ); } }