@aws-sdk/core 3.940.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.
- package/dist-cjs/index.js +124 -92
- package/dist-cjs/submodules/protocols/index.js +124 -92
- 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 +10 -8
- package/dist-es/submodules/protocols/json/JsonShapeDeserializer.js +30 -26
- package/dist-es/submodules/protocols/json/JsonShapeSerializer.js +75 -53
- package/dist-es/submodules/protocols/structIterator.js +5 -3
- package/dist-types/submodules/protocols/json/AwsJson1_0Protocol.d.ts +3 -1
- package/dist-types/submodules/protocols/json/AwsJson1_1Protocol.d.ts +3 -1
- package/dist-types/submodules/protocols/json/AwsJsonRpcProtocol.d.ts +2 -1
- package/dist-types/submodules/protocols/json/JsonShapeDeserializer.d.ts +1 -1
- package/dist-types/submodules/protocols/json/JsonShapeSerializer.d.ts +12 -3
- package/dist-types/ts3.4/submodules/protocols/json/AwsJson1_0Protocol.d.ts +3 -0
- package/dist-types/ts3.4/submodules/protocols/json/AwsJson1_1Protocol.d.ts +3 -0
- package/dist-types/ts3.4/submodules/protocols/json/AwsJsonRpcProtocol.d.ts +2 -0
- package/dist-types/ts3.4/submodules/protocols/json/JsonShapeDeserializer.d.ts +1 -1
- package/dist-types/ts3.4/submodules/protocols/json/JsonShapeSerializer.d.ts +9 -3
- package/package.json +1 -1
package/dist-cjs/index.js
CHANGED
|
@@ -546,7 +546,8 @@ function* serializingStructIterator(ns, sourceObject) {
|
|
|
546
546
|
const struct = ns.getSchema();
|
|
547
547
|
for (let i = 0; i < struct[4].length; ++i) {
|
|
548
548
|
const key = struct[4][i];
|
|
549
|
-
const
|
|
549
|
+
const memberSchema = struct[5][i];
|
|
550
|
+
const memberNs = new schema.NormalizedSchema([memberSchema, 0], key);
|
|
550
551
|
if (!(key in sourceObject) && !memberNs.isIdempotencyToken()) {
|
|
551
552
|
continue;
|
|
552
553
|
}
|
|
@@ -558,13 +559,14 @@ function* deserializingStructIterator(ns, sourceObject, nameTrait) {
|
|
|
558
559
|
return;
|
|
559
560
|
}
|
|
560
561
|
const struct = ns.getSchema();
|
|
561
|
-
let keysRemaining = Object.keys(sourceObject).length;
|
|
562
|
+
let keysRemaining = Object.keys(sourceObject).filter((k) => k !== "__type").length;
|
|
562
563
|
for (let i = 0; i < struct[4].length; ++i) {
|
|
563
564
|
if (keysRemaining === 0) {
|
|
564
565
|
break;
|
|
565
566
|
}
|
|
566
567
|
const key = struct[4][i];
|
|
567
|
-
const
|
|
568
|
+
const memberSchema = struct[5][i];
|
|
569
|
+
const memberNs = new schema.NormalizedSchema([memberSchema, 0], key);
|
|
568
570
|
let serializationKey = key;
|
|
569
571
|
if (nameTrait) {
|
|
570
572
|
serializationKey = memberNs.getMergedTraits()[nameTrait] ?? key;
|
|
@@ -666,38 +668,40 @@ class JsonShapeDeserializer extends SerdeContextConfig {
|
|
|
666
668
|
_read(schema$1, value) {
|
|
667
669
|
const isObject = value !== null && typeof value === "object";
|
|
668
670
|
const ns = schema.NormalizedSchema.of(schema$1);
|
|
669
|
-
if (
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
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
|
+
}
|
|
676
680
|
}
|
|
681
|
+
return out;
|
|
677
682
|
}
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
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
|
+
}
|
|
687
691
|
}
|
|
692
|
+
return out;
|
|
688
693
|
}
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
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
|
+
}
|
|
698
702
|
}
|
|
703
|
+
return out;
|
|
699
704
|
}
|
|
700
|
-
return out;
|
|
701
705
|
}
|
|
702
706
|
if (ns.isBlobSchema() && typeof value === "string") {
|
|
703
707
|
return utilBase64.fromBase64(value);
|
|
@@ -708,6 +712,7 @@ class JsonShapeDeserializer extends SerdeContextConfig {
|
|
|
708
712
|
if (isJson) {
|
|
709
713
|
return serde.LazyJsonString.from(value);
|
|
710
714
|
}
|
|
715
|
+
return value;
|
|
711
716
|
}
|
|
712
717
|
if (ns.isTimestampSchema() && value != null) {
|
|
713
718
|
const format = protocols.determineTimestampFormat(ns, this.settings);
|
|
@@ -745,6 +750,7 @@ class JsonShapeDeserializer extends SerdeContextConfig {
|
|
|
745
750
|
case "NaN":
|
|
746
751
|
return NaN;
|
|
747
752
|
}
|
|
753
|
+
return value;
|
|
748
754
|
}
|
|
749
755
|
if (ns.isDocumentSchema()) {
|
|
750
756
|
if (isObject) {
|
|
@@ -816,6 +822,7 @@ class JsonReplacer {
|
|
|
816
822
|
class JsonShapeSerializer extends SerdeContextConfig {
|
|
817
823
|
settings;
|
|
818
824
|
buffer;
|
|
825
|
+
useReplacer = false;
|
|
819
826
|
rootSchema;
|
|
820
827
|
constructor(settings) {
|
|
821
828
|
super();
|
|
@@ -832,9 +839,13 @@ class JsonShapeSerializer extends SerdeContextConfig {
|
|
|
832
839
|
}
|
|
833
840
|
}
|
|
834
841
|
flush() {
|
|
835
|
-
const { rootSchema } = this;
|
|
842
|
+
const { rootSchema, useReplacer } = this;
|
|
836
843
|
this.rootSchema = undefined;
|
|
844
|
+
this.useReplacer = false;
|
|
837
845
|
if (rootSchema?.isStructSchema() || rootSchema?.isDocumentSchema()) {
|
|
846
|
+
if (!useReplacer) {
|
|
847
|
+
return JSON.stringify(this.buffer);
|
|
848
|
+
}
|
|
838
849
|
const replacer = new JsonReplacer();
|
|
839
850
|
return replacer.replaceInJson(JSON.stringify(this.buffer, replacer.createReplacer(), 0));
|
|
840
851
|
}
|
|
@@ -843,68 +854,68 @@ class JsonShapeSerializer extends SerdeContextConfig {
|
|
|
843
854
|
_write(schema$1, value, container) {
|
|
844
855
|
const isObject = value !== null && typeof value === "object";
|
|
845
856
|
const ns = schema.NormalizedSchema.of(schema$1);
|
|
846
|
-
if (
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
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
|
+
}
|
|
853
867
|
}
|
|
868
|
+
return out;
|
|
854
869
|
}
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
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
|
+
}
|
|
864
878
|
}
|
|
879
|
+
return out;
|
|
865
880
|
}
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
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
|
+
}
|
|
875
889
|
}
|
|
890
|
+
return out;
|
|
876
891
|
}
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
if ((ns.isBlobSchema() && (value instanceof Uint8Array || typeof value === "string")) ||
|
|
883
|
-
(ns.isDocumentSchema() && value instanceof Uint8Array)) {
|
|
884
|
-
if (ns === this.rootSchema) {
|
|
885
|
-
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);
|
|
886
897
|
}
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
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
|
+
}
|
|
901
911
|
}
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
if (Math.abs(value) === Infinity || isNaN(value)) {
|
|
905
|
-
return String(value);
|
|
912
|
+
if (value instanceof serde.NumericValue) {
|
|
913
|
+
this.useReplacer = true;
|
|
906
914
|
}
|
|
907
915
|
}
|
|
916
|
+
if (value === null && container?.isStructSchema()) {
|
|
917
|
+
return void 0;
|
|
918
|
+
}
|
|
908
919
|
if (ns.isStringSchema()) {
|
|
909
920
|
if (typeof value === "undefined" && ns.isIdempotencyToken()) {
|
|
910
921
|
return serde.generateIdempotencyToken();
|
|
@@ -916,12 +927,29 @@ class JsonShapeSerializer extends SerdeContextConfig {
|
|
|
916
927
|
return serde.LazyJsonString.from(value);
|
|
917
928
|
}
|
|
918
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;
|
|
919
946
|
}
|
|
920
947
|
if (ns.isDocumentSchema()) {
|
|
921
948
|
if (isObject) {
|
|
922
949
|
const out = Array.isArray(value) ? [] : {};
|
|
923
950
|
for (const [k, v] of Object.entries(value)) {
|
|
924
951
|
if (v instanceof serde.NumericValue) {
|
|
952
|
+
this.useReplacer = true;
|
|
925
953
|
out[k] = v;
|
|
926
954
|
}
|
|
927
955
|
else {
|
|
@@ -963,18 +991,20 @@ class AwsJsonRpcProtocol extends protocols.RpcProtocol {
|
|
|
963
991
|
codec;
|
|
964
992
|
mixin;
|
|
965
993
|
awsQueryCompatible;
|
|
966
|
-
constructor({ defaultNamespace, serviceTarget, awsQueryCompatible, }) {
|
|
994
|
+
constructor({ defaultNamespace, serviceTarget, awsQueryCompatible, jsonCodec, }) {
|
|
967
995
|
super({
|
|
968
996
|
defaultNamespace,
|
|
969
997
|
});
|
|
970
998
|
this.serviceTarget = serviceTarget;
|
|
971
|
-
this.codec =
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
999
|
+
this.codec =
|
|
1000
|
+
jsonCodec ??
|
|
1001
|
+
new JsonCodec({
|
|
1002
|
+
timestampFormat: {
|
|
1003
|
+
useTrait: true,
|
|
1004
|
+
default: 7,
|
|
1005
|
+
},
|
|
1006
|
+
jsonName: false,
|
|
1007
|
+
});
|
|
978
1008
|
this.serializer = this.codec.createSerializer();
|
|
979
1009
|
this.deserializer = this.codec.createDeserializer();
|
|
980
1010
|
this.awsQueryCompatible = !!awsQueryCompatible;
|
|
@@ -1026,11 +1056,12 @@ class AwsJsonRpcProtocol extends protocols.RpcProtocol {
|
|
|
1026
1056
|
}
|
|
1027
1057
|
|
|
1028
1058
|
class AwsJson1_0Protocol extends AwsJsonRpcProtocol {
|
|
1029
|
-
constructor({ defaultNamespace, serviceTarget, awsQueryCompatible, }) {
|
|
1059
|
+
constructor({ defaultNamespace, serviceTarget, awsQueryCompatible, jsonCodec, }) {
|
|
1030
1060
|
super({
|
|
1031
1061
|
defaultNamespace,
|
|
1032
1062
|
serviceTarget,
|
|
1033
1063
|
awsQueryCompatible,
|
|
1064
|
+
jsonCodec,
|
|
1034
1065
|
});
|
|
1035
1066
|
}
|
|
1036
1067
|
getShapeId() {
|
|
@@ -1045,11 +1076,12 @@ class AwsJson1_0Protocol extends AwsJsonRpcProtocol {
|
|
|
1045
1076
|
}
|
|
1046
1077
|
|
|
1047
1078
|
class AwsJson1_1Protocol extends AwsJsonRpcProtocol {
|
|
1048
|
-
constructor({ defaultNamespace, serviceTarget, awsQueryCompatible, }) {
|
|
1079
|
+
constructor({ defaultNamespace, serviceTarget, awsQueryCompatible, jsonCodec, }) {
|
|
1049
1080
|
super({
|
|
1050
1081
|
defaultNamespace,
|
|
1051
1082
|
serviceTarget,
|
|
1052
1083
|
awsQueryCompatible,
|
|
1084
|
+
jsonCodec,
|
|
1053
1085
|
});
|
|
1054
1086
|
}
|
|
1055
1087
|
getShapeId() {
|
|
@@ -216,7 +216,8 @@ function* serializingStructIterator(ns, sourceObject) {
|
|
|
216
216
|
const struct = ns.getSchema();
|
|
217
217
|
for (let i = 0; i < struct[4].length; ++i) {
|
|
218
218
|
const key = struct[4][i];
|
|
219
|
-
const
|
|
219
|
+
const memberSchema = struct[5][i];
|
|
220
|
+
const memberNs = new schema.NormalizedSchema([memberSchema, 0], key);
|
|
220
221
|
if (!(key in sourceObject) && !memberNs.isIdempotencyToken()) {
|
|
221
222
|
continue;
|
|
222
223
|
}
|
|
@@ -228,13 +229,14 @@ function* deserializingStructIterator(ns, sourceObject, nameTrait) {
|
|
|
228
229
|
return;
|
|
229
230
|
}
|
|
230
231
|
const struct = ns.getSchema();
|
|
231
|
-
let keysRemaining = Object.keys(sourceObject).length;
|
|
232
|
+
let keysRemaining = Object.keys(sourceObject).filter((k) => k !== "__type").length;
|
|
232
233
|
for (let i = 0; i < struct[4].length; ++i) {
|
|
233
234
|
if (keysRemaining === 0) {
|
|
234
235
|
break;
|
|
235
236
|
}
|
|
236
237
|
const key = struct[4][i];
|
|
237
|
-
const
|
|
238
|
+
const memberSchema = struct[5][i];
|
|
239
|
+
const memberNs = new schema.NormalizedSchema([memberSchema, 0], key);
|
|
238
240
|
let serializationKey = key;
|
|
239
241
|
if (nameTrait) {
|
|
240
242
|
serializationKey = memberNs.getMergedTraits()[nameTrait] ?? key;
|
|
@@ -336,38 +338,40 @@ class JsonShapeDeserializer extends SerdeContextConfig {
|
|
|
336
338
|
_read(schema$1, value) {
|
|
337
339
|
const isObject = value !== null && typeof value === "object";
|
|
338
340
|
const ns = schema.NormalizedSchema.of(schema$1);
|
|
339
|
-
if (
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
341
|
+
if (isObject) {
|
|
342
|
+
if (ns.isStructSchema()) {
|
|
343
|
+
const out = {};
|
|
344
|
+
for (const [memberName, memberSchema] of deserializingStructIterator(ns, value, this.settings.jsonName ? "jsonName" : false)) {
|
|
345
|
+
const fromKey = this.settings.jsonName ? memberSchema.getMergedTraits().jsonName ?? memberName : memberName;
|
|
346
|
+
const deserializedValue = this._read(memberSchema, value[fromKey]);
|
|
347
|
+
if (deserializedValue != null) {
|
|
348
|
+
out[memberName] = deserializedValue;
|
|
349
|
+
}
|
|
346
350
|
}
|
|
351
|
+
return out;
|
|
347
352
|
}
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
out[_k] = this._read(mapMember, _v);
|
|
353
|
+
if (Array.isArray(value) && ns.isListSchema()) {
|
|
354
|
+
const listMember = ns.getValueSchema();
|
|
355
|
+
const out = [];
|
|
356
|
+
const sparse = !!ns.getMergedTraits().sparse;
|
|
357
|
+
for (const item of value) {
|
|
358
|
+
if (sparse || item != null) {
|
|
359
|
+
out.push(this._read(listMember, item));
|
|
360
|
+
}
|
|
357
361
|
}
|
|
362
|
+
return out;
|
|
358
363
|
}
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
out[memberName] = deserializedValue;
|
|
364
|
+
if (ns.isMapSchema()) {
|
|
365
|
+
const mapMember = ns.getValueSchema();
|
|
366
|
+
const out = {};
|
|
367
|
+
const sparse = !!ns.getMergedTraits().sparse;
|
|
368
|
+
for (const [_k, _v] of Object.entries(value)) {
|
|
369
|
+
if (sparse || _v != null) {
|
|
370
|
+
out[_k] = this._read(mapMember, _v);
|
|
371
|
+
}
|
|
368
372
|
}
|
|
373
|
+
return out;
|
|
369
374
|
}
|
|
370
|
-
return out;
|
|
371
375
|
}
|
|
372
376
|
if (ns.isBlobSchema() && typeof value === "string") {
|
|
373
377
|
return utilBase64.fromBase64(value);
|
|
@@ -378,6 +382,7 @@ class JsonShapeDeserializer extends SerdeContextConfig {
|
|
|
378
382
|
if (isJson) {
|
|
379
383
|
return serde.LazyJsonString.from(value);
|
|
380
384
|
}
|
|
385
|
+
return value;
|
|
381
386
|
}
|
|
382
387
|
if (ns.isTimestampSchema() && value != null) {
|
|
383
388
|
const format = protocols.determineTimestampFormat(ns, this.settings);
|
|
@@ -415,6 +420,7 @@ class JsonShapeDeserializer extends SerdeContextConfig {
|
|
|
415
420
|
case "NaN":
|
|
416
421
|
return NaN;
|
|
417
422
|
}
|
|
423
|
+
return value;
|
|
418
424
|
}
|
|
419
425
|
if (ns.isDocumentSchema()) {
|
|
420
426
|
if (isObject) {
|
|
@@ -486,6 +492,7 @@ class JsonReplacer {
|
|
|
486
492
|
class JsonShapeSerializer extends SerdeContextConfig {
|
|
487
493
|
settings;
|
|
488
494
|
buffer;
|
|
495
|
+
useReplacer = false;
|
|
489
496
|
rootSchema;
|
|
490
497
|
constructor(settings) {
|
|
491
498
|
super();
|
|
@@ -502,9 +509,13 @@ class JsonShapeSerializer extends SerdeContextConfig {
|
|
|
502
509
|
}
|
|
503
510
|
}
|
|
504
511
|
flush() {
|
|
505
|
-
const { rootSchema } = this;
|
|
512
|
+
const { rootSchema, useReplacer } = this;
|
|
506
513
|
this.rootSchema = undefined;
|
|
514
|
+
this.useReplacer = false;
|
|
507
515
|
if (rootSchema?.isStructSchema() || rootSchema?.isDocumentSchema()) {
|
|
516
|
+
if (!useReplacer) {
|
|
517
|
+
return JSON.stringify(this.buffer);
|
|
518
|
+
}
|
|
508
519
|
const replacer = new JsonReplacer();
|
|
509
520
|
return replacer.replaceInJson(JSON.stringify(this.buffer, replacer.createReplacer(), 0));
|
|
510
521
|
}
|
|
@@ -513,68 +524,68 @@ class JsonShapeSerializer extends SerdeContextConfig {
|
|
|
513
524
|
_write(schema$1, value, container) {
|
|
514
525
|
const isObject = value !== null && typeof value === "object";
|
|
515
526
|
const ns = schema.NormalizedSchema.of(schema$1);
|
|
516
|
-
if (
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
527
|
+
if (isObject) {
|
|
528
|
+
if (ns.isStructSchema()) {
|
|
529
|
+
const out = {};
|
|
530
|
+
for (const [memberName, memberSchema] of serializingStructIterator(ns, value)) {
|
|
531
|
+
const serializableValue = this._write(memberSchema, value[memberName], ns);
|
|
532
|
+
if (serializableValue !== undefined) {
|
|
533
|
+
const jsonName = memberSchema.getMergedTraits().jsonName;
|
|
534
|
+
const targetKey = this.settings.jsonName ? jsonName ?? memberName : memberName;
|
|
535
|
+
out[targetKey] = serializableValue;
|
|
536
|
+
}
|
|
523
537
|
}
|
|
538
|
+
return out;
|
|
524
539
|
}
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
out[_k] = this._write(mapMember, _v);
|
|
540
|
+
if (Array.isArray(value) && ns.isListSchema()) {
|
|
541
|
+
const listMember = ns.getValueSchema();
|
|
542
|
+
const out = [];
|
|
543
|
+
const sparse = !!ns.getMergedTraits().sparse;
|
|
544
|
+
for (const item of value) {
|
|
545
|
+
if (sparse || item != null) {
|
|
546
|
+
out.push(this._write(listMember, item));
|
|
547
|
+
}
|
|
534
548
|
}
|
|
549
|
+
return out;
|
|
535
550
|
}
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
out[targetKey] = serializableValue;
|
|
551
|
+
if (ns.isMapSchema()) {
|
|
552
|
+
const mapMember = ns.getValueSchema();
|
|
553
|
+
const out = {};
|
|
554
|
+
const sparse = !!ns.getMergedTraits().sparse;
|
|
555
|
+
for (const [_k, _v] of Object.entries(value)) {
|
|
556
|
+
if (sparse || _v != null) {
|
|
557
|
+
out[_k] = this._write(mapMember, _v);
|
|
558
|
+
}
|
|
545
559
|
}
|
|
560
|
+
return out;
|
|
546
561
|
}
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
if ((ns.isBlobSchema() && (value instanceof Uint8Array || typeof value === "string")) ||
|
|
553
|
-
(ns.isDocumentSchema() && value instanceof Uint8Array)) {
|
|
554
|
-
if (ns === this.rootSchema) {
|
|
555
|
-
return value;
|
|
562
|
+
if (value instanceof Uint8Array && (ns.isBlobSchema() || ns.isDocumentSchema())) {
|
|
563
|
+
if (ns === this.rootSchema) {
|
|
564
|
+
return value;
|
|
565
|
+
}
|
|
566
|
+
return (this.serdeContext?.base64Encoder ?? utilBase64.toBase64)(value);
|
|
556
567
|
}
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
return value.getTime() / 1000;
|
|
568
|
+
if (value instanceof Date && (ns.isTimestampSchema() || ns.isDocumentSchema())) {
|
|
569
|
+
const format = protocols.determineTimestampFormat(ns, this.settings);
|
|
570
|
+
switch (format) {
|
|
571
|
+
case 5:
|
|
572
|
+
return value.toISOString().replace(".000Z", "Z");
|
|
573
|
+
case 6:
|
|
574
|
+
return serde.dateToUtcString(value);
|
|
575
|
+
case 7:
|
|
576
|
+
return value.getTime() / 1000;
|
|
577
|
+
default:
|
|
578
|
+
console.warn("Missing timestamp format, using epoch seconds", value);
|
|
579
|
+
return value.getTime() / 1000;
|
|
580
|
+
}
|
|
571
581
|
}
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
if (Math.abs(value) === Infinity || isNaN(value)) {
|
|
575
|
-
return String(value);
|
|
582
|
+
if (value instanceof serde.NumericValue) {
|
|
583
|
+
this.useReplacer = true;
|
|
576
584
|
}
|
|
577
585
|
}
|
|
586
|
+
if (value === null && container?.isStructSchema()) {
|
|
587
|
+
return void 0;
|
|
588
|
+
}
|
|
578
589
|
if (ns.isStringSchema()) {
|
|
579
590
|
if (typeof value === "undefined" && ns.isIdempotencyToken()) {
|
|
580
591
|
return serde.generateIdempotencyToken();
|
|
@@ -586,12 +597,29 @@ class JsonShapeSerializer extends SerdeContextConfig {
|
|
|
586
597
|
return serde.LazyJsonString.from(value);
|
|
587
598
|
}
|
|
588
599
|
}
|
|
600
|
+
return value;
|
|
601
|
+
}
|
|
602
|
+
if (typeof value === "number" && ns.isNumericSchema()) {
|
|
603
|
+
if (Math.abs(value) === Infinity || isNaN(value)) {
|
|
604
|
+
return String(value);
|
|
605
|
+
}
|
|
606
|
+
return value;
|
|
607
|
+
}
|
|
608
|
+
if (typeof value === "string" && ns.isBlobSchema()) {
|
|
609
|
+
if (ns === this.rootSchema) {
|
|
610
|
+
return value;
|
|
611
|
+
}
|
|
612
|
+
return (this.serdeContext?.base64Encoder ?? utilBase64.toBase64)(value);
|
|
613
|
+
}
|
|
614
|
+
if (typeof value === "bigint") {
|
|
615
|
+
this.useReplacer = true;
|
|
589
616
|
}
|
|
590
617
|
if (ns.isDocumentSchema()) {
|
|
591
618
|
if (isObject) {
|
|
592
619
|
const out = Array.isArray(value) ? [] : {};
|
|
593
620
|
for (const [k, v] of Object.entries(value)) {
|
|
594
621
|
if (v instanceof serde.NumericValue) {
|
|
622
|
+
this.useReplacer = true;
|
|
595
623
|
out[k] = v;
|
|
596
624
|
}
|
|
597
625
|
else {
|
|
@@ -633,18 +661,20 @@ class AwsJsonRpcProtocol extends protocols.RpcProtocol {
|
|
|
633
661
|
codec;
|
|
634
662
|
mixin;
|
|
635
663
|
awsQueryCompatible;
|
|
636
|
-
constructor({ defaultNamespace, serviceTarget, awsQueryCompatible, }) {
|
|
664
|
+
constructor({ defaultNamespace, serviceTarget, awsQueryCompatible, jsonCodec, }) {
|
|
637
665
|
super({
|
|
638
666
|
defaultNamespace,
|
|
639
667
|
});
|
|
640
668
|
this.serviceTarget = serviceTarget;
|
|
641
|
-
this.codec =
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
669
|
+
this.codec =
|
|
670
|
+
jsonCodec ??
|
|
671
|
+
new JsonCodec({
|
|
672
|
+
timestampFormat: {
|
|
673
|
+
useTrait: true,
|
|
674
|
+
default: 7,
|
|
675
|
+
},
|
|
676
|
+
jsonName: false,
|
|
677
|
+
});
|
|
648
678
|
this.serializer = this.codec.createSerializer();
|
|
649
679
|
this.deserializer = this.codec.createDeserializer();
|
|
650
680
|
this.awsQueryCompatible = !!awsQueryCompatible;
|
|
@@ -696,11 +726,12 @@ class AwsJsonRpcProtocol extends protocols.RpcProtocol {
|
|
|
696
726
|
}
|
|
697
727
|
|
|
698
728
|
class AwsJson1_0Protocol extends AwsJsonRpcProtocol {
|
|
699
|
-
constructor({ defaultNamespace, serviceTarget, awsQueryCompatible, }) {
|
|
729
|
+
constructor({ defaultNamespace, serviceTarget, awsQueryCompatible, jsonCodec, }) {
|
|
700
730
|
super({
|
|
701
731
|
defaultNamespace,
|
|
702
732
|
serviceTarget,
|
|
703
733
|
awsQueryCompatible,
|
|
734
|
+
jsonCodec,
|
|
704
735
|
});
|
|
705
736
|
}
|
|
706
737
|
getShapeId() {
|
|
@@ -715,11 +746,12 @@ class AwsJson1_0Protocol extends AwsJsonRpcProtocol {
|
|
|
715
746
|
}
|
|
716
747
|
|
|
717
748
|
class AwsJson1_1Protocol extends AwsJsonRpcProtocol {
|
|
718
|
-
constructor({ defaultNamespace, serviceTarget, awsQueryCompatible, }) {
|
|
749
|
+
constructor({ defaultNamespace, serviceTarget, awsQueryCompatible, jsonCodec, }) {
|
|
719
750
|
super({
|
|
720
751
|
defaultNamespace,
|
|
721
752
|
serviceTarget,
|
|
722
753
|
awsQueryCompatible,
|
|
754
|
+
jsonCodec,
|
|
723
755
|
});
|
|
724
756
|
}
|
|
725
757
|
getShapeId() {
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { AwsJsonRpcProtocol } from "./AwsJsonRpcProtocol";
|
|
2
2
|
export class AwsJson1_0Protocol extends AwsJsonRpcProtocol {
|
|
3
|
-
constructor({ defaultNamespace, serviceTarget, awsQueryCompatible, }) {
|
|
3
|
+
constructor({ defaultNamespace, serviceTarget, awsQueryCompatible, jsonCodec, }) {
|
|
4
4
|
super({
|
|
5
5
|
defaultNamespace,
|
|
6
6
|
serviceTarget,
|
|
7
7
|
awsQueryCompatible,
|
|
8
|
+
jsonCodec,
|
|
8
9
|
});
|
|
9
10
|
}
|
|
10
11
|
getShapeId() {
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { AwsJsonRpcProtocol } from "./AwsJsonRpcProtocol";
|
|
2
2
|
export class AwsJson1_1Protocol extends AwsJsonRpcProtocol {
|
|
3
|
-
constructor({ defaultNamespace, serviceTarget, awsQueryCompatible, }) {
|
|
3
|
+
constructor({ defaultNamespace, serviceTarget, awsQueryCompatible, jsonCodec, }) {
|
|
4
4
|
super({
|
|
5
5
|
defaultNamespace,
|
|
6
6
|
serviceTarget,
|
|
7
7
|
awsQueryCompatible,
|
|
8
|
+
jsonCodec,
|
|
8
9
|
});
|
|
9
10
|
}
|
|
10
11
|
getShapeId() {
|
|
@@ -10,18 +10,20 @@ export class AwsJsonRpcProtocol extends RpcProtocol {
|
|
|
10
10
|
codec;
|
|
11
11
|
mixin;
|
|
12
12
|
awsQueryCompatible;
|
|
13
|
-
constructor({ defaultNamespace, serviceTarget, awsQueryCompatible, }) {
|
|
13
|
+
constructor({ defaultNamespace, serviceTarget, awsQueryCompatible, jsonCodec, }) {
|
|
14
14
|
super({
|
|
15
15
|
defaultNamespace,
|
|
16
16
|
});
|
|
17
17
|
this.serviceTarget = serviceTarget;
|
|
18
|
-
this.codec =
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
18
|
+
this.codec =
|
|
19
|
+
jsonCodec ??
|
|
20
|
+
new JsonCodec({
|
|
21
|
+
timestampFormat: {
|
|
22
|
+
useTrait: true,
|
|
23
|
+
default: 7,
|
|
24
|
+
},
|
|
25
|
+
jsonName: false,
|
|
26
|
+
});
|
|
25
27
|
this.serializer = this.codec.createSerializer();
|
|
26
28
|
this.deserializer = this.codec.createDeserializer();
|
|
27
29
|
this.awsQueryCompatible = !!awsQueryCompatible;
|
|
@@ -21,38 +21,40 @@ export class JsonShapeDeserializer extends SerdeContextConfig {
|
|
|
21
21
|
_read(schema, value) {
|
|
22
22
|
const isObject = value !== null && typeof value === "object";
|
|
23
23
|
const ns = NormalizedSchema.of(schema);
|
|
24
|
-
if (
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
24
|
+
if (isObject) {
|
|
25
|
+
if (ns.isStructSchema()) {
|
|
26
|
+
const out = {};
|
|
27
|
+
for (const [memberName, memberSchema] of deserializingStructIterator(ns, value, this.settings.jsonName ? "jsonName" : false)) {
|
|
28
|
+
const fromKey = this.settings.jsonName ? memberSchema.getMergedTraits().jsonName ?? memberName : memberName;
|
|
29
|
+
const deserializedValue = this._read(memberSchema, value[fromKey]);
|
|
30
|
+
if (deserializedValue != null) {
|
|
31
|
+
out[memberName] = deserializedValue;
|
|
32
|
+
}
|
|
31
33
|
}
|
|
34
|
+
return out;
|
|
32
35
|
}
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
out[_k] = this._read(mapMember, _v);
|
|
36
|
+
if (Array.isArray(value) && ns.isListSchema()) {
|
|
37
|
+
const listMember = ns.getValueSchema();
|
|
38
|
+
const out = [];
|
|
39
|
+
const sparse = !!ns.getMergedTraits().sparse;
|
|
40
|
+
for (const item of value) {
|
|
41
|
+
if (sparse || item != null) {
|
|
42
|
+
out.push(this._read(listMember, item));
|
|
43
|
+
}
|
|
42
44
|
}
|
|
45
|
+
return out;
|
|
43
46
|
}
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
out[memberName] = deserializedValue;
|
|
47
|
+
if (ns.isMapSchema()) {
|
|
48
|
+
const mapMember = ns.getValueSchema();
|
|
49
|
+
const out = {};
|
|
50
|
+
const sparse = !!ns.getMergedTraits().sparse;
|
|
51
|
+
for (const [_k, _v] of Object.entries(value)) {
|
|
52
|
+
if (sparse || _v != null) {
|
|
53
|
+
out[_k] = this._read(mapMember, _v);
|
|
54
|
+
}
|
|
53
55
|
}
|
|
56
|
+
return out;
|
|
54
57
|
}
|
|
55
|
-
return out;
|
|
56
58
|
}
|
|
57
59
|
if (ns.isBlobSchema() && typeof value === "string") {
|
|
58
60
|
return fromBase64(value);
|
|
@@ -63,6 +65,7 @@ export class JsonShapeDeserializer extends SerdeContextConfig {
|
|
|
63
65
|
if (isJson) {
|
|
64
66
|
return LazyJsonString.from(value);
|
|
65
67
|
}
|
|
68
|
+
return value;
|
|
66
69
|
}
|
|
67
70
|
if (ns.isTimestampSchema() && value != null) {
|
|
68
71
|
const format = determineTimestampFormat(ns, this.settings);
|
|
@@ -100,6 +103,7 @@ export class JsonShapeDeserializer extends SerdeContextConfig {
|
|
|
100
103
|
case "NaN":
|
|
101
104
|
return NaN;
|
|
102
105
|
}
|
|
106
|
+
return value;
|
|
103
107
|
}
|
|
104
108
|
if (ns.isDocumentSchema()) {
|
|
105
109
|
if (isObject) {
|
|
@@ -8,6 +8,7 @@ import { JsonReplacer } from "./jsonReplacer";
|
|
|
8
8
|
export class JsonShapeSerializer extends SerdeContextConfig {
|
|
9
9
|
settings;
|
|
10
10
|
buffer;
|
|
11
|
+
useReplacer = false;
|
|
11
12
|
rootSchema;
|
|
12
13
|
constructor(settings) {
|
|
13
14
|
super();
|
|
@@ -24,9 +25,13 @@ export class JsonShapeSerializer extends SerdeContextConfig {
|
|
|
24
25
|
}
|
|
25
26
|
}
|
|
26
27
|
flush() {
|
|
27
|
-
const { rootSchema } = this;
|
|
28
|
+
const { rootSchema, useReplacer } = this;
|
|
28
29
|
this.rootSchema = undefined;
|
|
30
|
+
this.useReplacer = false;
|
|
29
31
|
if (rootSchema?.isStructSchema() || rootSchema?.isDocumentSchema()) {
|
|
32
|
+
if (!useReplacer) {
|
|
33
|
+
return JSON.stringify(this.buffer);
|
|
34
|
+
}
|
|
30
35
|
const replacer = new JsonReplacer();
|
|
31
36
|
return replacer.replaceInJson(JSON.stringify(this.buffer, replacer.createReplacer(), 0));
|
|
32
37
|
}
|
|
@@ -35,68 +40,68 @@ export class JsonShapeSerializer extends SerdeContextConfig {
|
|
|
35
40
|
_write(schema, value, container) {
|
|
36
41
|
const isObject = value !== null && typeof value === "object";
|
|
37
42
|
const ns = NormalizedSchema.of(schema);
|
|
38
|
-
if (
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
43
|
+
if (isObject) {
|
|
44
|
+
if (ns.isStructSchema()) {
|
|
45
|
+
const out = {};
|
|
46
|
+
for (const [memberName, memberSchema] of serializingStructIterator(ns, value)) {
|
|
47
|
+
const serializableValue = this._write(memberSchema, value[memberName], ns);
|
|
48
|
+
if (serializableValue !== undefined) {
|
|
49
|
+
const jsonName = memberSchema.getMergedTraits().jsonName;
|
|
50
|
+
const targetKey = this.settings.jsonName ? jsonName ?? memberName : memberName;
|
|
51
|
+
out[targetKey] = serializableValue;
|
|
52
|
+
}
|
|
45
53
|
}
|
|
54
|
+
return out;
|
|
46
55
|
}
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
out[_k] = this._write(mapMember, _v);
|
|
56
|
+
if (Array.isArray(value) && ns.isListSchema()) {
|
|
57
|
+
const listMember = ns.getValueSchema();
|
|
58
|
+
const out = [];
|
|
59
|
+
const sparse = !!ns.getMergedTraits().sparse;
|
|
60
|
+
for (const item of value) {
|
|
61
|
+
if (sparse || item != null) {
|
|
62
|
+
out.push(this._write(listMember, item));
|
|
63
|
+
}
|
|
56
64
|
}
|
|
65
|
+
return out;
|
|
57
66
|
}
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
out[targetKey] = serializableValue;
|
|
67
|
+
if (ns.isMapSchema()) {
|
|
68
|
+
const mapMember = ns.getValueSchema();
|
|
69
|
+
const out = {};
|
|
70
|
+
const sparse = !!ns.getMergedTraits().sparse;
|
|
71
|
+
for (const [_k, _v] of Object.entries(value)) {
|
|
72
|
+
if (sparse || _v != null) {
|
|
73
|
+
out[_k] = this._write(mapMember, _v);
|
|
74
|
+
}
|
|
67
75
|
}
|
|
76
|
+
return out;
|
|
68
77
|
}
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
if ((ns.isBlobSchema() && (value instanceof Uint8Array || typeof value === "string")) ||
|
|
75
|
-
(ns.isDocumentSchema() && value instanceof Uint8Array)) {
|
|
76
|
-
if (ns === this.rootSchema) {
|
|
77
|
-
return value;
|
|
78
|
+
if (value instanceof Uint8Array && (ns.isBlobSchema() || ns.isDocumentSchema())) {
|
|
79
|
+
if (ns === this.rootSchema) {
|
|
80
|
+
return value;
|
|
81
|
+
}
|
|
82
|
+
return (this.serdeContext?.base64Encoder ?? toBase64)(value);
|
|
78
83
|
}
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
return value.getTime() / 1000;
|
|
84
|
+
if (value instanceof Date && (ns.isTimestampSchema() || ns.isDocumentSchema())) {
|
|
85
|
+
const format = determineTimestampFormat(ns, this.settings);
|
|
86
|
+
switch (format) {
|
|
87
|
+
case 5:
|
|
88
|
+
return value.toISOString().replace(".000Z", "Z");
|
|
89
|
+
case 6:
|
|
90
|
+
return dateToUtcString(value);
|
|
91
|
+
case 7:
|
|
92
|
+
return value.getTime() / 1000;
|
|
93
|
+
default:
|
|
94
|
+
console.warn("Missing timestamp format, using epoch seconds", value);
|
|
95
|
+
return value.getTime() / 1000;
|
|
96
|
+
}
|
|
93
97
|
}
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
if (Math.abs(value) === Infinity || isNaN(value)) {
|
|
97
|
-
return String(value);
|
|
98
|
+
if (value instanceof NumericValue) {
|
|
99
|
+
this.useReplacer = true;
|
|
98
100
|
}
|
|
99
101
|
}
|
|
102
|
+
if (value === null && container?.isStructSchema()) {
|
|
103
|
+
return void 0;
|
|
104
|
+
}
|
|
100
105
|
if (ns.isStringSchema()) {
|
|
101
106
|
if (typeof value === "undefined" && ns.isIdempotencyToken()) {
|
|
102
107
|
return generateIdempotencyToken();
|
|
@@ -108,12 +113,29 @@ export class JsonShapeSerializer extends SerdeContextConfig {
|
|
|
108
113
|
return LazyJsonString.from(value);
|
|
109
114
|
}
|
|
110
115
|
}
|
|
116
|
+
return value;
|
|
117
|
+
}
|
|
118
|
+
if (typeof value === "number" && ns.isNumericSchema()) {
|
|
119
|
+
if (Math.abs(value) === Infinity || isNaN(value)) {
|
|
120
|
+
return String(value);
|
|
121
|
+
}
|
|
122
|
+
return value;
|
|
123
|
+
}
|
|
124
|
+
if (typeof value === "string" && ns.isBlobSchema()) {
|
|
125
|
+
if (ns === this.rootSchema) {
|
|
126
|
+
return value;
|
|
127
|
+
}
|
|
128
|
+
return (this.serdeContext?.base64Encoder ?? toBase64)(value);
|
|
129
|
+
}
|
|
130
|
+
if (typeof value === "bigint") {
|
|
131
|
+
this.useReplacer = true;
|
|
111
132
|
}
|
|
112
133
|
if (ns.isDocumentSchema()) {
|
|
113
134
|
if (isObject) {
|
|
114
135
|
const out = Array.isArray(value) ? [] : {};
|
|
115
136
|
for (const [k, v] of Object.entries(value)) {
|
|
116
137
|
if (v instanceof NumericValue) {
|
|
138
|
+
this.useReplacer = true;
|
|
117
139
|
out[k] = v;
|
|
118
140
|
}
|
|
119
141
|
else {
|
|
@@ -6,7 +6,8 @@ export function* serializingStructIterator(ns, sourceObject) {
|
|
|
6
6
|
const struct = ns.getSchema();
|
|
7
7
|
for (let i = 0; i < struct[4].length; ++i) {
|
|
8
8
|
const key = struct[4][i];
|
|
9
|
-
const
|
|
9
|
+
const memberSchema = struct[5][i];
|
|
10
|
+
const memberNs = new NormalizedSchema([memberSchema, 0], key);
|
|
10
11
|
if (!(key in sourceObject) && !memberNs.isIdempotencyToken()) {
|
|
11
12
|
continue;
|
|
12
13
|
}
|
|
@@ -18,13 +19,14 @@ export function* deserializingStructIterator(ns, sourceObject, nameTrait) {
|
|
|
18
19
|
return;
|
|
19
20
|
}
|
|
20
21
|
const struct = ns.getSchema();
|
|
21
|
-
let keysRemaining = Object.keys(sourceObject).length;
|
|
22
|
+
let keysRemaining = Object.keys(sourceObject).filter((k) => k !== "__type").length;
|
|
22
23
|
for (let i = 0; i < struct[4].length; ++i) {
|
|
23
24
|
if (keysRemaining === 0) {
|
|
24
25
|
break;
|
|
25
26
|
}
|
|
26
27
|
const key = struct[4][i];
|
|
27
|
-
const
|
|
28
|
+
const memberSchema = struct[5][i];
|
|
29
|
+
const memberNs = new NormalizedSchema([memberSchema, 0], key);
|
|
28
30
|
let serializationKey = key;
|
|
29
31
|
if (nameTrait) {
|
|
30
32
|
serializationKey = memberNs.getMergedTraits()[nameTrait] ?? key;
|
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
import { AwsJsonRpcProtocol } from "./AwsJsonRpcProtocol";
|
|
2
|
+
import type { JsonCodec } from "./JsonCodec";
|
|
2
3
|
/**
|
|
3
4
|
* @public
|
|
4
5
|
* @see https://smithy.io/2.0/aws/protocols/aws-json-1_1-protocol.html#differences-between-awsjson1-0-and-awsjson1-1
|
|
5
6
|
*/
|
|
6
7
|
export declare class AwsJson1_0Protocol extends AwsJsonRpcProtocol {
|
|
7
|
-
constructor({ defaultNamespace, serviceTarget, awsQueryCompatible, }: {
|
|
8
|
+
constructor({ defaultNamespace, serviceTarget, awsQueryCompatible, jsonCodec, }: {
|
|
8
9
|
defaultNamespace: string;
|
|
9
10
|
serviceTarget: string;
|
|
10
11
|
awsQueryCompatible?: boolean;
|
|
12
|
+
jsonCodec?: JsonCodec;
|
|
11
13
|
});
|
|
12
14
|
getShapeId(): string;
|
|
13
15
|
protected getJsonRpcVersion(): "1.0";
|
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
import { AwsJsonRpcProtocol } from "./AwsJsonRpcProtocol";
|
|
2
|
+
import type { JsonCodec } from "./JsonCodec";
|
|
2
3
|
/**
|
|
3
4
|
* @public
|
|
4
5
|
* @see https://smithy.io/2.0/aws/protocols/aws-json-1_1-protocol.html#differences-between-awsjson1-0-and-awsjson1-1
|
|
5
6
|
*/
|
|
6
7
|
export declare class AwsJson1_1Protocol extends AwsJsonRpcProtocol {
|
|
7
|
-
constructor({ defaultNamespace, serviceTarget, awsQueryCompatible, }: {
|
|
8
|
+
constructor({ defaultNamespace, serviceTarget, awsQueryCompatible, jsonCodec, }: {
|
|
8
9
|
defaultNamespace: string;
|
|
9
10
|
serviceTarget: string;
|
|
10
11
|
awsQueryCompatible?: boolean;
|
|
12
|
+
jsonCodec?: JsonCodec;
|
|
11
13
|
});
|
|
12
14
|
getShapeId(): string;
|
|
13
15
|
protected getJsonRpcVersion(): "1.1";
|
|
@@ -11,10 +11,11 @@ export declare abstract class AwsJsonRpcProtocol extends RpcProtocol {
|
|
|
11
11
|
private readonly codec;
|
|
12
12
|
private readonly mixin;
|
|
13
13
|
private readonly awsQueryCompatible;
|
|
14
|
-
protected constructor({ defaultNamespace, serviceTarget, awsQueryCompatible, }: {
|
|
14
|
+
protected constructor({ defaultNamespace, serviceTarget, awsQueryCompatible, jsonCodec, }: {
|
|
15
15
|
defaultNamespace: string;
|
|
16
16
|
serviceTarget: string;
|
|
17
17
|
awsQueryCompatible?: boolean;
|
|
18
|
+
jsonCodec?: JsonCodec;
|
|
18
19
|
});
|
|
19
20
|
serializeRequest<Input extends object>(operationSchema: OperationSchema, input: Input, context: HandlerExecutionContext & SerdeFunctions & EndpointBearer): Promise<HttpRequest>;
|
|
20
21
|
getPayloadCodec(): JsonCodec;
|
|
@@ -9,5 +9,5 @@ export declare class JsonShapeDeserializer extends SerdeContextConfig implements
|
|
|
9
9
|
constructor(settings: JsonSettings);
|
|
10
10
|
read(schema: Schema, data: string | Uint8Array | unknown): Promise<any>;
|
|
11
11
|
readObject(schema: Schema, data: DocumentType): any;
|
|
12
|
-
|
|
12
|
+
protected _read(schema: Schema, value: unknown): any;
|
|
13
13
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { NormalizedSchema } from "@smithy/core/schema";
|
|
1
2
|
import type { Schema, ShapeSerializer } from "@smithy/types";
|
|
2
3
|
import { SerdeContextConfig } from "../ConfigurableSerdeContext";
|
|
3
4
|
import type { JsonSettings } from "./JsonCodec";
|
|
@@ -6,8 +7,13 @@ import type { JsonSettings } from "./JsonCodec";
|
|
|
6
7
|
*/
|
|
7
8
|
export declare class JsonShapeSerializer extends SerdeContextConfig implements ShapeSerializer<string> {
|
|
8
9
|
readonly settings: JsonSettings;
|
|
9
|
-
|
|
10
|
-
|
|
10
|
+
/**
|
|
11
|
+
* Write buffer. Reused per value serialization pass.
|
|
12
|
+
* In the initial implementation, this is not an incremental buffer.
|
|
13
|
+
*/
|
|
14
|
+
protected buffer: any;
|
|
15
|
+
protected useReplacer: boolean;
|
|
16
|
+
protected rootSchema: NormalizedSchema | undefined;
|
|
11
17
|
constructor(settings: JsonSettings);
|
|
12
18
|
write(schema: Schema, value: unknown): void;
|
|
13
19
|
/**
|
|
@@ -15,5 +21,8 @@ export declare class JsonShapeSerializer extends SerdeContextConfig implements S
|
|
|
15
21
|
*/
|
|
16
22
|
writeDiscriminatedDocument(schema: Schema, value: unknown): void;
|
|
17
23
|
flush(): string;
|
|
18
|
-
|
|
24
|
+
/**
|
|
25
|
+
* Order if-statements by order of likelihood.
|
|
26
|
+
*/
|
|
27
|
+
protected _write(schema: Schema, value: unknown, container?: NormalizedSchema): any;
|
|
19
28
|
}
|
|
@@ -1,13 +1,16 @@
|
|
|
1
1
|
import { AwsJsonRpcProtocol } from "./AwsJsonRpcProtocol";
|
|
2
|
+
import { JsonCodec } from "./JsonCodec";
|
|
2
3
|
export declare class AwsJson1_0Protocol extends AwsJsonRpcProtocol {
|
|
3
4
|
constructor({
|
|
4
5
|
defaultNamespace,
|
|
5
6
|
serviceTarget,
|
|
6
7
|
awsQueryCompatible,
|
|
8
|
+
jsonCodec,
|
|
7
9
|
}: {
|
|
8
10
|
defaultNamespace: string;
|
|
9
11
|
serviceTarget: string;
|
|
10
12
|
awsQueryCompatible?: boolean;
|
|
13
|
+
jsonCodec?: JsonCodec;
|
|
11
14
|
});
|
|
12
15
|
getShapeId(): string;
|
|
13
16
|
protected getJsonRpcVersion(): "1.0";
|
|
@@ -1,13 +1,16 @@
|
|
|
1
1
|
import { AwsJsonRpcProtocol } from "./AwsJsonRpcProtocol";
|
|
2
|
+
import { JsonCodec } from "./JsonCodec";
|
|
2
3
|
export declare class AwsJson1_1Protocol extends AwsJsonRpcProtocol {
|
|
3
4
|
constructor({
|
|
4
5
|
defaultNamespace,
|
|
5
6
|
serviceTarget,
|
|
6
7
|
awsQueryCompatible,
|
|
8
|
+
jsonCodec,
|
|
7
9
|
}: {
|
|
8
10
|
defaultNamespace: string;
|
|
9
11
|
serviceTarget: string;
|
|
10
12
|
awsQueryCompatible?: boolean;
|
|
13
|
+
jsonCodec?: JsonCodec;
|
|
11
14
|
});
|
|
12
15
|
getShapeId(): string;
|
|
13
16
|
protected getJsonRpcVersion(): "1.1";
|
|
@@ -22,10 +22,12 @@ export declare abstract class AwsJsonRpcProtocol extends RpcProtocol {
|
|
|
22
22
|
defaultNamespace,
|
|
23
23
|
serviceTarget,
|
|
24
24
|
awsQueryCompatible,
|
|
25
|
+
jsonCodec,
|
|
25
26
|
}: {
|
|
26
27
|
defaultNamespace: string;
|
|
27
28
|
serviceTarget: string;
|
|
28
29
|
awsQueryCompatible?: boolean;
|
|
30
|
+
jsonCodec?: JsonCodec;
|
|
29
31
|
});
|
|
30
32
|
serializeRequest<Input extends object>(
|
|
31
33
|
operationSchema: OperationSchema,
|
|
@@ -9,5 +9,5 @@ export declare class JsonShapeDeserializer
|
|
|
9
9
|
constructor(settings: JsonSettings);
|
|
10
10
|
read(schema: Schema, data: string | Uint8Array | unknown): Promise<any>;
|
|
11
11
|
readObject(schema: Schema, data: DocumentType): any;
|
|
12
|
-
|
|
12
|
+
protected _read(schema: Schema, value: unknown): any;
|
|
13
13
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { NormalizedSchema } from "@smithy/core/schema";
|
|
1
2
|
import { Schema, ShapeSerializer } from "@smithy/types";
|
|
2
3
|
import { SerdeContextConfig } from "../ConfigurableSerdeContext";
|
|
3
4
|
import { JsonSettings } from "./JsonCodec";
|
|
@@ -6,11 +7,16 @@ export declare class JsonShapeSerializer
|
|
|
6
7
|
implements ShapeSerializer<string>
|
|
7
8
|
{
|
|
8
9
|
readonly settings: JsonSettings;
|
|
9
|
-
|
|
10
|
-
|
|
10
|
+
protected buffer: any;
|
|
11
|
+
protected useReplacer: boolean;
|
|
12
|
+
protected rootSchema: NormalizedSchema | undefined;
|
|
11
13
|
constructor(settings: JsonSettings);
|
|
12
14
|
write(schema: Schema, value: unknown): void;
|
|
13
15
|
writeDiscriminatedDocument(schema: Schema, value: unknown): void;
|
|
14
16
|
flush(): string;
|
|
15
|
-
|
|
17
|
+
protected _write(
|
|
18
|
+
schema: Schema,
|
|
19
|
+
value: unknown,
|
|
20
|
+
container?: NormalizedSchema
|
|
21
|
+
): any;
|
|
16
22
|
}
|
package/package.json
CHANGED