@aws-sdk/core 3.953.0 → 3.956.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/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/dist-cjs/index.js CHANGED
@@ -604,6 +604,30 @@ function* deserializingStructIterator(ns, sourceObject, nameTrait) {
604
604
  }
605
605
  }
606
606
 
607
+ class UnionSerde {
608
+ from;
609
+ to;
610
+ keys;
611
+ constructor(from, to) {
612
+ this.from = from;
613
+ this.to = to;
614
+ this.keys = new Set(Object.keys(this.from).filter((k) => k !== "__type"));
615
+ }
616
+ mark(key) {
617
+ this.keys.delete(key);
618
+ }
619
+ hasUnknown() {
620
+ return this.keys.size === 1 && Object.keys(this.to).length === 0;
621
+ }
622
+ writeUnknown() {
623
+ if (this.hasUnknown()) {
624
+ const k = this.keys.values().next().value;
625
+ const v = this.from[k];
626
+ this.to.$unknown = [k, v];
627
+ }
628
+ }
629
+ }
630
+
607
631
  function jsonReviver(key, value, context) {
608
632
  if (context?.source) {
609
633
  const numericString = context.source;
@@ -695,13 +719,23 @@ class JsonShapeDeserializer extends SerdeContextConfig {
695
719
  const ns = schema.NormalizedSchema.of(schema$1);
696
720
  if (isObject) {
697
721
  if (ns.isStructSchema()) {
722
+ const union = ns.isUnionSchema();
698
723
  const out = {};
724
+ let unionSerde;
725
+ if (union) {
726
+ unionSerde = new UnionSerde(value, out);
727
+ }
699
728
  for (const [memberName, memberSchema] of deserializingStructIterator(ns, value, this.settings.jsonName ? "jsonName" : false)) {
700
729
  const fromKey = this.settings.jsonName ? memberSchema.getMergedTraits().jsonName ?? memberName : memberName;
701
- const deserializedValue = this._read(memberSchema, value[fromKey]);
702
- if (deserializedValue != null) {
703
- out[memberName] = deserializedValue;
730
+ if (union) {
731
+ unionSerde.mark(fromKey);
704
732
  }
733
+ if (value[fromKey] != null) {
734
+ out[memberName] = this._read(memberSchema, value[fromKey]);
735
+ }
736
+ }
737
+ if (union) {
738
+ unionSerde.writeUnknown();
705
739
  }
706
740
  return out;
707
741
  }
@@ -890,6 +924,13 @@ class JsonShapeSerializer extends SerdeContextConfig {
890
924
  out[targetKey] = serializableValue;
891
925
  }
892
926
  }
927
+ if (ns.isUnionSchema() && Object.keys(out).length === 0) {
928
+ const { $unknown } = value;
929
+ if (Array.isArray($unknown)) {
930
+ const [k, v] = $unknown;
931
+ out[k] = this._write(15, v);
932
+ }
933
+ }
893
934
  return out;
894
935
  }
895
936
  if (Array.isArray(value) && ns.isListSchema()) {
@@ -1296,15 +1337,26 @@ class XmlShapeDeserializer extends SerdeContextConfig {
1296
1337
  return buffer;
1297
1338
  }
1298
1339
  if (ns.isStructSchema()) {
1340
+ const union = ns.isUnionSchema();
1341
+ let unionSerde;
1342
+ if (union) {
1343
+ unionSerde = new UnionSerde(value, buffer);
1344
+ }
1299
1345
  for (const [memberName, memberSchema] of ns.structIterator()) {
1300
1346
  const memberTraits = memberSchema.getMergedTraits();
1301
1347
  const xmlObjectKey = !memberTraits.httpPayload
1302
1348
  ? memberSchema.getMemberTraits().xmlName ?? memberName
1303
1349
  : memberTraits.xmlName ?? memberSchema.getName();
1350
+ if (union) {
1351
+ unionSerde.mark(xmlObjectKey);
1352
+ }
1304
1353
  if (value[xmlObjectKey] != null) {
1305
1354
  buffer[memberName] = this.readSchema(memberSchema, value[xmlObjectKey]);
1306
1355
  }
1307
1356
  }
1357
+ if (union) {
1358
+ unionSerde.writeUnknown();
1359
+ }
1308
1360
  return buffer;
1309
1361
  }
1310
1362
  if (ns.isDocumentSchema()) {
@@ -1408,7 +1460,22 @@ class QueryShapeSerializer extends SerdeContextConfig {
1408
1460
  }
1409
1461
  }
1410
1462
  else if (ns.isDocumentSchema()) {
1411
- throw new Error(`@aws-sdk/core/protocols - QuerySerializer unsupported document type ${ns.getName(true)}`);
1463
+ if (Array.isArray(value)) {
1464
+ this.write(64 | 15, value, prefix);
1465
+ }
1466
+ else if (value instanceof Date) {
1467
+ this.write(4, value, prefix);
1468
+ }
1469
+ else if (value instanceof Uint8Array) {
1470
+ this.write(21, value, prefix);
1471
+ }
1472
+ else if (value && typeof value === "object") {
1473
+ this.write(128 | 15, value, prefix);
1474
+ }
1475
+ else {
1476
+ this.writeKey(prefix);
1477
+ this.writeValue(String(value));
1478
+ }
1412
1479
  }
1413
1480
  else if (ns.isListSchema()) {
1414
1481
  if (Array.isArray(value)) {
@@ -1456,6 +1523,7 @@ class QueryShapeSerializer extends SerdeContextConfig {
1456
1523
  }
1457
1524
  else if (ns.isStructSchema()) {
1458
1525
  if (value && typeof value === "object") {
1526
+ let didWriteMember = false;
1459
1527
  for (const [memberName, member] of serializingStructIterator(ns, value)) {
1460
1528
  if (value[memberName] == null && !member.isIdempotencyToken()) {
1461
1529
  continue;
@@ -1463,6 +1531,15 @@ class QueryShapeSerializer extends SerdeContextConfig {
1463
1531
  const suffix = this.getKey(memberName, member.getMergedTraits().xmlName);
1464
1532
  const key = `${prefix}${suffix}`;
1465
1533
  this.write(member, value[memberName], key);
1534
+ didWriteMember = true;
1535
+ }
1536
+ if (!didWriteMember && ns.isUnionSchema()) {
1537
+ const { $unknown } = value;
1538
+ if (Array.isArray($unknown)) {
1539
+ const [k, v] = $unknown;
1540
+ const key = `${prefix}${k}`;
1541
+ this.write(15, v, key);
1542
+ }
1466
1543
  }
1467
1544
  }
1468
1545
  }
@@ -1771,6 +1848,22 @@ class XmlShapeSerializer extends SerdeContextConfig {
1771
1848
  }
1772
1849
  }
1773
1850
  }
1851
+ const { $unknown } = value;
1852
+ if ($unknown && ns.isUnionSchema() && Array.isArray($unknown) && Object.keys(value).length === 1) {
1853
+ const [k, v] = $unknown;
1854
+ const node = xmlBuilder.XmlNode.of(k);
1855
+ if (typeof v !== "string") {
1856
+ if (value instanceof xmlBuilder.XmlNode || value instanceof xmlBuilder.XmlText) {
1857
+ structXmlNode.addChildNode(value);
1858
+ }
1859
+ else {
1860
+ throw new Error(`@aws-sdk - $unknown union member in XML requires ` +
1861
+ `value of type string, @aws-sdk/xml-builder::XmlNode or XmlText.`);
1862
+ }
1863
+ }
1864
+ this.writeSimpleInto(0, v, node, xmlns);
1865
+ structXmlNode.addChildNode(node);
1866
+ }
1774
1867
  if (xmlns) {
1775
1868
  structXmlNode.addAttribute(xmlnsAttr, xmlns);
1776
1869
  }
@@ -274,6 +274,30 @@ function* deserializingStructIterator(ns, sourceObject, nameTrait) {
274
274
  }
275
275
  }
276
276
 
277
+ class UnionSerde {
278
+ from;
279
+ to;
280
+ keys;
281
+ constructor(from, to) {
282
+ this.from = from;
283
+ this.to = to;
284
+ this.keys = new Set(Object.keys(this.from).filter((k) => k !== "__type"));
285
+ }
286
+ mark(key) {
287
+ this.keys.delete(key);
288
+ }
289
+ hasUnknown() {
290
+ return this.keys.size === 1 && Object.keys(this.to).length === 0;
291
+ }
292
+ writeUnknown() {
293
+ if (this.hasUnknown()) {
294
+ const k = this.keys.values().next().value;
295
+ const v = this.from[k];
296
+ this.to.$unknown = [k, v];
297
+ }
298
+ }
299
+ }
300
+
277
301
  function jsonReviver(key, value, context) {
278
302
  if (context?.source) {
279
303
  const numericString = context.source;
@@ -365,13 +389,23 @@ class JsonShapeDeserializer extends SerdeContextConfig {
365
389
  const ns = schema.NormalizedSchema.of(schema$1);
366
390
  if (isObject) {
367
391
  if (ns.isStructSchema()) {
392
+ const union = ns.isUnionSchema();
368
393
  const out = {};
394
+ let unionSerde;
395
+ if (union) {
396
+ unionSerde = new UnionSerde(value, out);
397
+ }
369
398
  for (const [memberName, memberSchema] of deserializingStructIterator(ns, value, this.settings.jsonName ? "jsonName" : false)) {
370
399
  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;
400
+ if (union) {
401
+ unionSerde.mark(fromKey);
374
402
  }
403
+ if (value[fromKey] != null) {
404
+ out[memberName] = this._read(memberSchema, value[fromKey]);
405
+ }
406
+ }
407
+ if (union) {
408
+ unionSerde.writeUnknown();
375
409
  }
376
410
  return out;
377
411
  }
@@ -560,6 +594,13 @@ class JsonShapeSerializer extends SerdeContextConfig {
560
594
  out[targetKey] = serializableValue;
561
595
  }
562
596
  }
597
+ if (ns.isUnionSchema() && Object.keys(out).length === 0) {
598
+ const { $unknown } = value;
599
+ if (Array.isArray($unknown)) {
600
+ const [k, v] = $unknown;
601
+ out[k] = this._write(15, v);
602
+ }
603
+ }
563
604
  return out;
564
605
  }
565
606
  if (Array.isArray(value) && ns.isListSchema()) {
@@ -966,15 +1007,26 @@ class XmlShapeDeserializer extends SerdeContextConfig {
966
1007
  return buffer;
967
1008
  }
968
1009
  if (ns.isStructSchema()) {
1010
+ const union = ns.isUnionSchema();
1011
+ let unionSerde;
1012
+ if (union) {
1013
+ unionSerde = new UnionSerde(value, buffer);
1014
+ }
969
1015
  for (const [memberName, memberSchema] of ns.structIterator()) {
970
1016
  const memberTraits = memberSchema.getMergedTraits();
971
1017
  const xmlObjectKey = !memberTraits.httpPayload
972
1018
  ? memberSchema.getMemberTraits().xmlName ?? memberName
973
1019
  : memberTraits.xmlName ?? memberSchema.getName();
1020
+ if (union) {
1021
+ unionSerde.mark(xmlObjectKey);
1022
+ }
974
1023
  if (value[xmlObjectKey] != null) {
975
1024
  buffer[memberName] = this.readSchema(memberSchema, value[xmlObjectKey]);
976
1025
  }
977
1026
  }
1027
+ if (union) {
1028
+ unionSerde.writeUnknown();
1029
+ }
978
1030
  return buffer;
979
1031
  }
980
1032
  if (ns.isDocumentSchema()) {
@@ -1078,7 +1130,22 @@ class QueryShapeSerializer extends SerdeContextConfig {
1078
1130
  }
1079
1131
  }
1080
1132
  else if (ns.isDocumentSchema()) {
1081
- throw new Error(`@aws-sdk/core/protocols - QuerySerializer unsupported document type ${ns.getName(true)}`);
1133
+ if (Array.isArray(value)) {
1134
+ this.write(64 | 15, value, prefix);
1135
+ }
1136
+ else if (value instanceof Date) {
1137
+ this.write(4, value, prefix);
1138
+ }
1139
+ else if (value instanceof Uint8Array) {
1140
+ this.write(21, value, prefix);
1141
+ }
1142
+ else if (value && typeof value === "object") {
1143
+ this.write(128 | 15, value, prefix);
1144
+ }
1145
+ else {
1146
+ this.writeKey(prefix);
1147
+ this.writeValue(String(value));
1148
+ }
1082
1149
  }
1083
1150
  else if (ns.isListSchema()) {
1084
1151
  if (Array.isArray(value)) {
@@ -1126,6 +1193,7 @@ class QueryShapeSerializer extends SerdeContextConfig {
1126
1193
  }
1127
1194
  else if (ns.isStructSchema()) {
1128
1195
  if (value && typeof value === "object") {
1196
+ let didWriteMember = false;
1129
1197
  for (const [memberName, member] of serializingStructIterator(ns, value)) {
1130
1198
  if (value[memberName] == null && !member.isIdempotencyToken()) {
1131
1199
  continue;
@@ -1133,6 +1201,15 @@ class QueryShapeSerializer extends SerdeContextConfig {
1133
1201
  const suffix = this.getKey(memberName, member.getMergedTraits().xmlName);
1134
1202
  const key = `${prefix}${suffix}`;
1135
1203
  this.write(member, value[memberName], key);
1204
+ didWriteMember = true;
1205
+ }
1206
+ if (!didWriteMember && ns.isUnionSchema()) {
1207
+ const { $unknown } = value;
1208
+ if (Array.isArray($unknown)) {
1209
+ const [k, v] = $unknown;
1210
+ const key = `${prefix}${k}`;
1211
+ this.write(15, v, key);
1212
+ }
1136
1213
  }
1137
1214
  }
1138
1215
  }
@@ -1441,6 +1518,22 @@ class XmlShapeSerializer extends SerdeContextConfig {
1441
1518
  }
1442
1519
  }
1443
1520
  }
1521
+ const { $unknown } = value;
1522
+ if ($unknown && ns.isUnionSchema() && Array.isArray($unknown) && Object.keys(value).length === 1) {
1523
+ const [k, v] = $unknown;
1524
+ const node = xmlBuilder.XmlNode.of(k);
1525
+ if (typeof v !== "string") {
1526
+ if (value instanceof xmlBuilder.XmlNode || value instanceof xmlBuilder.XmlText) {
1527
+ structXmlNode.addChildNode(value);
1528
+ }
1529
+ else {
1530
+ throw new Error(`@aws-sdk - $unknown union member in XML requires ` +
1531
+ `value of type string, @aws-sdk/xml-builder::XmlNode or XmlText.`);
1532
+ }
1533
+ }
1534
+ this.writeSimpleInto(0, v, node, xmlns);
1535
+ structXmlNode.addChildNode(node);
1536
+ }
1444
1537
  if (xmlns) {
1445
1538
  structXmlNode.addAttribute(xmlnsAttr, xmlns);
1446
1539
  }
@@ -0,0 +1,23 @@
1
+ export class UnionSerde {
2
+ from;
3
+ to;
4
+ keys;
5
+ constructor(from, to) {
6
+ this.from = from;
7
+ this.to = to;
8
+ this.keys = new Set(Object.keys(this.from).filter((k) => k !== "__type"));
9
+ }
10
+ mark(key) {
11
+ this.keys.delete(key);
12
+ }
13
+ hasUnknown() {
14
+ return this.keys.size === 1 && Object.keys(this.to).length === 0;
15
+ }
16
+ writeUnknown() {
17
+ if (this.hasUnknown()) {
18
+ const k = this.keys.values().next().value;
19
+ const v = this.from[k];
20
+ this.to.$unknown = [k, v];
21
+ }
22
+ }
23
+ }
@@ -4,6 +4,7 @@ import { LazyJsonString, NumericValue, parseEpochTimestamp, parseRfc3339DateTime
4
4
  import { fromBase64 } from "@smithy/util-base64";
5
5
  import { SerdeContextConfig } from "../ConfigurableSerdeContext";
6
6
  import { deserializingStructIterator } from "../structIterator";
7
+ import { UnionSerde } from "../UnionSerde";
7
8
  import { jsonReviver } from "./jsonReviver";
8
9
  import { parseJsonBody } from "./parseJsonBody";
9
10
  export class JsonShapeDeserializer extends SerdeContextConfig {
@@ -23,14 +24,24 @@ export class JsonShapeDeserializer extends SerdeContextConfig {
23
24
  const ns = NormalizedSchema.of(schema);
24
25
  if (isObject) {
25
26
  if (ns.isStructSchema()) {
27
+ const union = ns.isUnionSchema();
26
28
  const out = {};
29
+ let unionSerde;
30
+ if (union) {
31
+ unionSerde = new UnionSerde(value, out);
32
+ }
27
33
  for (const [memberName, memberSchema] of deserializingStructIterator(ns, value, this.settings.jsonName ? "jsonName" : false)) {
28
34
  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;
35
+ if (union) {
36
+ unionSerde.mark(fromKey);
37
+ }
38
+ if (value[fromKey] != null) {
39
+ out[memberName] = this._read(memberSchema, value[fromKey]);
32
40
  }
33
41
  }
42
+ if (union) {
43
+ unionSerde.writeUnknown();
44
+ }
34
45
  return out;
35
46
  }
36
47
  if (Array.isArray(value) && ns.isListSchema()) {
@@ -51,6 +51,13 @@ export class JsonShapeSerializer extends SerdeContextConfig {
51
51
  out[targetKey] = serializableValue;
52
52
  }
53
53
  }
54
+ if (ns.isUnionSchema() && Object.keys(out).length === 0) {
55
+ const { $unknown } = value;
56
+ if (Array.isArray($unknown)) {
57
+ const [k, v] = $unknown;
58
+ out[k] = this._write(15, v);
59
+ }
60
+ }
54
61
  return out;
55
62
  }
56
63
  if (Array.isArray(value) && ns.isListSchema()) {
@@ -45,15 +45,24 @@ export class SinglePassJsonShapeSerializer extends SerdeContextConfig {
45
45
  }
46
46
  else if (ns.isStructSchema()) {
47
47
  b += "{";
48
+ let didWriteMember = false;
48
49
  for (const [name, member] of serializingStructIterator(ns, value)) {
49
50
  const item = value[name];
50
51
  const targetKey = this.settings.jsonName ? member.getMergedTraits().jsonName ?? name : name;
51
52
  const serializableValue = this.writeValue(member, item);
52
53
  if (item != null || member.isIdempotencyToken()) {
54
+ didWriteMember = true;
53
55
  b += `"${targetKey}":${serializableValue}`;
54
56
  b += ",";
55
57
  }
56
58
  }
59
+ if (!didWriteMember && ns.isUnionSchema()) {
60
+ const { $unknown } = value;
61
+ if (Array.isArray($unknown)) {
62
+ const [k, v] = $unknown;
63
+ b += `"${k}":${this.writeValue(15, v)}`;
64
+ }
65
+ }
57
66
  }
58
67
  else if (ns.isMapSchema() || ns.isDocumentSchema()) {
59
68
  b += "{";
@@ -66,7 +66,22 @@ export class QueryShapeSerializer extends SerdeContextConfig {
66
66
  }
67
67
  }
68
68
  else if (ns.isDocumentSchema()) {
69
- throw new Error(`@aws-sdk/core/protocols - QuerySerializer unsupported document type ${ns.getName(true)}`);
69
+ if (Array.isArray(value)) {
70
+ this.write(64 | 15, value, prefix);
71
+ }
72
+ else if (value instanceof Date) {
73
+ this.write(4, value, prefix);
74
+ }
75
+ else if (value instanceof Uint8Array) {
76
+ this.write(21, value, prefix);
77
+ }
78
+ else if (value && typeof value === "object") {
79
+ this.write(128 | 15, value, prefix);
80
+ }
81
+ else {
82
+ this.writeKey(prefix);
83
+ this.writeValue(String(value));
84
+ }
70
85
  }
71
86
  else if (ns.isListSchema()) {
72
87
  if (Array.isArray(value)) {
@@ -114,6 +129,7 @@ export class QueryShapeSerializer extends SerdeContextConfig {
114
129
  }
115
130
  else if (ns.isStructSchema()) {
116
131
  if (value && typeof value === "object") {
132
+ let didWriteMember = false;
117
133
  for (const [memberName, member] of serializingStructIterator(ns, value)) {
118
134
  if (value[memberName] == null && !member.isIdempotencyToken()) {
119
135
  continue;
@@ -121,6 +137,15 @@ export class QueryShapeSerializer extends SerdeContextConfig {
121
137
  const suffix = this.getKey(memberName, member.getMergedTraits().xmlName);
122
138
  const key = `${prefix}${suffix}`;
123
139
  this.write(member, value[memberName], key);
140
+ didWriteMember = true;
141
+ }
142
+ if (!didWriteMember && ns.isUnionSchema()) {
143
+ const { $unknown } = value;
144
+ if (Array.isArray($unknown)) {
145
+ const [k, v] = $unknown;
146
+ const key = `${prefix}${k}`;
147
+ this.write(15, v, key);
148
+ }
124
149
  }
125
150
  }
126
151
  }
@@ -4,6 +4,7 @@ import { NormalizedSchema } from "@smithy/core/schema";
4
4
  import { getValueFromTextNode } from "@smithy/smithy-client";
5
5
  import { toUtf8 } from "@smithy/util-utf8";
6
6
  import { SerdeContextConfig } from "../ConfigurableSerdeContext";
7
+ import { UnionSerde } from "../UnionSerde";
7
8
  export class XmlShapeDeserializer extends SerdeContextConfig {
8
9
  settings;
9
10
  stringDeserializer;
@@ -91,15 +92,26 @@ export class XmlShapeDeserializer extends SerdeContextConfig {
91
92
  return buffer;
92
93
  }
93
94
  if (ns.isStructSchema()) {
95
+ const union = ns.isUnionSchema();
96
+ let unionSerde;
97
+ if (union) {
98
+ unionSerde = new UnionSerde(value, buffer);
99
+ }
94
100
  for (const [memberName, memberSchema] of ns.structIterator()) {
95
101
  const memberTraits = memberSchema.getMergedTraits();
96
102
  const xmlObjectKey = !memberTraits.httpPayload
97
103
  ? memberSchema.getMemberTraits().xmlName ?? memberName
98
104
  : memberTraits.xmlName ?? memberSchema.getName();
105
+ if (union) {
106
+ unionSerde.mark(xmlObjectKey);
107
+ }
99
108
  if (value[xmlObjectKey] != null) {
100
109
  buffer[memberName] = this.readSchema(memberSchema, value[xmlObjectKey]);
101
110
  }
102
111
  }
112
+ if (union) {
113
+ unionSerde.writeUnknown();
114
+ }
103
115
  return buffer;
104
116
  }
105
117
  if (ns.isDocumentSchema()) {
@@ -87,6 +87,22 @@ export class XmlShapeSerializer extends SerdeContextConfig {
87
87
  }
88
88
  }
89
89
  }
90
+ const { $unknown } = value;
91
+ if ($unknown && ns.isUnionSchema() && Array.isArray($unknown) && Object.keys(value).length === 1) {
92
+ const [k, v] = $unknown;
93
+ const node = XmlNode.of(k);
94
+ if (typeof v !== "string") {
95
+ if (value instanceof XmlNode || value instanceof XmlText) {
96
+ structXmlNode.addChildNode(value);
97
+ }
98
+ else {
99
+ throw new Error(`@aws-sdk - $unknown union member in XML requires ` +
100
+ `value of type string, @aws-sdk/xml-builder::XmlNode or XmlText.`);
101
+ }
102
+ }
103
+ this.writeSimpleInto(0, v, node, xmlns);
104
+ structXmlNode.addChildNode(node);
105
+ }
90
106
  if (xmlns) {
91
107
  structXmlNode.addAttribute(xmlnsAttr, xmlns);
92
108
  }
@@ -0,0 +1,24 @@
1
+ /**
2
+ * Helper for identifying unknown union members during deserialization.
3
+ */
4
+ export declare class UnionSerde {
5
+ private from;
6
+ private to;
7
+ private keys;
8
+ constructor(from: any, to: any);
9
+ /**
10
+ * Marks the key as being a known member.
11
+ * @param key - to mark.
12
+ */
13
+ mark(key: string): void;
14
+ /**
15
+ * @returns whether only one key remains unmarked and nothing has been written,
16
+ * implying the object is a union.
17
+ */
18
+ hasUnknown(): boolean;
19
+ /**
20
+ * Writes the unknown key-value pair, if present, into the $unknown property
21
+ * of the union object.
22
+ */
23
+ writeUnknown(): void;
24
+ }
@@ -0,0 +1,9 @@
1
+ export declare class UnionSerde {
2
+ private from;
3
+ private to;
4
+ private keys;
5
+ constructor(from: any, to: any);
6
+ mark(key: string): void;
7
+ hasUnknown(): boolean;
8
+ writeUnknown(): void;
9
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aws-sdk/core",
3
- "version": "3.953.0",
3
+ "version": "3.956.0",
4
4
  "description": "Core functions & classes shared by multiple AWS SDK clients.",
5
5
  "scripts": {
6
6
  "build": "yarn lint && concurrently 'yarn:build:cjs' 'yarn:build:es' 'yarn:build:types'",
@@ -81,17 +81,17 @@
81
81
  },
82
82
  "license": "Apache-2.0",
83
83
  "dependencies": {
84
- "@aws-sdk/types": "3.953.0",
85
- "@aws-sdk/xml-builder": "3.953.0",
86
- "@smithy/core": "^3.19.0",
87
- "@smithy/node-config-provider": "^4.3.6",
88
- "@smithy/property-provider": "^4.2.6",
89
- "@smithy/protocol-http": "^5.3.6",
90
- "@smithy/signature-v4": "^5.3.6",
91
- "@smithy/smithy-client": "^4.10.0",
92
- "@smithy/types": "^4.10.0",
84
+ "@aws-sdk/types": "3.956.0",
85
+ "@aws-sdk/xml-builder": "3.956.0",
86
+ "@smithy/core": "^3.20.0",
87
+ "@smithy/node-config-provider": "^4.3.7",
88
+ "@smithy/property-provider": "^4.2.7",
89
+ "@smithy/protocol-http": "^5.3.7",
90
+ "@smithy/signature-v4": "^5.3.7",
91
+ "@smithy/smithy-client": "^4.10.2",
92
+ "@smithy/types": "^4.11.0",
93
93
  "@smithy/util-base64": "^4.3.0",
94
- "@smithy/util-middleware": "^4.2.6",
94
+ "@smithy/util-middleware": "^4.2.7",
95
95
  "@smithy/util-utf8": "^4.2.0",
96
96
  "tslib": "^2.6.2"
97
97
  },