@smithy/core 3.19.0 → 3.20.1

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,12 +940,26 @@ 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);
951
+ }
952
+ if (value[key] != null) {
953
+ newObject[key] = this.readValue(memberSchema, value[key]);
942
954
  }
943
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]];
959
+ }
960
+ }
961
+ else if (value instanceof serde.NumericValue) {
962
+ return value;
944
963
  }
945
964
  return newObject;
946
965
  }
@@ -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();
@@ -1,6 +1,7 @@
1
1
  import { SerdeContext } from "@smithy/core/protocols";
2
2
  import { NormalizedSchema } from "@smithy/core/schema";
3
3
  import { _parseEpochTimestamp, generateIdempotencyToken } from "@smithy/core/serde";
4
+ import { NumericValue } from "@smithy/core/serde";
4
5
  import { fromBase64 } from "@smithy/util-base64";
5
6
  import { cbor } from "./cbor";
6
7
  import { dateToTag } from "./parseCborBody";
@@ -75,6 +76,11 @@ export class CborShapeSerializer extends SerdeContext {
75
76
  newObject[key] = value;
76
77
  }
77
78
  }
79
+ const isUnion = ns.isUnionSchema();
80
+ if (isUnion && Array.isArray(sourceObject.$unknown)) {
81
+ const [k, v] = sourceObject.$unknown;
82
+ newObject[k] = v;
83
+ }
78
84
  }
79
85
  else if (ns.isDocumentSchema()) {
80
86
  for (const key of Object.keys(sourceObject)) {
@@ -159,12 +165,26 @@ export class CborShapeDeserializer extends SerdeContext {
159
165
  }
160
166
  }
161
167
  else if (ns.isStructSchema()) {
168
+ const isUnion = ns.isUnionSchema();
169
+ let keys;
170
+ if (isUnion) {
171
+ keys = new Set(Object.keys(value).filter((k) => k !== "__type"));
172
+ }
162
173
  for (const [key, memberSchema] of ns.structIterator()) {
163
- const v = this.readValue(memberSchema, value[key]);
164
- if (v != null) {
165
- newObject[key] = v;
174
+ if (isUnion) {
175
+ keys.delete(key);
176
+ }
177
+ if (value[key] != null) {
178
+ newObject[key] = this.readValue(memberSchema, value[key]);
166
179
  }
167
180
  }
181
+ if (isUnion && keys?.size === 1 && Object.keys(newObject).length === 0) {
182
+ const k = keys.values().next().value;
183
+ newObject.$unknown = [k, value[k]];
184
+ }
185
+ }
186
+ else if (value instanceof NumericValue) {
187
+ return value;
168
188
  }
169
189
  return newObject;
170
190
  }
@@ -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.1",
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,12 +120,12 @@
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",
127
127
  "json-bigint": "^1.0.0",
128
- "rimraf": "3.0.2",
128
+ "rimraf": "5.0.10",
129
129
  "typedoc": "0.23.23"
130
130
  },
131
131
  "typedoc": {