@aws-sdk/core 3.936.0 → 3.943.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.
Files changed (24) hide show
  1. package/dist-cjs/index.js +161 -91
  2. package/dist-cjs/submodules/protocols/index.js +161 -91
  3. package/dist-es/submodules/protocols/json/AwsJson1_0Protocol.js +2 -1
  4. package/dist-es/submodules/protocols/json/AwsJson1_1Protocol.js +2 -1
  5. package/dist-es/submodules/protocols/json/AwsJsonRpcProtocol.js +10 -8
  6. package/dist-es/submodules/protocols/json/JsonShapeDeserializer.js +31 -26
  7. package/dist-es/submodules/protocols/json/JsonShapeSerializer.js +76 -53
  8. package/dist-es/submodules/protocols/json/experimental/SinglePassJsonShapeSerializer.js +2 -1
  9. package/dist-es/submodules/protocols/query/QueryShapeSerializer.js +2 -1
  10. package/dist-es/submodules/protocols/structIterator.js +40 -0
  11. package/dist-es/submodules/protocols/xml/XmlShapeSerializer.js +2 -1
  12. package/dist-types/submodules/protocols/json/AwsJson1_0Protocol.d.ts +3 -1
  13. package/dist-types/submodules/protocols/json/AwsJson1_1Protocol.d.ts +3 -1
  14. package/dist-types/submodules/protocols/json/AwsJsonRpcProtocol.d.ts +2 -1
  15. package/dist-types/submodules/protocols/json/JsonShapeDeserializer.d.ts +1 -1
  16. package/dist-types/submodules/protocols/json/JsonShapeSerializer.d.ts +12 -3
  17. package/dist-types/submodules/protocols/structIterator.d.ts +27 -0
  18. package/dist-types/ts3.4/submodules/protocols/json/AwsJson1_0Protocol.d.ts +3 -0
  19. package/dist-types/ts3.4/submodules/protocols/json/AwsJson1_1Protocol.d.ts +3 -0
  20. package/dist-types/ts3.4/submodules/protocols/json/AwsJsonRpcProtocol.d.ts +2 -0
  21. package/dist-types/ts3.4/submodules/protocols/json/JsonShapeDeserializer.d.ts +1 -1
  22. package/dist-types/ts3.4/submodules/protocols/json/JsonShapeSerializer.d.ts +9 -3
  23. package/dist-types/ts3.4/submodules/protocols/structIterator.d.ts +12 -0
  24. package/package.json +1 -1
package/dist-cjs/index.js CHANGED
@@ -539,6 +539,46 @@ class SerdeContextConfig {
539
539
  }
540
540
  }
541
541
 
