@smithy/core 3.19.0 → 3.20.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.
@@ -851,6 +851,11 @@ class CborShapeSerializer extends protocols.SerdeContext {
851
851
  newObject[key] = value;
852
852
  }
853
853
  }
854
+ const isUnion = ns.isUnionSchema();
855
+ if (isUnion && Array.isArray(sourceObject.$unknown)) {
856
+ const [k, v] = sourceObject.$unknown;
857
+ newObject[k] = v;
858
+ }
854
859
  }
855
860
  else if (ns.isDocumentSchema()) {
856
861
  for (const key of Object.keys(sourceObject)) {
@@ -935,11 +940,22 @@ class CborShapeDeserializer extends protocols.SerdeContext {
935
940
  }
936
941
  }
937
942
  else if (ns.isStructSchema()) {
943
+ const isUnion = ns.isUnionSchema();
944
+ let keys;
945
+ if (isUnion) {
946
+ keys = new Set(Object.keys(value).filter((k) => k !== "__type"));
947
+ }
938
948
  for (const [key, memberSchema] of ns.structIterator()) {
939
- const v = this.readValue(memberSchema, value[key]);
940
- if (v != null) {
941
- newObject[key] = v;
949
+ if (isUnion) {
950
+ keys.delete(key);
942
951
  }
952
+ if (value[key] != null) {
953
+ newObject[key] = this.readValue(memberSchema, value[key]);
954
+ }
955
+ }
956
+ if (isUnion && keys?.size === 1 && Object.keys(newObject).length === 0) {
957
+ const k = keys.values().next().value;
958
+ newObject.$unknown = [k, value[k]];
943
959
  }
944
960
  }
945
961
  return newObject;
@@ -350,8 +350,14 @@ class NormalizedSchema {
350
350
  }
351
351
  isStructSchema() {
352
352
  const sc = this.getSchema();
353
- return (sc[0] === 3 ||
354
- sc[0] === -3);
353
+ const id = sc[0];
354
+ return (id === 3 ||
355
+ id === -3 ||
356
+ id === 4);
357
+ }
358
+ isUnionSchema() {
359
+ const sc = this.getSchema();
360
+ return sc[0] === 4;
355
361
  }
356
362
  isBlobSchema() {
357
363
  const sc = this.getSchema();
@@ -75,6 +75,11 @@ export class CborShapeSerializer extends SerdeContext {
75
75
  newObject[key] = value;
76
76
  }
77
77
  }
78
+ const isUnion = ns.isUnionSchema();
79
+ if (isUnion && Array.isArray(sourceObject.$unknown)) {
80
+ const [k, v] = sourceObject.$unknown;
81
+ newObject[k] = v;
82
+ }
78
83
  }
79
84
  else if (ns.isDocumentSchema()) {
80
85
  for (const key of Object.keys(sourceObject)) {
@@ -159,11 +164,22 @@ export class CborShapeDeserializer extends SerdeContext {
159
164
  }
160
165
  }
161
166
  else if (ns.isStructSchema()) {
167
+ const isUnion = ns.isUnionSchema();
168
+ let keys;
169
+ if (isUnion) {
170
+ keys = new Set(Object.keys(value).filter((k) => k !== "__type"));
171
+ }
162
172
  for (const [key, memberSchema] of ns.structIterator()) {
163
- const v = this.readValue(memberSchema, value[key]);
164
- if (v != null) {
165
- newObject[key] = v;
173
+ if (isUnion) {
174
+ keys.delete(key);
166
175
  }
176
+ if (value[key] != null) {
177
+ newObject[key] = this.readValue(memberSchema, value[key]);
178
+ }
179
+ }
180
+ if (isUnion && keys?.size === 1 && Object.keys(newObject).length === 0) {
181
+ const k = keys.values().next().value;
182
+ newObject.$unknown = [k, value[k]];
167
183
  }
168
184
  }
169
185
  return newObject;
@@ -110,8 +110,14 @@ export class NormalizedSchema {
110
110
  }
111
111
  isStructSchema() {
112
112
  const sc = this.getSchema();
113
- return (sc[0] === 3 ||
114
- sc[0] === -3);
113
+ const id = sc[0];
114
+ return (id === 3 ||
115
+ id === -3 ||
116
+ id === 4);
117
+ }
118
+ isUnionSchema() {
119
+ const sc = this.getSchema();
120
+ return sc[0] === 4;
115
121
  }
116
122
  isBlobSchema() {
117
123
  const sc = this.getSchema();
@@ -45,7 +45,13 @@ export declare class NormalizedSchema implements INormalizedSchema {
45
45
  */
46
46
  isListSchema(): boolean;
47
47
  isMapSchema(): boolean;
48
+ /**
49
+ * To simplify serialization logic, static union schemas are considered a specialization
50
+ * of structs in the TypeScript typings and JS runtime, as well as static error schemas
51
+ * which have a different identifier.
52
+ */
48
53
  isStructSchema(): boolean;
54
+ isUnionSchema(): boolean;
49
55
  isBlobSchema(): boolean;
50
56
  isTimestampSchema(): boolean;
51
57
  isUnitSchema(): boolean;
@@ -45,7 +45,13 @@ export declare class NormalizedSchema implements INormalizedSchema {
45
45
  */
46
46
  isListSchema(): boolean;
47
47
  isMapSchema(): boolean;
48
+ /**
49
+ * To simplify serialization logic, static union schemas are considered a specialization
50
+ * of structs in the TypeScript typings and JS runtime, as well as static error schemas
51
+ * which have a different identifier.
52
+ */
48
53
  isStructSchema(): boolean;
54
+ isUnionSchema(): boolean;
49
55
  isBlobSchema(): boolean;
50
56
  isTimestampSchema(): boolean;
51
57
  isUnitSchema(): boolean;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@smithy/core",
3
- "version": "3.19.0",
3
+ "version": "3.20.0",
4
4
  "scripts": {
5
5
  "build": "yarn lint && concurrently 'yarn:build:cjs' 'yarn:build:es' 'yarn:build:types && yarn build:types:downlevel'",
6
6
  "build:cjs": "node ../../scripts/inline core",
@@ -79,13 +79,13 @@
79
79
  "license": "Apache-2.0",
80
80
  "sideEffects": false,
81
81
  "dependencies": {
82
- "@smithy/middleware-serde": "^4.2.7",
83
- "@smithy/protocol-http": "^5.3.6",
84
- "@smithy/types": "^4.10.0",
82
+ "@smithy/middleware-serde": "^4.2.8",
83
+ "@smithy/protocol-http": "^5.3.7",
84
+ "@smithy/types": "^4.11.0",
85
85
  "@smithy/util-base64": "^4.3.0",
86
86
  "@smithy/util-body-length-browser": "^4.2.0",
87
- "@smithy/util-middleware": "^4.2.6",
88
- "@smithy/util-stream": "^4.5.7",
87
+ "@smithy/util-middleware": "^4.2.7",
88
+ "@smithy/util-stream": "^4.5.8",
89
89
  "@smithy/util-utf8": "^4.2.0",
90
90
  "@smithy/uuid": "^1.1.0",
91
91
  "tslib": "^2.6.2"
@@ -120,7 +120,7 @@
120
120
  "directory": "packages/core"
121
121
  },
122
122
  "devDependencies": {
123
- "@smithy/eventstream-serde-node": "^4.2.6",
123
+ "@smithy/eventstream-serde-node": "^4.2.7",
124
124
  "@types/node": "^18.11.9",
125
125
  "concurrently": "7.0.0",
126
126
  "downlevel-dts": "0.10.1",