@aws-sdk/core 3.974.0 → 3.974.2

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/index.js CHANGED
@@ -450,12 +450,11 @@ class ProtocolLib {
450
450
  if (msg) {
451
451
  error.message = msg;
452
452
  }
453
- error.Error = {
454
- ...error.Error,
455
- Type: error.Error?.Type,
456
- Code: error.Error?.Code,
457
- Message: error.Error?.message ?? error.Error?.Message ?? msg,
458
- };
453
+ const errorObj = error.Error ?? {};
454
+ errorObj.Type = error.Error?.Type;
455
+ errorObj.Code = error.Error?.Code;
456
+ errorObj.Message = error.Error?.message ?? error.Error?.Message ?? msg;
457
+ error.Error = errorObj;
459
458
  const reqId = error.$metadata.requestId;
460
459
  if (reqId) {
461
460
  error.RequestId = reqId;
@@ -468,14 +467,16 @@ class ProtocolLib {
468
467
  const queryErrorHeader = response.headers?.["x-amzn-query-error"];
469
468
  if (output !== undefined && queryErrorHeader != null) {
470
469
  const [Code, Type] = queryErrorHeader.split(";");
471
- const entries = Object.entries(output);
470
+ const keys = Object.keys(output);
472
471
  const Error = {
473
472
  Code,
474
473
  Type,
475
474
  };
476
- Object.assign(output, Error);
477
- for (const [k, v] of entries) {
478
- Error[k === "message" ? "Message" : k] = v;
475
+ output.Code = Code;
476
+ output.Type = Type;
477
+ for (let i = 0; i < keys.length; i++) {
478
+ const k = keys[i];
479
+ Error[k === "message" ? "Message" : k] = output[k];
479
480
  }
480
481
  delete Error.__type;
481
482
  output.Error = Error;
@@ -614,7 +615,10 @@ class UnionSerde {
614
615
  constructor(from, to) {
615
616
  this.from = from;
616
617
  this.to = to;
617
- this.keys = new Set(Object.keys(this.from).filter((k) => k !== "__type"));
618
+ const keys = Object.keys(this.from);
619
+ const set = new Set(keys);
620
+ set.delete("__type");
621
+ this.keys = set;
618
622
  }
619
623
  mark(key) {
620
624
  this.keys.delete(key);
@@ -672,24 +676,24 @@ const parseJsonErrorBody = async (errorBody, context) => {
672
676
  value.message = value.message ?? value.Message;
673
677
  return value;
674
678
  };
679
+ const findKey = (object, key) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase());
680
+ const sanitizeErrorCode = (rawValue) => {
681
+ let cleanValue = rawValue;
682
+ if (typeof cleanValue === "number") {
683
+ cleanValue = cleanValue.toString();
684
+ }
685
+ if (cleanValue.indexOf(",") >= 0) {
686
+ cleanValue = cleanValue.split(",")[0];
687
+ }
688
+ if (cleanValue.indexOf(":") >= 0) {
689
+ cleanValue = cleanValue.split(":")[0];
690
+ }
691
+ if (cleanValue.indexOf("#") >= 0) {
692
+ cleanValue = cleanValue.split("#")[1];
693
+ }
694
+ return cleanValue;
695
+ };
675
696
  const loadRestJsonErrorCode = (output, data) => {
676
- const findKey = (object, key) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase());
677
- const sanitizeErrorCode = (rawValue) => {
678
- let cleanValue = rawValue;
679
- if (typeof cleanValue === "number") {
680
- cleanValue = cleanValue.toString();
681
- }
682
- if (cleanValue.indexOf(",") >= 0) {
683
- cleanValue = cleanValue.split(",")[0];
684
- }
685
- if (cleanValue.indexOf(":") >= 0) {
686
- cleanValue = cleanValue.split(":")[0];
687
- }
688
- if (cleanValue.indexOf("#") >= 0) {
689
- cleanValue = cleanValue.split("#")[1];
690
- }
691
- return cleanValue;
692
- };
693
697
  const headerKey = findKey(output.headers, "x-amzn-errortype");
694
698
  if (headerKey !== undefined) {
695
699
  return sanitizeErrorCode(output.headers[headerKey]);
@@ -751,7 +755,8 @@ class JsonShapeDeserializer extends SerdeContextConfig {
751
755
  unionSerde.writeUnknown();
752
756
  }
753
757
  else if (typeof record.__type === "string") {
754
- for (const [k, v] of Object.entries(record)) {
758
+ for (const k in record) {
759
+ const v = record[k];
755
760
  const t = jsonName ? nameMap[k] ?? k : k;
756
761
  if (!(t in out)) {
757
762
  out[t] = v;
@@ -771,8 +776,8 @@ class JsonShapeDeserializer extends SerdeContextConfig {
771
776
  if (ns.isMapSchema()) {
772
777
  const mapMember = ns.getValueSchema();
773
778
  const out = {};
774
- for (const [_k, _v] of Object.entries(value)) {
775
- out[_k] = this._read(mapMember, _v);
779
+ for (const _k in value) {
780
+ out[_k] = this._read(mapMember, value[_k]);
776
781
  }
777
782
  return out;
778
783
  }
@@ -829,7 +834,8 @@ class JsonShapeDeserializer extends SerdeContextConfig {
829
834
  if (ns.isDocumentSchema()) {
830
835
  if (isObject) {
831
836
  const out = Array.isArray(value) ? [] : {};
832
- for (const [k, v] of Object.entries(value)) {
837
+ for (const k in value) {
838
+ const v = value[k];
833
839
  if (v instanceof serde.NumericValue) {
834
840
  out[k] = v;
835
841
  }
@@ -937,6 +943,7 @@ class JsonShapeSerializer extends SerdeContextConfig {
937
943
  if (jsonName) {
938
944
  nameMap = {};
939
945
  }
946
+ let outCount = 0;
940
947
  for (const [memberName, memberSchema] of ns.structIterator()) {
941
948
  const serializableValue = this._write(memberSchema, record[memberName], ns);
942
949
  if (serializableValue !== undefined) {
@@ -946,9 +953,10 @@ class JsonShapeSerializer extends SerdeContextConfig {
946
953
  nameMap[memberName] = targetKey;
947
954
  }
948
955
  out[targetKey] = serializableValue;
956
+ outCount++;
949
957
  }
950
958
  }
951
- if (ns.isUnionSchema() && Object.keys(out).length === 0) {
959
+ if (ns.isUnionSchema() && outCount === 0) {
952
960
  const { $unknown } = record;
953
961
  if (Array.isArray($unknown)) {
954
962
  const [k, v] = $unknown;
@@ -956,7 +964,8 @@ class JsonShapeSerializer extends SerdeContextConfig {
956
964
  }
957
965
  }
958
966
  else if (typeof record.__type === "string") {
959
- for (const [k, v] of Object.entries(record)) {
967
+ for (const k in record) {
968
+ const v = record[k];
960
969
  const targetKey = jsonName ? nameMap[k] ?? k : k;
961
970
  if (!(targetKey in out)) {
962
971
  out[targetKey] = this._write(15, v);
@@ -980,7 +989,8 @@ class JsonShapeSerializer extends SerdeContextConfig {
980
989
  const mapMember = ns.getValueSchema();
981
990
  const out = {};
982
991
  const sparse = !!ns.getMergedTraits().sparse;
983
- for (const [_k, _v] of Object.entries(value)) {
992
+ for (const _k in value) {
993
+ const _v = value[_k];
984
994
  if (sparse || _v != null) {
985
995
  out[_k] = this._write(mapMember, _v);
986
996
  }
@@ -1045,7 +1055,8 @@ class JsonShapeSerializer extends SerdeContextConfig {
1045
1055
  if (ns.isDocumentSchema()) {
1046
1056
  if (isObject) {
1047
1057
  const out = Array.isArray(value) ? [] : {};
1048
- for (const [k, v] of Object.entries(value)) {
1058
+ for (const k in value) {
1059
+ const v = value[k];
1049
1060
  if (v instanceof serde.NumericValue) {
1050
1061
  this.useReplacer = true;
1051
1062
  out[k] = v;
@@ -1114,10 +1125,8 @@ class AwsJsonRpcProtocol extends protocols.RpcProtocol {
1114
1125
  if (!request.path.endsWith("/")) {
1115
1126
  request.path += "/";
1116
1127
  }
1117
- Object.assign(request.headers, {
1118
- "content-type": `application/x-amz-json-${this.getJsonRpcVersion()}`,
1119
- "x-amz-target": `${this.serviceTarget}.${operationSchema.name}`,
1120
- });
1128
+ request.headers["content-type"] = `application/x-amz-json-${this.getJsonRpcVersion()}`;
1129
+ request.headers["x-amz-target"] = `${this.serviceTarget}.${operationSchema.name}`;
1121
1130
  if (this.awsQueryCompatible) {
1122
1131
  request.headers["x-amzn-query-mode"] = "true";
1123
1132
  }
@@ -1141,9 +1150,10 @@ class AwsJsonRpcProtocol extends protocols.RpcProtocol {
1141
1150
  const ErrorCtor = this.compositeErrorRegistry.getErrorCtor(errorSchema) ?? Error;
1142
1151
  const exception = new ErrorCtor(message);
1143
1152
  const output = {};
1153
+ const errorDeserializer = this.codec.createDeserializer();
1144
1154
  for (const [name, member] of ns.structIterator()) {
1145
1155
  if (dataObject[name] != null) {
1146
- output[name] = this.codec.createDeserializer().readObject(member, dataObject[name]);
1156
+ output[name] = errorDeserializer.readObject(member, dataObject[name]);
1147
1157
  }
1148
1158
  }
1149
1159
  if (this.awsQueryCompatible) {
@@ -1264,9 +1274,10 @@ class AwsRestJsonProtocol extends protocols.HttpBindingProtocol {
1264
1274
  const exception = new ErrorCtor(message);
1265
1275
  await this.deserializeHttpMessage(errorSchema, context, response, dataObject);
1266
1276
  const output = {};
1277
+ const errorDeserializer = this.codec.createDeserializer();
1267
1278
  for (const [name, member] of ns.structIterator()) {
1268
1279
  const target = member.getMergedTraits().jsonName ?? name;
1269
- output[name] = this.codec.createDeserializer().readObject(member, dataObject[target]);
1280
+ output[name] = errorDeserializer.readObject(member, dataObject[target]);
1270
1281
  }
1271
1282
  throw this.mixin.decorateServiceException(Object.assign(exception, errorMetadata, {
1272
1283
  $fault: ns.getMergedTraits().error,
@@ -1544,7 +1555,8 @@ class QueryShapeSerializer extends SerdeContextConfig {
1544
1555
  const memberSchema = ns.getValueSchema();
1545
1556
  const flat = ns.getMergedTraits().xmlFlattened;
1546
1557
  let i = 1;
1547
- for (const [k, v] of Object.entries(value)) {
1558
+ for (const k in value) {
1559
+ const v = value[k];
1548
1560
  if (v == null) {
1549
1561
  continue;
1550
1562
  }
@@ -1657,9 +1669,7 @@ class AwsQueryProtocol extends protocols.RpcProtocol {
1657
1669
  if (!request.path.endsWith("/")) {
1658
1670
  request.path += "/";
1659
1671
  }
1660
- Object.assign(request.headers, {
1661
- "content-type": `application/x-www-form-urlencoded`,
1662
- });
1672
+ request.headers["content-type"] = "application/x-www-form-urlencoded";
1663
1673
  if (schema.deref(operationSchema.input) === "unit" || !request.body) {
1664
1674
  request.body = "";
1665
1675
  }
@@ -1692,11 +1702,8 @@ class AwsQueryProtocol extends protocols.RpcProtocol {
1692
1702
  if (bytes.byteLength > 0) {
1693
1703
  Object.assign(dataObject, await deserializer.read(ns, bytes, awsQueryResultKey));
1694
1704
  }
1695
- const output = {
1696
- $metadata: this.deserializeMetadata(response),
1697
- ...dataObject,
1698
- };
1699
- return output;
1705
+ dataObject.$metadata = this.deserializeMetadata(response);
1706
+ return dataObject;
1700
1707
  }
1701
1708
  useNestedResult() {
1702
1709
  return true;
@@ -2003,7 +2010,8 @@ class XmlShapeSerializer extends SerdeContextConfig {
2003
2010
  entry.addChildNode(valueNode);
2004
2011
  };
2005
2012
  if (flat) {
2006
- for (const [key, val] of Object.entries(map)) {
2013
+ for (const key in map) {
2014
+ const val = map[key];
2007
2015
  if (sparse || val != null) {
2008
2016
  const entry = xmlBuilder.XmlNode.of(mapTraits.xmlName ?? mapMember.getMemberName());
2009
2017
  addKeyValue(entry, key, val);
@@ -2020,7 +2028,8 @@ class XmlShapeSerializer extends SerdeContextConfig {
2020
2028
  }
2021
2029
  container.addChildNode(mapNode);
2022
2030
  }
2023
- for (const [key, val] of Object.entries(map)) {
2031
+ for (const key in map) {
2032
+ const val = map[key];
2024
2033
  if (sparse || val != null) {
2025
2034
  const entry = xmlBuilder.XmlNode.of("entry");
2026
2035
  addKeyValue(entry, key, val);
@@ -2196,10 +2205,11 @@ class AwsRestXmlProtocol extends protocols.HttpBindingProtocol {
2196
2205
  const exception = new ErrorCtor(message);
2197
2206
  await this.deserializeHttpMessage(errorSchema, context, response, dataObject);
2198
2207
  const output = {};
2208
+ const errorDeserializer = this.codec.createDeserializer();
2199
2209
  for (const [name, member] of ns.structIterator()) {
2200
2210
  const target = member.getMergedTraits().xmlName ?? name;
2201
2211
  const value = dataObject.Error?.[target] ?? dataObject[target];
2202
- output[name] = this.codec.createDeserializer().readSchema(member, value);
2212
+ output[name] = errorDeserializer.readSchema(member, value);
2203
2213
  }
2204
2214
  throw this.mixin.decorateServiceException(Object.assign(exception, errorMetadata, {
2205
2215
  $fault: ns.getMergedTraits().error,
@@ -96,12 +96,11 @@ class ProtocolLib {
96
96
  if (msg) {
97
97
  error.message = msg;
98
98
  }
99
- error.Error = {
100
- ...error.Error,
101
- Type: error.Error?.Type,
102
- Code: error.Error?.Code,
103
- Message: error.Error?.message ?? error.Error?.Message ?? msg,
104
- };
99
+ const errorObj = error.Error ?? {};
100
+ errorObj.Type = error.Error?.Type;
101
+ errorObj.Code = error.Error?.Code;
102
+ errorObj.Message = error.Error?.message ?? error.Error?.Message ?? msg;
103
+ error.Error = errorObj;
105
104
  const reqId = error.$metadata.requestId;
106
105
  if (reqId) {
107
106
  error.RequestId = reqId;
@@ -114,14 +113,16 @@ class ProtocolLib {
114
113
  const queryErrorHeader = response.headers?.["x-amzn-query-error"];
115
114
  if (output !== undefined && queryErrorHeader != null) {
116
115
  const [Code, Type] = queryErrorHeader.split(";");
117
- const entries = Object.entries(output);
116
+ const keys = Object.keys(output);
118
117
  const Error = {
119
118
  Code,
120
119
  Type,
121
120
  };
122
- Object.assign(output, Error);
123
- for (const [k, v] of entries) {
124
- Error[k === "message" ? "Message" : k] = v;
121
+ output.Code = Code;
122
+ output.Type = Type;
123
+ for (let i = 0; i < keys.length; i++) {
124
+ const k = keys[i];
125
+ Error[k === "message" ? "Message" : k] = output[k];
125
126
  }
126
127
  delete Error.__type;
127
128
  output.Error = Error;
@@ -260,7 +261,10 @@ class UnionSerde {
260
261
  constructor(from, to) {
261
262
  this.from = from;
262
263
  this.to = to;
263
- this.keys = new Set(Object.keys(this.from).filter((k) => k !== "__type"));
264
+ const keys = Object.keys(this.from);
265
+ const set = new Set(keys);
266
+ set.delete("__type");
267
+ this.keys = set;
264
268
  }
265
269
  mark(key) {
266
270
  this.keys.delete(key);
@@ -318,24 +322,24 @@ const parseJsonErrorBody = async (errorBody, context) => {
318
322
  value.message = value.message ?? value.Message;
319
323
  return value;
320
324
  };
325
+ const findKey = (object, key) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase());
326
+ const sanitizeErrorCode = (rawValue) => {
327
+ let cleanValue = rawValue;
328
+ if (typeof cleanValue === "number") {
329
+ cleanValue = cleanValue.toString();
330
+ }
331
+ if (cleanValue.indexOf(",") >= 0) {
332
+ cleanValue = cleanValue.split(",")[0];
333
+ }
334
+ if (cleanValue.indexOf(":") >= 0) {
335
+ cleanValue = cleanValue.split(":")[0];
336
+ }
337
+ if (cleanValue.indexOf("#") >= 0) {
338
+ cleanValue = cleanValue.split("#")[1];
339
+ }
340
+ return cleanValue;
341
+ };
321
342
  const loadRestJsonErrorCode = (output, data) => {
322
- const findKey = (object, key) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase());
323
- const sanitizeErrorCode = (rawValue) => {
324
- let cleanValue = rawValue;
325
- if (typeof cleanValue === "number") {
326
- cleanValue = cleanValue.toString();
327
- }
328
- if (cleanValue.indexOf(",") >= 0) {
329
- cleanValue = cleanValue.split(",")[0];
330
- }
331
- if (cleanValue.indexOf(":") >= 0) {
332
- cleanValue = cleanValue.split(":")[0];
333
- }
334
- if (cleanValue.indexOf("#") >= 0) {
335
- cleanValue = cleanValue.split("#")[1];
336
- }
337
- return cleanValue;
338
- };
339
343
  const headerKey = findKey(output.headers, "x-amzn-errortype");
340
344
  if (headerKey !== undefined) {
341
345
  return sanitizeErrorCode(output.headers[headerKey]);
@@ -397,7 +401,8 @@ class JsonShapeDeserializer extends SerdeContextConfig {
397
401
  unionSerde.writeUnknown();
398
402
  }
399
403
  else if (typeof record.__type === "string") {
400
- for (const [k, v] of Object.entries(record)) {
404
+ for (const k in record) {
405
+ const v = record[k];
401
406
  const t = jsonName ? nameMap[k] ?? k : k;
402
407
  if (!(t in out)) {
403
408
  out[t] = v;
@@ -417,8 +422,8 @@ class JsonShapeDeserializer extends SerdeContextConfig {
417
422
  if (ns.isMapSchema()) {
418
423
  const mapMember = ns.getValueSchema();
419
424
  const out = {};
420
- for (const [_k, _v] of Object.entries(value)) {
421
- out[_k] = this._read(mapMember, _v);
425
+ for (const _k in value) {
426
+ out[_k] = this._read(mapMember, value[_k]);
422
427
  }
423
428
  return out;
424
429
  }
@@ -475,7 +480,8 @@ class JsonShapeDeserializer extends SerdeContextConfig {
475
480
  if (ns.isDocumentSchema()) {
476
481
  if (isObject) {
477
482
  const out = Array.isArray(value) ? [] : {};
478
- for (const [k, v] of Object.entries(value)) {
483
+ for (const k in value) {
484
+ const v = value[k];
479
485
  if (v instanceof serde.NumericValue) {
480
486
  out[k] = v;
481
487
  }
@@ -583,6 +589,7 @@ class JsonShapeSerializer extends SerdeContextConfig {
583
589
  if (jsonName) {
584
590
  nameMap = {};
585
591
  }
592
+ let outCount = 0;
586
593
  for (const [memberName, memberSchema] of ns.structIterator()) {
587
594
  const serializableValue = this._write(memberSchema, record[memberName], ns);
588
595
  if (serializableValue !== undefined) {
@@ -592,9 +599,10 @@ class JsonShapeSerializer extends SerdeContextConfig {
592
599
  nameMap[memberName] = targetKey;
593
600
  }
594
601
  out[targetKey] = serializableValue;
602
+ outCount++;
595
603
  }
596
604
  }
597
- if (ns.isUnionSchema() && Object.keys(out).length === 0) {
605
+ if (ns.isUnionSchema() && outCount === 0) {
598
606
  const { $unknown } = record;
599
607
  if (Array.isArray($unknown)) {
600
608
  const [k, v] = $unknown;
@@ -602,7 +610,8 @@ class JsonShapeSerializer extends SerdeContextConfig {
602
610
  }
603
611
  }
604
612
  else if (typeof record.__type === "string") {
605
- for (const [k, v] of Object.entries(record)) {
613
+ for (const k in record) {
614
+ const v = record[k];
606
615
  const targetKey = jsonName ? nameMap[k] ?? k : k;
607
616
  if (!(targetKey in out)) {
608
617
  out[targetKey] = this._write(15, v);
@@ -626,7 +635,8 @@ class JsonShapeSerializer extends SerdeContextConfig {
626
635
  const mapMember = ns.getValueSchema();
627
636
  const out = {};
628
637
  const sparse = !!ns.getMergedTraits().sparse;
629
- for (const [_k, _v] of Object.entries(value)) {
638
+ for (const _k in value) {
639
+ const _v = value[_k];
630
640
  if (sparse || _v != null) {
631
641
  out[_k] = this._write(mapMember, _v);
632
642
  }
@@ -691,7 +701,8 @@ class JsonShapeSerializer extends SerdeContextConfig {
691
701
  if (ns.isDocumentSchema()) {
692
702
  if (isObject) {
693
703
  const out = Array.isArray(value) ? [] : {};
694
- for (const [k, v] of Object.entries(value)) {
704
+ for (const k in value) {
705
+ const v = value[k];
695
706
  if (v instanceof serde.NumericValue) {
696
707
  this.useReplacer = true;
697
708
  out[k] = v;
@@ -760,10 +771,8 @@ class AwsJsonRpcProtocol extends protocols.RpcProtocol {
760
771
  if (!request.path.endsWith("/")) {
761
772
  request.path += "/";
762
773
  }
763
- Object.assign(request.headers, {
764
- "content-type": `application/x-amz-json-${this.getJsonRpcVersion()}`,
765
- "x-amz-target": `${this.serviceTarget}.${operationSchema.name}`,
766
- });
774
+ request.headers["content-type"] = `application/x-amz-json-${this.getJsonRpcVersion()}`;
775
+ request.headers["x-amz-target"] = `${this.serviceTarget}.${operationSchema.name}`;
767
776
  if (this.awsQueryCompatible) {
768
777
  request.headers["x-amzn-query-mode"] = "true";
769
778
  }
@@ -787,9 +796,10 @@ class AwsJsonRpcProtocol extends protocols.RpcProtocol {
787
796
  const ErrorCtor = this.compositeErrorRegistry.getErrorCtor(errorSchema) ?? Error;
788
797
  const exception = new ErrorCtor(message);
789
798
  const output = {};
799
+ const errorDeserializer = this.codec.createDeserializer();
790
800
  for (const [name, member] of ns.structIterator()) {
791
801
  if (dataObject[name] != null) {
792
- output[name] = this.codec.createDeserializer().readObject(member, dataObject[name]);
802
+ output[name] = errorDeserializer.readObject(member, dataObject[name]);
793
803
  }
794
804
  }
795
805
  if (this.awsQueryCompatible) {
@@ -910,9 +920,10 @@ class AwsRestJsonProtocol extends protocols.HttpBindingProtocol {
910
920
  const exception = new ErrorCtor(message);
911
921
  await this.deserializeHttpMessage(errorSchema, context, response, dataObject);
912
922
  const output = {};
923
+ const errorDeserializer = this.codec.createDeserializer();
913
924
  for (const [name, member] of ns.structIterator()) {
914
925
  const target = member.getMergedTraits().jsonName ?? name;
915
- output[name] = this.codec.createDeserializer().readObject(member, dataObject[target]);
926
+ output[name] = errorDeserializer.readObject(member, dataObject[target]);
916
927
  }
917
928
  throw this.mixin.decorateServiceException(Object.assign(exception, errorMetadata, {
918
929
  $fault: ns.getMergedTraits().error,
@@ -1190,7 +1201,8 @@ class QueryShapeSerializer extends SerdeContextConfig {
1190
1201
  const memberSchema = ns.getValueSchema();
1191
1202
  const flat = ns.getMergedTraits().xmlFlattened;
1192
1203
  let i = 1;
1193
- for (const [k, v] of Object.entries(value)) {
1204
+ for (const k in value) {
1205
+ const v = value[k];
1194
1206
  if (v == null) {
1195
1207
  continue;
1196
1208
  }
@@ -1303,9 +1315,7 @@ class AwsQueryProtocol extends protocols.RpcProtocol {
1303
1315
  if (!request.path.endsWith("/")) {
1304
1316
  request.path += "/";
1305
1317
  }
1306
- Object.assign(request.headers, {
1307
- "content-type": `application/x-www-form-urlencoded`,
1308
- });
1318
+ request.headers["content-type"] = "application/x-www-form-urlencoded";
1309
1319
  if (schema.deref(operationSchema.input) === "unit" || !request.body) {
1310
1320
  request.body = "";
1311
1321
  }
@@ -1338,11 +1348,8 @@ class AwsQueryProtocol extends protocols.RpcProtocol {
1338
1348
  if (bytes.byteLength > 0) {
1339
1349
  Object.assign(dataObject, await deserializer.read(ns, bytes, awsQueryResultKey));
1340
1350
  }
1341
- const output = {
1342
- $metadata: this.deserializeMetadata(response),
1343
- ...dataObject,
1344
- };
1345
- return output;
1351
+ dataObject.$metadata = this.deserializeMetadata(response);
1352
+ return dataObject;
1346
1353
  }
1347
1354
  useNestedResult() {
1348
1355
  return true;
@@ -1649,7 +1656,8 @@ class XmlShapeSerializer extends SerdeContextConfig {
1649
1656
  entry.addChildNode(valueNode);
1650
1657
  };
1651
1658
  if (flat) {
1652
- for (const [key, val] of Object.entries(map)) {
1659
+ for (const key in map) {
1660
+ const val = map[key];
1653
1661
  if (sparse || val != null) {
1654
1662
  const entry = xmlBuilder.XmlNode.of(mapTraits.xmlName ?? mapMember.getMemberName());
1655
1663
  addKeyValue(entry, key, val);
@@ -1666,7 +1674,8 @@ class XmlShapeSerializer extends SerdeContextConfig {
1666
1674
  }
1667
1675
  container.addChildNode(mapNode);
1668
1676
  }
1669
- for (const [key, val] of Object.entries(map)) {
1677
+ for (const key in map) {
1678
+ const val = map[key];
1670
1679
  if (sparse || val != null) {
1671
1680
  const entry = xmlBuilder.XmlNode.of("entry");
1672
1681
  addKeyValue(entry, key, val);
@@ -1842,10 +1851,11 @@ class AwsRestXmlProtocol extends protocols.HttpBindingProtocol {
1842
1851
  const exception = new ErrorCtor(message);
1843
1852
  await this.deserializeHttpMessage(errorSchema, context, response, dataObject);
1844
1853
  const output = {};
1854
+ const errorDeserializer = this.codec.createDeserializer();
1845
1855
  for (const [name, member] of ns.structIterator()) {
1846
1856
  const target = member.getMergedTraits().xmlName ?? name;
1847
1857
  const value = dataObject.Error?.[target] ?? dataObject[target];
1848
- output[name] = this.codec.createDeserializer().readSchema(member, value);
1858
+ output[name] = errorDeserializer.readSchema(member, value);
1849
1859
  }
1850
1860
  throw this.mixin.decorateServiceException(Object.assign(exception, errorMetadata, {
1851
1861
  $fault: ns.getMergedTraits().error,
@@ -87,12 +87,11 @@ export class ProtocolLib {
87
87
  if (msg) {
88
88
  error.message = msg;
89
89
  }
90
- error.Error = {
91
- ...error.Error,
92
- Type: error.Error?.Type,
93
- Code: error.Error?.Code,
94
- Message: error.Error?.message ?? error.Error?.Message ?? msg,
95
- };
90
+ const errorObj = error.Error ?? {};
91
+ errorObj.Type = error.Error?.Type;
92
+ errorObj.Code = error.Error?.Code;
93
+ errorObj.Message = error.Error?.message ?? error.Error?.Message ?? msg;
94
+ error.Error = errorObj;
96
95
  const reqId = error.$metadata.requestId;
97
96
  if (reqId) {
98
97
  error.RequestId = reqId;
@@ -105,14 +104,16 @@ export class ProtocolLib {
105
104
  const queryErrorHeader = response.headers?.["x-amzn-query-error"];
106
105
  if (output !== undefined && queryErrorHeader != null) {
107
106
  const [Code, Type] = queryErrorHeader.split(";");
108
- const entries = Object.entries(output);
107
+ const keys = Object.keys(output);
109
108
  const Error = {
110
109
  Code,
111
110
  Type,
112
111
  };
113
- Object.assign(output, Error);
114
- for (const [k, v] of entries) {
115
- Error[k === "message" ? "Message" : k] = v;
112
+ output.Code = Code;
113
+ output.Type = Type;
114
+ for (let i = 0; i < keys.length; i++) {
115
+ const k = keys[i];
116
+ Error[k === "message" ? "Message" : k] = output[k];
116
117
  }
117
118
  delete Error.__type;
118
119
  output.Error = Error;
@@ -5,7 +5,10 @@ export class UnionSerde {
5
5
  constructor(from, to) {
6
6
  this.from = from;
7
7
  this.to = to;
8
- this.keys = new Set(Object.keys(this.from).filter((k) => k !== "__type"));
8
+ const keys = Object.keys(this.from);
9
+ const set = new Set(keys);
10
+ set.delete("__type");
11
+ this.keys = set;
9
12
  }
10
13
  mark(key) {
11
14
  this.keys.delete(key);
@@ -35,10 +35,8 @@ export class AwsJsonRpcProtocol extends RpcProtocol {
35
35
  if (!request.path.endsWith("/")) {
36
36
  request.path += "/";
37
37
  }
38
- Object.assign(request.headers, {
39
- "content-type": `application/x-amz-json-${this.getJsonRpcVersion()}`,
40
- "x-amz-target": `${this.serviceTarget}.${operationSchema.name}`,
41
- });
38
+ request.headers["content-type"] = `application/x-amz-json-${this.getJsonRpcVersion()}`;
39
+ request.headers["x-amz-target"] = `${this.serviceTarget}.${operationSchema.name}`;
42
40
  if (this.awsQueryCompatible) {
43
41
  request.headers["x-amzn-query-mode"] = "true";
44
42
  }
@@ -62,9 +60,10 @@ export class AwsJsonRpcProtocol extends RpcProtocol {
62
60
  const ErrorCtor = this.compositeErrorRegistry.getErrorCtor(errorSchema) ?? Error;
63
61
  const exception = new ErrorCtor(message);
64
62
  const output = {};
63
+ const errorDeserializer = this.codec.createDeserializer();
65
64
  for (const [name, member] of ns.structIterator()) {
66
65
  if (dataObject[name] != null) {
67
- output[name] = this.codec.createDeserializer().readObject(member, dataObject[name]);
66
+ output[name] = errorDeserializer.readObject(member, dataObject[name]);
68
67
  }
69
68
  }
70
69
  if (this.awsQueryCompatible) {
@@ -69,9 +69,10 @@ export class AwsRestJsonProtocol extends HttpBindingProtocol {
69
69
  const exception = new ErrorCtor(message);
70
70
  await this.deserializeHttpMessage(errorSchema, context, response, dataObject);
71
71
  const output = {};
72
+ const errorDeserializer = this.codec.createDeserializer();
72
73
  for (const [name, member] of ns.structIterator()) {
73
74
  const target = member.getMergedTraits().jsonName ?? name;
74
- output[name] = this.codec.createDeserializer().readObject(member, dataObject[target]);
75
+ output[name] = errorDeserializer.readObject(member, dataObject[target]);
75
76
  }
76
77
  throw this.mixin.decorateServiceException(Object.assign(exception, errorMetadata, {
77
78
  $fault: ns.getMergedTraits().error,
@@ -52,7 +52,8 @@ export class JsonShapeDeserializer extends SerdeContextConfig {
52
52
  unionSerde.writeUnknown();
53
53
  }
54
54
  else if (typeof record.__type === "string") {
55
- for (const [k, v] of Object.entries(record)) {
55
+ for (const k in record) {
56
+ const v = record[k];
56
57
  const t = jsonName ? nameMap[k] ?? k : k;
57
58
  if (!(t in out)) {
58
59
  out[t] = v;
@@ -72,8 +73,8 @@ export class JsonShapeDeserializer extends SerdeContextConfig {
72
73
  if (ns.isMapSchema()) {
73
74
  const mapMember = ns.getValueSchema();
74
75
  const out = {};
75
- for (const [_k, _v] of Object.entries(value)) {
76
- out[_k] = this._read(mapMember, _v);
76
+ for (const _k in value) {
77
+ out[_k] = this._read(mapMember, value[_k]);
77
78
  }
78
79
  return out;
79
80
  }
@@ -130,7 +131,8 @@ export class JsonShapeDeserializer extends SerdeContextConfig {
130
131
  if (ns.isDocumentSchema()) {
131
132
  if (isObject) {
132
133
  const out = Array.isArray(value) ? [] : {};
133
- for (const [k, v] of Object.entries(value)) {
134
+ for (const k in value) {
135
+ const v = value[k];
134
136
  if (v instanceof NumericValue) {
135
137
  out[k] = v;
136
138
  }
@@ -48,6 +48,7 @@ export class JsonShapeSerializer extends SerdeContextConfig {
48
48
  if (jsonName) {
49
49
  nameMap = {};
50
50
  }
51
+ let outCount = 0;
51
52
  for (const [memberName, memberSchema] of ns.structIterator()) {
52
53
  const serializableValue = this._write(memberSchema, record[memberName], ns);
53
54
  if (serializableValue !== undefined) {
@@ -57,9 +58,10 @@ export class JsonShapeSerializer extends SerdeContextConfig {
57
58
  nameMap[memberName] = targetKey;
58
59
  }
59
60
  out[targetKey] = serializableValue;
61
+ outCount++;
60
62
  }
61
63
  }
62
- if (ns.isUnionSchema() && Object.keys(out).length === 0) {
64
+ if (ns.isUnionSchema() && outCount === 0) {
63
65
  const { $unknown } = record;
64
66
  if (Array.isArray($unknown)) {
65
67
  const [k, v] = $unknown;
@@ -67,7 +69,8 @@ export class JsonShapeSerializer extends SerdeContextConfig {
67
69
  }
68
70
  }
69
71
  else if (typeof record.__type === "string") {
70
- for (const [k, v] of Object.entries(record)) {
72
+ for (const k in record) {
73
+ const v = record[k];
71
74
  const targetKey = jsonName ? nameMap[k] ?? k : k;
72
75
  if (!(targetKey in out)) {
73
76
  out[targetKey] = this._write(15, v);
@@ -91,7 +94,8 @@ export class JsonShapeSerializer extends SerdeContextConfig {
91
94
  const mapMember = ns.getValueSchema();
92
95
  const out = {};
93
96
  const sparse = !!ns.getMergedTraits().sparse;
94
- for (const [_k, _v] of Object.entries(value)) {
97
+ for (const _k in value) {
98
+ const _v = value[_k];
95
99
  if (sparse || _v != null) {
96
100
  out[_k] = this._write(mapMember, _v);
97
101
  }
@@ -156,7 +160,8 @@ export class JsonShapeSerializer extends SerdeContextConfig {
156
160
  if (ns.isDocumentSchema()) {
157
161
  if (isObject) {
158
162
  const out = Array.isArray(value) ? [] : {};
159
- for (const [k, v] of Object.entries(value)) {
163
+ for (const k in value) {
164
+ const v = value[k];
160
165
  if (v instanceof NumericValue) {
161
166
  this.useReplacer = true;
162
167
  out[k] = v;
@@ -65,7 +65,8 @@ export class SinglePassJsonShapeSerializer extends SerdeContextConfig {
65
65
  }
66
66
  else if (ns.isMapSchema() || ns.isDocumentSchema()) {
67
67
  b += "{";
68
- for (const [k, v] of Object.entries(value)) {
68
+ for (const k in value) {
69
+ const v = value[k];
69
70
  if (v != null || sparse) {
70
71
  b += `"${k}":${this.writeValue(ns, v)}`;
71
72
  b += ",";
@@ -20,24 +20,24 @@ export const parseJsonErrorBody = async (errorBody, context) => {
20
20
  value.message = value.message ?? value.Message;
21
21
  return value;
22
22
  };
23
+ const findKey = (object, key) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase());
24
+ const sanitizeErrorCode = (rawValue) => {
25
+ let cleanValue = rawValue;
26
+ if (typeof cleanValue === "number") {
27
+ cleanValue = cleanValue.toString();
28
+ }
29
+ if (cleanValue.indexOf(",") >= 0) {
30
+ cleanValue = cleanValue.split(",")[0];
31
+ }
32
+ if (cleanValue.indexOf(":") >= 0) {
33
+ cleanValue = cleanValue.split(":")[0];
34
+ }
35
+ if (cleanValue.indexOf("#") >= 0) {
36
+ cleanValue = cleanValue.split("#")[1];
37
+ }
38
+ return cleanValue;
39
+ };
23
40
  export const loadRestJsonErrorCode = (output, data) => {
24
- const findKey = (object, key) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase());
25
- const sanitizeErrorCode = (rawValue) => {
26
- let cleanValue = rawValue;
27
- if (typeof cleanValue === "number") {
28
- cleanValue = cleanValue.toString();
29
- }
30
- if (cleanValue.indexOf(",") >= 0) {
31
- cleanValue = cleanValue.split(",")[0];
32
- }
33
- if (cleanValue.indexOf(":") >= 0) {
34
- cleanValue = cleanValue.split(":")[0];
35
- }
36
- if (cleanValue.indexOf("#") >= 0) {
37
- cleanValue = cleanValue.split("#")[1];
38
- }
39
- return cleanValue;
40
- };
41
41
  const headerKey = findKey(output.headers, "x-amzn-errortype");
42
42
  if (headerKey !== undefined) {
43
43
  return sanitizeErrorCode(output.headers[headerKey]);
@@ -42,9 +42,7 @@ export class AwsQueryProtocol extends RpcProtocol {
42
42
  if (!request.path.endsWith("/")) {
43
43
  request.path += "/";
44
44
  }
45
- Object.assign(request.headers, {
46
- "content-type": `application/x-www-form-urlencoded`,
47
- });
45
+ request.headers["content-type"] = "application/x-www-form-urlencoded";
48
46
  if (deref(operationSchema.input) === "unit" || !request.body) {
49
47
  request.body = "";
50
48
  }
@@ -77,11 +75,8 @@ export class AwsQueryProtocol extends RpcProtocol {
77
75
  if (bytes.byteLength > 0) {
78
76
  Object.assign(dataObject, await deserializer.read(ns, bytes, awsQueryResultKey));
79
77
  }
80
- const output = {
81
- $metadata: this.deserializeMetadata(response),
82
- ...dataObject,
83
- };
84
- return output;
78
+ dataObject.$metadata = this.deserializeMetadata(response);
79
+ return dataObject;
85
80
  }
86
81
  useNestedResult() {
87
82
  return true;
@@ -113,7 +113,8 @@ export class QueryShapeSerializer extends SerdeContextConfig {
113
113
  const memberSchema = ns.getValueSchema();
114
114
  const flat = ns.getMergedTraits().xmlFlattened;
115
115
  let i = 1;
116
- for (const [k, v] of Object.entries(value)) {
116
+ for (const k in value) {
117
+ const v = value[k];
117
118
  if (v == null) {
118
119
  continue;
119
120
  }
@@ -75,10 +75,11 @@ export class AwsRestXmlProtocol extends HttpBindingProtocol {
75
75
  const exception = new ErrorCtor(message);
76
76
  await this.deserializeHttpMessage(errorSchema, context, response, dataObject);
77
77
  const output = {};
78
+ const errorDeserializer = this.codec.createDeserializer();
78
79
  for (const [name, member] of ns.structIterator()) {
79
80
  const target = member.getMergedTraits().xmlName ?? name;
80
81
  const value = dataObject.Error?.[target] ?? dataObject[target];
81
- output[name] = this.codec.createDeserializer().readSchema(member, value);
82
+ output[name] = errorDeserializer.readSchema(member, value);
82
83
  }
83
84
  throw this.mixin.decorateServiceException(Object.assign(exception, errorMetadata, {
84
85
  $fault: ns.getMergedTraits().error,
@@ -191,7 +191,8 @@ export class XmlShapeSerializer extends SerdeContextConfig {
191
191
  entry.addChildNode(valueNode);
192
192
  };
193
193
  if (flat) {
194
- for (const [key, val] of Object.entries(map)) {
194
+ for (const key in map) {
195
+ const val = map[key];
195
196
  if (sparse || val != null) {
196
197
  const entry = XmlNode.of(mapTraits.xmlName ?? mapMember.getMemberName());
197
198
  addKeyValue(entry, key, val);
@@ -208,7 +209,8 @@ export class XmlShapeSerializer extends SerdeContextConfig {
208
209
  }
209
210
  container.addChildNode(mapNode);
210
211
  }
211
- for (const [key, val] of Object.entries(map)) {
212
+ for (const key in map) {
213
+ const val = map[key];
212
214
  if (sparse || val != null) {
213
215
  const entry = XmlNode.of("entry");
214
216
  addKeyValue(entry, key, val);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aws-sdk/core",
3
- "version": "3.974.0",
3
+ "version": "3.974.2",
4
4
  "description": "Core functions & classes shared by multiple AWS SDK clients.",
5
5
  "scripts": {
6
6
  "build": "yarn lint && concurrently 'yarn:build:types' 'yarn:build:es' && yarn build:cjs",