@aws-sdk/core 3.873.0 → 3.879.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist-cjs/submodules/protocols/index.js +361 -224
- package/dist-es/submodules/protocols/ProtocolLib.js +94 -0
- package/dist-es/submodules/protocols/cbor/AwsSmithyRpcV2CborProtocol.js +39 -0
- package/dist-es/submodules/protocols/common.js +2 -1
- package/dist-es/submodules/protocols/index.js +1 -0
- package/dist-es/submodules/protocols/json/AwsJson1_0Protocol.js +2 -1
- package/dist-es/submodules/protocols/json/AwsJson1_1Protocol.js +2 -1
- package/dist-es/submodules/protocols/json/AwsJsonRpcProtocol.js +19 -29
- package/dist-es/submodules/protocols/json/AwsRestJsonProtocol.js +10 -54
- package/dist-es/submodules/protocols/query/AwsQueryProtocol.js +9 -32
- package/dist-es/submodules/protocols/xml/AwsRestXmlProtocol.js +11 -62
- package/dist-es/submodules/protocols/xml/XmlShapeSerializer.js +3 -3
- package/dist-types/submodules/protocols/ProtocolLib.d.ts +57 -0
- package/dist-types/submodules/protocols/cbor/AwsSmithyRpcV2CborProtocol.d.ts +23 -0
- package/dist-types/submodules/protocols/index.d.ts +1 -0
- package/dist-types/submodules/protocols/json/AwsJson1_0Protocol.d.ts +2 -1
- package/dist-types/submodules/protocols/json/AwsJson1_1Protocol.d.ts +2 -1
- package/dist-types/submodules/protocols/json/AwsJsonRpcProtocol.d.ts +6 -3
- package/dist-types/submodules/protocols/json/AwsRestJsonProtocol.d.ts +2 -1
- package/dist-types/submodules/protocols/query/AwsQueryProtocol.d.ts +2 -2
- package/dist-types/submodules/protocols/xml/AwsRestXmlProtocol.d.ts +1 -0
- package/dist-types/ts3.4/submodules/protocols/ProtocolLib.d.ts +39 -0
- package/dist-types/ts3.4/submodules/protocols/cbor/AwsSmithyRpcV2CborProtocol.d.ts +33 -0
- package/dist-types/ts3.4/submodules/protocols/index.d.ts +1 -0
- package/dist-types/ts3.4/submodules/protocols/json/AwsJson1_0Protocol.d.ts +2 -0
- package/dist-types/ts3.4/submodules/protocols/json/AwsJson1_1Protocol.d.ts +2 -0
- package/dist-types/ts3.4/submodules/protocols/json/AwsJsonRpcProtocol.d.ts +5 -1
- package/dist-types/ts3.4/submodules/protocols/json/AwsRestJsonProtocol.d.ts +1 -0
- package/dist-types/ts3.4/submodules/protocols/query/AwsQueryProtocol.d.ts +2 -1
- package/dist-types/ts3.4/submodules/protocols/xml/AwsRestXmlProtocol.d.ts +1 -0
- package/package.json +3 -3
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { TypeRegistry } from "@smithy/core/schema";
|
|
2
|
+
import { calculateBodyLength } from "@smithy/util-body-length-browser";
|
|
3
|
+
export class ProtocolLib {
|
|
4
|
+
calculateContentLength(body, serdeContext) {
|
|
5
|
+
const bodyLengthCalculator = serdeContext?.bodyLengthChecker ?? calculateBodyLength;
|
|
6
|
+
return String(bodyLengthCalculator(body));
|
|
7
|
+
}
|
|
8
|
+
resolveRestContentType(defaultContentType, inputSchema) {
|
|
9
|
+
const members = inputSchema.getMemberSchemas();
|
|
10
|
+
const httpPayloadMember = Object.values(members).find((m) => {
|
|
11
|
+
return !!m.getMergedTraits().httpPayload;
|
|
12
|
+
});
|
|
13
|
+
if (httpPayloadMember) {
|
|
14
|
+
const mediaType = httpPayloadMember.getMergedTraits().mediaType;
|
|
15
|
+
if (mediaType) {
|
|
16
|
+
return mediaType;
|
|
17
|
+
}
|
|
18
|
+
else if (httpPayloadMember.isStringSchema()) {
|
|
19
|
+
return "text/plain";
|
|
20
|
+
}
|
|
21
|
+
else if (httpPayloadMember.isBlobSchema()) {
|
|
22
|
+
return "application/octet-stream";
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
25
|
+
return defaultContentType;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
else if (!inputSchema.isUnitSchema()) {
|
|
29
|
+
const hasBody = Object.values(members).find((m) => {
|
|
30
|
+
const { httpQuery, httpQueryParams, httpHeader, httpLabel, httpPrefixHeaders } = m.getMergedTraits();
|
|
31
|
+
return !httpQuery && !httpQueryParams && !httpHeader && !httpLabel && httpPrefixHeaders === void 0;
|
|
32
|
+
});
|
|
33
|
+
if (hasBody) {
|
|
34
|
+
return defaultContentType;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
async getErrorSchemaOrThrowBaseException(errorIdentifier, defaultNamespace, response, dataObject, metadata, getErrorSchema) {
|
|
39
|
+
let namespace = defaultNamespace;
|
|
40
|
+
let errorName = errorIdentifier;
|
|
41
|
+
if (errorIdentifier.includes("#")) {
|
|
42
|
+
[namespace, errorName] = errorIdentifier.split("#");
|
|
43
|
+
}
|
|
44
|
+
const errorMetadata = {
|
|
45
|
+
$metadata: metadata,
|
|
46
|
+
$response: response,
|
|
47
|
+
$fault: response.statusCode < 500 ? "client" : "server",
|
|
48
|
+
};
|
|
49
|
+
const registry = TypeRegistry.for(namespace);
|
|
50
|
+
try {
|
|
51
|
+
const errorSchema = getErrorSchema?.(registry, errorName) ?? registry.getSchema(errorIdentifier);
|
|
52
|
+
return { errorSchema, errorMetadata };
|
|
53
|
+
}
|
|
54
|
+
catch (e) {
|
|
55
|
+
if (dataObject.Message) {
|
|
56
|
+
dataObject.message = dataObject.Message;
|
|
57
|
+
}
|
|
58
|
+
const baseExceptionSchema = TypeRegistry.for("smithy.ts.sdk.synthetic." + namespace).getBaseException();
|
|
59
|
+
if (baseExceptionSchema) {
|
|
60
|
+
const ErrorCtor = baseExceptionSchema.ctor;
|
|
61
|
+
throw Object.assign(new ErrorCtor({ name: errorName }), errorMetadata, dataObject);
|
|
62
|
+
}
|
|
63
|
+
throw Object.assign(new Error(errorName), errorMetadata, dataObject);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
setQueryCompatError(output, response) {
|
|
67
|
+
const queryErrorHeader = response.headers?.["x-amzn-query-error"];
|
|
68
|
+
if (output !== undefined && queryErrorHeader != null) {
|
|
69
|
+
const [Code, Type] = queryErrorHeader.split(";");
|
|
70
|
+
const entries = Object.entries(output);
|
|
71
|
+
const Error = {
|
|
72
|
+
Code,
|
|
73
|
+
Type,
|
|
74
|
+
};
|
|
75
|
+
Object.assign(output, Error);
|
|
76
|
+
for (const [k, v] of entries) {
|
|
77
|
+
Error[k] = v;
|
|
78
|
+
}
|
|
79
|
+
delete Error.__type;
|
|
80
|
+
output.Error = Error;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
queryCompatOutput(queryCompatErrorData, errorData) {
|
|
84
|
+
if (queryCompatErrorData.Error) {
|
|
85
|
+
errorData.Error = queryCompatErrorData.Error;
|
|
86
|
+
}
|
|
87
|
+
if (queryCompatErrorData.Type) {
|
|
88
|
+
errorData.Type = queryCompatErrorData.Type;
|
|
89
|
+
}
|
|
90
|
+
if (queryCompatErrorData.Code) {
|
|
91
|
+
errorData.Code = queryCompatErrorData.Code;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { loadSmithyRpcV2CborErrorCode, SmithyRpcV2CborProtocol } from "@smithy/core/cbor";
|
|
2
|
+
import { NormalizedSchema } from "@smithy/core/schema";
|
|
3
|
+
import { ProtocolLib } from "../ProtocolLib";
|
|
4
|
+
export class AwsSmithyRpcV2CborProtocol extends SmithyRpcV2CborProtocol {
|
|
5
|
+
awsQueryCompatible;
|
|
6
|
+
mixin = new ProtocolLib();
|
|
7
|
+
constructor({ defaultNamespace, awsQueryCompatible, }) {
|
|
8
|
+
super({ defaultNamespace });
|
|
9
|
+
this.awsQueryCompatible = !!awsQueryCompatible;
|
|
10
|
+
}
|
|
11
|
+
async serializeRequest(operationSchema, input, context) {
|
|
12
|
+
const request = await super.serializeRequest(operationSchema, input, context);
|
|
13
|
+
if (this.awsQueryCompatible) {
|
|
14
|
+
request.headers["x-amzn-query-mode"] = "true";
|
|
15
|
+
}
|
|
16
|
+
return request;
|
|
17
|
+
}
|
|
18
|
+
async handleError(operationSchema, context, response, dataObject, metadata) {
|
|
19
|
+
if (this.awsQueryCompatible) {
|
|
20
|
+
this.mixin.setQueryCompatError(dataObject, response);
|
|
21
|
+
}
|
|
22
|
+
const errorName = loadSmithyRpcV2CborErrorCode(response, dataObject) ?? "Unknown";
|
|
23
|
+
const { errorSchema, errorMetadata } = await this.mixin.getErrorSchemaOrThrowBaseException(errorName, this.options.defaultNamespace, response, dataObject, metadata);
|
|
24
|
+
const ns = NormalizedSchema.of(errorSchema);
|
|
25
|
+
const message = dataObject.message ?? dataObject.Message ?? "Unknown";
|
|
26
|
+
const exception = new errorSchema.ctor(message);
|
|
27
|
+
const output = {};
|
|
28
|
+
for (const [name, member] of ns.structIterator()) {
|
|
29
|
+
output[name] = this.deserializer.readValue(member, dataObject[name]);
|
|
30
|
+
}
|
|
31
|
+
if (this.awsQueryCompatible) {
|
|
32
|
+
this.mixin.queryCompatOutput(dataObject, output);
|
|
33
|
+
}
|
|
34
|
+
throw Object.assign(exception, errorMetadata, {
|
|
35
|
+
$fault: ns.getMergedTraits().error,
|
|
36
|
+
message,
|
|
37
|
+
}, output);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
@@ -1,2 +1,3 @@
|
|
|
1
1
|
import { collectBody } from "@smithy/smithy-client";
|
|
2
|
-
|
|
2
|
+
import { toUtf8 } from "@smithy/util-utf8";
|
|
3
|
+
export const collectBodyString = (streamBody, context) => collectBody(streamBody, context).then((body) => (context?.utf8Encoder ?? toUtf8)(body));
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { AwsJsonRpcProtocol } from "./AwsJsonRpcProtocol";
|
|
2
2
|
export class AwsJson1_0Protocol extends AwsJsonRpcProtocol {
|
|
3
|
-
constructor({ defaultNamespace, serviceTarget }) {
|
|
3
|
+
constructor({ defaultNamespace, serviceTarget, awsQueryCompatible, }) {
|
|
4
4
|
super({
|
|
5
5
|
defaultNamespace,
|
|
6
6
|
serviceTarget,
|
|
7
|
+
awsQueryCompatible,
|
|
7
8
|
});
|
|
8
9
|
}
|
|
9
10
|
getShapeId() {
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { AwsJsonRpcProtocol } from "./AwsJsonRpcProtocol";
|
|
2
2
|
export class AwsJson1_1Protocol extends AwsJsonRpcProtocol {
|
|
3
|
-
constructor({ defaultNamespace, serviceTarget }) {
|
|
3
|
+
constructor({ defaultNamespace, serviceTarget, awsQueryCompatible, }) {
|
|
4
4
|
super({
|
|
5
5
|
defaultNamespace,
|
|
6
6
|
serviceTarget,
|
|
7
|
+
awsQueryCompatible,
|
|
7
8
|
});
|
|
8
9
|
}
|
|
9
10
|
getShapeId() {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { RpcProtocol } from "@smithy/core/protocols";
|
|
2
|
-
import { deref, NormalizedSchema, SCHEMA
|
|
3
|
-
import {
|
|
2
|
+
import { deref, NormalizedSchema, SCHEMA } from "@smithy/core/schema";
|
|
3
|
+
import { ProtocolLib } from "../ProtocolLib";
|
|
4
4
|
import { JsonCodec } from "./JsonCodec";
|
|
5
5
|
import { loadRestJsonErrorCode } from "./parseJsonBody";
|
|
6
6
|
export class AwsJsonRpcProtocol extends RpcProtocol {
|
|
@@ -8,7 +8,9 @@ export class AwsJsonRpcProtocol extends RpcProtocol {
|
|
|
8
8
|
deserializer;
|
|
9
9
|
serviceTarget;
|
|
10
10
|
codec;
|
|
11
|
-
|
|
11
|
+
mixin = new ProtocolLib();
|
|
12
|
+
awsQueryCompatible;
|
|
13
|
+
constructor({ defaultNamespace, serviceTarget, awsQueryCompatible, }) {
|
|
12
14
|
super({
|
|
13
15
|
defaultNamespace,
|
|
14
16
|
});
|
|
@@ -22,6 +24,7 @@ export class AwsJsonRpcProtocol extends RpcProtocol {
|
|
|
22
24
|
});
|
|
23
25
|
this.serializer = this.codec.createSerializer();
|
|
24
26
|
this.deserializer = this.codec.createDeserializer();
|
|
27
|
+
this.awsQueryCompatible = !!awsQueryCompatible;
|
|
25
28
|
}
|
|
26
29
|
async serializeRequest(operationSchema, input, context) {
|
|
27
30
|
const request = await super.serializeRequest(operationSchema, input, context);
|
|
@@ -32,11 +35,14 @@ export class AwsJsonRpcProtocol extends RpcProtocol {
|
|
|
32
35
|
"content-type": `application/x-amz-json-${this.getJsonRpcVersion()}`,
|
|
33
36
|
"x-amz-target": `${this.serviceTarget}.${NormalizedSchema.of(operationSchema).getName()}`,
|
|
34
37
|
});
|
|
38
|
+
if (this.awsQueryCompatible) {
|
|
39
|
+
request.headers["x-amzn-query-mode"] = "true";
|
|
40
|
+
}
|
|
35
41
|
if (deref(operationSchema.input) === "unit" || !request.body) {
|
|
36
42
|
request.body = "{}";
|
|
37
43
|
}
|
|
38
44
|
try {
|
|
39
|
-
request.headers["content-length"] =
|
|
45
|
+
request.headers["content-length"] = this.mixin.calculateContentLength(request.body, this.serdeContext);
|
|
40
46
|
}
|
|
41
47
|
catch (e) { }
|
|
42
48
|
return request;
|
|
@@ -45,41 +51,25 @@ export class AwsJsonRpcProtocol extends RpcProtocol {
|
|
|
45
51
|
return this.codec;
|
|
46
52
|
}
|
|
47
53
|
async handleError(operationSchema, context, response, dataObject, metadata) {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
let errorName = errorIdentifier;
|
|
51
|
-
if (errorIdentifier.includes("#")) {
|
|
52
|
-
[namespace, errorName] = errorIdentifier.split("#");
|
|
53
|
-
}
|
|
54
|
-
const registry = TypeRegistry.for(namespace);
|
|
55
|
-
let errorSchema;
|
|
56
|
-
try {
|
|
57
|
-
errorSchema = registry.getSchema(errorIdentifier);
|
|
58
|
-
}
|
|
59
|
-
catch (e) {
|
|
60
|
-
const baseExceptionSchema = TypeRegistry.for("smithy.ts.sdk.synthetic." + namespace).getBaseException();
|
|
61
|
-
if (baseExceptionSchema) {
|
|
62
|
-
const ErrorCtor = baseExceptionSchema.ctor;
|
|
63
|
-
throw Object.assign(new ErrorCtor(errorName), dataObject);
|
|
64
|
-
}
|
|
65
|
-
throw new Error(errorName);
|
|
54
|
+
if (this.awsQueryCompatible) {
|
|
55
|
+
this.mixin.setQueryCompatError(dataObject, response);
|
|
66
56
|
}
|
|
57
|
+
const errorIdentifier = loadRestJsonErrorCode(response, dataObject) ?? "Unknown";
|
|
58
|
+
const { errorSchema, errorMetadata } = await this.mixin.getErrorSchemaOrThrowBaseException(errorIdentifier, this.options.defaultNamespace, response, dataObject, metadata);
|
|
67
59
|
const ns = NormalizedSchema.of(errorSchema);
|
|
68
60
|
const message = dataObject.message ?? dataObject.Message ?? "Unknown";
|
|
69
61
|
const exception = new errorSchema.ctor(message);
|
|
70
|
-
await this.deserializeHttpMessage(errorSchema, context, response, dataObject);
|
|
71
62
|
const output = {};
|
|
72
63
|
for (const [name, member] of ns.structIterator()) {
|
|
73
64
|
const target = member.getMergedTraits().jsonName ?? name;
|
|
74
65
|
output[name] = this.codec.createDeserializer().readObject(member, dataObject[target]);
|
|
75
66
|
}
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
67
|
+
if (this.awsQueryCompatible) {
|
|
68
|
+
this.mixin.queryCompatOutput(dataObject, output);
|
|
69
|
+
}
|
|
70
|
+
throw Object.assign(exception, errorMetadata, {
|
|
79
71
|
$fault: ns.getMergedTraits().error,
|
|
80
72
|
message,
|
|
81
|
-
|
|
82
|
-
});
|
|
83
|
-
throw exception;
|
|
73
|
+
}, output);
|
|
84
74
|
}
|
|
85
75
|
}
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { HttpBindingProtocol, HttpInterceptingShapeDeserializer, HttpInterceptingShapeSerializer, } from "@smithy/core/protocols";
|
|
2
|
-
import { NormalizedSchema, SCHEMA
|
|
3
|
-
import {
|
|
2
|
+
import { NormalizedSchema, SCHEMA } from "@smithy/core/schema";
|
|
3
|
+
import { ProtocolLib } from "../ProtocolLib";
|
|
4
4
|
import { JsonCodec } from "./JsonCodec";
|
|
5
5
|
import { loadRestJsonErrorCode } from "./parseJsonBody";
|
|
6
6
|
export class AwsRestJsonProtocol extends HttpBindingProtocol {
|
|
7
7
|
serializer;
|
|
8
8
|
deserializer;
|
|
9
9
|
codec;
|
|
10
|
+
mixin = new ProtocolLib();
|
|
10
11
|
constructor({ defaultNamespace }) {
|
|
11
12
|
super({
|
|
12
13
|
defaultNamespace,
|
|
@@ -36,34 +37,10 @@ export class AwsRestJsonProtocol extends HttpBindingProtocol {
|
|
|
36
37
|
async serializeRequest(operationSchema, input, context) {
|
|
37
38
|
const request = await super.serializeRequest(operationSchema, input, context);
|
|
38
39
|
const inputSchema = NormalizedSchema.of(operationSchema.input);
|
|
39
|
-
const members = inputSchema.getMemberSchemas();
|
|
40
40
|
if (!request.headers["content-type"]) {
|
|
41
|
-
const
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
if (httpPayloadMember) {
|
|
45
|
-
const mediaType = httpPayloadMember.getMergedTraits().mediaType;
|
|
46
|
-
if (mediaType) {
|
|
47
|
-
request.headers["content-type"] = mediaType;
|
|
48
|
-
}
|
|
49
|
-
else if (httpPayloadMember.isStringSchema()) {
|
|
50
|
-
request.headers["content-type"] = "text/plain";
|
|
51
|
-
}
|
|
52
|
-
else if (httpPayloadMember.isBlobSchema()) {
|
|
53
|
-
request.headers["content-type"] = "application/octet-stream";
|
|
54
|
-
}
|
|
55
|
-
else {
|
|
56
|
-
request.headers["content-type"] = this.getDefaultContentType();
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
else if (!inputSchema.isUnitSchema()) {
|
|
60
|
-
const hasBody = Object.values(members).find((m) => {
|
|
61
|
-
const { httpQuery, httpQueryParams, httpHeader, httpLabel, httpPrefixHeaders } = m.getMergedTraits();
|
|
62
|
-
return !httpQuery && !httpQueryParams && !httpHeader && !httpLabel && httpPrefixHeaders === void 0;
|
|
63
|
-
});
|
|
64
|
-
if (hasBody) {
|
|
65
|
-
request.headers["content-type"] = this.getDefaultContentType();
|
|
66
|
-
}
|
|
41
|
+
const contentType = this.mixin.resolveRestContentType(this.getDefaultContentType(), inputSchema);
|
|
42
|
+
if (contentType) {
|
|
43
|
+
request.headers["content-type"] = contentType;
|
|
67
44
|
}
|
|
68
45
|
}
|
|
69
46
|
if (request.headers["content-type"] && !request.body) {
|
|
@@ -71,7 +48,7 @@ export class AwsRestJsonProtocol extends HttpBindingProtocol {
|
|
|
71
48
|
}
|
|
72
49
|
if (request.body) {
|
|
73
50
|
try {
|
|
74
|
-
request.headers["content-length"] =
|
|
51
|
+
request.headers["content-length"] = this.mixin.calculateContentLength(request.body, this.serdeContext);
|
|
75
52
|
}
|
|
76
53
|
catch (e) { }
|
|
77
54
|
}
|
|
@@ -79,24 +56,7 @@ export class AwsRestJsonProtocol extends HttpBindingProtocol {
|
|
|
79
56
|
}
|
|
80
57
|
async handleError(operationSchema, context, response, dataObject, metadata) {
|
|
81
58
|
const errorIdentifier = loadRestJsonErrorCode(response, dataObject) ?? "Unknown";
|
|
82
|
-
|
|
83
|
-
let errorName = errorIdentifier;
|
|
84
|
-
if (errorIdentifier.includes("#")) {
|
|
85
|
-
[namespace, errorName] = errorIdentifier.split("#");
|
|
86
|
-
}
|
|
87
|
-
const registry = TypeRegistry.for(namespace);
|
|
88
|
-
let errorSchema;
|
|
89
|
-
try {
|
|
90
|
-
errorSchema = registry.getSchema(errorIdentifier);
|
|
91
|
-
}
|
|
92
|
-
catch (e) {
|
|
93
|
-
const baseExceptionSchema = TypeRegistry.for("smithy.ts.sdk.synthetic." + namespace).getBaseException();
|
|
94
|
-
if (baseExceptionSchema) {
|
|
95
|
-
const ErrorCtor = baseExceptionSchema.ctor;
|
|
96
|
-
throw Object.assign(new ErrorCtor(errorName), dataObject);
|
|
97
|
-
}
|
|
98
|
-
throw new Error(errorName);
|
|
99
|
-
}
|
|
59
|
+
const { errorSchema, errorMetadata } = await this.mixin.getErrorSchemaOrThrowBaseException(errorIdentifier, this.options.defaultNamespace, response, dataObject, metadata);
|
|
100
60
|
const ns = NormalizedSchema.of(errorSchema);
|
|
101
61
|
const message = dataObject.message ?? dataObject.Message ?? "Unknown";
|
|
102
62
|
const exception = new errorSchema.ctor(message);
|
|
@@ -106,14 +66,10 @@ export class AwsRestJsonProtocol extends HttpBindingProtocol {
|
|
|
106
66
|
const target = member.getMergedTraits().jsonName ?? name;
|
|
107
67
|
output[name] = this.codec.createDeserializer().readObject(member, dataObject[target]);
|
|
108
68
|
}
|
|
109
|
-
Object.assign(exception, {
|
|
110
|
-
$metadata: metadata,
|
|
111
|
-
$response: response,
|
|
69
|
+
throw Object.assign(exception, errorMetadata, {
|
|
112
70
|
$fault: ns.getMergedTraits().error,
|
|
113
71
|
message,
|
|
114
|
-
|
|
115
|
-
});
|
|
116
|
-
throw exception;
|
|
72
|
+
}, output);
|
|
117
73
|
}
|
|
118
74
|
getDefaultContentType() {
|
|
119
75
|
return "application/json";
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { collectBody, RpcProtocol } from "@smithy/core/protocols";
|
|
2
|
-
import { deref, NormalizedSchema, SCHEMA
|
|
3
|
-
import {
|
|
2
|
+
import { deref, NormalizedSchema, SCHEMA } from "@smithy/core/schema";
|
|
3
|
+
import { ProtocolLib } from "../ProtocolLib";
|
|
4
4
|
import { XmlShapeDeserializer } from "../xml/XmlShapeDeserializer";
|
|
5
5
|
import { QueryShapeSerializer } from "./QueryShapeSerializer";
|
|
6
6
|
export class AwsQueryProtocol extends RpcProtocol {
|
|
7
7
|
options;
|
|
8
8
|
serializer;
|
|
9
9
|
deserializer;
|
|
10
|
+
mixin = new ProtocolLib();
|
|
10
11
|
constructor(options) {
|
|
11
12
|
super({
|
|
12
13
|
defaultNamespace: options.defaultNamespace,
|
|
@@ -51,7 +52,7 @@ export class AwsQueryProtocol extends RpcProtocol {
|
|
|
51
52
|
request.body = request.body.slice(-1);
|
|
52
53
|
}
|
|
53
54
|
try {
|
|
54
|
-
request.headers["content-length"] =
|
|
55
|
+
request.headers["content-length"] = this.mixin.calculateContentLength(request.body, this.serdeContext);
|
|
55
56
|
}
|
|
56
57
|
catch (e) { }
|
|
57
58
|
return request;
|
|
@@ -88,45 +89,21 @@ export class AwsQueryProtocol extends RpcProtocol {
|
|
|
88
89
|
}
|
|
89
90
|
async handleError(operationSchema, context, response, dataObject, metadata) {
|
|
90
91
|
const errorIdentifier = this.loadQueryErrorCode(response, dataObject) ?? "Unknown";
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
if (errorIdentifier.includes("#")) {
|
|
94
|
-
[namespace, errorName] = errorIdentifier.split("#");
|
|
95
|
-
}
|
|
96
|
-
const errorDataSource = this.loadQueryError(dataObject);
|
|
97
|
-
const registry = TypeRegistry.for(namespace);
|
|
98
|
-
let errorSchema;
|
|
99
|
-
try {
|
|
100
|
-
errorSchema = registry.find((schema) => NormalizedSchema.of(schema).getMergedTraits().awsQueryError?.[0] === errorName);
|
|
101
|
-
if (!errorSchema) {
|
|
102
|
-
errorSchema = registry.getSchema(errorIdentifier);
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
catch (e) {
|
|
106
|
-
const baseExceptionSchema = TypeRegistry.for("smithy.ts.sdk.synthetic." + namespace).getBaseException();
|
|
107
|
-
if (baseExceptionSchema) {
|
|
108
|
-
const ErrorCtor = baseExceptionSchema.ctor;
|
|
109
|
-
throw Object.assign(new ErrorCtor(errorName), errorDataSource);
|
|
110
|
-
}
|
|
111
|
-
throw new Error(errorName);
|
|
112
|
-
}
|
|
92
|
+
const errorData = this.loadQueryError(dataObject);
|
|
93
|
+
const { errorSchema, errorMetadata } = await this.mixin.getErrorSchemaOrThrowBaseException(errorIdentifier, this.options.defaultNamespace, response, errorData, metadata, (registry, errorName) => registry.find((schema) => NormalizedSchema.of(schema).getMergedTraits().awsQueryError?.[0] === errorName));
|
|
113
94
|
const ns = NormalizedSchema.of(errorSchema);
|
|
114
95
|
const message = this.loadQueryErrorMessage(dataObject);
|
|
115
96
|
const exception = new errorSchema.ctor(message);
|
|
116
97
|
const output = {};
|
|
117
98
|
for (const [name, member] of ns.structIterator()) {
|
|
118
99
|
const target = member.getMergedTraits().xmlName ?? name;
|
|
119
|
-
const value =
|
|
100
|
+
const value = errorData[target] ?? dataObject[target];
|
|
120
101
|
output[name] = this.deserializer.readSchema(member, value);
|
|
121
102
|
}
|
|
122
|
-
Object.assign(exception, {
|
|
123
|
-
$metadata: metadata,
|
|
124
|
-
$response: response,
|
|
103
|
+
throw Object.assign(exception, errorMetadata, {
|
|
125
104
|
$fault: ns.getMergedTraits().error,
|
|
126
105
|
message,
|
|
127
|
-
|
|
128
|
-
});
|
|
129
|
-
throw exception;
|
|
106
|
+
}, output);
|
|
130
107
|
}
|
|
131
108
|
loadQueryErrorCode(output, data) {
|
|
132
109
|
const code = (data.Errors?.[0]?.Error ?? data.Errors?.Error ?? data.Error)?.Code;
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { HttpBindingProtocol, HttpInterceptingShapeDeserializer, HttpInterceptingShapeSerializer, } from "@smithy/core/protocols";
|
|
2
|
-
import { NormalizedSchema, SCHEMA
|
|
3
|
-
import {
|
|
2
|
+
import { NormalizedSchema, SCHEMA } from "@smithy/core/schema";
|
|
3
|
+
import { ProtocolLib } from "../ProtocolLib";
|
|
4
4
|
import { loadRestXmlErrorCode } from "./parseXmlBody";
|
|
5
5
|
import { XmlCodec } from "./XmlCodec";
|
|
6
6
|
export class AwsRestXmlProtocol extends HttpBindingProtocol {
|
|
7
7
|
codec;
|
|
8
8
|
serializer;
|
|
9
9
|
deserializer;
|
|
10
|
+
mixin = new ProtocolLib();
|
|
10
11
|
constructor(options) {
|
|
11
12
|
super(options);
|
|
12
13
|
const settings = {
|
|
@@ -30,42 +31,11 @@ export class AwsRestXmlProtocol extends HttpBindingProtocol {
|
|
|
30
31
|
}
|
|
31
32
|
async serializeRequest(operationSchema, input, context) {
|
|
32
33
|
const request = await super.serializeRequest(operationSchema, input, context);
|
|
33
|
-
const
|
|
34
|
-
const members = ns.getMemberSchemas();
|
|
35
|
-
request.path =
|
|
36
|
-
String(request.path)
|
|
37
|
-
.split("/")
|
|
38
|
-
.filter((segment) => {
|
|
39
|
-
return segment !== "{Bucket}";
|
|
40
|
-
})
|
|
41
|
-
.join("/") || "/";
|
|
34
|
+
const inputSchema = NormalizedSchema.of(operationSchema.input);
|
|
42
35
|
if (!request.headers["content-type"]) {
|
|
43
|
-
const
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
if (httpPayloadMember) {
|
|
47
|
-
const mediaType = httpPayloadMember.getMergedTraits().mediaType;
|
|
48
|
-
if (mediaType) {
|
|
49
|
-
request.headers["content-type"] = mediaType;
|
|
50
|
-
}
|
|
51
|
-
else if (httpPayloadMember.isStringSchema()) {
|
|
52
|
-
request.headers["content-type"] = "text/plain";
|
|
53
|
-
}
|
|
54
|
-
else if (httpPayloadMember.isBlobSchema()) {
|
|
55
|
-
request.headers["content-type"] = "application/octet-stream";
|
|
56
|
-
}
|
|
57
|
-
else {
|
|
58
|
-
request.headers["content-type"] = this.getDefaultContentType();
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
else if (!ns.isUnitSchema()) {
|
|
62
|
-
const hasBody = Object.values(members).find((m) => {
|
|
63
|
-
const { httpQuery, httpQueryParams, httpHeader, httpLabel, httpPrefixHeaders } = m.getMergedTraits();
|
|
64
|
-
return !httpQuery && !httpQueryParams && !httpHeader && !httpLabel && httpPrefixHeaders === void 0;
|
|
65
|
-
});
|
|
66
|
-
if (hasBody) {
|
|
67
|
-
request.headers["content-type"] = this.getDefaultContentType();
|
|
68
|
-
}
|
|
36
|
+
const contentType = this.mixin.resolveRestContentType(this.getDefaultContentType(), inputSchema);
|
|
37
|
+
if (contentType) {
|
|
38
|
+
request.headers["content-type"] = contentType;
|
|
69
39
|
}
|
|
70
40
|
}
|
|
71
41
|
if (request.headers["content-type"] === this.getDefaultContentType()) {
|
|
@@ -75,7 +45,7 @@ export class AwsRestXmlProtocol extends HttpBindingProtocol {
|
|
|
75
45
|
}
|
|
76
46
|
if (request.body) {
|
|
77
47
|
try {
|
|
78
|
-
request.headers["content-length"] =
|
|
48
|
+
request.headers["content-length"] = this.mixin.calculateContentLength(request.body, this.serdeContext);
|
|
79
49
|
}
|
|
80
50
|
catch (e) { }
|
|
81
51
|
}
|
|
@@ -86,24 +56,7 @@ export class AwsRestXmlProtocol extends HttpBindingProtocol {
|
|
|
86
56
|
}
|
|
87
57
|
async handleError(operationSchema, context, response, dataObject, metadata) {
|
|
88
58
|
const errorIdentifier = loadRestXmlErrorCode(response, dataObject) ?? "Unknown";
|
|
89
|
-
|
|
90
|
-
let errorName = errorIdentifier;
|
|
91
|
-
if (errorIdentifier.includes("#")) {
|
|
92
|
-
[namespace, errorName] = errorIdentifier.split("#");
|
|
93
|
-
}
|
|
94
|
-
const registry = TypeRegistry.for(namespace);
|
|
95
|
-
let errorSchema;
|
|
96
|
-
try {
|
|
97
|
-
errorSchema = registry.getSchema(errorIdentifier);
|
|
98
|
-
}
|
|
99
|
-
catch (e) {
|
|
100
|
-
const baseExceptionSchema = TypeRegistry.for("smithy.ts.sdk.synthetic." + namespace).getBaseException();
|
|
101
|
-
if (baseExceptionSchema) {
|
|
102
|
-
const ErrorCtor = baseExceptionSchema.ctor;
|
|
103
|
-
throw Object.assign(new ErrorCtor(errorName), dataObject);
|
|
104
|
-
}
|
|
105
|
-
throw new Error(errorName);
|
|
106
|
-
}
|
|
59
|
+
const { errorSchema, errorMetadata } = await this.mixin.getErrorSchemaOrThrowBaseException(errorIdentifier, this.options.defaultNamespace, response, dataObject, metadata);
|
|
107
60
|
const ns = NormalizedSchema.of(errorSchema);
|
|
108
61
|
const message = dataObject.Error?.message ?? dataObject.Error?.Message ?? dataObject.message ?? dataObject.Message ?? "Unknown";
|
|
109
62
|
const exception = new errorSchema.ctor(message);
|
|
@@ -114,14 +67,10 @@ export class AwsRestXmlProtocol extends HttpBindingProtocol {
|
|
|
114
67
|
const value = dataObject.Error?.[target] ?? dataObject[target];
|
|
115
68
|
output[name] = this.codec.createDeserializer().readSchema(member, value);
|
|
116
69
|
}
|
|
117
|
-
Object.assign(exception, {
|
|
118
|
-
$metadata: metadata,
|
|
119
|
-
$response: response,
|
|
70
|
+
throw Object.assign(exception, errorMetadata, {
|
|
120
71
|
$fault: ns.getMergedTraits().error,
|
|
121
72
|
message,
|
|
122
|
-
|
|
123
|
-
});
|
|
124
|
-
throw exception;
|
|
73
|
+
}, output);
|
|
125
74
|
}
|
|
126
75
|
getDefaultContentType() {
|
|
127
76
|
return "application/xml";
|
|
@@ -62,9 +62,6 @@ export class XmlShapeSerializer extends SerdeContextConfig {
|
|
|
62
62
|
}
|
|
63
63
|
const structXmlNode = XmlNode.of(name);
|
|
64
64
|
const [xmlnsAttr, xmlns] = this.getXmlnsAttribute(ns, parentXmlns);
|
|
65
|
-
if (xmlns) {
|
|
66
|
-
structXmlNode.addAttribute(xmlnsAttr, xmlns);
|
|
67
|
-
}
|
|
68
65
|
for (const [memberName, memberSchema] of ns.structIterator()) {
|
|
69
66
|
const val = value[memberName];
|
|
70
67
|
if (val != null || memberSchema.isIdempotencyToken()) {
|
|
@@ -88,6 +85,9 @@ export class XmlShapeSerializer extends SerdeContextConfig {
|
|
|
88
85
|
}
|
|
89
86
|
}
|
|
90
87
|
}
|
|
88
|
+
if (xmlns) {
|
|
89
|
+
structXmlNode.addAttribute(xmlnsAttr, xmlns);
|
|
90
|
+
}
|
|
91
91
|
return structXmlNode;
|
|
92
92
|
}
|
|
93
93
|
writeList(listMember, array, container, parentXmlns) {
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { ErrorSchema, NormalizedSchema, TypeRegistry } from "@smithy/core/schema";
|
|
2
|
+
import type { HttpResponse as IHttpResponse, MetadataBearer, ResponseMetadata, SerdeFunctions } from "@smithy/types";
|
|
3
|
+
/**
|
|
4
|
+
* @internal
|
|
5
|
+
*/
|
|
6
|
+
type ErrorMetadataBearer = MetadataBearer & {
|
|
7
|
+
$response: IHttpResponse;
|
|
8
|
+
$fault: "client" | "server";
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* Shared code for Protocols.
|
|
12
|
+
*
|
|
13
|
+
* @internal
|
|
14
|
+
*/
|
|
15
|
+
export declare class ProtocolLib {
|
|
16
|
+
/**
|
|
17
|
+
* @param body - to be inspected.
|
|
18
|
+
* @param serdeContext - this is a subset type but in practice is the client.config having a property called bodyLengthChecker.
|
|
19
|
+
*
|
|
20
|
+
* @returns content-length value for the body if possible.
|
|
21
|
+
* @throws Error and should be caught and handled if not possible to determine length.
|
|
22
|
+
*/
|
|
23
|
+
calculateContentLength(body: any, serdeContext?: SerdeFunctions): string;
|
|
24
|
+
/**
|
|
25
|
+
* This is only for REST protocols.
|
|
26
|
+
*
|
|
27
|
+
* @param defaultContentType - of the protocol.
|
|
28
|
+
* @param inputSchema - schema for which to determine content type.
|
|
29
|
+
*
|
|
30
|
+
* @returns content-type header value or undefined when not applicable.
|
|
31
|
+
*/
|
|
32
|
+
resolveRestContentType(defaultContentType: string, inputSchema: NormalizedSchema): string | undefined;
|
|
33
|
+
/**
|
|
34
|
+
* Shared code for finding error schema or throwing an unmodeled base error.
|
|
35
|
+
* @returns error schema and error metadata.
|
|
36
|
+
*
|
|
37
|
+
* @throws ServiceBaseException or generic Error if no error schema could be found.
|
|
38
|
+
*/
|
|
39
|
+
getErrorSchemaOrThrowBaseException(errorIdentifier: string, defaultNamespace: string, response: IHttpResponse, dataObject: any, metadata: ResponseMetadata, getErrorSchema?: (registry: TypeRegistry, errorName: string) => ErrorSchema): Promise<{
|
|
40
|
+
errorSchema: ErrorSchema;
|
|
41
|
+
errorMetadata: ErrorMetadataBearer;
|
|
42
|
+
}>;
|
|
43
|
+
/**
|
|
44
|
+
* Reads the x-amzn-query-error header for awsQuery compatibility.
|
|
45
|
+
*
|
|
46
|
+
* @param output - values that will be assigned to an error object.
|
|
47
|
+
* @param response - from which to read awsQueryError headers.
|
|
48
|
+
*/
|
|
49
|
+
setQueryCompatError(output: Record<string, any>, response: IHttpResponse): void;
|
|
50
|
+
/**
|
|
51
|
+
* Assigns Error, Type, Code from the awsQuery error object to the output error object.
|
|
52
|
+
* @param queryCompatErrorData - query compat error object.
|
|
53
|
+
* @param errorData - canonical error object returned to the caller.
|
|
54
|
+
*/
|
|
55
|
+
queryCompatOutput(queryCompatErrorData: any, errorData: any): void;
|
|
56
|
+
}
|
|
57
|
+
export {};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { SmithyRpcV2CborProtocol } from "@smithy/core/cbor";
|
|
2
|
+
import type { EndpointBearer, HandlerExecutionContext, HttpRequest, HttpResponse, OperationSchema, ResponseMetadata, SerdeFunctions } from "@smithy/types";
|
|
3
|
+
/**
|
|
4
|
+
* Extends the Smithy implementation to add AwsQueryCompatibility support.
|
|
5
|
+
*
|
|
6
|
+
* @alpha
|
|
7
|
+
*/
|
|
8
|
+
export declare class AwsSmithyRpcV2CborProtocol extends SmithyRpcV2CborProtocol {
|
|
9
|
+
private readonly awsQueryCompatible;
|
|
10
|
+
private readonly mixin;
|
|
11
|
+
constructor({ defaultNamespace, awsQueryCompatible, }: {
|
|
12
|
+
defaultNamespace: string;
|
|
13
|
+
awsQueryCompatible?: boolean;
|
|
14
|
+
});
|
|
15
|
+
/**
|
|
16
|
+
* @override
|
|
17
|
+
*/
|
|
18
|
+
serializeRequest<Input extends object>(operationSchema: OperationSchema, input: Input, context: HandlerExecutionContext & SerdeFunctions & EndpointBearer): Promise<HttpRequest>;
|
|
19
|
+
/**
|
|
20
|
+
* @override
|
|
21
|
+
*/
|
|
22
|
+
protected handleError(operationSchema: OperationSchema, context: HandlerExecutionContext & SerdeFunctions, response: HttpResponse, dataObject: any, metadata: ResponseMetadata): Promise<never>;
|
|
23
|
+
}
|