@aws-sdk/core 3.940.0 → 3.946.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 +164 -109
- package/dist-cjs/submodules/protocols/index.js +164 -109
- package/dist-es/submodules/protocols/ProtocolLib.js +20 -3
- package/dist-es/submodules/protocols/cbor/AwsSmithyRpcV2CborProtocol.js +11 -3
- 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 +14 -11
- 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/query/AwsQueryProtocol.js +3 -8
- package/dist-es/submodules/protocols/structIterator.js +5 -3
- package/dist-es/submodules/protocols/xml/AwsRestXmlProtocol.js +3 -1
- package/dist-types/submodules/protocols/ProtocolLib.d.ts +6 -0
- 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/ProtocolLib.d.ts +4 -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/package.json +3 -3
|
@@ -76,9 +76,18 @@ class ProtocolLib {
|
|
|
76
76
|
const msg = exception.Message ?? additions.Message;
|
|
77
77
|
const error = smithyClient.decorateServiceException(exception, additions);
|
|
78
78
|
if (msg) {
|
|
79
|
-
error.Message = msg;
|
|
80
79
|
error.message = msg;
|
|
81
80
|
}
|
|
81
|
+
error.Error = {
|
|
82
|
+
...error.Error,
|
|
83
|
+
Type: error.Error.Type,
|
|
84
|
+
Code: error.Error.Code,
|
|
85
|
+
Message: error.Error.message ?? error.Error.Message ?? msg,
|
|
86
|
+
};
|
|
87
|
+
const reqId = error.$metadata.requestId;
|
|
88
|
+
if (reqId) {
|
|
89
|
+
error.RequestId = reqId;
|
|
90
|
+
}
|
|
82
91
|
return error;
|
|
83
92
|
}
|
|
84
93
|
return smithyClient.decorateServiceException(exception, additions);
|
|
@@ -94,7 +103,7 @@ class ProtocolLib {
|
|
|
94
103
|
};
|
|
95
104
|
Object.assign(output, Error);
|
|
96
105
|
for (const [k, v] of entries) {
|
|
97
|
-
Error[k] = v;
|
|
106
|
+
Error[k === "message" ? "Message" : k] = v;
|
|
98
107
|
}
|
|
99
108
|
delete Error.__type;
|
|
100
109
|
output.Error = Error;
|
|
@@ -111,6 +120,14 @@ class ProtocolLib {
|
|
|
111
120
|
errorData.Code = queryCompatErrorData.Code;
|
|
112
121
|
}
|
|
113
122
|
}
|
|
123
|
+
findQueryCompatibleError(registry, errorName) {
|
|
124
|
+
try {
|
|
125
|
+
return registry.getSchema(errorName);
|
|
126
|
+
}
|
|
127
|
+
catch (e) {
|
|
128
|
+
return registry.find((schema$1) => schema.NormalizedSchema.of(schema$1).getMergedTraits().awsQueryError?.[0] === errorName);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
114
131
|
}
|
|
115
132
|
|
|
116
133
|
class AwsSmithyRpcV2CborProtocol extends cbor.SmithyRpcV2CborProtocol {
|
|
@@ -132,15 +149,23 @@ class AwsSmithyRpcV2CborProtocol extends cbor.SmithyRpcV2CborProtocol {
|
|
|
132
149
|
if (this.awsQueryCompatible) {
|
|
133
150
|
this.mixin.setQueryCompatError(dataObject, response);
|
|
134
151
|
}
|
|
135
|
-
const errorName =
|
|
136
|
-
|
|
152
|
+
const errorName = (() => {
|
|
153
|
+
const compatHeader = response.headers["x-amzn-query-error"];
|
|
154
|
+
if (compatHeader && this.awsQueryCompatible) {
|
|
155
|
+
return compatHeader.split(";")[0];
|
|
156
|
+
}
|
|
157
|
+
return cbor.loadSmithyRpcV2CborErrorCode(response, dataObject) ?? "Unknown";
|
|
158
|
+
})();
|
|
159
|
+
const { errorSchema, errorMetadata } = await this.mixin.getErrorSchemaOrThrowBaseException(errorName, this.options.defaultNamespace, response, dataObject, metadata, this.awsQueryCompatible ? this.mixin.findQueryCompatibleError : undefined);
|
|
137
160
|
const ns = schema.NormalizedSchema.of(errorSchema);
|
|
138
161
|
const message = dataObject.message ?? dataObject.Message ?? "Unknown";
|
|
139
162
|
const ErrorCtor = schema.TypeRegistry.for(errorSchema[1]).getErrorCtor(errorSchema) ?? Error;
|
|
140
163
|
const exception = new ErrorCtor(message);
|
|
141
164
|
const output = {};
|
|
142
165
|
for (const [name, member] of ns.structIterator()) {
|
|
143
|
-
|
|
166
|
+
if (dataObject[name] != null) {
|
|
167
|
+
output[name] = this.deserializer.readValue(member, dataObject[name]);
|
|
168
|
+
}
|
|
144
169
|
}
|
|
145
170
|
if (this.awsQueryCompatible) {
|
|
146
171
|
this.mixin.queryCompatOutput(dataObject, output);
|
|
@@ -216,7 +241,8 @@ function* serializingStructIterator(ns, sourceObject) {
|
|
|
216
241
|
const struct = ns.getSchema();
|
|
217
242
|
for (let i = 0; i < struct[4].length; ++i) {
|
|
218
243
|
const key = struct[4][i];
|
|
219
|
-
const
|
|
244
|
+
const memberSchema = struct[5][i];
|
|
245
|
+
const memberNs = new schema.NormalizedSchema([memberSchema, 0], key);
|
|
220
246
|
if (!(key in sourceObject) && !memberNs.isIdempotencyToken()) {
|
|
221
247
|
continue;
|
|
222
248
|
}
|
|
@@ -228,13 +254,14 @@ function* deserializingStructIterator(ns, sourceObject, nameTrait) {
|
|
|
228
254
|
return;
|
|
229
255
|
}
|
|
230
256
|
const struct = ns.getSchema();
|
|
231
|
-
let keysRemaining = Object.keys(sourceObject).length;
|
|
257
|
+
let keysRemaining = Object.keys(sourceObject).filter((k) => k !== "__type").length;
|
|
232
258
|
for (let i = 0; i < struct[4].length; ++i) {
|
|
233
259
|
if (keysRemaining === 0) {
|
|
234
260
|
break;
|
|
235
261
|
}
|
|
236
262
|
const key = struct[4][i];
|
|
237
|
-
const
|
|
263
|
+
const memberSchema = struct[5][i];
|
|
264
|
+
const memberNs = new schema.NormalizedSchema([memberSchema, 0], key);
|
|
238
265
|
let serializationKey = key;
|
|
239
266
|
if (nameTrait) {
|
|
240
267
|
serializationKey = memberNs.getMergedTraits()[nameTrait] ?? key;
|
|
@@ -336,38 +363,40 @@ class JsonShapeDeserializer extends SerdeContextConfig {
|
|
|
336
363
|
_read(schema$1, value) {
|
|
337
364
|
const isObject = value !== null && typeof value === "object";
|
|
338
365
|
const ns = schema.NormalizedSchema.of(schema$1);
|
|
339
|
-
if (
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
366
|
+
if (isObject) {
|
|
367
|
+
if (ns.isStructSchema()) {
|
|
368
|
+
const out = {};
|
|
369
|
+
for (const [memberName, memberSchema] of deserializingStructIterator(ns, value, this.settings.jsonName ? "jsonName" : false)) {
|
|
370
|
+
const fromKey = this.settings.jsonName ? memberSchema.getMergedTraits().jsonName ?? memberName : memberName;
|
|
371
|
+
const deserializedValue = this._read(memberSchema, value[fromKey]);
|
|
372
|
+
if (deserializedValue != null) {
|
|
373
|
+
out[memberName] = deserializedValue;
|
|
374
|
+
}
|
|
346
375
|
}
|
|
376
|
+
return out;
|
|
347
377
|
}
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
out[_k] = this._read(mapMember, _v);
|
|
378
|
+
if (Array.isArray(value) && ns.isListSchema()) {
|
|
379
|
+
const listMember = ns.getValueSchema();
|
|
380
|
+
const out = [];
|
|
381
|
+
const sparse = !!ns.getMergedTraits().sparse;
|
|
382
|
+
for (const item of value) {
|
|
383
|
+
if (sparse || item != null) {
|
|
384
|
+
out.push(this._read(listMember, item));
|
|
385
|
+
}
|
|
357
386
|
}
|
|
387
|
+
return out;
|
|
358
388
|
}
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
out[memberName] = deserializedValue;
|
|
389
|
+
if (ns.isMapSchema()) {
|
|
390
|
+
const mapMember = ns.getValueSchema();
|
|
391
|
+
const out = {};
|
|
392
|
+
const sparse = !!ns.getMergedTraits().sparse;
|
|
393
|
+
for (const [_k, _v] of Object.entries(value)) {
|
|
394
|
+
if (sparse || _v != null) {
|
|
395
|
+
out[_k] = this._read(mapMember, _v);
|
|
396
|
+
}
|
|
368
397
|
}
|
|
398
|
+
return out;
|
|
369
399
|
}
|
|
370
|
-
return out;
|
|
371
400
|
}
|
|
372
401
|
if (ns.isBlobSchema() && typeof value === "string") {
|
|
373
402
|
return utilBase64.fromBase64(value);
|
|
@@ -378,6 +407,7 @@ class JsonShapeDeserializer extends SerdeContextConfig {
|
|
|
378
407
|
if (isJson) {
|
|
379
408
|
return serde.LazyJsonString.from(value);
|
|
380
409
|
}
|
|
410
|
+
return value;
|
|
381
411
|
}
|
|
382
412
|
if (ns.isTimestampSchema() && value != null) {
|
|
383
413
|
const format = protocols.determineTimestampFormat(ns, this.settings);
|
|
@@ -415,6 +445,7 @@ class JsonShapeDeserializer extends SerdeContextConfig {
|
|
|
415
445
|
case "NaN":
|
|
416
446
|
return NaN;
|
|
417
447
|
}
|
|
448
|
+
return value;
|
|
418
449
|
}
|
|
419
450
|
if (ns.isDocumentSchema()) {
|
|
420
451
|
if (isObject) {
|
|
@@ -486,6 +517,7 @@ class JsonReplacer {
|
|
|
486
517
|
class JsonShapeSerializer extends SerdeContextConfig {
|
|
487
518
|
settings;
|
|
488
519
|
buffer;
|
|
520
|
+
useReplacer = false;
|
|
489
521
|
rootSchema;
|
|
490
522
|
constructor(settings) {
|
|
491
523
|
super();
|
|
@@ -502,9 +534,13 @@ class JsonShapeSerializer extends SerdeContextConfig {
|
|
|
502
534
|
}
|
|
503
535
|
}
|
|
504
536
|
flush() {
|
|
505
|
-
const { rootSchema } = this;
|
|
537
|
+
const { rootSchema, useReplacer } = this;
|
|
506
538
|
this.rootSchema = undefined;
|
|
539
|
+
this.useReplacer = false;
|
|
507
540
|
if (rootSchema?.isStructSchema() || rootSchema?.isDocumentSchema()) {
|
|
541
|
+
if (!useReplacer) {
|
|
542
|
+
return JSON.stringify(this.buffer);
|
|
543
|
+
}
|
|
508
544
|
const replacer = new JsonReplacer();
|
|
509
545
|
return replacer.replaceInJson(JSON.stringify(this.buffer, replacer.createReplacer(), 0));
|
|
510
546
|
}
|
|
@@ -513,68 +549,68 @@ class JsonShapeSerializer extends SerdeContextConfig {
|
|
|
513
549
|
_write(schema$1, value, container) {
|
|
514
550
|
const isObject = value !== null && typeof value === "object";
|
|
515
551
|
const ns = schema.NormalizedSchema.of(schema$1);
|
|
516
|
-
if (
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
552
|
+
if (isObject) {
|
|
553
|
+
if (ns.isStructSchema()) {
|
|
554
|
+
const out = {};
|
|
555
|
+
for (const [memberName, memberSchema] of serializingStructIterator(ns, value)) {
|
|
556
|
+
const serializableValue = this._write(memberSchema, value[memberName], ns);
|
|
557
|
+
if (serializableValue !== undefined) {
|
|
558
|
+
const jsonName = memberSchema.getMergedTraits().jsonName;
|
|
559
|
+
const targetKey = this.settings.jsonName ? jsonName ?? memberName : memberName;
|
|
560
|
+
out[targetKey] = serializableValue;
|
|
561
|
+
}
|
|
523
562
|
}
|
|
563
|
+
return out;
|
|
524
564
|
}
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
out[_k] = this._write(mapMember, _v);
|
|
565
|
+
if (Array.isArray(value) && ns.isListSchema()) {
|
|
566
|
+
const listMember = ns.getValueSchema();
|
|
567
|
+
const out = [];
|
|
568
|
+
const sparse = !!ns.getMergedTraits().sparse;
|
|
569
|
+
for (const item of value) {
|
|
570
|
+
if (sparse || item != null) {
|
|
571
|
+
out.push(this._write(listMember, item));
|
|
572
|
+
}
|
|
534
573
|
}
|
|
574
|
+
return out;
|
|
535
575
|
}
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
out[targetKey] = serializableValue;
|
|
576
|
+
if (ns.isMapSchema()) {
|
|
577
|
+
const mapMember = ns.getValueSchema();
|
|
578
|
+
const out = {};
|
|
579
|
+
const sparse = !!ns.getMergedTraits().sparse;
|
|
580
|
+
for (const [_k, _v] of Object.entries(value)) {
|
|
581
|
+
if (sparse || _v != null) {
|
|
582
|
+
out[_k] = this._write(mapMember, _v);
|
|
583
|
+
}
|
|
545
584
|
}
|
|
585
|
+
return out;
|
|
546
586
|
}
|
|
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;
|
|
587
|
+
if (value instanceof Uint8Array && (ns.isBlobSchema() || ns.isDocumentSchema())) {
|
|
588
|
+
if (ns === this.rootSchema) {
|
|
589
|
+
return value;
|
|
590
|
+
}
|
|
591
|
+
return (this.serdeContext?.base64Encoder ?? utilBase64.toBase64)(value);
|
|
556
592
|
}
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
return value.getTime() / 1000;
|
|
593
|
+
if (value instanceof Date && (ns.isTimestampSchema() || ns.isDocumentSchema())) {
|
|
594
|
+
const format = protocols.determineTimestampFormat(ns, this.settings);
|
|
595
|
+
switch (format) {
|
|
596
|
+
case 5:
|
|
597
|
+
return value.toISOString().replace(".000Z", "Z");
|
|
598
|
+
case 6:
|
|
599
|
+
return serde.dateToUtcString(value);
|
|
600
|
+
case 7:
|
|
601
|
+
return value.getTime() / 1000;
|
|
602
|
+
default:
|
|
603
|
+
console.warn("Missing timestamp format, using epoch seconds", value);
|
|
604
|
+
return value.getTime() / 1000;
|
|
605
|
+
}
|
|
571
606
|
}
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
if (Math.abs(value) === Infinity || isNaN(value)) {
|
|
575
|
-
return String(value);
|
|
607
|
+
if (value instanceof serde.NumericValue) {
|
|
608
|
+
this.useReplacer = true;
|
|
576
609
|
}
|
|
577
610
|
}
|
|
611
|
+
if (value === null && container?.isStructSchema()) {
|
|
612
|
+
return void 0;
|
|
613
|
+
}
|
|
578
614
|
if (ns.isStringSchema()) {
|
|
579
615
|
if (typeof value === "undefined" && ns.isIdempotencyToken()) {
|
|
580
616
|
return serde.generateIdempotencyToken();
|
|
@@ -586,12 +622,29 @@ class JsonShapeSerializer extends SerdeContextConfig {
|
|
|
586
622
|
return serde.LazyJsonString.from(value);
|
|
587
623
|
}
|
|
588
624
|
}
|
|
625
|
+
return value;
|
|
626
|
+
}
|
|
627
|
+
if (typeof value === "number" && ns.isNumericSchema()) {
|
|
628
|
+
if (Math.abs(value) === Infinity || isNaN(value)) {
|
|
629
|
+
return String(value);
|
|
630
|
+
}
|
|
631
|
+
return value;
|
|
632
|
+
}
|
|
633
|
+
if (typeof value === "string" && ns.isBlobSchema()) {
|
|
634
|
+
if (ns === this.rootSchema) {
|
|
635
|
+
return value;
|
|
636
|
+
}
|
|
637
|
+
return (this.serdeContext?.base64Encoder ?? utilBase64.toBase64)(value);
|
|
638
|
+
}
|
|
639
|
+
if (typeof value === "bigint") {
|
|
640
|
+
this.useReplacer = true;
|
|
589
641
|
}
|
|
590
642
|
if (ns.isDocumentSchema()) {
|
|
591
643
|
if (isObject) {
|
|
592
644
|
const out = Array.isArray(value) ? [] : {};
|
|
593
645
|
for (const [k, v] of Object.entries(value)) {
|
|
594
646
|
if (v instanceof serde.NumericValue) {
|
|
647
|
+
this.useReplacer = true;
|
|
595
648
|
out[k] = v;
|
|
596
649
|
}
|
|
597
650
|
else {
|
|
@@ -633,18 +686,20 @@ class AwsJsonRpcProtocol extends protocols.RpcProtocol {
|
|
|
633
686
|
codec;
|
|
634
687
|
mixin;
|
|
635
688
|
awsQueryCompatible;
|
|
636
|
-
constructor({ defaultNamespace, serviceTarget, awsQueryCompatible, }) {
|
|
689
|
+
constructor({ defaultNamespace, serviceTarget, awsQueryCompatible, jsonCodec, }) {
|
|
637
690
|
super({
|
|
638
691
|
defaultNamespace,
|
|
639
692
|
});
|
|
640
693
|
this.serviceTarget = serviceTarget;
|
|
641
|
-
this.codec =
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
694
|
+
this.codec =
|
|
695
|
+
jsonCodec ??
|
|
696
|
+
new JsonCodec({
|
|
697
|
+
timestampFormat: {
|
|
698
|
+
useTrait: true,
|
|
699
|
+
default: 7,
|
|
700
|
+
},
|
|
701
|
+
jsonName: false,
|
|
702
|
+
});
|
|
648
703
|
this.serializer = this.codec.createSerializer();
|
|
649
704
|
this.deserializer = this.codec.createDeserializer();
|
|
650
705
|
this.awsQueryCompatible = !!awsQueryCompatible;
|
|
@@ -675,15 +730,16 @@ class AwsJsonRpcProtocol extends protocols.RpcProtocol {
|
|
|
675
730
|
this.mixin.setQueryCompatError(dataObject, response);
|
|
676
731
|
}
|
|
677
732
|
const errorIdentifier = loadRestJsonErrorCode(response, dataObject) ?? "Unknown";
|
|
678
|
-
const { errorSchema, errorMetadata } = await this.mixin.getErrorSchemaOrThrowBaseException(errorIdentifier, this.options.defaultNamespace, response, dataObject, metadata);
|
|
733
|
+
const { errorSchema, errorMetadata } = await this.mixin.getErrorSchemaOrThrowBaseException(errorIdentifier, this.options.defaultNamespace, response, dataObject, metadata, this.awsQueryCompatible ? this.mixin.findQueryCompatibleError : undefined);
|
|
679
734
|
const ns = schema.NormalizedSchema.of(errorSchema);
|
|
680
735
|
const message = dataObject.message ?? dataObject.Message ?? "Unknown";
|
|
681
736
|
const ErrorCtor = schema.TypeRegistry.for(errorSchema[1]).getErrorCtor(errorSchema) ?? Error;
|
|
682
737
|
const exception = new ErrorCtor(message);
|
|
683
738
|
const output = {};
|
|
684
739
|
for (const [name, member] of ns.structIterator()) {
|
|
685
|
-
|
|
686
|
-
|
|
740
|
+
if (dataObject[name] != null) {
|
|
741
|
+
output[name] = this.codec.createDeserializer().readObject(member, dataObject[name]);
|
|
742
|
+
}
|
|
687
743
|
}
|
|
688
744
|
if (this.awsQueryCompatible) {
|
|
689
745
|
this.mixin.queryCompatOutput(dataObject, output);
|
|
@@ -696,11 +752,12 @@ class AwsJsonRpcProtocol extends protocols.RpcProtocol {
|
|
|
696
752
|
}
|
|
697
753
|
|
|
698
754
|
class AwsJson1_0Protocol extends AwsJsonRpcProtocol {
|
|
699
|
-
constructor({ defaultNamespace, serviceTarget, awsQueryCompatible, }) {
|
|
755
|
+
constructor({ defaultNamespace, serviceTarget, awsQueryCompatible, jsonCodec, }) {
|
|
700
756
|
super({
|
|
701
757
|
defaultNamespace,
|
|
702
758
|
serviceTarget,
|
|
703
759
|
awsQueryCompatible,
|
|
760
|
+
jsonCodec,
|
|
704
761
|
});
|
|
705
762
|
}
|
|
706
763
|
getShapeId() {
|
|
@@ -715,11 +772,12 @@ class AwsJson1_0Protocol extends AwsJsonRpcProtocol {
|
|
|
715
772
|
}
|
|
716
773
|
|
|
717
774
|
class AwsJson1_1Protocol extends AwsJsonRpcProtocol {
|
|
718
|
-
constructor({ defaultNamespace, serviceTarget, awsQueryCompatible, }) {
|
|
775
|
+
constructor({ defaultNamespace, serviceTarget, awsQueryCompatible, jsonCodec, }) {
|
|
719
776
|
super({
|
|
720
777
|
defaultNamespace,
|
|
721
778
|
serviceTarget,
|
|
722
779
|
awsQueryCompatible,
|
|
780
|
+
jsonCodec,
|
|
723
781
|
});
|
|
724
782
|
}
|
|
725
783
|
getShapeId() {
|
|
@@ -1201,18 +1259,13 @@ class AwsQueryProtocol extends protocols.RpcProtocol {
|
|
|
1201
1259
|
Code: errorData.Code,
|
|
1202
1260
|
Message: message,
|
|
1203
1261
|
};
|
|
1204
|
-
const { errorSchema, errorMetadata } = await this.mixin.getErrorSchemaOrThrowBaseException(errorIdentifier, this.options.defaultNamespace, response, errorData, metadata,
|
|
1205
|
-
try {
|
|
1206
|
-
return registry.getSchema(errorName);
|
|
1207
|
-
}
|
|
1208
|
-
catch (e) {
|
|
1209
|
-
return registry.find((schema$1) => schema.NormalizedSchema.of(schema$1).getMergedTraits().awsQueryError?.[0] === errorName);
|
|
1210
|
-
}
|
|
1211
|
-
});
|
|
1262
|
+
const { errorSchema, errorMetadata } = await this.mixin.getErrorSchemaOrThrowBaseException(errorIdentifier, this.options.defaultNamespace, response, errorData, metadata, this.mixin.findQueryCompatibleError);
|
|
1212
1263
|
const ns = schema.NormalizedSchema.of(errorSchema);
|
|
1213
1264
|
const ErrorCtor = schema.TypeRegistry.for(errorSchema[1]).getErrorCtor(errorSchema) ?? Error;
|
|
1214
1265
|
const exception = new ErrorCtor(message);
|
|
1215
1266
|
const output = {
|
|
1267
|
+
Type: errorData.Error.Type,
|
|
1268
|
+
Code: errorData.Error.Code,
|
|
1216
1269
|
Error: errorData.Error,
|
|
1217
1270
|
};
|
|
1218
1271
|
for (const [name, member] of ns.structIterator()) {
|
|
@@ -1635,7 +1688,9 @@ class AwsRestXmlProtocol extends protocols.HttpBindingProtocol {
|
|
|
1635
1688
|
}
|
|
1636
1689
|
if (request.headers["content-type"] === this.getDefaultContentType()) {
|
|
1637
1690
|
if (typeof request.body === "string") {
|
|
1638
|
-
request.body
|
|
1691
|
+
if (!request.body.startsWith("<?xml ")) {
|
|
1692
|
+
request.body = '<?xml version="1.0" encoding="UTF-8"?>' + request.body;
|
|
1693
|
+
}
|
|
1639
1694
|
}
|
|
1640
1695
|
}
|
|
1641
1696
|
return request;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { TypeRegistry } from "@smithy/core/schema";
|
|
1
|
+
import { NormalizedSchema, TypeRegistry } from "@smithy/core/schema";
|
|
2
2
|
import { decorateServiceException } from "@smithy/smithy-client";
|
|
3
3
|
export class ProtocolLib {
|
|
4
4
|
queryCompat;
|
|
@@ -67,9 +67,18 @@ export class ProtocolLib {
|
|
|
67
67
|
const msg = exception.Message ?? additions.Message;
|
|
68
68
|
const error = decorateServiceException(exception, additions);
|
|
69
69
|
if (msg) {
|
|
70
|
-
error.Message = msg;
|
|
71
70
|
error.message = msg;
|
|
72
71
|
}
|
|
72
|
+
error.Error = {
|
|
73
|
+
...error.Error,
|
|
74
|
+
Type: error.Error.Type,
|
|
75
|
+
Code: error.Error.Code,
|
|
76
|
+
Message: error.Error.message ?? error.Error.Message ?? msg,
|
|
77
|
+
};
|
|
78
|
+
const reqId = error.$metadata.requestId;
|
|
79
|
+
if (reqId) {
|
|
80
|
+
error.RequestId = reqId;
|
|
81
|
+
}
|
|
73
82
|
return error;
|
|
74
83
|
}
|
|
75
84
|
return decorateServiceException(exception, additions);
|
|
@@ -85,7 +94,7 @@ export class ProtocolLib {
|
|
|
85
94
|
};
|
|
86
95
|
Object.assign(output, Error);
|
|
87
96
|
for (const [k, v] of entries) {
|
|
88
|
-
Error[k] = v;
|
|
97
|
+
Error[k === "message" ? "Message" : k] = v;
|
|
89
98
|
}
|
|
90
99
|
delete Error.__type;
|
|
91
100
|
output.Error = Error;
|
|
@@ -102,4 +111,12 @@ export class ProtocolLib {
|
|
|
102
111
|
errorData.Code = queryCompatErrorData.Code;
|
|
103
112
|
}
|
|
104
113
|
}
|
|
114
|
+
findQueryCompatibleError(registry, errorName) {
|
|
115
|
+
try {
|
|
116
|
+
return registry.getSchema(errorName);
|
|
117
|
+
}
|
|
118
|
+
catch (e) {
|
|
119
|
+
return registry.find((schema) => NormalizedSchema.of(schema).getMergedTraits().awsQueryError?.[0] === errorName);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
105
122
|
}
|
|
@@ -20,15 +20,23 @@ export class AwsSmithyRpcV2CborProtocol extends SmithyRpcV2CborProtocol {
|
|
|
20
20
|
if (this.awsQueryCompatible) {
|
|
21
21
|
this.mixin.setQueryCompatError(dataObject, response);
|
|
22
22
|
}
|
|
23
|
-
const errorName =
|
|
24
|
-
|
|
23
|
+
const errorName = (() => {
|
|
24
|
+
const compatHeader = response.headers["x-amzn-query-error"];
|
|
25
|
+
if (compatHeader && this.awsQueryCompatible) {
|
|
26
|
+
return compatHeader.split(";")[0];
|
|
27
|
+
}
|
|
28
|
+
return loadSmithyRpcV2CborErrorCode(response, dataObject) ?? "Unknown";
|
|
29
|
+
})();
|
|
30
|
+
const { errorSchema, errorMetadata } = await this.mixin.getErrorSchemaOrThrowBaseException(errorName, this.options.defaultNamespace, response, dataObject, metadata, this.awsQueryCompatible ? this.mixin.findQueryCompatibleError : undefined);
|
|
25
31
|
const ns = NormalizedSchema.of(errorSchema);
|
|
26
32
|
const message = dataObject.message ?? dataObject.Message ?? "Unknown";
|
|
27
33
|
const ErrorCtor = TypeRegistry.for(errorSchema[1]).getErrorCtor(errorSchema) ?? Error;
|
|
28
34
|
const exception = new ErrorCtor(message);
|
|
29
35
|
const output = {};
|
|
30
36
|
for (const [name, member] of ns.structIterator()) {
|
|
31
|
-
|
|
37
|
+
if (dataObject[name] != null) {
|
|
38
|
+
output[name] = this.deserializer.readValue(member, dataObject[name]);
|
|
39
|
+
}
|
|
32
40
|
}
|
|
33
41
|
if (this.awsQueryCompatible) {
|
|
34
42
|
this.mixin.queryCompatOutput(dataObject, output);
|
|
@@ -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;
|
|
@@ -52,15 +54,16 @@ export class AwsJsonRpcProtocol extends RpcProtocol {
|
|
|
52
54
|
this.mixin.setQueryCompatError(dataObject, response);
|
|
53
55
|
}
|
|
54
56
|
const errorIdentifier = loadRestJsonErrorCode(response, dataObject) ?? "Unknown";
|
|
55
|
-
const { errorSchema, errorMetadata } = await this.mixin.getErrorSchemaOrThrowBaseException(errorIdentifier, this.options.defaultNamespace, response, dataObject, metadata);
|
|
57
|
+
const { errorSchema, errorMetadata } = await this.mixin.getErrorSchemaOrThrowBaseException(errorIdentifier, this.options.defaultNamespace, response, dataObject, metadata, this.awsQueryCompatible ? this.mixin.findQueryCompatibleError : undefined);
|
|
56
58
|
const ns = NormalizedSchema.of(errorSchema);
|
|
57
59
|
const message = dataObject.message ?? dataObject.Message ?? "Unknown";
|
|
58
60
|
const ErrorCtor = TypeRegistry.for(errorSchema[1]).getErrorCtor(errorSchema) ?? Error;
|
|
59
61
|
const exception = new ErrorCtor(message);
|
|
60
62
|
const output = {};
|
|
61
63
|
for (const [name, member] of ns.structIterator()) {
|
|
62
|
-
|
|
63
|
-
|
|
64
|
+
if (dataObject[name] != null) {
|
|
65
|
+
output[name] = this.codec.createDeserializer().readObject(member, dataObject[name]);
|
|
66
|
+
}
|
|
64
67
|
}
|
|
65
68
|
if (this.awsQueryCompatible) {
|
|
66
69
|
this.mixin.queryCompatOutput(dataObject, output);
|