@smithy/core 3.18.7 → 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.
- package/dist-cjs/submodules/cbor/index.js +19 -3
- package/dist-cjs/submodules/schema/index.js +8 -2
- package/dist-es/submodules/cbor/CborCodec.js +19 -3
- package/dist-es/submodules/schema/schemas/NormalizedSchema.js +8 -2
- package/dist-types/submodules/schema/schemas/NormalizedSchema.d.ts +6 -0
- package/dist-types/ts3.4/submodules/schema/schemas/NormalizedSchema.d.ts +6 -0
- package/package.json +10 -8
|
@@ -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
|
-
|
|
940
|
-
|
|
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
|
-
|
|
354
|
-
|
|
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
|
-
|
|
164
|
-
|
|
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
|
-
|
|
114
|
-
|
|
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.
|
|
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",
|
|
@@ -14,7 +14,9 @@
|
|
|
14
14
|
"extract:docs": "api-extractor run --local",
|
|
15
15
|
"test:cbor:perf": "node ./scripts/cbor-perf.mjs",
|
|
16
16
|
"test": "yarn g:vitest run",
|
|
17
|
-
"test:watch": "yarn g:vitest watch"
|
|
17
|
+
"test:watch": "yarn g:vitest watch",
|
|
18
|
+
"test:integration": "yarn g:vitest run -c vitest.config.integ.mts",
|
|
19
|
+
"test:integration:watch": "yarn g:vitest watch -c vitest.config.integ.mts"
|
|
18
20
|
},
|
|
19
21
|
"main": "./dist-cjs/index.js",
|
|
20
22
|
"module": "./dist-es/index.js",
|
|
@@ -77,13 +79,13 @@
|
|
|
77
79
|
"license": "Apache-2.0",
|
|
78
80
|
"sideEffects": false,
|
|
79
81
|
"dependencies": {
|
|
80
|
-
"@smithy/middleware-serde": "^4.2.
|
|
81
|
-
"@smithy/protocol-http": "^5.3.
|
|
82
|
-
"@smithy/types": "^4.
|
|
82
|
+
"@smithy/middleware-serde": "^4.2.8",
|
|
83
|
+
"@smithy/protocol-http": "^5.3.7",
|
|
84
|
+
"@smithy/types": "^4.11.0",
|
|
83
85
|
"@smithy/util-base64": "^4.3.0",
|
|
84
86
|
"@smithy/util-body-length-browser": "^4.2.0",
|
|
85
|
-
"@smithy/util-middleware": "^4.2.
|
|
86
|
-
"@smithy/util-stream": "^4.5.
|
|
87
|
+
"@smithy/util-middleware": "^4.2.7",
|
|
88
|
+
"@smithy/util-stream": "^4.5.8",
|
|
87
89
|
"@smithy/util-utf8": "^4.2.0",
|
|
88
90
|
"@smithy/uuid": "^1.1.0",
|
|
89
91
|
"tslib": "^2.6.2"
|
|
@@ -118,7 +120,7 @@
|
|
|
118
120
|
"directory": "packages/core"
|
|
119
121
|
},
|
|
120
122
|
"devDependencies": {
|
|
121
|
-
"@smithy/eventstream-serde-node": "^4.2.
|
|
123
|
+
"@smithy/eventstream-serde-node": "^4.2.7",
|
|
122
124
|
"@types/node": "^18.11.9",
|
|
123
125
|
"concurrently": "7.0.0",
|
|
124
126
|
"downlevel-dts": "0.10.1",
|