@smithy/core 3.7.2 → 3.9.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 +121 -53
- package/dist-cjs/submodules/event-streams/index.js +261 -0
- package/dist-cjs/submodules/protocols/index.js +197 -104
- package/dist-cjs/submodules/schema/index.js +37 -0
- package/dist-cjs/submodules/serde/index.js +6 -51
- package/dist-es/submodules/cbor/CborCodec.js +77 -41
- package/dist-es/submodules/cbor/SmithyRpcV2CborProtocol.js +36 -15
- package/dist-es/submodules/event-streams/EventStreamSerde.js +200 -0
- package/dist-es/submodules/event-streams/index.js +1 -0
- package/dist-es/submodules/protocols/HttpBindingProtocol.js +86 -6
- package/dist-es/submodules/protocols/HttpProtocol.js +42 -94
- package/dist-es/submodules/protocols/RpcProtocol.js +36 -10
- package/dist-es/submodules/protocols/index.js +1 -0
- package/dist-es/submodules/schema/schemas/NormalizedSchema.js +26 -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-types/submodules/cbor/CborCodec.d.ts +11 -2
- package/dist-types/submodules/cbor/SmithyRpcV2CborProtocol.d.ts +1 -0
- package/dist-types/submodules/cbor/parseCborBody.d.ts +1 -1
- package/dist-types/submodules/event-streams/EventStreamSerde.d.ts +60 -0
- package/dist-types/submodules/event-streams/index.d.ts +1 -0
- package/dist-types/submodules/protocols/HttpBindingProtocol.d.ts +9 -1
- package/dist-types/submodules/protocols/HttpProtocol.d.ts +42 -2
- package/dist-types/submodules/protocols/RpcProtocol.d.ts +1 -1
- package/dist-types/submodules/protocols/index.d.ts +1 -0
- package/dist-types/submodules/protocols/serde/FromStringShapeDeserializer.d.ts +1 -1
- package/dist-types/submodules/protocols/serde/HttpInterceptingShapeDeserializer.d.ts +1 -1
- package/dist-types/submodules/protocols/serde/HttpInterceptingShapeSerializer.d.ts +1 -1
- package/dist-types/submodules/protocols/serde/ToStringShapeSerializer.d.ts +1 -1
- package/dist-types/submodules/protocols/serde/determineTimestampFormat.d.ts +1 -1
- package/dist-types/submodules/schema/middleware/getSchemaSerdePlugin.d.ts +1 -1
- package/dist-types/submodules/schema/middleware/schemaDeserializationMiddleware.d.ts +1 -1
- package/dist-types/submodules/schema/schemas/NormalizedSchema.d.ts +15 -0
- package/dist-types/submodules/schema/schemas/SimpleSchema.d.ts +1 -1
- package/dist-types/submodules/schema/schemas/sentinels.d.ts +1 -1
- package/dist-types/submodules/serde/copyDocumentWithTransform.d.ts +2 -1
- package/dist-types/submodules/serde/generateIdempotencyToken.d.ts +2 -0
- package/dist-types/submodules/serde/index.d.ts +1 -0
- package/dist-types/ts3.4/submodules/cbor/CborCodec.d.ts +10 -1
- package/dist-types/ts3.4/submodules/cbor/SmithyRpcV2CborProtocol.d.ts +1 -0
- package/dist-types/ts3.4/submodules/event-streams/EventStreamSerde.d.ts +60 -0
- package/dist-types/ts3.4/submodules/event-streams/index.d.ts +1 -0
- package/dist-types/ts3.4/submodules/protocols/HttpBindingProtocol.d.ts +9 -1
- package/dist-types/ts3.4/submodules/protocols/HttpProtocol.d.ts +42 -2
- package/dist-types/ts3.4/submodules/protocols/index.d.ts +1 -0
- package/dist-types/ts3.4/submodules/protocols/serde/determineTimestampFormat.d.ts +1 -1
- package/dist-types/ts3.4/submodules/schema/schemas/NormalizedSchema.d.ts +15 -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/event-streams.d.ts +7 -0
- package/event-streams.js +6 -0
- package/package.json +19 -7
|
@@ -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,5 +1,5 @@
|
|
|
1
1
|
import { RpcProtocol } from "@smithy/core/protocols";
|
|
2
|
-
import { deref, TypeRegistry } from "@smithy/core/schema";
|
|
2
|
+
import { deref, NormalizedSchema, TypeRegistry } from "@smithy/core/schema";
|
|
3
3
|
import { getSmithyContext } from "@smithy/util-middleware";
|
|
4
4
|
import { CborCodec } from "./CborCodec";
|
|
5
5
|
import { loadSmithyRpcV2CborErrorCode } from "./parseCborBody";
|
|
@@ -19,9 +19,9 @@ export class SmithyRpcV2CborProtocol extends RpcProtocol {
|
|
|
19
19
|
async serializeRequest(operationSchema, input, context) {
|
|
20
20
|
const request = await super.serializeRequest(operationSchema, input, context);
|
|
21
21
|
Object.assign(request.headers, {
|
|
22
|
-
"content-type":
|
|
22
|
+
"content-type": this.getDefaultContentType(),
|
|
23
23
|
"smithy-protocol": "rpc-v2-cbor",
|
|
24
|
-
accept:
|
|
24
|
+
accept: this.getDefaultContentType(),
|
|
25
25
|
});
|
|
26
26
|
if (deref(operationSchema.input) === "unit") {
|
|
27
27
|
delete request.body;
|
|
@@ -51,24 +51,45 @@ export class SmithyRpcV2CborProtocol extends RpcProtocol {
|
|
|
51
51
|
return super.deserializeResponse(operationSchema, context, response);
|
|
52
52
|
}
|
|
53
53
|
async handleError(operationSchema, context, response, dataObject, metadata) {
|
|
54
|
-
const
|
|
54
|
+
const errorName = loadSmithyRpcV2CborErrorCode(response, dataObject) ?? "Unknown";
|
|
55
55
|
let namespace = this.options.defaultNamespace;
|
|
56
|
-
if (
|
|
57
|
-
[namespace] =
|
|
56
|
+
if (errorName.includes("#")) {
|
|
57
|
+
[namespace] = errorName.split("#");
|
|
58
58
|
}
|
|
59
|
+
const errorMetadata = {
|
|
60
|
+
$metadata: metadata,
|
|
61
|
+
$response: response,
|
|
62
|
+
$fault: response.statusCode <= 500 ? "client" : "server",
|
|
63
|
+
};
|
|
59
64
|
const registry = TypeRegistry.for(namespace);
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
65
|
+
let errorSchema;
|
|
66
|
+
try {
|
|
67
|
+
errorSchema = registry.getSchema(errorName);
|
|
68
|
+
}
|
|
69
|
+
catch (e) {
|
|
70
|
+
if (dataObject.Message) {
|
|
71
|
+
dataObject.message = dataObject.Message;
|
|
72
|
+
}
|
|
73
|
+
const baseExceptionSchema = TypeRegistry.for("smithy.ts.sdk.synthetic." + namespace).getBaseException();
|
|
74
|
+
if (baseExceptionSchema) {
|
|
75
|
+
const ErrorCtor = baseExceptionSchema.ctor;
|
|
76
|
+
throw Object.assign(new ErrorCtor({ name: errorName }), errorMetadata, dataObject);
|
|
77
|
+
}
|
|
78
|
+
throw Object.assign(new Error(errorName), errorMetadata, dataObject);
|
|
63
79
|
}
|
|
80
|
+
const ns = NormalizedSchema.of(errorSchema);
|
|
64
81
|
const message = dataObject.message ?? dataObject.Message ?? "Unknown";
|
|
65
82
|
const exception = new errorSchema.ctor(message);
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
83
|
+
const output = {};
|
|
84
|
+
for (const [name, member] of ns.structIterator()) {
|
|
85
|
+
output[name] = this.deserializer.readValue(member, dataObject[name]);
|
|
86
|
+
}
|
|
87
|
+
throw Object.assign(exception, errorMetadata, {
|
|
88
|
+
$fault: ns.getMergedTraits().error,
|
|
69
89
|
message,
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
90
|
+
}, output);
|
|
91
|
+
}
|
|
92
|
+
getDefaultContentType() {
|
|
93
|
+
return "application/cbor";
|
|
73
94
|
}
|
|
74
95
|
}
|
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
import { SCHEMA } from "@smithy/core/schema";
|
|
2
|
+
import { fromUtf8 } from "@smithy/util-utf8";
|
|
3
|
+
export class EventStreamSerde {
|
|
4
|
+
constructor({ marshaller, serializer, deserializer, serdeContext, defaultContentType, }) {
|
|
5
|
+
this.marshaller = marshaller;
|
|
6
|
+
this.serializer = serializer;
|
|
7
|
+
this.deserializer = deserializer;
|
|
8
|
+
this.serdeContext = serdeContext;
|
|
9
|
+
this.defaultContentType = defaultContentType;
|
|
10
|
+
}
|
|
11
|
+
async serializeEventStream({ eventStream, requestSchema, initialRequest, }) {
|
|
12
|
+
const marshaller = this.marshaller;
|
|
13
|
+
const eventStreamMember = requestSchema.getEventStreamMember();
|
|
14
|
+
const unionSchema = requestSchema.getMemberSchema(eventStreamMember);
|
|
15
|
+
const memberSchemas = unionSchema.getMemberSchemas();
|
|
16
|
+
const serializer = this.serializer;
|
|
17
|
+
const defaultContentType = this.defaultContentType;
|
|
18
|
+
const initialRequestMarker = Symbol("initialRequestMarker");
|
|
19
|
+
const eventStreamIterable = {
|
|
20
|
+
async *[Symbol.asyncIterator]() {
|
|
21
|
+
if (initialRequest) {
|
|
22
|
+
const headers = {
|
|
23
|
+
":event-type": { type: "string", value: "initial-request" },
|
|
24
|
+
":message-type": { type: "string", value: "event" },
|
|
25
|
+
":content-type": { type: "string", value: defaultContentType },
|
|
26
|
+
};
|
|
27
|
+
serializer.write(requestSchema, initialRequest);
|
|
28
|
+
const body = serializer.flush();
|
|
29
|
+
yield {
|
|
30
|
+
[initialRequestMarker]: true,
|
|
31
|
+
headers,
|
|
32
|
+
body,
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
for await (const page of eventStream) {
|
|
36
|
+
yield page;
|
|
37
|
+
}
|
|
38
|
+
},
|
|
39
|
+
};
|
|
40
|
+
return marshaller.serialize(eventStreamIterable, (event) => {
|
|
41
|
+
if (event[initialRequestMarker]) {
|
|
42
|
+
return {
|
|
43
|
+
headers: event.headers,
|
|
44
|
+
body: event.body,
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
const unionMember = Object.keys(event).find((key) => {
|
|
48
|
+
return key !== "__type";
|
|
49
|
+
}) ?? "";
|
|
50
|
+
const { additionalHeaders, body, eventType, explicitPayloadContentType } = this.writeEventBody(unionMember, unionSchema, event);
|
|
51
|
+
const headers = {
|
|
52
|
+
":event-type": { type: "string", value: eventType },
|
|
53
|
+
":message-type": { type: "string", value: "event" },
|
|
54
|
+
":content-type": { type: "string", value: explicitPayloadContentType ?? defaultContentType },
|
|
55
|
+
...additionalHeaders,
|
|
56
|
+
};
|
|
57
|
+
return {
|
|
58
|
+
headers,
|
|
59
|
+
body,
|
|
60
|
+
};
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
async deserializeEventStream({ response, responseSchema, initialResponseContainer, }) {
|
|
64
|
+
const marshaller = this.marshaller;
|
|
65
|
+
const eventStreamMember = responseSchema.getEventStreamMember();
|
|
66
|
+
const unionSchema = responseSchema.getMemberSchema(eventStreamMember);
|
|
67
|
+
const memberSchemas = unionSchema.getMemberSchemas();
|
|
68
|
+
const initialResponseMarker = Symbol("initialResponseMarker");
|
|
69
|
+
const asyncIterable = marshaller.deserialize(response.body, async (event) => {
|
|
70
|
+
const unionMember = Object.keys(event).find((key) => {
|
|
71
|
+
return key !== "__type";
|
|
72
|
+
}) ?? "";
|
|
73
|
+
if (unionMember === "initial-response") {
|
|
74
|
+
const dataObject = await this.deserializer.read(responseSchema, event[unionMember].body);
|
|
75
|
+
delete dataObject[eventStreamMember];
|
|
76
|
+
return {
|
|
77
|
+
[initialResponseMarker]: true,
|
|
78
|
+
...dataObject,
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
else if (unionMember in memberSchemas) {
|
|
82
|
+
const eventStreamSchema = memberSchemas[unionMember];
|
|
83
|
+
return {
|
|
84
|
+
[unionMember]: await this.deserializer.read(eventStreamSchema, event[unionMember].body),
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
else {
|
|
88
|
+
return {
|
|
89
|
+
$unknown: event,
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
const asyncIterator = asyncIterable[Symbol.asyncIterator]();
|
|
94
|
+
const firstEvent = await asyncIterator.next();
|
|
95
|
+
if (firstEvent.done) {
|
|
96
|
+
return asyncIterable;
|
|
97
|
+
}
|
|
98
|
+
if (firstEvent.value?.[initialResponseMarker]) {
|
|
99
|
+
if (!responseSchema) {
|
|
100
|
+
throw new Error("@smithy::core/protocols - initial-response event encountered in event stream but no response schema given.");
|
|
101
|
+
}
|
|
102
|
+
for (const [key, value] of Object.entries(firstEvent.value)) {
|
|
103
|
+
initialResponseContainer[key] = value;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
return {
|
|
107
|
+
async *[Symbol.asyncIterator]() {
|
|
108
|
+
if (!firstEvent?.value?.[initialResponseMarker]) {
|
|
109
|
+
yield firstEvent.value;
|
|
110
|
+
}
|
|
111
|
+
while (true) {
|
|
112
|
+
const { done, value } = await asyncIterator.next();
|
|
113
|
+
if (done) {
|
|
114
|
+
break;
|
|
115
|
+
}
|
|
116
|
+
yield value;
|
|
117
|
+
}
|
|
118
|
+
},
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
writeEventBody(unionMember, unionSchema, event) {
|
|
122
|
+
const serializer = this.serializer;
|
|
123
|
+
let eventType = unionMember;
|
|
124
|
+
let explicitPayloadMember = null;
|
|
125
|
+
let explicitPayloadContentType;
|
|
126
|
+
const isKnownSchema = unionSchema.hasMemberSchema(unionMember);
|
|
127
|
+
const additionalHeaders = {};
|
|
128
|
+
if (!isKnownSchema) {
|
|
129
|
+
const [type, value] = event[unionMember];
|
|
130
|
+
eventType = type;
|
|
131
|
+
serializer.write(SCHEMA.DOCUMENT, value);
|
|
132
|
+
}
|
|
133
|
+
else {
|
|
134
|
+
const eventSchema = unionSchema.getMemberSchema(unionMember);
|
|
135
|
+
if (eventSchema.isStructSchema()) {
|
|
136
|
+
for (const [memberName, memberSchema] of eventSchema.structIterator()) {
|
|
137
|
+
const { eventHeader, eventPayload } = memberSchema.getMergedTraits();
|
|
138
|
+
if (eventPayload) {
|
|
139
|
+
explicitPayloadMember = memberName;
|
|
140
|
+
break;
|
|
141
|
+
}
|
|
142
|
+
else if (eventHeader) {
|
|
143
|
+
const value = event[unionMember][memberName];
|
|
144
|
+
let type = "binary";
|
|
145
|
+
if (memberSchema.isNumericSchema()) {
|
|
146
|
+
if ((-2) ** 31 <= value && value <= 2 ** 31 - 1) {
|
|
147
|
+
type = "integer";
|
|
148
|
+
}
|
|
149
|
+
else {
|
|
150
|
+
type = "long";
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
else if (memberSchema.isTimestampSchema()) {
|
|
154
|
+
type = "timestamp";
|
|
155
|
+
}
|
|
156
|
+
else if (memberSchema.isStringSchema()) {
|
|
157
|
+
type = "string";
|
|
158
|
+
}
|
|
159
|
+
else if (memberSchema.isBooleanSchema()) {
|
|
160
|
+
type = "boolean";
|
|
161
|
+
}
|
|
162
|
+
if (value != null) {
|
|
163
|
+
additionalHeaders[memberName] = {
|
|
164
|
+
type,
|
|
165
|
+
value,
|
|
166
|
+
};
|
|
167
|
+
delete event[unionMember][memberName];
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
if (explicitPayloadMember !== null) {
|
|
172
|
+
const payloadSchema = eventSchema.getMemberSchema(explicitPayloadMember);
|
|
173
|
+
if (payloadSchema.isBlobSchema()) {
|
|
174
|
+
explicitPayloadContentType = "application/octet-stream";
|
|
175
|
+
}
|
|
176
|
+
else if (payloadSchema.isStringSchema()) {
|
|
177
|
+
explicitPayloadContentType = "text/plain";
|
|
178
|
+
}
|
|
179
|
+
serializer.write(payloadSchema, event[unionMember][explicitPayloadMember]);
|
|
180
|
+
}
|
|
181
|
+
else {
|
|
182
|
+
serializer.write(eventSchema, event[unionMember]);
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
else {
|
|
186
|
+
throw new Error("@smithy/core/event-streams - non-struct member not supported in event stream union.");
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
const messageSerialization = serializer.flush();
|
|
190
|
+
const body = typeof messageSerialization === "string"
|
|
191
|
+
? (this.serdeContext?.utf8Decoder ?? fromUtf8)(messageSerialization)
|
|
192
|
+
: messageSerialization;
|
|
193
|
+
return {
|
|
194
|
+
body,
|
|
195
|
+
eventType,
|
|
196
|
+
explicitPayloadContentType,
|
|
197
|
+
additionalHeaders,
|
|
198
|
+
};
|
|
199
|
+
}
|
|
200
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./EventStreamSerde";
|
|
@@ -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";
|
|
@@ -54,7 +56,12 @@ export class HttpBindingProtocol extends HttpProtocol {
|
|
|
54
56
|
if (isStreaming) {
|
|
55
57
|
const isEventStream = memberNs.isStructSchema();
|
|
56
58
|
if (isEventStream) {
|
|
57
|
-
|
|
59
|
+
if (input[memberName]) {
|
|
60
|
+
payload = await this.serializeEventStream({
|
|
61
|
+
eventStream: input[memberName],
|
|
62
|
+
requestSchema: ns,
|
|
63
|
+
});
|
|
64
|
+
}
|
|
58
65
|
}
|
|
59
66
|
else {
|
|
60
67
|
payload = inputMemberValue;
|
|
@@ -169,10 +176,83 @@ export class HttpBindingProtocol extends HttpProtocol {
|
|
|
169
176
|
}
|
|
170
177
|
}
|
|
171
178
|
}
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
179
|
+
dataObject.$metadata = this.deserializeMetadata(response);
|
|
180
|
+
return dataObject;
|
|
181
|
+
}
|
|
182
|
+
async deserializeHttpMessage(schema, context, response, arg4, arg5) {
|
|
183
|
+
let dataObject;
|
|
184
|
+
if (arg4 instanceof Set) {
|
|
185
|
+
dataObject = arg5;
|
|
186
|
+
}
|
|
187
|
+
else {
|
|
188
|
+
dataObject = arg4;
|
|
189
|
+
}
|
|
190
|
+
const deserializer = this.deserializer;
|
|
191
|
+
const ns = NormalizedSchema.of(schema);
|
|
192
|
+
const nonHttpBindingMembers = [];
|
|
193
|
+
for (const [memberName, memberSchema] of ns.structIterator()) {
|
|
194
|
+
const memberTraits = memberSchema.getMemberTraits();
|
|
195
|
+
if (memberTraits.httpPayload) {
|
|
196
|
+
const isStreaming = memberSchema.isStreaming();
|
|
197
|
+
if (isStreaming) {
|
|
198
|
+
const isEventStream = memberSchema.isStructSchema();
|
|
199
|
+
if (isEventStream) {
|
|
200
|
+
dataObject[memberName] = await this.deserializeEventStream({
|
|
201
|
+
response,
|
|
202
|
+
responseSchema: ns,
|
|
203
|
+
});
|
|
204
|
+
}
|
|
205
|
+
else {
|
|
206
|
+
dataObject[memberName] = sdkStreamMixin(response.body);
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
else if (response.body) {
|
|
210
|
+
const bytes = await collectBody(response.body, context);
|
|
211
|
+
if (bytes.byteLength > 0) {
|
|
212
|
+
dataObject[memberName] = await deserializer.read(memberSchema, bytes);
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
else if (memberTraits.httpHeader) {
|
|
217
|
+
const key = String(memberTraits.httpHeader).toLowerCase();
|
|
218
|
+
const value = response.headers[key];
|
|
219
|
+
if (null != value) {
|
|
220
|
+
if (memberSchema.isListSchema()) {
|
|
221
|
+
const headerListValueSchema = memberSchema.getValueSchema();
|
|
222
|
+
let sections;
|
|
223
|
+
if (headerListValueSchema.isTimestampSchema() &&
|
|
224
|
+
headerListValueSchema.getSchema() === SCHEMA.TIMESTAMP_DEFAULT) {
|
|
225
|
+
sections = splitEvery(value, ",", 2);
|
|
226
|
+
}
|
|
227
|
+
else {
|
|
228
|
+
sections = splitHeader(value);
|
|
229
|
+
}
|
|
230
|
+
const list = [];
|
|
231
|
+
for (const section of sections) {
|
|
232
|
+
list.push(await deserializer.read([headerListValueSchema, { httpHeader: key }], section.trim()));
|
|
233
|
+
}
|
|
234
|
+
dataObject[memberName] = list;
|
|
235
|
+
}
|
|
236
|
+
else {
|
|
237
|
+
dataObject[memberName] = await deserializer.read(memberSchema, value);
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
else if (memberTraits.httpPrefixHeaders !== undefined) {
|
|
242
|
+
dataObject[memberName] = {};
|
|
243
|
+
for (const [header, value] of Object.entries(response.headers)) {
|
|
244
|
+
if (header.startsWith(memberTraits.httpPrefixHeaders)) {
|
|
245
|
+
dataObject[memberName][header.slice(memberTraits.httpPrefixHeaders.length)] = await deserializer.read([memberSchema.getValueSchema(), { httpHeader: header }], value);
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
else if (memberTraits.httpResponseCode) {
|
|
250
|
+
dataObject[memberName] = response.statusCode;
|
|
251
|
+
}
|
|
252
|
+
else {
|
|
253
|
+
nonHttpBindingMembers.push(memberName);
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
return nonHttpBindingMembers;
|
|
177
257
|
}
|
|
178
258
|
}
|