@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.
- package/dist-cjs/index.js +161 -91
- package/dist-cjs/submodules/protocols/index.js +161 -91
- 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 +31 -26
- package/dist-es/submodules/protocols/json/JsonShapeSerializer.js +76 -53
- package/dist-es/submodules/protocols/json/experimental/SinglePassJsonShapeSerializer.js +2 -1
- package/dist-es/submodules/protocols/query/QueryShapeSerializer.js +2 -1
- package/dist-es/submodules/protocols/structIterator.js +40 -0
- package/dist-es/submodules/protocols/xml/XmlShapeSerializer.js +2 -1
- 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/submodules/protocols/structIterator.d.ts +27 -0
- 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/dist-types/ts3.4/submodules/protocols/structIterator.d.ts +12 -0
- package/package.json +1 -1
|
@@ -209,6 +209,46 @@ class SerdeContextConfig {
|
|
|
209
209
|
}
|
|
210
210
|
}
|
|
211
211
|
|
|
212
|
+
function* serializingStructIterator(ns, sourceObject) {
|
|
213
|
+
if (ns.isUnitSchema()) {
|
|
214
|
+
return;
|
|
215
|
+
}
|
|
216
|
+
const struct = ns.getSchema();
|
|
217
|
+
for (let i = 0; i < struct[4].length; ++i) {
|
|
218
|
+
const key = struct[4][i];
|
|
219
|
+
const memberSchema = struct[5][i];
|
|
220
|
+
const memberNs = new schema.NormalizedSchema([memberSchema, 0], key);
|
|
221
|
+
if (!(key in sourceObject) && !memberNs.isIdempotencyToken()) {
|
|
222
|
+
continue;
|
|
223
|
+
}
|
|
224
|
+
yield [key, memberNs];
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
function* deserializingStructIterator(ns, sourceObject, nameTrait) {
|
|
228
|
+
if (ns.isUnitSchema()) {
|
|
229
|
+
return;
|
|
230
|
+
}
|
|
231
|
+
const struct = ns.getSchema();
|
|
232
|
+
let keysRemaining = Object.keys(sourceObject).filter((k) => k !== "__type").length;
|
|
233
|
+
for (let i = 0; i < struct[4].length; ++i) {
|
|
234
|
+
if (keysRemaining === 0) {
|
|
235
|
+
break;
|
|
236
|
+
}
|
|
237
|
+
const key = struct[4][i];
|
|
238
|
+
const memberSchema = struct[5][i];
|
|
239
|
+
const memberNs = new schema.NormalizedSchema([memberSchema, 0], key);
|
|
240
|
+
let serializationKey = key;
|
|
241
|
+
if (nameTrait) {
|
|
242
|
+
serializationKey = memberNs.getMergedTraits()[nameTrait] ?? key;
|
|
243
|
+
}
|
|
244
|
+
if (!(serializationKey in sourceObject)) {
|
|
245
|
+
continue;
|
|
246
|
+
}
|
|
247
|
+
yield [key, memberNs];
|
|
248
|
+
keysRemaining -= 1;
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
|
|
212
252
|
function jsonReviver(key, value, context) {
|
|
213
253
|
if (context?.source) {
|
|
214
254
|
const numericString = context.source;
|
|
@@ -298,38 +338,40 @@ class JsonShapeDeserializer extends SerdeContextConfig {
|
|
|
298
338
|
_read(schema$1, value) {
|
|
299
339
|
const isObject = value !== null && typeof value === "object";
|
|
300
340
|
const ns = schema.NormalizedSchema.of(schema$1);
|
|
301
|
-
if (
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
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
|
+
}
|
|
308
350
|
}
|
|
351
|
+
return out;
|
|
309
352
|
}
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
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
|
+
}
|
|
319
361
|
}
|
|
362
|
+
return out;
|
|
320
363
|
}
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
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
|
+
}
|
|
330
372
|
}
|
|
373
|
+
return out;
|
|
331
374
|
}
|
|
332
|
-
return out;
|
|
333
375
|
}
|
|
334
376
|
if (ns.isBlobSchema() && typeof value === "string") {
|
|
335
377
|
return utilBase64.fromBase64(value);
|
|
@@ -340,6 +382,7 @@ class JsonShapeDeserializer extends SerdeContextConfig {
|
|
|
340
382
|
if (isJson) {
|
|
341
383
|
return serde.LazyJsonString.from(value);
|
|
342
384
|
}
|
|
385
|
+
return value;
|
|
343
386
|
}
|
|
344
387
|
if (ns.isTimestampSchema() && value != null) {
|
|
345
388
|
const format = protocols.determineTimestampFormat(ns, this.settings);
|
|
@@ -377,6 +420,7 @@ class JsonShapeDeserializer extends SerdeContextConfig {
|
|
|
377
420
|
case "NaN":
|
|
378
421
|
return NaN;
|
|
379
422
|
}
|
|
423
|
+
return value;
|
|
380
424
|
}
|
|
381
425
|
if (ns.isDocumentSchema()) {
|
|
382
426
|
if (isObject) {
|
|
@@ -448,6 +492,7 @@ class JsonReplacer {
|
|
|
448
492
|
class JsonShapeSerializer extends SerdeContextConfig {
|
|
449
493
|
settings;
|
|
450
494
|
buffer;
|
|
495
|
+
useReplacer = false;
|
|
451
496
|
rootSchema;
|
|
452
497
|
constructor(settings) {
|
|
453
498
|
super();
|
|
@@ -464,9 +509,13 @@ class JsonShapeSerializer extends SerdeContextConfig {
|
|
|
464
509
|
}
|
|
465
510
|
}
|
|
466
511
|
flush() {
|
|
467
|
-
const { rootSchema } = this;
|
|
512
|
+
const { rootSchema, useReplacer } = this;
|
|
468
513
|
this.rootSchema = undefined;
|
|
514
|
+
this.useReplacer = false;
|
|
469
515
|
if (rootSchema?.isStructSchema() || rootSchema?.isDocumentSchema()) {
|
|
516
|
+
if (!useReplacer) {
|
|
517
|
+
return JSON.stringify(this.buffer);
|
|
518
|
+
}
|
|
470
519
|
const replacer = new JsonReplacer();
|
|
471
520
|
return replacer.replaceInJson(JSON.stringify(this.buffer, replacer.createReplacer(), 0));
|
|
472
521
|
}
|
|
@@ -475,68 +524,68 @@ class JsonShapeSerializer extends SerdeContextConfig {
|
|
|
475
524
|
_write(schema$1, value, container) {
|
|
476
525
|
const isObject = value !== null && typeof value === "object";
|
|
477
526
|
const ns = schema.NormalizedSchema.of(schema$1);
|
|
478
|
-
if (
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
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
|
+
}
|
|
485
537
|
}
|
|
538
|
+
return out;
|
|
486
539
|
}
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
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
|
+
}
|
|
496
548
|
}
|
|
549
|
+
return out;
|
|
497
550
|
}
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
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
|
+
}
|
|
507
559
|
}
|
|
560
|
+
return out;
|
|
508
561
|
}
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
if ((ns.isBlobSchema() && (value instanceof Uint8Array || typeof value === "string")) ||
|
|
515
|
-
(ns.isDocumentSchema() && value instanceof Uint8Array)) {
|
|
516
|
-
if (ns === this.rootSchema) {
|
|
517
|
-
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);
|
|
518
567
|
}
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
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
|
+
}
|
|
533
581
|
}
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
if (Math.abs(value) === Infinity || isNaN(value)) {
|
|
537
|
-
return String(value);
|
|
582
|
+
if (value instanceof serde.NumericValue) {
|
|
583
|
+
this.useReplacer = true;
|
|
538
584
|
}
|
|
539
585
|
}
|
|
586
|
+
if (value === null && container?.isStructSchema()) {
|
|
587
|
+
return void 0;
|
|
588
|
+
}
|
|
540
589
|
if (ns.isStringSchema()) {
|
|
541
590
|
if (typeof value === "undefined" && ns.isIdempotencyToken()) {
|
|
542
591
|
return serde.generateIdempotencyToken();
|
|
@@ -548,12 +597,29 @@ class JsonShapeSerializer extends SerdeContextConfig {
|
|
|
548
597
|
return serde.LazyJsonString.from(value);
|
|
549
598
|
}
|
|
550
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;
|
|
551
616
|
}
|
|
552
617
|
if (ns.isDocumentSchema()) {
|
|
553
618
|
if (isObject) {
|
|
554
619
|
const out = Array.isArray(value) ? [] : {};
|
|
555
620
|
for (const [k, v] of Object.entries(value)) {
|
|
556
621
|
if (v instanceof serde.NumericValue) {
|
|
622
|
+
this.useReplacer = true;
|
|
557
623
|
out[k] = v;
|
|
558
624
|
}
|
|
559
625
|
else {
|
|
@@ -595,18 +661,20 @@ class AwsJsonRpcProtocol extends protocols.RpcProtocol {
|
|
|
595
661
|
codec;
|
|
596
662
|
mixin;
|
|
597
663
|
awsQueryCompatible;
|
|
598
|
-
constructor({ defaultNamespace, serviceTarget, awsQueryCompatible, }) {
|
|
664
|
+
constructor({ defaultNamespace, serviceTarget, awsQueryCompatible, jsonCodec, }) {
|
|
599
665
|
super({
|
|
600
666
|
defaultNamespace,
|
|
601
667
|
});
|
|
602
668
|
this.serviceTarget = serviceTarget;
|
|
603
|
-
this.codec =
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
669
|
+
this.codec =
|
|
670
|
+
jsonCodec ??
|
|
671
|
+
new JsonCodec({
|
|
672
|
+
timestampFormat: {
|
|
673
|
+
useTrait: true,
|
|
674
|
+
default: 7,
|
|
675
|
+
},
|
|
676
|
+
jsonName: false,
|
|
677
|
+
});
|
|
610
678
|
this.serializer = this.codec.createSerializer();
|
|
611
679
|
this.deserializer = this.codec.createDeserializer();
|
|
612
680
|
this.awsQueryCompatible = !!awsQueryCompatible;
|
|
@@ -658,11 +726,12 @@ class AwsJsonRpcProtocol extends protocols.RpcProtocol {
|
|
|
658
726
|
}
|
|
659
727
|
|
|
660
728
|
class AwsJson1_0Protocol extends AwsJsonRpcProtocol {
|
|
661
|
-
constructor({ defaultNamespace, serviceTarget, awsQueryCompatible, }) {
|
|
729
|
+
constructor({ defaultNamespace, serviceTarget, awsQueryCompatible, jsonCodec, }) {
|
|
662
730
|
super({
|
|
663
731
|
defaultNamespace,
|
|
664
732
|
serviceTarget,
|
|
665
733
|
awsQueryCompatible,
|
|
734
|
+
jsonCodec,
|
|
666
735
|
});
|
|
667
736
|
}
|
|
668
737
|
getShapeId() {
|
|
@@ -677,11 +746,12 @@ class AwsJson1_0Protocol extends AwsJsonRpcProtocol {
|
|
|
677
746
|
}
|
|
678
747
|
|
|
679
748
|
class AwsJson1_1Protocol extends AwsJsonRpcProtocol {
|
|
680
|
-
constructor({ defaultNamespace, serviceTarget, awsQueryCompatible, }) {
|
|
749
|
+
constructor({ defaultNamespace, serviceTarget, awsQueryCompatible, jsonCodec, }) {
|
|
681
750
|
super({
|
|
682
751
|
defaultNamespace,
|
|
683
752
|
serviceTarget,
|
|
684
753
|
awsQueryCompatible,
|
|
754
|
+
jsonCodec,
|
|
685
755
|
});
|
|
686
756
|
}
|
|
687
757
|
getShapeId() {
|
|
@@ -1030,7 +1100,7 @@ class QueryShapeSerializer extends SerdeContextConfig {
|
|
|
1030
1100
|
}
|
|
1031
1101
|
else if (ns.isStructSchema()) {
|
|
1032
1102
|
if (value && typeof value === "object") {
|
|
1033
|
-
for (const [memberName, member] of ns
|
|
1103
|
+
for (const [memberName, member] of serializingStructIterator(ns, value)) {
|
|
1034
1104
|
if (value[memberName] == null && !member.isIdempotencyToken()) {
|
|
1035
1105
|
continue;
|
|
1036
1106
|
}
|
|
@@ -1327,7 +1397,7 @@ class XmlShapeSerializer extends SerdeContextConfig {
|
|
|
1327
1397
|
}
|
|
1328
1398
|
const structXmlNode = xmlBuilder.XmlNode.of(name);
|
|
1329
1399
|
const [xmlnsAttr, xmlns] = this.getXmlnsAttribute(ns, parentXmlns);
|
|
1330
|
-
for (const [memberName, memberSchema] of ns
|
|
1400
|
+
for (const [memberName, memberSchema] of serializingStructIterator(ns, value)) {
|
|
1331
1401
|
const val = value[memberName];
|
|
1332
1402
|
if (val != null || memberSchema.isIdempotencyToken()) {
|
|
1333
1403
|
if (memberSchema.getMergedTraits().xmlAttribute) {
|
|
@@ -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;
|
|
@@ -3,6 +3,7 @@ import { NormalizedSchema } from "@smithy/core/schema";
|
|
|
3
3
|
import { LazyJsonString, NumericValue, parseEpochTimestamp, parseRfc3339DateTimeWithOffset, parseRfc7231DateTime, } from "@smithy/core/serde";
|
|
4
4
|
import { fromBase64 } from "@smithy/util-base64";
|
|
5
5
|
import { SerdeContextConfig } from "../ConfigurableSerdeContext";
|
|
6
|
+
import { deserializingStructIterator } from "../structIterator";
|
|
6
7
|
import { jsonReviver } from "./jsonReviver";
|
|
7
8
|
import { parseJsonBody } from "./parseJsonBody";
|
|
8
9
|
export class JsonShapeDeserializer extends SerdeContextConfig {
|
|
@@ -20,38 +21,40 @@ export class JsonShapeDeserializer extends SerdeContextConfig {
|
|
|
20
21
|
_read(schema, value) {
|
|
21
22
|
const isObject = value !== null && typeof value === "object";
|
|
22
23
|
const ns = NormalizedSchema.of(schema);
|
|
23
|
-
if (
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
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
|
+
}
|
|
30
33
|
}
|
|
34
|
+
return out;
|
|
31
35
|
}
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
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
|
+
}
|
|
41
44
|
}
|
|
45
|
+
return out;
|
|
42
46
|
}
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
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
|
+
}
|
|
52
55
|
}
|
|
56
|
+
return out;
|
|
53
57
|
}
|
|
54
|
-
return out;
|
|
55
58
|
}
|
|
56
59
|
if (ns.isBlobSchema() && typeof value === "string") {
|
|
57
60
|
return fromBase64(value);
|
|
@@ -62,6 +65,7 @@ export class JsonShapeDeserializer extends SerdeContextConfig {
|
|
|
62
65
|
if (isJson) {
|
|
63
66
|
return LazyJsonString.from(value);
|
|
64
67
|
}
|
|
68
|
+
return value;
|
|
65
69
|
}
|
|
66
70
|
if (ns.isTimestampSchema() && value != null) {
|
|
67
71
|
const format = determineTimestampFormat(ns, this.settings);
|
|
@@ -99,6 +103,7 @@ export class JsonShapeDeserializer extends SerdeContextConfig {
|
|
|
99
103
|
case "NaN":
|
|
100
104
|
return NaN;
|
|
101
105
|
}
|
|
106
|
+
return value;
|
|
102
107
|
}
|
|
103
108
|
if (ns.isDocumentSchema()) {
|
|
104
109
|
if (isObject) {
|