@smithy/core 3.7.1 → 3.8.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 +93 -42
- package/dist-cjs/submodules/protocols/index.js +88 -85
- package/dist-cjs/submodules/schema/index.js +12 -0
- package/dist-cjs/submodules/serde/index.js +13 -54
- package/dist-es/submodules/cbor/CborCodec.js +77 -41
- package/dist-es/submodules/cbor/cbor-decode.js +20 -5
- package/dist-es/submodules/protocols/HttpBindingProtocol.js +95 -0
- package/dist-es/submodules/protocols/HttpProtocol.js +7 -95
- package/dist-es/submodules/schema/schemas/NormalizedSchema.js +9 -0
- package/dist-es/submodules/serde/copyDocumentWithTransform.js +1 -53
- package/dist-es/submodules/serde/generateIdempotencyToken.js +2 -0
- package/dist-es/submodules/serde/index.js +1 -0
- package/dist-es/submodules/serde/value/NumericValue.js +6 -2
- package/dist-types/submodules/cbor/CborCodec.d.ts +5 -0
- package/dist-types/submodules/protocols/HttpBindingProtocol.d.ts +9 -1
- package/dist-types/submodules/protocols/HttpProtocol.d.ts +3 -1
- package/dist-types/submodules/schema/schemas/NormalizedSchema.d.ts +5 -0
- package/dist-types/submodules/serde/copyDocumentWithTransform.d.ts +1 -0
- package/dist-types/submodules/serde/generateIdempotencyToken.d.ts +2 -0
- package/dist-types/submodules/serde/index.d.ts +1 -0
- package/dist-types/submodules/serde/value/NumericValue.d.ts +1 -1
- package/dist-types/ts3.4/submodules/cbor/CborCodec.d.ts +5 -0
- package/dist-types/ts3.4/submodules/protocols/HttpBindingProtocol.d.ts +9 -1
- package/dist-types/ts3.4/submodules/protocols/HttpProtocol.d.ts +3 -1
- package/dist-types/ts3.4/submodules/schema/schemas/NormalizedSchema.d.ts +5 -0
- package/dist-types/ts3.4/submodules/serde/copyDocumentWithTransform.d.ts +1 -0
- package/dist-types/ts3.4/submodules/serde/generateIdempotencyToken.d.ts +2 -0
- package/dist-types/ts3.4/submodules/serde/index.d.ts +1 -0
- package/dist-types/ts3.4/submodules/serde/value/NumericValue.d.ts +1 -1
- package/package.json +9 -7
|
@@ -139,14 +139,26 @@ function decode(at, to) {
|
|
|
139
139
|
for (let i = start; i < start + length; ++i) {
|
|
140
140
|
b = b << BigInt(8) | BigInt(payload[i]);
|
|
141
141
|
}
|
|
142
|
-
_offset = offset + length;
|
|
142
|
+
_offset = offset + _offset + length;
|
|
143
143
|
return minor === 3 ? -b - BigInt(1) : b;
|
|
144
144
|
} else if (minor === 4) {
|
|
145
145
|
const decimalFraction = decode(at + offset, to);
|
|
146
146
|
const [exponent, mantissa] = decimalFraction;
|
|
147
|
-
const
|
|
148
|
-
const
|
|
149
|
-
|
|
147
|
+
const normalizer = mantissa < 0 ? -1 : 1;
|
|
148
|
+
const mantissaStr = "0".repeat(Math.abs(exponent) + 1) + String(BigInt(normalizer) * BigInt(mantissa));
|
|
149
|
+
let numericString;
|
|
150
|
+
const sign = mantissa < 0 ? "-" : "";
|
|
151
|
+
numericString = exponent === 0 ? mantissaStr : mantissaStr.slice(0, mantissaStr.length + exponent) + "." + mantissaStr.slice(exponent);
|
|
152
|
+
numericString = numericString.replace(/^0+/g, "");
|
|
153
|
+
if (numericString === "") {
|
|
154
|
+
numericString = "0";
|
|
155
|
+
}
|
|
156
|
+
if (numericString[0] === ".") {
|
|
157
|
+
numericString = "0" + numericString;
|
|
158
|
+
}
|
|
159
|
+
numericString = sign + numericString;
|
|
160
|
+
_offset = offset + _offset;
|
|
161
|
+
return (0, import_serde.nv)(numericString);
|
|
150
162
|
} else {
|
|
151
163
|
const value = decode(at + offset, to);
|
|
152
164
|
const valueOffset = _offset;
|
|
@@ -780,6 +792,7 @@ var import_util_middleware = require("@smithy/util-middleware");
|
|
|
780
792
|
// src/submodules/cbor/CborCodec.ts
|
|
781
793
|
var import_schema = require("@smithy/core/schema");
|
|
782
794
|
var import_serde3 = require("@smithy/core/serde");
|
|
795
|
+
var import_util_base64 = require("@smithy/util-base64");
|
|
783
796
|
var CborCodec = class {
|
|
784
797
|
createSerializer() {
|
|
785
798
|
const serializer = new CborShapeSerializer();
|
|
@@ -800,35 +813,73 @@ var CborShapeSerializer = class {
|
|
|
800
813
|
this.serdeContext = serdeContext;
|
|
801
814
|
}
|
|
802
815
|
write(schema, value) {
|
|
803
|
-
this.value =
|
|
804
|
-
|
|
805
|
-
|
|
816
|
+
this.value = this.serialize(schema, value);
|
|
817
|
+
}
|
|
818
|
+
/**
|
|
819
|
+
* Recursive serializer transform that copies and prepares the user input object
|
|
820
|
+
* for CBOR serialization.
|
|
821
|
+
*/
|
|
822
|
+
serialize(schema, source) {
|
|
823
|
+
const ns = import_schema.NormalizedSchema.of(schema);
|
|
824
|
+
if (source == null) {
|
|
825
|
+
if (ns.isIdempotencyToken()) {
|
|
826
|
+
return (0, import_serde3.generateIdempotencyToken)();
|
|
827
|
+
}
|
|
828
|
+
return source;
|
|
829
|
+
}
|
|
830
|
+
if (ns.isBlobSchema()) {
|
|
831
|
+
if (typeof source === "string") {
|
|
832
|
+
return (this.serdeContext?.base64Decoder ?? import_util_base64.fromBase64)(source);
|
|
806
833
|
}
|
|
807
|
-
|
|
808
|
-
|
|
834
|
+
return source;
|
|
835
|
+
}
|
|
836
|
+
if (ns.isTimestampSchema()) {
|
|
837
|
+
if (typeof source === "number" || typeof source === "bigint") {
|
|
838
|
+
return dateToTag(new Date(Number(source) / 1e3 | 0));
|
|
809
839
|
}
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
840
|
+
return dateToTag(source);
|
|
841
|
+
}
|
|
842
|
+
if (typeof source === "function" || typeof source === "object") {
|
|
843
|
+
const sourceObject = source;
|
|
844
|
+
if (ns.isListSchema() && Array.isArray(sourceObject)) {
|
|
845
|
+
const sparse = !!ns.getMergedTraits().sparse;
|
|
846
|
+
const newArray = [];
|
|
847
|
+
let i = 0;
|
|
848
|
+
for (const item of sourceObject) {
|
|
849
|
+
const value = this.serialize(ns.getValueSchema(), item);
|
|
850
|
+
if (value != null || sparse) {
|
|
851
|
+
newArray[i++] = value;
|
|
852
|
+
}
|
|
815
853
|
}
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
854
|
+
return newArray;
|
|
855
|
+
}
|
|
856
|
+
if (sourceObject instanceof Date) {
|
|
857
|
+
return dateToTag(sourceObject);
|
|
858
|
+
}
|
|
859
|
+
const newObject = {};
|
|
860
|
+
if (ns.isMapSchema()) {
|
|
861
|
+
const sparse = !!ns.getMergedTraits().sparse;
|
|
862
|
+
for (const key of Object.keys(sourceObject)) {
|
|
863
|
+
const value = this.serialize(ns.getValueSchema(), sourceObject[key]);
|
|
864
|
+
if (value != null || sparse) {
|
|
865
|
+
newObject[key] = value;
|
|
866
|
+
}
|
|
867
|
+
}
|
|
868
|
+
} else if (ns.isStructSchema()) {
|
|
869
|
+
for (const [key, memberSchema] of ns.structIterator()) {
|
|
870
|
+
const value = this.serialize(memberSchema, sourceObject[key]);
|
|
871
|
+
if (value != null) {
|
|
872
|
+
newObject[key] = value;
|
|
826
873
|
}
|
|
827
|
-
|
|
874
|
+
}
|
|
875
|
+
} else if (ns.isDocumentSchema()) {
|
|
876
|
+
for (const key of Object.keys(sourceObject)) {
|
|
877
|
+
newObject[key] = this.serialize(ns.getValueSchema(), sourceObject[key]);
|
|
828
878
|
}
|
|
829
879
|
}
|
|
830
|
-
return
|
|
831
|
-
}
|
|
880
|
+
return newObject;
|
|
881
|
+
}
|
|
882
|
+
return source;
|
|
832
883
|
}
|
|
833
884
|
flush() {
|
|
834
885
|
const buffer = cbor.serialize(this.value);
|
|
@@ -846,14 +897,14 @@ var CborShapeDeserializer = class {
|
|
|
846
897
|
}
|
|
847
898
|
readValue(_schema, value) {
|
|
848
899
|
const ns = import_schema.NormalizedSchema.of(_schema);
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
return value;
|
|
900
|
+
if (ns.isTimestampSchema() && typeof value === "number") {
|
|
901
|
+
return (0, import_serde3.parseEpochTimestamp)(value);
|
|
902
|
+
}
|
|
903
|
+
if (ns.isBlobSchema()) {
|
|
904
|
+
if (typeof value === "string") {
|
|
905
|
+
return (this.serdeContext?.base64Decoder ?? import_util_base64.fromBase64)(value);
|
|
856
906
|
}
|
|
907
|
+
return value;
|
|
857
908
|
}
|
|
858
909
|
if (typeof value === "undefined" || typeof value === "boolean" || typeof value === "number" || typeof value === "string" || typeof value === "bigint" || typeof value === "symbol") {
|
|
859
910
|
return value;
|
|
@@ -873,23 +924,23 @@ var CborShapeDeserializer = class {
|
|
|
873
924
|
if (ns.isListSchema()) {
|
|
874
925
|
const newArray = [];
|
|
875
926
|
const memberSchema = ns.getValueSchema();
|
|
876
|
-
const sparse =
|
|
927
|
+
const sparse = !!ns.getMergedTraits().sparse;
|
|
877
928
|
for (const item of value) {
|
|
878
|
-
|
|
879
|
-
if (
|
|
880
|
-
newArray.
|
|
929
|
+
const itemValue = this.readValue(memberSchema, item);
|
|
930
|
+
if (itemValue != null || sparse) {
|
|
931
|
+
newArray.push(itemValue);
|
|
881
932
|
}
|
|
882
933
|
}
|
|
883
934
|
return newArray;
|
|
884
935
|
}
|
|
885
936
|
const newObject = {};
|
|
886
937
|
if (ns.isMapSchema()) {
|
|
887
|
-
const sparse = ns.getMergedTraits().sparse;
|
|
938
|
+
const sparse = !!ns.getMergedTraits().sparse;
|
|
888
939
|
const targetSchema = ns.getValueSchema();
|
|
889
940
|
for (const key of Object.keys(value)) {
|
|
890
|
-
|
|
891
|
-
if (
|
|
892
|
-
|
|
941
|
+
const itemValue = this.readValue(targetSchema, value[key]);
|
|
942
|
+
if (itemValue != null || sparse) {
|
|
943
|
+
newObject[key] = itemValue;
|
|
893
944
|
}
|
|
894
945
|
}
|
|
895
946
|
} else if (ns.isStructSchema()) {
|
|
@@ -56,13 +56,13 @@ function extendedEncodeURIComponent(str) {
|
|
|
56
56
|
|
|
57
57
|
// src/submodules/protocols/HttpBindingProtocol.ts
|
|
58
58
|
var import_schema2 = require("@smithy/core/schema");
|
|
59
|
+
var import_serde = require("@smithy/core/serde");
|
|
59
60
|
var import_protocol_http2 = require("@smithy/protocol-http");
|
|
61
|
+
var import_util_stream2 = require("@smithy/util-stream");
|
|
60
62
|
|
|
61
63
|
// src/submodules/protocols/HttpProtocol.ts
|
|
62
64
|
var import_schema = require("@smithy/core/schema");
|
|
63
|
-
var import_serde = require("@smithy/core/serde");
|
|
64
65
|
var import_protocol_http = require("@smithy/protocol-http");
|
|
65
|
-
var import_util_stream2 = require("@smithy/util-stream");
|
|
66
66
|
var HttpProtocol = class {
|
|
67
67
|
constructor(options) {
|
|
68
68
|
this.options = options;
|
|
@@ -137,89 +137,7 @@ var HttpProtocol = class {
|
|
|
137
137
|
};
|
|
138
138
|
}
|
|
139
139
|
async deserializeHttpMessage(schema, context, response, arg4, arg5) {
|
|
140
|
-
|
|
141
|
-
if (arg4 instanceof Set) {
|
|
142
|
-
dataObject = arg5;
|
|
143
|
-
} else {
|
|
144
|
-
dataObject = arg4;
|
|
145
|
-
}
|
|
146
|
-
const deserializer = this.deserializer;
|
|
147
|
-
const ns = import_schema.NormalizedSchema.of(schema);
|
|
148
|
-
const nonHttpBindingMembers = [];
|
|
149
|
-
for (const [memberName, memberSchema] of ns.structIterator()) {
|
|
150
|
-
const memberTraits = memberSchema.getMemberTraits();
|
|
151
|
-
if (memberTraits.httpPayload) {
|
|
152
|
-
const isStreaming = memberSchema.isStreaming();
|
|
153
|
-
if (isStreaming) {
|
|
154
|
-
const isEventStream = memberSchema.isStructSchema();
|
|
155
|
-
if (isEventStream) {
|
|
156
|
-
const context2 = this.serdeContext;
|
|
157
|
-
if (!context2.eventStreamMarshaller) {
|
|
158
|
-
throw new Error("@smithy/core - HttpProtocol: eventStreamMarshaller missing in serdeContext.");
|
|
159
|
-
}
|
|
160
|
-
const memberSchemas = memberSchema.getMemberSchemas();
|
|
161
|
-
dataObject[memberName] = context2.eventStreamMarshaller.deserialize(response.body, async (event) => {
|
|
162
|
-
const unionMember = Object.keys(event).find((key) => {
|
|
163
|
-
return key !== "__type";
|
|
164
|
-
}) ?? "";
|
|
165
|
-
if (unionMember in memberSchemas) {
|
|
166
|
-
const eventStreamSchema = memberSchemas[unionMember];
|
|
167
|
-
return {
|
|
168
|
-
[unionMember]: await deserializer.read(eventStreamSchema, event[unionMember].body)
|
|
169
|
-
};
|
|
170
|
-
} else {
|
|
171
|
-
return {
|
|
172
|
-
$unknown: event
|
|
173
|
-
};
|
|
174
|
-
}
|
|
175
|
-
});
|
|
176
|
-
} else {
|
|
177
|
-
dataObject[memberName] = (0, import_util_stream2.sdkStreamMixin)(response.body);
|
|
178
|
-
}
|
|
179
|
-
} else if (response.body) {
|
|
180
|
-
const bytes = await collectBody(response.body, context);
|
|
181
|
-
if (bytes.byteLength > 0) {
|
|
182
|
-
dataObject[memberName] = await deserializer.read(memberSchema, bytes);
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
} else if (memberTraits.httpHeader) {
|
|
186
|
-
const key = String(memberTraits.httpHeader).toLowerCase();
|
|
187
|
-
const value = response.headers[key];
|
|
188
|
-
if (null != value) {
|
|
189
|
-
if (memberSchema.isListSchema()) {
|
|
190
|
-
const headerListValueSchema = memberSchema.getValueSchema();
|
|
191
|
-
let sections;
|
|
192
|
-
if (headerListValueSchema.isTimestampSchema() && headerListValueSchema.getSchema() === import_schema.SCHEMA.TIMESTAMP_DEFAULT) {
|
|
193
|
-
sections = (0, import_serde.splitEvery)(value, ",", 2);
|
|
194
|
-
} else {
|
|
195
|
-
sections = (0, import_serde.splitHeader)(value);
|
|
196
|
-
}
|
|
197
|
-
const list = [];
|
|
198
|
-
for (const section of sections) {
|
|
199
|
-
list.push(await deserializer.read([headerListValueSchema, { httpHeader: key }], section.trim()));
|
|
200
|
-
}
|
|
201
|
-
dataObject[memberName] = list;
|
|
202
|
-
} else {
|
|
203
|
-
dataObject[memberName] = await deserializer.read(memberSchema, value);
|
|
204
|
-
}
|
|
205
|
-
}
|
|
206
|
-
} else if (memberTraits.httpPrefixHeaders !== void 0) {
|
|
207
|
-
dataObject[memberName] = {};
|
|
208
|
-
for (const [header, value] of Object.entries(response.headers)) {
|
|
209
|
-
if (header.startsWith(memberTraits.httpPrefixHeaders)) {
|
|
210
|
-
dataObject[memberName][header.slice(memberTraits.httpPrefixHeaders.length)] = await deserializer.read(
|
|
211
|
-
[memberSchema.getValueSchema(), { httpHeader: header }],
|
|
212
|
-
value
|
|
213
|
-
);
|
|
214
|
-
}
|
|
215
|
-
}
|
|
216
|
-
} else if (memberTraits.httpResponseCode) {
|
|
217
|
-
dataObject[memberName] = response.statusCode;
|
|
218
|
-
} else {
|
|
219
|
-
nonHttpBindingMembers.push(memberName);
|
|
220
|
-
}
|
|
221
|
-
}
|
|
222
|
-
return nonHttpBindingMembers;
|
|
140
|
+
return [];
|
|
223
141
|
}
|
|
224
142
|
};
|
|
225
143
|
|
|
@@ -395,6 +313,91 @@ var HttpBindingProtocol = class extends HttpProtocol {
|
|
|
395
313
|
};
|
|
396
314
|
return output;
|
|
397
315
|
}
|
|
316
|
+
async deserializeHttpMessage(schema, context, response, arg4, arg5) {
|
|
317
|
+
let dataObject;
|
|
318
|
+
if (arg4 instanceof Set) {
|
|
319
|
+
dataObject = arg5;
|
|
320
|
+
} else {
|
|
321
|
+
dataObject = arg4;
|
|
322
|
+
}
|
|
323
|
+
const deserializer = this.deserializer;
|
|
324
|
+
const ns = import_schema2.NormalizedSchema.of(schema);
|
|
325
|
+
const nonHttpBindingMembers = [];
|
|
326
|
+
for (const [memberName, memberSchema] of ns.structIterator()) {
|
|
327
|
+
const memberTraits = memberSchema.getMemberTraits();
|
|
328
|
+
if (memberTraits.httpPayload) {
|
|
329
|
+
const isStreaming = memberSchema.isStreaming();
|
|
330
|
+
if (isStreaming) {
|
|
331
|
+
const isEventStream = memberSchema.isStructSchema();
|
|
332
|
+
if (isEventStream) {
|
|
333
|
+
const context2 = this.serdeContext;
|
|
334
|
+
if (!context2.eventStreamMarshaller) {
|
|
335
|
+
throw new Error("@smithy/core - HttpProtocol: eventStreamMarshaller missing in serdeContext.");
|
|
336
|
+
}
|
|
337
|
+
const memberSchemas = memberSchema.getMemberSchemas();
|
|
338
|
+
dataObject[memberName] = context2.eventStreamMarshaller.deserialize(response.body, async (event) => {
|
|
339
|
+
const unionMember = Object.keys(event).find((key) => {
|
|
340
|
+
return key !== "__type";
|
|
341
|
+
}) ?? "";
|
|
342
|
+
if (unionMember in memberSchemas) {
|
|
343
|
+
const eventStreamSchema = memberSchemas[unionMember];
|
|
344
|
+
return {
|
|
345
|
+
[unionMember]: await deserializer.read(eventStreamSchema, event[unionMember].body)
|
|
346
|
+
};
|
|
347
|
+
} else {
|
|
348
|
+
return {
|
|
349
|
+
$unknown: event
|
|
350
|
+
};
|
|
351
|
+
}
|
|
352
|
+
});
|
|
353
|
+
} else {
|
|
354
|
+
dataObject[memberName] = (0, import_util_stream2.sdkStreamMixin)(response.body);
|
|
355
|
+
}
|
|
356
|
+
} else if (response.body) {
|
|
357
|
+
const bytes = await collectBody(response.body, context);
|
|
358
|
+
if (bytes.byteLength > 0) {
|
|
359
|
+
dataObject[memberName] = await deserializer.read(memberSchema, bytes);
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
} else if (memberTraits.httpHeader) {
|
|
363
|
+
const key = String(memberTraits.httpHeader).toLowerCase();
|
|
364
|
+
const value = response.headers[key];
|
|
365
|
+
if (null != value) {
|
|
366
|
+
if (memberSchema.isListSchema()) {
|
|
367
|
+
const headerListValueSchema = memberSchema.getValueSchema();
|
|
368
|
+
let sections;
|
|
369
|
+
if (headerListValueSchema.isTimestampSchema() && headerListValueSchema.getSchema() === import_schema2.SCHEMA.TIMESTAMP_DEFAULT) {
|
|
370
|
+
sections = (0, import_serde.splitEvery)(value, ",", 2);
|
|
371
|
+
} else {
|
|
372
|
+
sections = (0, import_serde.splitHeader)(value);
|
|
373
|
+
}
|
|
374
|
+
const list = [];
|
|
375
|
+
for (const section of sections) {
|
|
376
|
+
list.push(await deserializer.read([headerListValueSchema, { httpHeader: key }], section.trim()));
|
|
377
|
+
}
|
|
378
|
+
dataObject[memberName] = list;
|
|
379
|
+
} else {
|
|
380
|
+
dataObject[memberName] = await deserializer.read(memberSchema, value);
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
} else if (memberTraits.httpPrefixHeaders !== void 0) {
|
|
384
|
+
dataObject[memberName] = {};
|
|
385
|
+
for (const [header, value] of Object.entries(response.headers)) {
|
|
386
|
+
if (header.startsWith(memberTraits.httpPrefixHeaders)) {
|
|
387
|
+
dataObject[memberName][header.slice(memberTraits.httpPrefixHeaders.length)] = await deserializer.read(
|
|
388
|
+
[memberSchema.getValueSchema(), { httpHeader: header }],
|
|
389
|
+
value
|
|
390
|
+
);
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
} else if (memberTraits.httpResponseCode) {
|
|
394
|
+
dataObject[memberName] = response.statusCode;
|
|
395
|
+
} else {
|
|
396
|
+
nonHttpBindingMembers.push(memberName);
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
return nonHttpBindingMembers;
|
|
400
|
+
}
|
|
398
401
|
};
|
|
399
402
|
|
|
400
403
|
// src/submodules/protocols/RpcProtocol.ts
|
|
@@ -658,6 +658,18 @@ var NormalizedSchema = class _NormalizedSchema {
|
|
|
658
658
|
}
|
|
659
659
|
return this.getSchema() === SCHEMA.STREAMING_BLOB;
|
|
660
660
|
}
|
|
661
|
+
/**
|
|
662
|
+
* This is a shortcut to avoid calling `getMergedTraits().idempotencyToken` on every string.
|
|
663
|
+
* @returns whether the schema has the idempotencyToken trait.
|
|
664
|
+
*/
|
|
665
|
+
isIdempotencyToken() {
|
|
666
|
+
if (typeof this.traits === "number") {
|
|
667
|
+
return (this.traits & 4) === 4;
|
|
668
|
+
} else if (typeof this.traits === "object") {
|
|
669
|
+
return !!this.traits.idempotencyToken;
|
|
670
|
+
}
|
|
671
|
+
return false;
|
|
672
|
+
}
|
|
661
673
|
/**
|
|
662
674
|
* @returns own traits merged with member traits, where member traits of the same trait key take priority.
|
|
663
675
|
* This method is cached.
|
|
@@ -35,6 +35,7 @@ __export(serde_exports, {
|
|
|
35
35
|
expectShort: () => expectShort,
|
|
36
36
|
expectString: () => expectString,
|
|
37
37
|
expectUnion: () => expectUnion,
|
|
38
|
+
generateIdempotencyToken: () => import_uuid.v4,
|
|
38
39
|
handleFloat: () => handleFloat,
|
|
39
40
|
limitedParseDouble: () => limitedParseDouble,
|
|
40
41
|
limitedParseFloat: () => limitedParseFloat,
|
|
@@ -61,57 +62,7 @@ __export(serde_exports, {
|
|
|
61
62
|
module.exports = __toCommonJS(serde_exports);
|
|
62
63
|
|
|
63
64
|
// src/submodules/serde/copyDocumentWithTransform.ts
|
|
64
|
-
var
|
|
65
|
-
var copyDocumentWithTransform = (source, schemaRef, transform = (_) => _) => {
|
|
66
|
-
const ns = import_schema.NormalizedSchema.of(schemaRef);
|
|
67
|
-
switch (typeof source) {
|
|
68
|
-
case "undefined":
|
|
69
|
-
case "boolean":
|
|
70
|
-
case "number":
|
|
71
|
-
case "string":
|
|
72
|
-
case "bigint":
|
|
73
|
-
case "symbol":
|
|
74
|
-
return transform(source, ns);
|
|
75
|
-
case "function":
|
|
76
|
-
case "object":
|
|
77
|
-
if (source === null) {
|
|
78
|
-
return transform(null, ns);
|
|
79
|
-
}
|
|
80
|
-
if (Array.isArray(source)) {
|
|
81
|
-
const newArray = new Array(source.length);
|
|
82
|
-
let i = 0;
|
|
83
|
-
for (const item of source) {
|
|
84
|
-
newArray[i++] = copyDocumentWithTransform(item, ns.getValueSchema(), transform);
|
|
85
|
-
}
|
|
86
|
-
return transform(newArray, ns);
|
|
87
|
-
}
|
|
88
|
-
if ("byteLength" in source) {
|
|
89
|
-
const newBytes = new Uint8Array(source.byteLength);
|
|
90
|
-
newBytes.set(source, 0);
|
|
91
|
-
return transform(newBytes, ns);
|
|
92
|
-
}
|
|
93
|
-
if (source instanceof Date) {
|
|
94
|
-
return transform(source, ns);
|
|
95
|
-
}
|
|
96
|
-
const newObject = {};
|
|
97
|
-
if (ns.isMapSchema()) {
|
|
98
|
-
for (const key of Object.keys(source)) {
|
|
99
|
-
newObject[key] = copyDocumentWithTransform(source[key], ns.getValueSchema(), transform);
|
|
100
|
-
}
|
|
101
|
-
} else if (ns.isStructSchema()) {
|
|
102
|
-
for (const [key, memberSchema] of ns.structIterator()) {
|
|
103
|
-
newObject[key] = copyDocumentWithTransform(source[key], memberSchema, transform);
|
|
104
|
-
}
|
|
105
|
-
} else if (ns.isDocumentSchema()) {
|
|
106
|
-
for (const key of Object.keys(source)) {
|
|
107
|
-
newObject[key] = copyDocumentWithTransform(source[key], ns.getValueSchema(), transform);
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
return transform(newObject, ns);
|
|
111
|
-
default:
|
|
112
|
-
return transform(source, ns);
|
|
113
|
-
}
|
|
114
|
-
};
|
|
65
|
+
var copyDocumentWithTransform = (source, schemaRef, transform = (_) => _) => source;
|
|
115
66
|
|
|
116
67
|
// src/submodules/serde/parse-utils.ts
|
|
117
68
|
var parseBoolean = (value) => {
|
|
@@ -566,6 +517,9 @@ var stripLeadingZeroes = (value) => {
|
|
|
566
517
|
return value.slice(idx);
|
|
567
518
|
};
|
|
568
519
|
|
|
520
|
+
// src/submodules/serde/generateIdempotencyToken.ts
|
|
521
|
+
var import_uuid = require("uuid");
|
|
522
|
+
|
|
569
523
|
// src/submodules/serde/lazy-json.ts
|
|
570
524
|
var LazyJsonString = function LazyJsonString2(val) {
|
|
571
525
|
const str = Object.assign(new String(val), {
|
|
@@ -667,7 +621,7 @@ var splitHeader = (value) => {
|
|
|
667
621
|
};
|
|
668
622
|
|
|
669
623
|
// src/submodules/serde/value/NumericValue.ts
|
|
670
|
-
var NumericValue = class {
|
|
624
|
+
var NumericValue = class _NumericValue {
|
|
671
625
|
constructor(string, type) {
|
|
672
626
|
this.string = string;
|
|
673
627
|
this.type = type;
|
|
@@ -694,15 +648,19 @@ var NumericValue = class {
|
|
|
694
648
|
toString() {
|
|
695
649
|
return this.string;
|
|
696
650
|
}
|
|
697
|
-
[Symbol.hasInstance](object) {
|
|
651
|
+
static [Symbol.hasInstance](object) {
|
|
698
652
|
if (!object || typeof object !== "object") {
|
|
699
653
|
return false;
|
|
700
654
|
}
|
|
701
655
|
const _nv = object;
|
|
656
|
+
const prototypeMatch = _NumericValue.prototype.isPrototypeOf(object.constructor?.prototype);
|
|
657
|
+
if (prototypeMatch) {
|
|
658
|
+
return prototypeMatch;
|
|
659
|
+
}
|
|
702
660
|
if (typeof _nv.string === "string" && typeof _nv.type === "string" && _nv.constructor?.name === "NumericValue") {
|
|
703
661
|
return true;
|
|
704
662
|
}
|
|
705
|
-
return
|
|
663
|
+
return prototypeMatch;
|
|
706
664
|
}
|
|
707
665
|
};
|
|
708
666
|
function nv(input) {
|
|
@@ -726,6 +684,7 @@ function nv(input) {
|
|
|
726
684
|
expectShort,
|
|
727
685
|
expectString,
|
|
728
686
|
expectUnion,
|
|
687
|
+
generateIdempotencyToken,
|
|
729
688
|
handleFloat,
|
|
730
689
|
limitedParseDouble,
|
|
731
690
|
limitedParseFloat,
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { NormalizedSchema } from "@smithy/core/schema";
|
|
2
|
-
import {
|
|
2
|
+
import { generateIdempotencyToken, parseEpochTimestamp } from "@smithy/core/serde";
|
|
3
|
+
import { fromBase64 } from "@smithy/util-base64";
|
|
3
4
|
import { cbor } from "./cbor";
|
|
4
5
|
import { dateToTag } from "./parseCborBody";
|
|
5
6
|
export class CborCodec {
|
|
@@ -22,36 +23,71 @@ export class CborShapeSerializer {
|
|
|
22
23
|
this.serdeContext = serdeContext;
|
|
23
24
|
}
|
|
24
25
|
write(schema, value) {
|
|
25
|
-
this.value =
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
26
|
+
this.value = this.serialize(schema, value);
|
|
27
|
+
}
|
|
28
|
+
serialize(schema, source) {
|
|
29
|
+
const ns = NormalizedSchema.of(schema);
|
|
30
|
+
if (source == null) {
|
|
31
|
+
if (ns.isIdempotencyToken()) {
|
|
32
|
+
return generateIdempotencyToken();
|
|
33
|
+
}
|
|
34
|
+
return source;
|
|
35
|
+
}
|
|
36
|
+
if (ns.isBlobSchema()) {
|
|
37
|
+
if (typeof source === "string") {
|
|
38
|
+
return (this.serdeContext?.base64Decoder ?? fromBase64)(source);
|
|
39
|
+
}
|
|
40
|
+
return source;
|
|
41
|
+
}
|
|
42
|
+
if (ns.isTimestampSchema()) {
|
|
43
|
+
if (typeof source === "number" || typeof source === "bigint") {
|
|
44
|
+
return dateToTag(new Date((Number(source) / 1000) | 0));
|
|
45
|
+
}
|
|
46
|
+
return dateToTag(source);
|
|
47
|
+
}
|
|
48
|
+
if (typeof source === "function" || typeof source === "object") {
|
|
49
|
+
const sourceObject = source;
|
|
50
|
+
if (ns.isListSchema() && Array.isArray(sourceObject)) {
|
|
51
|
+
const sparse = !!ns.getMergedTraits().sparse;
|
|
52
|
+
const newArray = [];
|
|
53
|
+
let i = 0;
|
|
54
|
+
for (const item of sourceObject) {
|
|
55
|
+
const value = this.serialize(ns.getValueSchema(), item);
|
|
56
|
+
if (value != null || sparse) {
|
|
57
|
+
newArray[i++] = value;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return newArray;
|
|
61
|
+
}
|
|
62
|
+
if (sourceObject instanceof Date) {
|
|
63
|
+
return dateToTag(sourceObject);
|
|
64
|
+
}
|
|
65
|
+
const newObject = {};
|
|
66
|
+
if (ns.isMapSchema()) {
|
|
67
|
+
const sparse = !!ns.getMergedTraits().sparse;
|
|
68
|
+
for (const key of Object.keys(sourceObject)) {
|
|
69
|
+
const value = this.serialize(ns.getValueSchema(), sourceObject[key]);
|
|
70
|
+
if (value != null || sparse) {
|
|
71
|
+
newObject[key] = value;
|
|
72
|
+
}
|
|
37
73
|
}
|
|
38
74
|
}
|
|
39
|
-
else if (
|
|
40
|
-
const
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
const filteredOutByNonSparse = !sparse && v == null;
|
|
45
|
-
const filteredOutByUnrecognizedMember = isStruct && !(k in members);
|
|
46
|
-
if (filteredOutByNonSparse || filteredOutByUnrecognizedMember) {
|
|
47
|
-
delete _[k];
|
|
48
|
-
}
|
|
75
|
+
else if (ns.isStructSchema()) {
|
|
76
|
+
for (const [key, memberSchema] of ns.structIterator()) {
|
|
77
|
+
const value = this.serialize(memberSchema, sourceObject[key]);
|
|
78
|
+
if (value != null) {
|
|
79
|
+
newObject[key] = value;
|
|
49
80
|
}
|
|
50
|
-
return _;
|
|
51
81
|
}
|
|
52
82
|
}
|
|
53
|
-
|
|
54
|
-
|
|
83
|
+
else if (ns.isDocumentSchema()) {
|
|
84
|
+
for (const key of Object.keys(sourceObject)) {
|
|
85
|
+
newObject[key] = this.serialize(ns.getValueSchema(), sourceObject[key]);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
return newObject;
|
|
89
|
+
}
|
|
90
|
+
return source;
|
|
55
91
|
}
|
|
56
92
|
flush() {
|
|
57
93
|
const buffer = cbor.serialize(this.value);
|
|
@@ -69,14 +105,14 @@ export class CborShapeDeserializer {
|
|
|
69
105
|
}
|
|
70
106
|
readValue(_schema, value) {
|
|
71
107
|
const ns = NormalizedSchema.of(_schema);
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
return value;
|
|
108
|
+
if (ns.isTimestampSchema() && typeof value === "number") {
|
|
109
|
+
return parseEpochTimestamp(value);
|
|
110
|
+
}
|
|
111
|
+
if (ns.isBlobSchema()) {
|
|
112
|
+
if (typeof value === "string") {
|
|
113
|
+
return (this.serdeContext?.base64Decoder ?? fromBase64)(value);
|
|
79
114
|
}
|
|
115
|
+
return value;
|
|
80
116
|
}
|
|
81
117
|
if (typeof value === "undefined" ||
|
|
82
118
|
typeof value === "boolean" ||
|
|
@@ -102,23 +138,23 @@ export class CborShapeDeserializer {
|
|
|
102
138
|
if (ns.isListSchema()) {
|
|
103
139
|
const newArray = [];
|
|
104
140
|
const memberSchema = ns.getValueSchema();
|
|
105
|
-
const sparse =
|
|
141
|
+
const sparse = !!ns.getMergedTraits().sparse;
|
|
106
142
|
for (const item of value) {
|
|
107
|
-
|
|
108
|
-
if (
|
|
109
|
-
newArray.
|
|
143
|
+
const itemValue = this.readValue(memberSchema, item);
|
|
144
|
+
if (itemValue != null || sparse) {
|
|
145
|
+
newArray.push(itemValue);
|
|
110
146
|
}
|
|
111
147
|
}
|
|
112
148
|
return newArray;
|
|
113
149
|
}
|
|
114
150
|
const newObject = {};
|
|
115
151
|
if (ns.isMapSchema()) {
|
|
116
|
-
const sparse = ns.getMergedTraits().sparse;
|
|
152
|
+
const sparse = !!ns.getMergedTraits().sparse;
|
|
117
153
|
const targetSchema = ns.getValueSchema();
|
|
118
154
|
for (const key of Object.keys(value)) {
|
|
119
|
-
|
|
120
|
-
if (
|
|
121
|
-
|
|
155
|
+
const itemValue = this.readValue(targetSchema, value[key]);
|
|
156
|
+
if (itemValue != null || sparse) {
|
|
157
|
+
newObject[key] = itemValue;
|
|
122
158
|
}
|
|
123
159
|
}
|
|
124
160
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { nv } from "@smithy/core/serde";
|
|
2
2
|
import { toUtf8 } from "@smithy/util-utf8";
|
|
3
3
|
import { alloc, extendedFloat16, extendedFloat32, extendedFloat64, extendedOneByte, majorList, majorMap, majorNegativeInt64, majorTag, majorUint64, majorUnstructuredByteString, majorUtf8String, minorIndefinite, specialFalse, specialNull, specialTrue, specialUndefined, tag, } from "./cbor-types";
|
|
4
4
|
const USE_TEXT_DECODER = typeof TextDecoder !== "undefined";
|
|
@@ -80,15 +80,30 @@ export function decode(at, to) {
|
|
|
80
80
|
for (let i = start; i < start + length; ++i) {
|
|
81
81
|
b = (b << BigInt(8)) | BigInt(payload[i]);
|
|
82
82
|
}
|
|
83
|
-
_offset = offset + length;
|
|
83
|
+
_offset = offset + _offset + length;
|
|
84
84
|
return minor === 3 ? -b - BigInt(1) : b;
|
|
85
85
|
}
|
|
86
86
|
else if (minor === 4) {
|
|
87
87
|
const decimalFraction = decode(at + offset, to);
|
|
88
88
|
const [exponent, mantissa] = decimalFraction;
|
|
89
|
-
const
|
|
90
|
-
const
|
|
91
|
-
|
|
89
|
+
const normalizer = mantissa < 0 ? -1 : 1;
|
|
90
|
+
const mantissaStr = "0".repeat(Math.abs(exponent) + 1) + String(BigInt(normalizer) * BigInt(mantissa));
|
|
91
|
+
let numericString;
|
|
92
|
+
const sign = mantissa < 0 ? "-" : "";
|
|
93
|
+
numericString =
|
|
94
|
+
exponent === 0
|
|
95
|
+
? mantissaStr
|
|
96
|
+
: mantissaStr.slice(0, mantissaStr.length + exponent) + "." + mantissaStr.slice(exponent);
|
|
97
|
+
numericString = numericString.replace(/^0+/g, "");
|
|
98
|
+
if (numericString === "") {
|
|
99
|
+
numericString = "0";
|
|
100
|
+
}
|
|
101
|
+
if (numericString[0] === ".") {
|
|
102
|
+
numericString = "0" + numericString;
|
|
103
|
+
}
|
|
104
|
+
numericString = sign + numericString;
|
|
105
|
+
_offset = offset + _offset;
|
|
106
|
+
return nv(numericString);
|
|
92
107
|
}
|
|
93
108
|
else {
|
|
94
109
|
const value = decode(at + offset, to);
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { NormalizedSchema, SCHEMA } from "@smithy/core/schema";
|
|
2
|
+
import { splitEvery, splitHeader } from "@smithy/core/serde";
|
|
2
3
|
import { HttpRequest } from "@smithy/protocol-http";
|
|
4
|
+
import { sdkStreamMixin } from "@smithy/util-stream";
|
|
3
5
|
import { collectBody } from "./collect-stream-body";
|
|
4
6
|
import { extendedEncodeURIComponent } from "./extended-encode-uri-component";
|
|
5
7
|
import { HttpProtocol } from "./HttpProtocol";
|
|
@@ -175,4 +177,97 @@ export class HttpBindingProtocol extends HttpProtocol {
|
|
|
175
177
|
};
|
|
176
178
|
return output;
|
|
177
179
|
}
|
|
180
|
+
async deserializeHttpMessage(schema, context, response, arg4, arg5) {
|
|
181
|
+
let dataObject;
|
|
182
|
+
if (arg4 instanceof Set) {
|
|
183
|
+
dataObject = arg5;
|
|
184
|
+
}
|
|
185
|
+
else {
|
|
186
|
+
dataObject = arg4;
|
|
187
|
+
}
|
|
188
|
+
const deserializer = this.deserializer;
|
|
189
|
+
const ns = NormalizedSchema.of(schema);
|
|
190
|
+
const nonHttpBindingMembers = [];
|
|
191
|
+
for (const [memberName, memberSchema] of ns.structIterator()) {
|
|
192
|
+
const memberTraits = memberSchema.getMemberTraits();
|
|
193
|
+
if (memberTraits.httpPayload) {
|
|
194
|
+
const isStreaming = memberSchema.isStreaming();
|
|
195
|
+
if (isStreaming) {
|
|
196
|
+
const isEventStream = memberSchema.isStructSchema();
|
|
197
|
+
if (isEventStream) {
|
|
198
|
+
const context = this.serdeContext;
|
|
199
|
+
if (!context.eventStreamMarshaller) {
|
|
200
|
+
throw new Error("@smithy/core - HttpProtocol: eventStreamMarshaller missing in serdeContext.");
|
|
201
|
+
}
|
|
202
|
+
const memberSchemas = memberSchema.getMemberSchemas();
|
|
203
|
+
dataObject[memberName] = context.eventStreamMarshaller.deserialize(response.body, async (event) => {
|
|
204
|
+
const unionMember = Object.keys(event).find((key) => {
|
|
205
|
+
return key !== "__type";
|
|
206
|
+
}) ?? "";
|
|
207
|
+
if (unionMember in memberSchemas) {
|
|
208
|
+
const eventStreamSchema = memberSchemas[unionMember];
|
|
209
|
+
return {
|
|
210
|
+
[unionMember]: await deserializer.read(eventStreamSchema, event[unionMember].body),
|
|
211
|
+
};
|
|
212
|
+
}
|
|
213
|
+
else {
|
|
214
|
+
return {
|
|
215
|
+
$unknown: event,
|
|
216
|
+
};
|
|
217
|
+
}
|
|
218
|
+
});
|
|
219
|
+
}
|
|
220
|
+
else {
|
|
221
|
+
dataObject[memberName] = sdkStreamMixin(response.body);
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
else if (response.body) {
|
|
225
|
+
const bytes = await collectBody(response.body, context);
|
|
226
|
+
if (bytes.byteLength > 0) {
|
|
227
|
+
dataObject[memberName] = await deserializer.read(memberSchema, bytes);
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
else if (memberTraits.httpHeader) {
|
|
232
|
+
const key = String(memberTraits.httpHeader).toLowerCase();
|
|
233
|
+
const value = response.headers[key];
|
|
234
|
+
if (null != value) {
|
|
235
|
+
if (memberSchema.isListSchema()) {
|
|
236
|
+
const headerListValueSchema = memberSchema.getValueSchema();
|
|
237
|
+
let sections;
|
|
238
|
+
if (headerListValueSchema.isTimestampSchema() &&
|
|
239
|
+
headerListValueSchema.getSchema() === SCHEMA.TIMESTAMP_DEFAULT) {
|
|
240
|
+
sections = splitEvery(value, ",", 2);
|
|
241
|
+
}
|
|
242
|
+
else {
|
|
243
|
+
sections = splitHeader(value);
|
|
244
|
+
}
|
|
245
|
+
const list = [];
|
|
246
|
+
for (const section of sections) {
|
|
247
|
+
list.push(await deserializer.read([headerListValueSchema, { httpHeader: key }], section.trim()));
|
|
248
|
+
}
|
|
249
|
+
dataObject[memberName] = list;
|
|
250
|
+
}
|
|
251
|
+
else {
|
|
252
|
+
dataObject[memberName] = await deserializer.read(memberSchema, value);
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
else if (memberTraits.httpPrefixHeaders !== undefined) {
|
|
257
|
+
dataObject[memberName] = {};
|
|
258
|
+
for (const [header, value] of Object.entries(response.headers)) {
|
|
259
|
+
if (header.startsWith(memberTraits.httpPrefixHeaders)) {
|
|
260
|
+
dataObject[memberName][header.slice(memberTraits.httpPrefixHeaders.length)] = await deserializer.read([memberSchema.getValueSchema(), { httpHeader: header }], value);
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
else if (memberTraits.httpResponseCode) {
|
|
265
|
+
dataObject[memberName] = response.statusCode;
|
|
266
|
+
}
|
|
267
|
+
else {
|
|
268
|
+
nonHttpBindingMembers.push(memberName);
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
return nonHttpBindingMembers;
|
|
272
|
+
}
|
|
178
273
|
}
|
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
import { NormalizedSchema
|
|
2
|
-
import { splitEvery, splitHeader } from "@smithy/core/serde";
|
|
1
|
+
import { NormalizedSchema } from "@smithy/core/schema";
|
|
3
2
|
import { HttpRequest, HttpResponse } from "@smithy/protocol-http";
|
|
4
|
-
import { sdkStreamMixin } from "@smithy/util-stream";
|
|
5
|
-
import { collectBody } from "./collect-stream-body";
|
|
6
3
|
export class HttpProtocol {
|
|
7
4
|
constructor(options) {
|
|
8
5
|
this.options = options;
|
|
@@ -76,96 +73,11 @@ export class HttpProtocol {
|
|
|
76
73
|
};
|
|
77
74
|
}
|
|
78
75
|
async deserializeHttpMessage(schema, context, response, arg4, arg5) {
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
}
|
|
86
|
-
const deserializer = this.deserializer;
|
|
87
|
-
const ns = NormalizedSchema.of(schema);
|
|
88
|
-
const nonHttpBindingMembers = [];
|
|
89
|
-
for (const [memberName, memberSchema] of ns.structIterator()) {
|
|
90
|
-
const memberTraits = memberSchema.getMemberTraits();
|
|
91
|
-
if (memberTraits.httpPayload) {
|
|
92
|
-
const isStreaming = memberSchema.isStreaming();
|
|
93
|
-
if (isStreaming) {
|
|
94
|
-
const isEventStream = memberSchema.isStructSchema();
|
|
95
|
-
if (isEventStream) {
|
|
96
|
-
const context = this.serdeContext;
|
|
97
|
-
if (!context.eventStreamMarshaller) {
|
|
98
|
-
throw new Error("@smithy/core - HttpProtocol: eventStreamMarshaller missing in serdeContext.");
|
|
99
|
-
}
|
|
100
|
-
const memberSchemas = memberSchema.getMemberSchemas();
|
|
101
|
-
dataObject[memberName] = context.eventStreamMarshaller.deserialize(response.body, async (event) => {
|
|
102
|
-
const unionMember = Object.keys(event).find((key) => {
|
|
103
|
-
return key !== "__type";
|
|
104
|
-
}) ?? "";
|
|
105
|
-
if (unionMember in memberSchemas) {
|
|
106
|
-
const eventStreamSchema = memberSchemas[unionMember];
|
|
107
|
-
return {
|
|
108
|
-
[unionMember]: await deserializer.read(eventStreamSchema, event[unionMember].body),
|
|
109
|
-
};
|
|
110
|
-
}
|
|
111
|
-
else {
|
|
112
|
-
return {
|
|
113
|
-
$unknown: event,
|
|
114
|
-
};
|
|
115
|
-
}
|
|
116
|
-
});
|
|
117
|
-
}
|
|
118
|
-
else {
|
|
119
|
-
dataObject[memberName] = sdkStreamMixin(response.body);
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
else if (response.body) {
|
|
123
|
-
const bytes = await collectBody(response.body, context);
|
|
124
|
-
if (bytes.byteLength > 0) {
|
|
125
|
-
dataObject[memberName] = await deserializer.read(memberSchema, bytes);
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
else if (memberTraits.httpHeader) {
|
|
130
|
-
const key = String(memberTraits.httpHeader).toLowerCase();
|
|
131
|
-
const value = response.headers[key];
|
|
132
|
-
if (null != value) {
|
|
133
|
-
if (memberSchema.isListSchema()) {
|
|
134
|
-
const headerListValueSchema = memberSchema.getValueSchema();
|
|
135
|
-
let sections;
|
|
136
|
-
if (headerListValueSchema.isTimestampSchema() &&
|
|
137
|
-
headerListValueSchema.getSchema() === SCHEMA.TIMESTAMP_DEFAULT) {
|
|
138
|
-
sections = splitEvery(value, ",", 2);
|
|
139
|
-
}
|
|
140
|
-
else {
|
|
141
|
-
sections = splitHeader(value);
|
|
142
|
-
}
|
|
143
|
-
const list = [];
|
|
144
|
-
for (const section of sections) {
|
|
145
|
-
list.push(await deserializer.read([headerListValueSchema, { httpHeader: key }], section.trim()));
|
|
146
|
-
}
|
|
147
|
-
dataObject[memberName] = list;
|
|
148
|
-
}
|
|
149
|
-
else {
|
|
150
|
-
dataObject[memberName] = await deserializer.read(memberSchema, value);
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
else if (memberTraits.httpPrefixHeaders !== undefined) {
|
|
155
|
-
dataObject[memberName] = {};
|
|
156
|
-
for (const [header, value] of Object.entries(response.headers)) {
|
|
157
|
-
if (header.startsWith(memberTraits.httpPrefixHeaders)) {
|
|
158
|
-
dataObject[memberName][header.slice(memberTraits.httpPrefixHeaders.length)] = await deserializer.read([memberSchema.getValueSchema(), { httpHeader: header }], value);
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
else if (memberTraits.httpResponseCode) {
|
|
163
|
-
dataObject[memberName] = response.statusCode;
|
|
164
|
-
}
|
|
165
|
-
else {
|
|
166
|
-
nonHttpBindingMembers.push(memberName);
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
return nonHttpBindingMembers;
|
|
76
|
+
void schema;
|
|
77
|
+
void context;
|
|
78
|
+
void response;
|
|
79
|
+
void arg4;
|
|
80
|
+
void arg5;
|
|
81
|
+
return [];
|
|
170
82
|
}
|
|
171
83
|
}
|
|
@@ -183,6 +183,15 @@ export class NormalizedSchema {
|
|
|
183
183
|
}
|
|
184
184
|
return this.getSchema() === SCHEMA.STREAMING_BLOB;
|
|
185
185
|
}
|
|
186
|
+
isIdempotencyToken() {
|
|
187
|
+
if (typeof this.traits === "number") {
|
|
188
|
+
return (this.traits & 0b0100) === 0b0100;
|
|
189
|
+
}
|
|
190
|
+
else if (typeof this.traits === "object") {
|
|
191
|
+
return !!this.traits.idempotencyToken;
|
|
192
|
+
}
|
|
193
|
+
return false;
|
|
194
|
+
}
|
|
186
195
|
getMergedTraits() {
|
|
187
196
|
if (this.normalizedTraits) {
|
|
188
197
|
return this.normalizedTraits;
|
|
@@ -1,53 +1 @@
|
|
|
1
|
-
|
|
2
|
-
export const copyDocumentWithTransform = (source, schemaRef, transform = (_) => _) => {
|
|
3
|
-
const ns = NormalizedSchema.of(schemaRef);
|
|
4
|
-
switch (typeof source) {
|
|
5
|
-
case "undefined":
|
|
6
|
-
case "boolean":
|
|
7
|
-
case "number":
|
|
8
|
-
case "string":
|
|
9
|
-
case "bigint":
|
|
10
|
-
case "symbol":
|
|
11
|
-
return transform(source, ns);
|
|
12
|
-
case "function":
|
|
13
|
-
case "object":
|
|
14
|
-
if (source === null) {
|
|
15
|
-
return transform(null, ns);
|
|
16
|
-
}
|
|
17
|
-
if (Array.isArray(source)) {
|
|
18
|
-
const newArray = new Array(source.length);
|
|
19
|
-
let i = 0;
|
|
20
|
-
for (const item of source) {
|
|
21
|
-
newArray[i++] = copyDocumentWithTransform(item, ns.getValueSchema(), transform);
|
|
22
|
-
}
|
|
23
|
-
return transform(newArray, ns);
|
|
24
|
-
}
|
|
25
|
-
if ("byteLength" in source) {
|
|
26
|
-
const newBytes = new Uint8Array(source.byteLength);
|
|
27
|
-
newBytes.set(source, 0);
|
|
28
|
-
return transform(newBytes, ns);
|
|
29
|
-
}
|
|
30
|
-
if (source instanceof Date) {
|
|
31
|
-
return transform(source, ns);
|
|
32
|
-
}
|
|
33
|
-
const newObject = {};
|
|
34
|
-
if (ns.isMapSchema()) {
|
|
35
|
-
for (const key of Object.keys(source)) {
|
|
36
|
-
newObject[key] = copyDocumentWithTransform(source[key], ns.getValueSchema(), transform);
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
else if (ns.isStructSchema()) {
|
|
40
|
-
for (const [key, memberSchema] of ns.structIterator()) {
|
|
41
|
-
newObject[key] = copyDocumentWithTransform(source[key], memberSchema, transform);
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
else if (ns.isDocumentSchema()) {
|
|
45
|
-
for (const key of Object.keys(source)) {
|
|
46
|
-
newObject[key] = copyDocumentWithTransform(source[key], ns.getValueSchema(), transform);
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
return transform(newObject, ns);
|
|
50
|
-
default:
|
|
51
|
-
return transform(source, ns);
|
|
52
|
-
}
|
|
53
|
-
};
|
|
1
|
+
export const copyDocumentWithTransform = (source, schemaRef, transform = (_) => _) => source;
|
|
@@ -23,15 +23,19 @@ export class NumericValue {
|
|
|
23
23
|
toString() {
|
|
24
24
|
return this.string;
|
|
25
25
|
}
|
|
26
|
-
[Symbol.hasInstance](object) {
|
|
26
|
+
static [Symbol.hasInstance](object) {
|
|
27
27
|
if (!object || typeof object !== "object") {
|
|
28
28
|
return false;
|
|
29
29
|
}
|
|
30
30
|
const _nv = object;
|
|
31
|
+
const prototypeMatch = NumericValue.prototype.isPrototypeOf(object.constructor?.prototype);
|
|
32
|
+
if (prototypeMatch) {
|
|
33
|
+
return prototypeMatch;
|
|
34
|
+
}
|
|
31
35
|
if (typeof _nv.string === "string" && typeof _nv.type === "string" && _nv.constructor?.name === "NumericValue") {
|
|
32
36
|
return true;
|
|
33
37
|
}
|
|
34
|
-
return
|
|
38
|
+
return prototypeMatch;
|
|
35
39
|
}
|
|
36
40
|
}
|
|
37
41
|
export function nv(input) {
|
|
@@ -16,6 +16,11 @@ export declare class CborShapeSerializer implements ShapeSerializer {
|
|
|
16
16
|
private value;
|
|
17
17
|
setSerdeContext(serdeContext: SerdeFunctions): void;
|
|
18
18
|
write(schema: Schema, value: unknown): void;
|
|
19
|
+
/**
|
|
20
|
+
* Recursive serializer transform that copies and prepares the user input object
|
|
21
|
+
* for CBOR serialization.
|
|
22
|
+
*/
|
|
23
|
+
serialize(schema: Schema, source: unknown): any;
|
|
19
24
|
flush(): Uint8Array;
|
|
20
25
|
}
|
|
21
26
|
/**
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { NormalizedSchema } from "@smithy/core/schema";
|
|
2
2
|
import { HttpRequest } from "@smithy/protocol-http";
|
|
3
|
-
import { EndpointBearer, HandlerExecutionContext, HttpRequest as IHttpRequest, HttpResponse as IHttpResponse, MetadataBearer, OperationSchema, SerdeFunctions } from "@smithy/types";
|
|
3
|
+
import { EndpointBearer, HandlerExecutionContext, HttpRequest as IHttpRequest, HttpResponse as IHttpResponse, MetadataBearer, OperationSchema, Schema, SerdeFunctions } from "@smithy/types";
|
|
4
4
|
import { HttpProtocol } from "./HttpProtocol";
|
|
5
5
|
/**
|
|
6
6
|
* Base for HTTP-binding protocols. Downstream examples
|
|
@@ -12,4 +12,12 @@ export declare abstract class HttpBindingProtocol extends HttpProtocol {
|
|
|
12
12
|
serializeRequest<Input extends object>(operationSchema: OperationSchema, _input: Input, context: HandlerExecutionContext & SerdeFunctions & EndpointBearer): Promise<IHttpRequest>;
|
|
13
13
|
protected serializeQuery(ns: NormalizedSchema, data: any, query: HttpRequest["query"]): void;
|
|
14
14
|
deserializeResponse<Output extends MetadataBearer>(operationSchema: OperationSchema, context: HandlerExecutionContext & SerdeFunctions, response: IHttpResponse): Promise<Output>;
|
|
15
|
+
/**
|
|
16
|
+
* The base method ignores HTTP bindings.
|
|
17
|
+
*
|
|
18
|
+
* @deprecated (only this signature) use signature without headerBindings.
|
|
19
|
+
* @override
|
|
20
|
+
*/
|
|
21
|
+
protected deserializeHttpMessage(schema: Schema, context: HandlerExecutionContext & SerdeFunctions, response: IHttpResponse, headerBindings: Set<string>, dataObject: any): Promise<string[]>;
|
|
22
|
+
protected deserializeHttpMessage(schema: Schema, context: HandlerExecutionContext & SerdeFunctions, response: IHttpResponse, dataObject: any): Promise<string[]>;
|
|
15
23
|
}
|
|
@@ -26,7 +26,9 @@ export declare abstract class HttpProtocol implements ClientProtocol<IHttpReques
|
|
|
26
26
|
protected abstract handleError(operationSchema: OperationSchema, context: HandlerExecutionContext & SerdeFunctions, response: IHttpResponse, dataObject: any, metadata: ResponseMetadata): Promise<never>;
|
|
27
27
|
protected deserializeMetadata(output: IHttpResponse): ResponseMetadata;
|
|
28
28
|
/**
|
|
29
|
-
*
|
|
29
|
+
* For HTTP binding protocols, this method is overridden in {@link HttpBindingProtocol}.
|
|
30
|
+
*
|
|
31
|
+
* @deprecated only use this for HTTP binding protocols.
|
|
30
32
|
*/
|
|
31
33
|
protected deserializeHttpMessage(schema: Schema, context: HandlerExecutionContext & SerdeFunctions, response: IHttpResponse, headerBindings: Set<string>, dataObject: any): Promise<string[]>;
|
|
32
34
|
protected deserializeHttpMessage(schema: Schema, context: HandlerExecutionContext & SerdeFunctions, response: IHttpResponse, dataObject: any): Promise<string[]>;
|
|
@@ -66,6 +66,11 @@ export declare class NormalizedSchema implements INormalizedSchema {
|
|
|
66
66
|
isBigIntegerSchema(): boolean;
|
|
67
67
|
isBigDecimalSchema(): boolean;
|
|
68
68
|
isStreaming(): boolean;
|
|
69
|
+
/**
|
|
70
|
+
* This is a shortcut to avoid calling `getMergedTraits().idempotencyToken` on every string.
|
|
71
|
+
* @returns whether the schema has the idempotencyToken trait.
|
|
72
|
+
*/
|
|
73
|
+
isIdempotencyToken(): boolean;
|
|
69
74
|
/**
|
|
70
75
|
* @returns own traits merged with member traits, where member traits of the same trait key take priority.
|
|
71
76
|
* This method is cached.
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { SchemaRef } from "@smithy/types";
|
|
2
2
|
/**
|
|
3
3
|
* @internal
|
|
4
|
+
* @deprecated the former functionality has been internalized to the CborCodec.
|
|
4
5
|
*/
|
|
5
6
|
export declare const copyDocumentWithTransform: (source: any, schemaRef: SchemaRef, transform?: (_: any, schemaRef: SchemaRef) => any) => any;
|
|
@@ -24,7 +24,7 @@ export declare class NumericValue {
|
|
|
24
24
|
readonly type: NumericType;
|
|
25
25
|
constructor(string: string, type: NumericType);
|
|
26
26
|
toString(): string;
|
|
27
|
-
[Symbol.hasInstance](object: unknown): boolean;
|
|
27
|
+
static [Symbol.hasInstance](object: unknown): boolean;
|
|
28
28
|
}
|
|
29
29
|
/**
|
|
30
30
|
* Serde shortcut.
|
|
@@ -16,6 +16,11 @@ export declare class CborShapeSerializer implements ShapeSerializer {
|
|
|
16
16
|
private value;
|
|
17
17
|
setSerdeContext(serdeContext: SerdeFunctions): void;
|
|
18
18
|
write(schema: Schema, value: unknown): void;
|
|
19
|
+
/**
|
|
20
|
+
* Recursive serializer transform that copies and prepares the user input object
|
|
21
|
+
* for CBOR serialization.
|
|
22
|
+
*/
|
|
23
|
+
serialize(schema: Schema, source: unknown): any;
|
|
19
24
|
flush(): Uint8Array;
|
|
20
25
|
}
|
|
21
26
|
/**
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { NormalizedSchema } from "@smithy/core/schema";
|
|
2
2
|
import { HttpRequest } from "@smithy/protocol-http";
|
|
3
|
-
import { EndpointBearer, HandlerExecutionContext, HttpRequest as IHttpRequest, HttpResponse as IHttpResponse, MetadataBearer, OperationSchema, SerdeFunctions } from "@smithy/types";
|
|
3
|
+
import { EndpointBearer, HandlerExecutionContext, HttpRequest as IHttpRequest, HttpResponse as IHttpResponse, MetadataBearer, OperationSchema, Schema, SerdeFunctions } from "@smithy/types";
|
|
4
4
|
import { HttpProtocol } from "./HttpProtocol";
|
|
5
5
|
/**
|
|
6
6
|
* Base for HTTP-binding protocols. Downstream examples
|
|
@@ -12,4 +12,12 @@ export declare abstract class HttpBindingProtocol extends HttpProtocol {
|
|
|
12
12
|
serializeRequest<Input extends object>(operationSchema: OperationSchema, _input: Input, context: HandlerExecutionContext & SerdeFunctions & EndpointBearer): Promise<IHttpRequest>;
|
|
13
13
|
protected serializeQuery(ns: NormalizedSchema, data: any, query: HttpRequest["query"]): void;
|
|
14
14
|
deserializeResponse<Output extends MetadataBearer>(operationSchema: OperationSchema, context: HandlerExecutionContext & SerdeFunctions, response: IHttpResponse): Promise<Output>;
|
|
15
|
+
/**
|
|
16
|
+
* The base method ignores HTTP bindings.
|
|
17
|
+
*
|
|
18
|
+
* @deprecated (only this signature) use signature without headerBindings.
|
|
19
|
+
* @override
|
|
20
|
+
*/
|
|
21
|
+
protected deserializeHttpMessage(schema: Schema, context: HandlerExecutionContext & SerdeFunctions, response: IHttpResponse, headerBindings: Set<string>, dataObject: any): Promise<string[]>;
|
|
22
|
+
protected deserializeHttpMessage(schema: Schema, context: HandlerExecutionContext & SerdeFunctions, response: IHttpResponse, dataObject: any): Promise<string[]>;
|
|
15
23
|
}
|
|
@@ -26,7 +26,9 @@ export declare abstract class HttpProtocol implements ClientProtocol<IHttpReques
|
|
|
26
26
|
protected abstract handleError(operationSchema: OperationSchema, context: HandlerExecutionContext & SerdeFunctions, response: IHttpResponse, dataObject: any, metadata: ResponseMetadata): Promise<never>;
|
|
27
27
|
protected deserializeMetadata(output: IHttpResponse): ResponseMetadata;
|
|
28
28
|
/**
|
|
29
|
-
*
|
|
29
|
+
* For HTTP binding protocols, this method is overridden in {@link HttpBindingProtocol}.
|
|
30
|
+
*
|
|
31
|
+
* @deprecated only use this for HTTP binding protocols.
|
|
30
32
|
*/
|
|
31
33
|
protected deserializeHttpMessage(schema: Schema, context: HandlerExecutionContext & SerdeFunctions, response: IHttpResponse, headerBindings: Set<string>, dataObject: any): Promise<string[]>;
|
|
32
34
|
protected deserializeHttpMessage(schema: Schema, context: HandlerExecutionContext & SerdeFunctions, response: IHttpResponse, dataObject: any): Promise<string[]>;
|
|
@@ -66,6 +66,11 @@ export declare class NormalizedSchema implements INormalizedSchema {
|
|
|
66
66
|
isBigIntegerSchema(): boolean;
|
|
67
67
|
isBigDecimalSchema(): boolean;
|
|
68
68
|
isStreaming(): boolean;
|
|
69
|
+
/**
|
|
70
|
+
* This is a shortcut to avoid calling `getMergedTraits().idempotencyToken` on every string.
|
|
71
|
+
* @returns whether the schema has the idempotencyToken trait.
|
|
72
|
+
*/
|
|
73
|
+
isIdempotencyToken(): boolean;
|
|
69
74
|
/**
|
|
70
75
|
* @returns own traits merged with member traits, where member traits of the same trait key take priority.
|
|
71
76
|
* This method is cached.
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { SchemaRef } from "@smithy/types";
|
|
2
2
|
/**
|
|
3
3
|
* @internal
|
|
4
|
+
* @deprecated the former functionality has been internalized to the CborCodec.
|
|
4
5
|
*/
|
|
5
6
|
export declare const copyDocumentWithTransform: (source: any, schemaRef: SchemaRef, transform?: (_: any, schemaRef: SchemaRef) => any) => any;
|
|
@@ -24,7 +24,7 @@ export declare class NumericValue {
|
|
|
24
24
|
readonly type: NumericType;
|
|
25
25
|
constructor(string: string, type: NumericType);
|
|
26
26
|
toString(): string;
|
|
27
|
-
[Symbol.hasInstance](object: unknown): boolean;
|
|
27
|
+
static [Symbol.hasInstance](object: unknown): boolean;
|
|
28
28
|
}
|
|
29
29
|
/**
|
|
30
30
|
* Serde shortcut.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@smithy/core",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.8.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",
|
|
@@ -70,15 +70,17 @@
|
|
|
70
70
|
"license": "Apache-2.0",
|
|
71
71
|
"sideEffects": false,
|
|
72
72
|
"dependencies": {
|
|
73
|
-
"@smithy/middleware-serde": "^4.0.
|
|
74
|
-
"@smithy/protocol-http": "^5.1.
|
|
75
|
-
"@smithy/types": "^4.3.
|
|
73
|
+
"@smithy/middleware-serde": "^4.0.9",
|
|
74
|
+
"@smithy/protocol-http": "^5.1.3",
|
|
75
|
+
"@smithy/types": "^4.3.2",
|
|
76
76
|
"@smithy/util-base64": "^4.0.0",
|
|
77
77
|
"@smithy/util-body-length-browser": "^4.0.0",
|
|
78
|
-
"@smithy/util-middleware": "^4.0.
|
|
79
|
-
"@smithy/util-stream": "^4.2.
|
|
78
|
+
"@smithy/util-middleware": "^4.0.5",
|
|
79
|
+
"@smithy/util-stream": "^4.2.4",
|
|
80
80
|
"@smithy/util-utf8": "^4.0.0",
|
|
81
|
-
"
|
|
81
|
+
"@types/uuid": "^9.0.1",
|
|
82
|
+
"tslib": "^2.6.2",
|
|
83
|
+
"uuid": "^9.0.1"
|
|
82
84
|
},
|
|
83
85
|
"engines": {
|
|
84
86
|
"node": ">=18.0.0"
|