Skip to content

Commit

Permalink
feat(codegen): restore __ prefix on XmlNode, XmlText
Browse files Browse the repository at this point in the history
  • Loading branch information
kuhe committed Aug 1, 2022
1 parent 4ea8b6d commit 40d7d17
Show file tree
Hide file tree
Showing 18 changed files with 1,306 additions and 1,313 deletions.
756 changes: 380 additions & 376 deletions clients/client-cloudfront/src/protocols/Aws_restXml.ts

Large diffs are not rendered by default.

326 changes: 164 additions & 162 deletions clients/client-route-53/src/protocols/Aws_restXml.ts

Large diffs are not rendered by default.

534 changes: 267 additions & 267 deletions clients/client-s3-control/src/protocols/Aws_restXml.ts

Large diffs are not rendered by default.

628 changes: 317 additions & 311 deletions clients/client-s3/src/protocols/Aws_restXml.ts

Large diffs are not rendered by default.

18 changes: 0 additions & 18 deletions clients/client-shield/src/protocols/Aws_json1_1.ts
Expand Up @@ -3006,9 +3006,6 @@ const serializeAws_json1_1ProtectedResourceTypeFilters = (
return input
.filter((e: any) => e != null)
.map((entry) => {
if (entry === null) {
return null as any;
}
return entry;
});
};
Expand All @@ -3020,9 +3017,6 @@ const serializeAws_json1_1ProtectionGroupAggregationFilters = (
return input
.filter((e: any) => e != null)
.map((entry) => {
if (entry === null) {
return null as any;
}
return entry;
});
};
Expand All @@ -3031,9 +3025,6 @@ const serializeAws_json1_1ProtectionGroupIdFilters = (input: string[], context:
return input
.filter((e: any) => e != null)
.map((entry) => {
if (entry === null) {
return null as any;
}
return entry;
});
};
Expand All @@ -3053,9 +3044,6 @@ const serializeAws_json1_1ProtectionGroupPatternFilters = (
return input
.filter((e: any) => e != null)
.map((entry) => {
if (entry === null) {
return null as any;
}
return entry;
});
};
Expand All @@ -3064,9 +3052,6 @@ const serializeAws_json1_1ProtectionNameFilters = (input: string[], context: __S
return input
.filter((e: any) => e != null)
.map((entry) => {
if (entry === null) {
return null as any;
}
return entry;
});
};
Expand All @@ -3083,9 +3068,6 @@ const serializeAws_json1_1ResourceArnFilters = (input: string[], context: __Serd
return input
.filter((e: any) => e != null)
.map((entry) => {
if (entry === null) {
return null as any;
}
return entry;
});
};
Expand Down
16 changes: 5 additions & 11 deletions clients/client-workspaces/src/protocols/Aws_json1_1.ts
Expand Up @@ -3402,7 +3402,6 @@ const deserializeAws_json1_1ModifySamlPropertiesCommandError = async (
...output,
body: await parseBody(output.body, context),
};
let response: __BaseException;
const errorCode = loadRestJsonErrorCode(output, parsedOutput.body);
switch (errorCode) {
case "AccessDeniedException":
Expand All @@ -3419,14 +3418,12 @@ const deserializeAws_json1_1ModifySamlPropertiesCommandError = async (
throw await deserializeAws_json1_1ResourceNotFoundExceptionResponse(parsedOutput, context);
default:
const parsedBody = parsedOutput.body;
const $metadata = deserializeMetadata(output);
const statusCode = $metadata.httpStatusCode ? $metadata.httpStatusCode + "" : undefined;
response = new __BaseException({
name: parsedBody.code || parsedBody.Code || errorCode || statusCode || "UnknowError",
$fault: "client",
$metadata,
throwDefaultError({
output,
parsedBody,
exceptionCtor: __BaseException,
errorCode,
});
throw __decorateServiceException(response, parsedBody);
}
};

Expand Down Expand Up @@ -4656,9 +4653,6 @@ const serializeAws_json1_1DeletableSamlPropertiesList = (
return input
.filter((e: any) => e != null)
.map((entry) => {
if (entry === null) {
return null as any;
}
return entry;
});
};
Expand Down
Expand Up @@ -194,14 +194,14 @@ private void serializeDocumentBody(
// Start with the XML declaration.
writer.write("body = \"<?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?>\";");

writer.addImport("XmlNode", "XmlNode", "@aws-sdk/xml-builder");
writer.addImport("XmlNode", "__XmlNode", "@aws-sdk/xml-builder");

// Handle the @xmlName trait for the input shape.
StructureShape inputShape = context.getModel().expectShape(inputShapeId, StructureShape.class);
String nodeName = inputShape.getTrait(XmlNameTrait.class)
.map(XmlNameTrait::getValue)
.orElse(inputShapeId.getName(serviceShape));
writer.write("const bodyNode = new XmlNode($S);", nodeName);
writer.write("const bodyNode = new __XmlNode($S);", nodeName);

// Add @xmlNamespace value of the service to the root node,
// fall back to one from the input shape.
Expand Down
Expand Up @@ -119,9 +119,9 @@ String getAsXmlText(Shape shape, String dataSource) {
.orElse(shape.getId().getName(context.getService()));

TypeScriptWriter writer = getContext().getWriter();
writer.addImport("XmlNode", "XmlNode", "@aws-sdk/xml-builder");
writer.addImport("XmlText", "XmlText", "@aws-sdk/xml-builder");
return "XmlNode.of(\"" + nodeName + "\", " + dataSource + ")";
writer.addImport("XmlNode", "__XmlNode", "@aws-sdk/xml-builder");
writer.addImport("XmlText", "__XmlText", "@aws-sdk/xml-builder");
return "__XmlNode.of(\"" + nodeName + "\", " + dataSource + ")";
}

@Override
Expand Down
Expand Up @@ -67,7 +67,7 @@ protected void serializeCollection(GenerationContext context, CollectionShape sh
TypeScriptWriter writer = context.getWriter();
MemberShape memberShape = shape.getMember();
Shape target = context.getModel().expectShape(memberShape.getTarget());
writer.addImport("XmlNode", "XmlNode", "@aws-sdk/xml-builder");
writer.addImport("XmlNode", "__XmlNode", "@aws-sdk/xml-builder");

// Use the @xmlName trait if present on the member, otherwise use "member".
String locationName = memberShape.getTrait(XmlNameTrait.class)
Expand All @@ -91,12 +91,12 @@ protected void serializeCollection(GenerationContext context, CollectionShape sh
writer.write("const node = $L;", target.accept(getMemberVisitor("entry")));
// Handle proper unwrapping of target nodes.
if (serializationReturnsArray(target)) {
writer.openBlock("return node.reduce((acc: XmlNode, workingNode: any) => {", "}", () -> {
writer.openBlock("return node.reduce((acc: __XmlNode, workingNode: any) => {", "}", () -> {
// Add @xmlNamespace value of the target member.
AwsProtocolUtils.writeXmlNamespace(context, memberShape, "workingNode");
writer.write("return acc.addChildNode(workingNode);");
});
writer.write(", new XmlNode($S));", locationName);
writer.write(", new __XmlNode($S));", locationName);
} else {
// Add @xmlNamespace value of the target member.
AwsProtocolUtils.writeXmlNamespace(context, memberShape, "node");
Expand All @@ -115,7 +115,7 @@ protected void serializeDocument(GenerationContext context, DocumentShape shape)
protected void serializeMap(GenerationContext context, MapShape shape) {
TypeScriptWriter writer = context.getWriter();
Model model = context.getModel();
writer.addImport("XmlNode", "XmlNode", "@aws-sdk/xml-builder");
writer.addImport("XmlNode", "__XmlNode", "@aws-sdk/xml-builder");

// Filter out null entries if we don't have the sparse trait.
String potentialFilter = "";
Expand All @@ -126,7 +126,7 @@ protected void serializeMap(GenerationContext context, MapShape shape) {
// Use the keys as an iteration point to dispatch to the input value providers.
writer.openBlock("return Object.keys(input)$L.map(key => {", "});", potentialFilter, () -> {
// Prepare a containing node for each entry's k/v pair.
writer.write("const entryNode = new XmlNode(\"entry\");");
writer.write("const entryNode = new __XmlNode(\"entry\");");

// Prepare the key's node.
// Use the @xmlName trait if present on the member, otherwise use "key".
Expand Down Expand Up @@ -154,7 +154,7 @@ protected void serializeMap(GenerationContext context, MapShape shape) {
writer.write("var node;");
if (shape.hasTrait(SparseTrait.ID)) {
writer.openBlock("if (value === null) {", "} else {", () ->
writer.write("node = XmlNode.of($S, null);", valueName));
writer.write("node = __XmlNode.of($S, null);", valueName));
writer.indent();
}

Expand All @@ -169,12 +169,12 @@ protected void serializeMap(GenerationContext context, MapShape shape) {
// Handle proper unwrapping of target nodes.
if (serializationReturnsArray(valueTarget)) {
writer.openBlock("entryNode.addChildNode(", ");", () -> {
writer.openBlock("node.reduce((acc: XmlNode, workingNode: any) => {", "}", () -> {
writer.openBlock("node.reduce((acc: __XmlNode, workingNode: any) => {", "}", () -> {
// Add @xmlNamespace value of the value member.
AwsProtocolUtils.writeXmlNamespace(context, valueMember, "workingNode");
writer.write("return acc.addChildNode(workingNode);");
});
writer.write(", new XmlNode($S))", valueName);
writer.write(", new __XmlNode($S))", valueName);
});
} else {
// Add @xmlNamespace value of the target member.
Expand All @@ -190,15 +190,15 @@ protected void serializeMap(GenerationContext context, MapShape shape) {
protected void serializeStructure(GenerationContext context, StructureShape shape) {
TypeScriptWriter writer = context.getWriter();
ServiceShape serviceShape = context.getService();
writer.addImport("XmlNode", "XmlNode", "@aws-sdk/xml-builder");
writer.addImport("XmlNode", "__XmlNode", "@aws-sdk/xml-builder");

// Handle the @xmlName trait for the structure itself.
String nodeName = shape.getTrait(XmlNameTrait.class)
.map(XmlNameTrait::getValue)
.orElse(shape.getId().getName(serviceShape));

// Create the structure's node.
writer.write("const bodyNode = new XmlNode($S);", nodeName);
writer.write("const bodyNode = new __XmlNode($S);", nodeName);

// Serialize every member of the structure if present.
Map<String, MemberShape> members = shape.getAllMembers();
Expand Down Expand Up @@ -277,7 +277,7 @@ private void serializeNamedMemberFromArray(

// Prepare a containing node to hold the nodes if not flattened.
if (!isFlattened) {
writer.write("const containerNode = new XmlNode($S);", locationName);
writer.write("const containerNode = new __XmlNode($S);", locationName);
// Add @xmlNamespace value of the target member.
AwsProtocolUtils.writeXmlNamespace(context, memberShape, "containerNode");
}
Expand Down Expand Up @@ -306,16 +306,16 @@ private boolean serializationReturnsArray(Shape shape) {
protected void serializeUnion(GenerationContext context, UnionShape shape) {
TypeScriptWriter writer = context.getWriter();
ServiceShape serviceShape = context.getService();
writer.addImport("XmlNode", "XmlNode", "@aws-sdk/xml-builder");
writer.addImport("XmlText", "XmlText", "@aws-sdk/xml-builder");
writer.addImport("XmlNode", "__XmlNode", "@aws-sdk/xml-builder");
writer.addImport("XmlText", "__XmlText", "@aws-sdk/xml-builder");

// Handle the @xmlName trait for the union itself.
String nodeName = shape.getTrait(XmlNameTrait.class)
.map(XmlNameTrait::getValue)
.orElse(shape.getId().getName(serviceShape));

// Create the union's node.
writer.write("const bodyNode = new XmlNode($S);", nodeName);
writer.write("const bodyNode = new __XmlNode($S);", nodeName);

// Visit over the union type, then get the right serialization for the member.
writer.openBlock("$L.visit(input, {", "});", shape.getId().getName(serviceShape), () -> {
Expand All @@ -329,12 +329,12 @@ protected void serializeUnion(GenerationContext context, UnionShape shape) {
// Handle the unknown property.
writer.openBlock("_: (name: string, value: any) => {", "}", () -> {
// Throw an exception if we're trying to serialize something that we wouldn't know how to.
writer.openBlock("if (!(value instanceof XmlNode || value instanceof XmlText)) {", "}", () -> {
writer.openBlock("if (!(value instanceof __XmlNode || value instanceof __XmlText)) {", "}", () -> {
writer.write("throw new Error(\"Unable to serialize unknown union members in XML.\");");
});

// Set the node explicitly for potentially correct cases.
writer.write("bodyNode.addChildNode(new XmlNode(name).addChildNode(value));");
writer.write("bodyNode.addChildNode(new __XmlNode(name).addChildNode(value));");
});
});

Expand Down
2 changes: 2 additions & 0 deletions packages/smithy-client/src/default-error-handler.ts
Expand Up @@ -5,6 +5,8 @@ import { decorateServiceException } from "./exceptions";
/**
* Always throws an error with the given {@param exceptionCtor} and other arguments.
* This is only called from an error handling code path.
* @private
* @internal
*/
export const throwDefaultError = ({ output, parsedBody, exceptionCtor, errorCode }: any) => {
const $metadata = deserializeMetadata(output);
Expand Down
3 changes: 3 additions & 0 deletions packages/smithy-client/src/object-mapping.ts
Expand Up @@ -102,6 +102,7 @@ export type Value = any;
*
* @see ObjectMappingInstructions for an example.
* @private
* @internal
*/
export function map(
target: any,
Expand Down Expand Up @@ -167,6 +168,7 @@ export function map(arg0: any, arg1?: any, arg2?: any): any {
* filter.
*
* @private
* @internal
*/
export const convertMap = (target: any): Record<string, any> => {
const output: Record<string, any> = {};
Expand All @@ -184,6 +186,7 @@ export const convertMap = (target: any): Record<string, any> => {
* @param instructions - map of keys and values/suppliers (will be evaluated)
*
* @private
* @internal
*/
const mapWithFilter = (
target: any,
Expand Down
2 changes: 1 addition & 1 deletion private/aws-protocoltests-ec2/README.md
Expand Up @@ -165,7 +165,7 @@ try {
const data = await client.send(command);
// process data.
} catch (error) {
const { requestId, cfId, extendedRequestId } = error.$metadata;
const { requestId, cfId, extendedRequestId } = error.$$metadata;
console.log({ requestId, cfId, extendedRequestId });
/**
* The keys within exceptions are also parsed.
Expand Down
2 changes: 1 addition & 1 deletion private/aws-protocoltests-json-10/README.md
Expand Up @@ -163,7 +163,7 @@ try {
const data = await client.send(command);
// process data.
} catch (error) {
const { requestId, cfId, extendedRequestId } = error.$metadata;
const { requestId, cfId, extendedRequestId } = error.$$metadata;
console.log({ requestId, cfId, extendedRequestId });
/**
* The keys within exceptions are also parsed.
Expand Down
2 changes: 1 addition & 1 deletion private/aws-protocoltests-json/README.md
Expand Up @@ -163,7 +163,7 @@ try {
const data = await client.send(command);
// process data.
} catch (error) {
const { requestId, cfId, extendedRequestId } = error.$metadata;
const { requestId, cfId, extendedRequestId } = error.$$metadata;
console.log({ requestId, cfId, extendedRequestId });
/**
* The keys within exceptions are also parsed.
Expand Down
2 changes: 1 addition & 1 deletion private/aws-protocoltests-query/README.md
Expand Up @@ -165,7 +165,7 @@ try {
const data = await client.send(command);
// process data.
} catch (error) {
const { requestId, cfId, extendedRequestId } = error.$metadata;
const { requestId, cfId, extendedRequestId } = error.$$metadata;
console.log({ requestId, cfId, extendedRequestId });
/**
* The keys within exceptions are also parsed.
Expand Down
2 changes: 1 addition & 1 deletion private/aws-protocoltests-restjson/README.md
Expand Up @@ -165,7 +165,7 @@ try {
const data = await client.send(command);
// process data.
} catch (error) {
const { requestId, cfId, extendedRequestId } = error.$metadata;
const { requestId, cfId, extendedRequestId } = error.$$metadata;
console.log({ requestId, cfId, extendedRequestId });
/**
* The keys within exceptions are also parsed.
Expand Down
2 changes: 1 addition & 1 deletion private/aws-protocoltests-restxml/README.md
Expand Up @@ -165,7 +165,7 @@ try {
const data = await client.send(command);
// process data.
} catch (error) {
const { requestId, cfId, extendedRequestId } = error.$metadata;
const { requestId, cfId, extendedRequestId } = error.$$metadata;
console.log({ requestId, cfId, extendedRequestId });
/**
* The keys within exceptions are also parsed.
Expand Down

0 comments on commit 40d7d17

Please sign in to comment.