542
+ function* serializingStructIterator(ns, sourceObject) {
543
+ if (ns.isUnitSchema()) {
544
+ return;
545
+ }
546
+ const struct = ns.getSchema();
547
+ for (let i = 0; i < struct[4].length; ++i) {
548
+ const key = struct[4][i];
549
+ const memberSchema = struct[5][i];
550
+ const memberNs = new schema.NormalizedSchema([memberSchema, 0], key);
551
+ if (!(key in sourceObject) && !memberNs.isIdempotencyToken()) {
552
+ continue;
553
+ }
554
+ yield [key, memberNs];
555
+ }
556
+ }
557
+ function* deserializingStructIterator(ns, sourceObject, nameTrait) {
558
+ if (ns.isUnitSchema()) {
559
+ return;
560
+ }
561
+ const struct = ns.getSchema();
562
+ let keysRemaining = Object.keys(sourceObject).filter((k) => k !== "__type").length;
563
+ for (let i = 0; i < struct[4].length; ++i) {
564
+ if (keysRemaining === 0) {
565
+ break;
566
+ }
567
+ const key = struct[4][i];
568
+ const memberSchema = struct[5][i];
569
+ const memberNs = new schema.NormalizedSchema([memberSchema, 0], key);
570
+ let serializationKey = key;
571
+ if (nameTrait) {
572
+ serializationKey = memberNs.getMergedTraits()[nameTrait] ?? key;
573
+ }
574
+ if (!(serializationKey in sourceObject)) {
575
+ continue;
576
+ }
577
+ yield [key, memberNs];
578
+ keysRemaining -= 1;
579
+ }
580
+ }
581
+
542
582
  function jsonReviver(key, value, context) {
543
583
  if (context?.source) {
544
584
  const numericString = context.source;
@@ -628,38 +668,40 @@ class JsonShapeDeserializer extends SerdeContextConfig {
628
668
  _read(schema$1, value) {
629
669
  const isObject = value !== null && typeof value === "object";
630
670
  const ns = schema.NormalizedSchema.of(schema$1);
631
- if (ns.isListSchema() && Array.isArray(value)) {
632
- const listMember = ns.getValueSchema();
633
- const out = [];
634
- const sparse = !!ns.getMergedTraits().sparse;
635
- for (const item of value) {
636
- if (sparse || item != null) {
637
- out.push(this._read(listMember, item));
671
+ if (isObject) {
672
+ if (ns.isStructSchema()) {
673
+ const out = {};
674
+ for (const [memberName, memberSchema] of deserializingStructIterator(ns, value, this.settings.jsonName ? "jsonName" : false)) {
675
+ const fromKey = this.settings.jsonName ? memberSchema.getMergedTraits().jsonName ?? memberName : memberName;
676
+ const deserializedValue = this._read(memberSchema, value[fromKey]);
677
+ if (deserializedValue != null) {
678
+ out[memberName] = deserializedValue;
679
+ }
638
680
  }
681
+ return out;
639
682
  }
640
- return out;
641
- }
642
- else if (ns.isMapSchema() && isObject) {
643
- const mapMember = ns.getValueSchema();
644
- const out = {};
645
- const sparse = !!ns.getMergedTraits().sparse;
646
- for (const [_k, _v] of Object.entries(value)) {
647
- if (sparse || _v != null) {
648
- out[_k] = this._read(mapMember, _v);
683
+ if (Array.isArray(value) && ns.isListSchema()) {
684
+ const listMember = ns.getValueSchema();
685
+ const out = [];
686
+ const sparse = !!ns.getMergedTraits().sparse;
687
+ for (const item of value) {
688
+ if (sparse || item != null) {
689
+ out.push(this._read(listMember, item));
690
+ }
649
691
  }
692
+ return out;
650
693
  }
651
- return out;
652
- }
653
- else if (ns.isStructSchema() && isObject) {
654
- const out = {};
655
- for (const [memberName, memberSchema] of ns.structIterator()) {
656
- const fromKey = this.settings.jsonName ? memberSchema.getMergedTraits().jsonName ?? memberName : memberName;
657
- const deserializedValue = this._read(memberSchema, value[fromKey]);
658
- if (deserializedValue != null) {
659
- out[memberName] = deserializedValue;
694
+ if (ns.isMapSchema()) {
695
+ const mapMember = ns.getValueSchema();
696
+ const out = {};
697
+ const sparse = !!ns.getMergedTraits().sparse;
698
+ for (const [_k, _v] of Object.entries(value)) {
699
+ if (sparse || _v != null) {
700
+ out[_k] = this._read(mapMember, _v);
701
+ }
660
702
  }
703
+ return out;
661
704
  }
662
- return out;
663
705
  }
664
706
  if (ns.isBlobSchema() && typeof value === "string") {
665
707
  return utilBase64.fromBase64(value);
@@ -670,6 +712,7 @@ class JsonShapeDeserializer extends SerdeContextConfig {
670
712
  if (isJson) {
671
713
  return serde.LazyJsonString.from(value);
672
714
  }
715
+ return value;
673
716
  }
674
717
  if (ns.isTimestampSchema() && value != null) {
675
718
  const format = protocols.determineTimestampFormat(ns, this.settings);
@@ -707,6 +750,7 @@ class JsonShapeDeserializer extends SerdeContextConfig {
707
750
  case "NaN":
708
751
  return NaN;
709
752
  }
753
+ return value;
710
754
  }
711
755
  if (ns.isDocumentSchema()) {
712
756
  if (isObject) {
@@ -778,6 +822,7 @@ class JsonReplacer {
778
822
  class JsonShapeSerializer extends SerdeContextConfig {
779
823
  settings;
780
824
  buffer;
825
+ useReplacer = false;
781
826
  rootSchema;
782
827
  constructor(settings) {
783
828
  super();
@@ -794,9 +839,13 @@ class JsonShapeSerializer extends SerdeContextConfig {
794
839
  }
795
840
  }
796
841
  flush() {
797
- const { rootSchema } = this;
842
+ const { rootSchema, useReplacer } = this;
798
843
  this.rootSchema = undefined;
844
+ this.useReplacer = false;
799
845
  if (rootSchema?.isStructSchema() || rootSchema?.isDocumentSchema()) {
846
+ if (!useReplacer) {
847
+ return JSON.stringify(this.buffer);
848
+ }
800
849
  const replacer = new JsonReplacer();
801
850
  return replacer.replaceInJson(JSON.stringify(this.buffer, replacer.createReplacer(), 0));
802
851
  }
@@ -805,68 +854,68 @@ class JsonShapeSerializer extends SerdeContextConfig {
805
854
  _write(schema$1, value, container) {
806
855
  const isObject = value !== null && typeof value === "object";
807
856
  const ns = schema.NormalizedSchema.of(schema$1);
808
- if (ns.isListSchema() && Array.isArray(value)) {
809
- const listMember = ns.getValueSchema();
810
- const out = [];
811
- const sparse = !!ns.getMergedTraits().sparse;
812
- for (const item of value) {
813
- if (sparse || item != null) {
814
- out.push(this._write(listMember, item));
857
+ if (isObject) {
858
+ if (ns.isStructSchema()) {
859
+ const out = {};
860
+ for (const [memberName, memberSchema] of serializingStructIterator(ns, value)) {
861
+ const serializableValue = this._write(memberSchema, value[memberName], ns);
862
+ if (serializableValue !== undefined) {
863
+ const jsonName = memberSchema.getMergedTraits().jsonName;
864
+ const targetKey = this.settings.jsonName ? jsonName ?? memberName : memberName;
865
+ out[targetKey] = serializableValue;
866
+ }
815
867
  }
868
+ return out;
816
869
  }
817
- return out;
818
- }
819
- else if (ns.isMapSchema() && isObject) {
820
- const mapMember = ns.getValueSchema();
821
- const out = {};
822
- const sparse = !!ns.getMergedTraits().sparse;
823
- for (const [_k, _v] of Object.entries(value)) {
824
- if (sparse || _v != null) {
825
- out[_k] = this._write(mapMember, _v);
870
+ if (Array.isArray(value) && ns.isListSchema()) {
871
+ const listMember = ns.getValueSchema();
872
+ const out = [];
873
+ const sparse = !!ns.getMergedTraits().sparse;
874
+ for (const item of value) {
875
+ if (sparse || item != null) {
876
+ out.push(this._write(listMember, item));
877
+ }
826
878
  }
879
+ return out;
827
880
  }
828
- return out;
829
- }
830
- else if (ns.isStructSchema() && isObject) {
831
- const out = {};
832
- for (const [memberName, memberSchema] of ns.structIterator()) {
833
- const targetKey = this.settings.jsonName ? memberSchema.getMergedTraits().jsonName ?? memberName : memberName;
834
- const serializableValue = this._write(memberSchema, value[memberName], ns);
835
- if (serializableValue !== undefined) {
836
- out[targetKey] = serializableValue;
881
+ if (ns.isMapSchema()) {
882
+ const mapMember = ns.getValueSchema();
883
+ const out = {};
884
+ const sparse = !!ns.getMergedTraits().sparse;
885
+ for (const [_k, _v] of Object.entries(value)) {
886
+ if (sparse || _v != null) {
887
+ out[_k] = this._write(mapMember, _v);
888
+ }
837
889
  }
890
+ return out;
838
891
  }
839
- return out;
840
- }
841
- if (value === null && container?.isStructSchema()) {
842
- return void 0;
843
- }
844
- if ((ns.isBlobSchema() && (value instanceof Uint8Array || typeof value === "string")) ||
845
- (ns.isDocumentSchema() && value instanceof Uint8Array)) {
846
- if (ns === this.rootSchema) {
847
- return value;
892
+ if (value instanceof Uint8Array && (ns.isBlobSchema() || ns.isDocumentSchema())) {
893
+ if (ns === this.rootSchema) {
894
+ return value;
895
+ }
896
+ return (this.serdeContext?.base64Encoder ?? utilBase64.toBase64)(value);
848
897
  }
849
- return (this.serdeContext?.base64Encoder ?? utilBase64.toBase64)(value);
850
- }
851
- if ((ns.isTimestampSchema() || ns.isDocumentSchema()) && value instanceof Date) {
852
- const format = protocols.determineTimestampFormat(ns, this.settings);
853
- switch (format) {
854
- case 5:
855
- return value.toISOString().replace(".000Z", "Z");
856
- case 6:
857
- return serde.dateToUtcString(value);
858
- case 7:
859
- return value.getTime() / 1000;
860
- default:
861
- console.warn("Missing timestamp format, using epoch seconds", value);
862
- return value.getTime() / 1000;
898
+ if (value instanceof Date && (ns.isTimestampSchema() || ns.isDocumentSchema())) {
899
+ const format = protocols.determineTimestampFormat(ns, this.settings);
900
+ switch (format) {
901
+ case 5:
902
+ return value.toISOString().replace(".000Z", "Z");
903
+ case 6:
904
+ return serde.dateToUtcString(value);
905
+ case 7:
906
+ return value.getTime() / 1000;
907
+ default:
908
+ console.warn("Missing timestamp format, using epoch seconds", value);
909
+ return value.getTime() / 1000;
910
+ }
863
911
  }
864
- }
865
- if (ns.isNumericSchema() && typeof value === "number") {
866
- if (Math.abs(value) === Infinity || isNaN(value)) {
867
- return String(value);
912
+ if (value instanceof serde.NumericValue) {
913
+ this.useReplacer = true;
868
914
  }
869
915
  }
916
+ if (value === null && container?.isStructSchema()) {
917
+ return void 0;
918
+ }
870
919
  if (ns.isStringSchema()) {
871
920
  if (typeof value === "undefined" && ns.isIdempotencyToken()) {
872
921
  return serde.generateIdempotencyToken();
@@ -878,12 +927,29 @@ class JsonShapeSerializer extends SerdeContextConfig {
878
927
  return serde.LazyJsonString.from(value);
879
928
  }
880
929
  }
930
+ return value;
931
+ }
932
+ if (typeof value === "number" && ns.isNumericSchema()) {
933
+ if (Math.abs(value) === Infinity || isNaN(value)) {
934
+ return String(value);
935
+ }
936
+ return value;
937
+ }
938
+ if (typeof value === "string" && ns.isBlobSchema()) {
939
+ if (ns === this.rootSchema) {
940
+ return value;
941
+ }
942
+ return (this.serdeContext?.base64Encoder ?? utilBase64.toBase64)(value);
943
+ }
944
+ if (typeof value === "bigint") {
945
+ this.useReplacer = true;
881
946
  }
882
947
  if (ns.isDocumentSchema()) {
883
948
  if (isObject) {
884
949
  const out = Array.isArray(value) ? [] : {};
885
950
  for (const [k, v] of Object.entries(value)) {
886
951
  if (v instanceof serde.NumericValue) {
952
+ this.useReplacer = true;
887
953
  out[k] = v;
888
954
  }
889
955
  else {
@@ -925,18 +991,20 @@ class AwsJsonRpcProtocol extends protocols.RpcProtocol {
925
991
  codec;
926
992
  mixin;
927
993
  awsQueryCompatible;
928
- constructor({ defaultNamespace, serviceTarget, awsQueryCompatible, }) {
994
+ constructor({ defaultNamespace, serviceTarget, awsQueryCompatible, jsonCodec, }) {
929
995
  super({
930
996
  defaultNamespace,
931
997
  });
932
998
  this.serviceTarget = serviceTarget;
933
- this.codec = new JsonCodec({
934
- timestampFormat: {
935
- useTrait: true,
936
- default: 7,
937
- },
938
- jsonName: false,
939
- });
999
+ this.codec =
1000
+ jsonCodec ??
1001
+ new JsonCodec({
1002
+ timestampFormat: {
1003
+ useTrait: true,
1004
+ default: 7,
1005
+ },
1006
+ jsonName: false,
1007
+ });
940
1008
  this.serializer = this.codec.createSerializer();
941
1009
  this.deserializer = this.codec.createDeserializer();
942
1010
  this.awsQueryCompatible = !!awsQueryCompatible;
@@ -988,11 +1056,12 @@ class AwsJsonRpcProtocol extends protocols.RpcProtocol {
988
1056
  }
989
1057
 
990
1058
  class AwsJson1_0Protocol extends AwsJsonRpcProtocol {
991
- constructor({ defaultNamespace, serviceTarget, awsQueryCompatible, }) {
1059
+ constructor({ defaultNamespace, serviceTarget, awsQueryCompatible, jsonCodec, }) {
992
1060
  super({
993
1061
  defaultNamespace,
994
1062
  serviceTarget,
995
1063
  awsQueryCompatible,
1064
+ jsonCodec,
996
1065
  });
997
1066
  }
998
1067
  getShapeId() {
@@ -1007,11 +1076,12 @@ class AwsJson1_0Protocol extends AwsJsonRpcProtocol {
1007
1076
  }
1008
1077
 
1009
1078
  class AwsJson1_1Protocol extends AwsJsonRpcProtocol {
1010
- constructor({ defaultNamespace, serviceTarget, awsQueryCompatible, }) {
1079
+ constructor({ defaultNamespace, serviceTarget, awsQueryCompatible, jsonCodec, }) {
1011
1080
  super({
1012
1081
  defaultNamespace,
1013
1082
  serviceTarget,
1014
1083
  awsQueryCompatible,
1084
+ jsonCodec,
1015
1085
  });
1016
1086
  }
1017
1087
  getShapeId() {
@@ -1360,7 +1430,7 @@ class QueryShapeSerializer extends SerdeContextConfig {
1360
1430
  }
1361
1431
  else if (ns.isStructSchema()) {
1362
1432
  if (value && typeof value === "object") {
1363
- for (const [memberName, member] of ns.structIterator()) {
1433
+ for (const [memberName, member] of serializingStructIterator(ns, value)) {
1364
1434
  if (value[memberName] == null && !member.isIdempotencyToken()) {
1365
1435
  continue;
1366
1436
  }
@@ -1657,7 +1727,7 @@ class XmlShapeSerializer extends SerdeContextConfig {
1657
1727
  }
1658
1728
  const structXmlNode = xmlBuilder.XmlNode.of(name);
1659
1729
  const [xmlnsAttr, xmlns] = this.getXmlnsAttribute(ns, parentXmlns);
1660
- for (const [memberName, memberSchema] of ns.structIterator()) {
1730
+ for (const [memberName, memberSchema] of serializingStructIterator(ns, value)) {
1661
1731
  const val = value[memberName];
1662
1732
  if (val != null || memberSchema.isIdempotencyToken()) {
1663
1733
  if (memberSchema.getMergedTraits().xmlAttribute) {