@smithy/core 3.40.0 → 3.41.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/CHANGELOG.md +10 -0
- package/dist-cjs/submodules/protocols/index.js +600 -328
- package/dist-cjs/submodules/serde/index.browser.js +9 -4
- package/dist-cjs/submodules/serde/index.js +9 -4
- package/dist-cjs/submodules/serde/index.native.js +9 -4
- package/dist-es/submodules/protocols/HttpBindingNormalizedSchema.js +215 -0
- package/dist-es/submodules/protocols/HttpBindingProtocol.js +223 -195
- package/dist-es/submodules/protocols/HttpProtocol.js +22 -23
- package/dist-es/submodules/protocols/extended-encode-uri-component.js +3 -0
- package/dist-es/submodules/protocols/serde/FromStringShapeDeserializer.js +54 -47
- package/dist-es/submodules/protocols/serde/HttpInterceptingShapeDeserializer.js +23 -18
- package/dist-es/submodules/protocols/serde/HttpInterceptingShapeSerializer.js +12 -5
- package/dist-es/submodules/protocols/serde/ToStringShapeSerializer.js +33 -27
- package/dist-es/submodules/protocols/serde/determineTimestampFormat.js +5 -5
- package/dist-es/submodules/serde/quote-header.js +1 -1
- package/dist-es/submodules/serde/schema-serde-lib/schema-date-utils.js +4 -0
- package/dist-es/submodules/serde/split-header.js +4 -3
- package/dist-types/submodules/protocols/HttpBindingNormalizedSchema.d.ts +75 -0
- package/dist-types/submodules/protocols/HttpBindingProtocol.d.ts +11 -8
- package/dist-types/submodules/protocols/HttpProtocol.d.ts +2 -2
- package/dist-types/submodules/protocols/serde/FromStringShapeDeserializer.d.ts +2 -1
- package/dist-types/submodules/protocols/serde/HttpInterceptingShapeDeserializer.d.ts +4 -0
- package/dist-types/submodules/protocols/serde/HttpInterceptingShapeSerializer.d.ts +3 -0
- package/dist-types/submodules/protocols/serde/ToStringShapeSerializer.d.ts +2 -0
- package/dist-types/submodules/schema/schemas/NormalizedSchema.d.ts +1 -1
- package/dist-types/ts3.4/submodules/protocols/HttpBindingNormalizedSchema.d.ts +81 -0
- package/dist-types/ts3.4/submodules/protocols/HttpBindingProtocol.d.ts +11 -8
- package/dist-types/ts3.4/submodules/protocols/HttpProtocol.d.ts +1 -1
- package/dist-types/ts3.4/submodules/protocols/serde/FromStringShapeDeserializer.d.ts +2 -1
- package/dist-types/ts3.4/submodules/protocols/serde/HttpInterceptingShapeDeserializer.d.ts +4 -0
- package/dist-types/ts3.4/submodules/protocols/serde/HttpInterceptingShapeSerializer.d.ts +3 -0
- package/dist-types/ts3.4/submodules/protocols/serde/ToStringShapeSerializer.d.ts +2 -0
- package/dist-types/ts3.4/submodules/schema/schemas/NormalizedSchema.d.ts +1 -1
- package/package.json +1 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const { Uint8ArrayBlobAdapter, sdkStreamMixin, splitEvery, splitHeader,
|
|
1
|
+
const { Uint8ArrayBlobAdapter, writeKey, sdkStreamMixin, splitEvery, splitHeader, NumericValue, toUtf8, fromBase64, LazyJsonString, _parseEpochTimestamp, _parseRfc7231DateTime, _parseRfc3339DateTimeWithOffset, fromUtf8, generateIdempotencyToken, toBase64, dateToUtcString, quoteHeader, parseEpochTimestamp, parseRfc7231DateTime, parseRfc3339DateTimeWithOffset } = require("@smithy/core/serde");
|
|
2
2
|
const { HttpRequest, HttpResponse, hasOwn, isValidHostname, getSmithyContext } = require("@smithy/core/transport");
|
|
3
3
|
const { parseQueryString, parseUrl } = require("@smithy/core/transport");
|
|
4
4
|
exports.HttpRequest = HttpRequest;
|
|
@@ -6,7 +6,7 @@ exports.HttpResponse = HttpResponse;
|
|
|
6
6
|
exports.isValidHostname = isValidHostname;
|
|
7
7
|
exports.parseQueryString = parseQueryString;
|
|
8
8
|
exports.parseUrl = parseUrl;
|
|
9
|
-
const {
|
|
9
|
+
const { NormalizedSchema, translateTraits, TypeRegistry, deref } = require("@smithy/core/schema");
|
|
10
10
|
const { FieldPosition } = require("@smithy/types");
|
|
11
11
|
|
|
12
12
|
const collectBody = async (streamBody = new Uint8Array(), context) => {
|
|
@@ -21,11 +21,228 @@ const collectBody = async (streamBody = new Uint8Array(), context) => {
|
|
|
21
21
|
};
|
|
22
22
|
|
|
23
23
|
function extendedEncodeURIComponent(str) {
|
|
24
|
+
if (/^[\w.~-]+$/.test(str)) {
|
|
25
|
+
return str;
|
|
26
|
+
}
|
|
24
27
|
return encodeURIComponent(str).replace(/[!'()*]/g, function (c) {
|
|
25
28
|
return "%" + c.charCodeAt(0).toString(16).toUpperCase();
|
|
26
29
|
});
|
|
27
30
|
}
|
|
28
31
|
|
|
32
|
+
const HTTP_BINDINGS = Symbol.for("@smithy/schema-x");
|
|
33
|
+
class HttpBindingNormalizedSchema extends NormalizedSchema {
|
|
34
|
+
static identity = Symbol.for("@smithy/HttpBindingNormalizedSchema");
|
|
35
|
+
identity = HttpBindingNormalizedSchema.identity;
|
|
36
|
+
bindings;
|
|
37
|
+
constructor(schema) {
|
|
38
|
+
super(schema);
|
|
39
|
+
}
|
|
40
|
+
static of(schema) {
|
|
41
|
+
const ns = NormalizedSchema.of(schema);
|
|
42
|
+
if (ns.identity === HttpBindingNormalizedSchema.identity) {
|
|
43
|
+
return ns;
|
|
44
|
+
}
|
|
45
|
+
const schemaCache = ns.isMemberSchema() ? ns : ns.getSchema();
|
|
46
|
+
const cache = typeof schemaCache === "object" && schemaCache !== null ? schemaCache : ns;
|
|
47
|
+
return (cache[HTTP_BINDINGS] ??= new HttpBindingNormalizedSchema(ns));
|
|
48
|
+
}
|
|
49
|
+
getHttpBindingLocation(traits) {
|
|
50
|
+
if (traits.httpPayload) {
|
|
51
|
+
return 0b100_100;
|
|
52
|
+
}
|
|
53
|
+
if (traits.httpLabel) {
|
|
54
|
+
return 0b100_001;
|
|
55
|
+
}
|
|
56
|
+
if (traits.httpHeader) {
|
|
57
|
+
return 0b100_110;
|
|
58
|
+
}
|
|
59
|
+
if (typeof traits.httpPrefixHeaders === "string") {
|
|
60
|
+
return 0b100_111;
|
|
61
|
+
}
|
|
62
|
+
if (traits.httpQuery) {
|
|
63
|
+
return 0b100_010;
|
|
64
|
+
}
|
|
65
|
+
if (traits.httpQueryParams) {
|
|
66
|
+
return 0b100_011;
|
|
67
|
+
}
|
|
68
|
+
if (traits.httpResponseCode) {
|
|
69
|
+
return 0b100_101;
|
|
70
|
+
}
|
|
71
|
+
return 0b100_000;
|
|
72
|
+
}
|
|
73
|
+
getHttpBindingValue(location, traits, nested = false) {
|
|
74
|
+
const raw = this.getSchema();
|
|
75
|
+
const type = typeof raw === "number" ? raw & 0xff : this.isListSchema() ? 0b0100_0000 : 0xff;
|
|
76
|
+
const slot = location & 0b111;
|
|
77
|
+
const media = (traits.mediaType ? (traits.mediaType === "application/json" || traits.mediaType.endsWith("+json") ? 2 : 1) : 0);
|
|
78
|
+
const stream = (traits.streaming || type === 42 ? (this.isStructSchema() ? 2 : 1) : 0);
|
|
79
|
+
const timestamp = (type >= 4 && type <= 7
|
|
80
|
+
? slot >= 6
|
|
81
|
+
? 2
|
|
82
|
+
: slot > 0 && slot < 4
|
|
83
|
+
? 1
|
|
84
|
+
: 0
|
|
85
|
+
: 0);
|
|
86
|
+
let flags = type |
|
|
87
|
+
(media << 8) |
|
|
88
|
+
((traits.idempotencyToken ? 1 : 0) << 10) |
|
|
89
|
+
(stream << 11) |
|
|
90
|
+
((traits.sparse ? 1 : 0) << 13) |
|
|
91
|
+
(timestamp << 14) |
|
|
92
|
+
((traits.hostLabel ? 1 : 0) << 17) |
|
|
93
|
+
((location === 0b100_100 && typeof raw !== "object" ? 1 : 0) << 18);
|
|
94
|
+
const category = type & 0b1100_0000;
|
|
95
|
+
const collectionValue = slot & 0b010 && (category === 0b0100_0000 || (!nested && slot & 1))
|
|
96
|
+
? this.getHttpBindingCollectionValue(location, traits)
|
|
97
|
+
: undefined;
|
|
98
|
+
const valueType = (collectionValue?.[1] ?? 0) & 0xff;
|
|
99
|
+
flags |=
|
|
100
|
+
(slot >= 6 &&
|
|
101
|
+
(valueType === 4 || valueType === 6)
|
|
102
|
+
? 1
|
|
103
|
+
: 0) << 16;
|
|
104
|
+
return [this, flags, collectionValue];
|
|
105
|
+
}
|
|
106
|
+
getHttpBindingCollectionValue(location, traits = this.getMergedTraits()) {
|
|
107
|
+
const valueSchema = HttpBindingNormalizedSchema.of(this.getValueSchema());
|
|
108
|
+
return valueSchema.getHttpBindingValue(location, { ...valueSchema.getMergedTraits(), ...traits }, true);
|
|
109
|
+
}
|
|
110
|
+
getHttpBindings() {
|
|
111
|
+
const source = this.getSchema();
|
|
112
|
+
return typeof source !== "object" || source === null ? EMPTY_BINDINGS : (this.bindings ??= buildHttpBindings(this));
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
const buildHttpBindings = (schema) => {
|
|
116
|
+
const bodyMemberNames = [];
|
|
117
|
+
const bodyMemberSchemas = [];
|
|
118
|
+
const requestBodyMemberNames = [];
|
|
119
|
+
const requestBodyMemberSchemas = [];
|
|
120
|
+
const memberBindings = [];
|
|
121
|
+
const byName = {};
|
|
122
|
+
const headers = {};
|
|
123
|
+
const prefixHeaders = [];
|
|
124
|
+
const responseBindings = { headers, prefixHeaders };
|
|
125
|
+
const bindings = {
|
|
126
|
+
request: { memberBindings, byName },
|
|
127
|
+
response: {
|
|
128
|
+
bodyMemberNames,
|
|
129
|
+
bindings: responseBindings,
|
|
130
|
+
},
|
|
131
|
+
};
|
|
132
|
+
const { request, response } = bindings;
|
|
133
|
+
for (const [name, member] of schema.structIterator()) {
|
|
134
|
+
const bindingSchema = HttpBindingNormalizedSchema.of(member);
|
|
135
|
+
const traits = bindingSchema.getMergedTraits();
|
|
136
|
+
const location = bindingSchema.getHttpBindingLocation(traits);
|
|
137
|
+
const wireName = traits.httpHeader?.toLowerCase() ?? traits.httpPrefixHeaders?.toLowerCase() ?? traits.httpQuery;
|
|
138
|
+
const value = bindingSchema.getHttpBindingValue(location, traits);
|
|
139
|
+
const binding = [name, value, location, wireName];
|
|
140
|
+
if (name === "__proto__") {
|
|
141
|
+
writeKey(byName);
|
|
142
|
+
}
|
|
143
|
+
byName[name] = binding;
|
|
144
|
+
if ((value[1] >> 10) & 1) {
|
|
145
|
+
request.hasIdempotency = true;
|
|
146
|
+
}
|
|
147
|
+
memberBindings.push(binding);
|
|
148
|
+
const slot = location & 0b111;
|
|
149
|
+
if (slot === 0) {
|
|
150
|
+
requestBodyMemberNames.push(name);
|
|
151
|
+
requestBodyMemberSchemas.push(member);
|
|
152
|
+
}
|
|
153
|
+
if ((slot & 0b100) === 0) {
|
|
154
|
+
bodyMemberNames.push(name);
|
|
155
|
+
bodyMemberSchemas.push(member);
|
|
156
|
+
}
|
|
157
|
+
else if ((slot & 0b110) === 0b100) {
|
|
158
|
+
if (slot & 0b001) {
|
|
159
|
+
responseBindings.statusCode = binding;
|
|
160
|
+
}
|
|
161
|
+
else {
|
|
162
|
+
responseBindings.payload = binding;
|
|
163
|
+
const type = value[1] & 0xff;
|
|
164
|
+
request.contentTypeInstruction =
|
|
165
|
+
traits.mediaType ??
|
|
166
|
+
(type === 0
|
|
167
|
+
? "text/plain"
|
|
168
|
+
: type === 21 || type === 42
|
|
169
|
+
? "application/octet-stream"
|
|
170
|
+
: null);
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
else if (slot & 0b001) {
|
|
174
|
+
request.hasPrefixHeaders = true;
|
|
175
|
+
prefixHeaders.push(binding);
|
|
176
|
+
}
|
|
177
|
+
else {
|
|
178
|
+
if (wireName === "__proto__") {
|
|
179
|
+
writeKey(headers);
|
|
180
|
+
}
|
|
181
|
+
headers[wireName] = binding;
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
if (request.contentTypeInstruction === undefined && requestBodyMemberNames.length) {
|
|
185
|
+
request.contentTypeInstruction = null;
|
|
186
|
+
}
|
|
187
|
+
request.syntheticBodySchema = createBodySchema(schema, requestBodyMemberNames, requestBodyMemberSchemas);
|
|
188
|
+
response.syntheticBodySchema = createBodySchema(schema, bodyMemberNames, bodyMemberSchemas);
|
|
189
|
+
return bindings;
|
|
190
|
+
};
|
|
191
|
+
const buildPathSegments = (path) => {
|
|
192
|
+
const segments = [];
|
|
193
|
+
let offset = 0;
|
|
194
|
+
for (const match of path.matchAll(/\{([^{}+]+)(\+)?\}/g)) {
|
|
195
|
+
if (match.index > offset) {
|
|
196
|
+
segments.push([path.slice(offset, match.index), 0]);
|
|
197
|
+
}
|
|
198
|
+
segments.push([match[1], match[2] ? 2 : 1]);
|
|
199
|
+
offset = match.index + match[0].length;
|
|
200
|
+
}
|
|
201
|
+
if (segments.length && offset < path.length) {
|
|
202
|
+
segments.push([path.slice(offset), 0]);
|
|
203
|
+
}
|
|
204
|
+
return segments.length ? segments : undefined;
|
|
205
|
+
};
|
|
206
|
+
const buildHttpOperationBindings = (schema) => {
|
|
207
|
+
const { http, endpoint } = translateTraits(schema.traits ?? {});
|
|
208
|
+
const [path, search] = http?.[1].split("?") ?? [];
|
|
209
|
+
return [
|
|
210
|
+
http?.[0],
|
|
211
|
+
path,
|
|
212
|
+
search ? [...new URLSearchParams(search)] : [],
|
|
213
|
+
path ? buildPathSegments(path) : undefined,
|
|
214
|
+
endpoint?.[0],
|
|
215
|
+
];
|
|
216
|
+
};
|
|
217
|
+
const EMPTY_BINDINGS = {
|
|
218
|
+
request: { memberBindings: [], byName: {} },
|
|
219
|
+
response: {
|
|
220
|
+
bodyMemberNames: [],
|
|
221
|
+
bindings: { headers: {}, prefixHeaders: [] },
|
|
222
|
+
},
|
|
223
|
+
};
|
|
224
|
+
const getHttpOperationBindings = (schema) => (schema[HTTP_BINDINGS] ??= buildHttpOperationBindings(schema));
|
|
225
|
+
const createBodySchema = (schema, memberNames, memberSchemas) => {
|
|
226
|
+
if (!memberNames.length) {
|
|
227
|
+
return undefined;
|
|
228
|
+
}
|
|
229
|
+
const source = schema.getSchema();
|
|
230
|
+
const body = [
|
|
231
|
+
3,
|
|
232
|
+
source[1],
|
|
233
|
+
source[2],
|
|
234
|
+
schema.getMergedTraits(),
|
|
235
|
+
memberNames,
|
|
236
|
+
memberSchemas,
|
|
237
|
+
];
|
|
238
|
+
const required = source[6];
|
|
239
|
+
const bodyRequired = required && memberNames.reduce((count, name) => count + (source[4].indexOf(name) < required ? 1 : 0), 0);
|
|
240
|
+
if (bodyRequired) {
|
|
241
|
+
body[6] = bodyRequired;
|
|
242
|
+
}
|
|
243
|
+
return body;
|
|
244
|
+
};
|
|
245
|
+
|
|
29
246
|
class SerdeContext {
|
|
30
247
|
serdeContext;
|
|
31
248
|
setSerdeContext(serdeContext) {
|
|
@@ -102,30 +319,29 @@ class HttpProtocol extends SerdeContext {
|
|
|
102
319
|
return request;
|
|
103
320
|
}
|
|
104
321
|
}
|
|
105
|
-
setHostPrefix(request, operationSchema, input) {
|
|
322
|
+
setHostPrefix(request, operationSchema, input, operation = getHttpOperationBindings(operationSchema)) {
|
|
106
323
|
if (this.serdeContext?.disableHostPrefix) {
|
|
107
324
|
return;
|
|
108
325
|
}
|
|
109
|
-
const
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
hostPrefix = hostPrefix.replace(`{${name}}`, replacement);
|
|
123
|
-
}
|
|
124
|
-
request.hostname = hostPrefix + request.hostname;
|
|
125
|
-
if (!isValidHostname(request.hostname)) {
|
|
126
|
-
throw new Error(`[${request.hostname}] is not a valid hostname.`);
|
|
127
|
-
}
|
|
326
|
+
const hostPrefix = operation[4];
|
|
327
|
+
if (typeof hostPrefix !== "string") {
|
|
328
|
+
return;
|
|
329
|
+
}
|
|
330
|
+
let resolvedHostPrefix = hostPrefix;
|
|
331
|
+
for (const [name, [, flags]] of HttpBindingNormalizedSchema.of(operationSchema.input).getHttpBindings().request
|
|
332
|
+
.memberBindings) {
|
|
333
|
+
if (!((flags >> 17) & 1)) {
|
|
334
|
+
continue;
|
|
335
|
+
}
|
|
336
|
+
const replacement = input[name];
|
|
337
|
+
if (typeof replacement !== "string") {
|
|
338
|
+
throw new Error(`@smithy/core/schema - ${name} in input must be a string as hostLabel.`);
|
|
128
339
|
}
|
|
340
|
+
resolvedHostPrefix = resolvedHostPrefix.replace(`{${name}}`, replacement);
|
|
341
|
+
}
|
|
342
|
+
request.hostname = resolvedHostPrefix + request.hostname;
|
|
343
|
+
if (!isValidHostname(request.hostname)) {
|
|
344
|
+
throw new Error(`[${request.hostname}] is not a valid hostname.`);
|
|
129
345
|
}
|
|
130
346
|
}
|
|
131
347
|
deserializeMetadata(output) {
|
|
@@ -230,177 +446,214 @@ class HttpProtocol extends SerdeContext {
|
|
|
230
446
|
class HttpBindingProtocol extends HttpProtocol {
|
|
231
447
|
async serializeRequest(operationSchema, _input, context) {
|
|
232
448
|
const input = _input && typeof _input === "object" ? _input : {};
|
|
233
|
-
const serializer = this.serializer;
|
|
234
449
|
const query = {};
|
|
235
450
|
const headers = {};
|
|
236
451
|
const endpoint = await context.endpoint();
|
|
237
|
-
const ns =
|
|
238
|
-
const
|
|
239
|
-
const
|
|
240
|
-
|
|
241
|
-
let payload;
|
|
242
|
-
const request = new HttpRequest({
|
|
243
|
-
protocol: "",
|
|
244
|
-
hostname: "",
|
|
245
|
-
port: undefined,
|
|
246
|
-
path: "",
|
|
247
|
-
fragment: undefined,
|
|
248
|
-
query: query,
|
|
249
|
-
headers: headers,
|
|
250
|
-
body: undefined,
|
|
251
|
-
});
|
|
452
|
+
const ns = HttpBindingNormalizedSchema.of(operationSchema?.input);
|
|
453
|
+
const bindings = ns.getHttpBindings().request;
|
|
454
|
+
const operation = getHttpOperationBindings(operationSchema);
|
|
455
|
+
const request = new HttpRequest({ query, headers });
|
|
252
456
|
if (endpoint) {
|
|
253
457
|
this.updateServiceEndpoint(request, endpoint);
|
|
254
|
-
this.setHostPrefix(request, operationSchema, input);
|
|
255
|
-
const
|
|
256
|
-
if (
|
|
257
|
-
request.method =
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
request.path = path;
|
|
261
|
-
}
|
|
262
|
-
else {
|
|
263
|
-
request.path += path;
|
|
264
|
-
}
|
|
265
|
-
const traitSearchParams = new URLSearchParams(search ?? "");
|
|
266
|
-
for (const [key, value] of traitSearchParams) {
|
|
458
|
+
this.setHostPrefix(request, operationSchema, input, operation);
|
|
459
|
+
const [method, path, staticQuery] = operation;
|
|
460
|
+
if (method) {
|
|
461
|
+
request.method = method;
|
|
462
|
+
request.path = request.path === "/" ? path : request.path + path;
|
|
463
|
+
for (const [key, value] of staticQuery) {
|
|
267
464
|
query[key] = value;
|
|
268
465
|
}
|
|
269
466
|
}
|
|
270
467
|
}
|
|
271
|
-
|
|
272
|
-
|
|
468
|
+
request.query = query;
|
|
469
|
+
const eventStream = this.serializeHttpBindings(input, request, bindings, operation);
|
|
470
|
+
if (eventStream) {
|
|
471
|
+
request.body = await this.serializeEventStream({ eventStream, requestSchema: ns });
|
|
472
|
+
}
|
|
473
|
+
return request;
|
|
474
|
+
}
|
|
475
|
+
serializeHttpBindings(input, request, bindings, operation) {
|
|
476
|
+
const serializer = this.serializer;
|
|
477
|
+
const directSerializer = typeof serializer.writeCodec === "function"
|
|
478
|
+
? serializer
|
|
479
|
+
: undefined;
|
|
480
|
+
const query = request.query;
|
|
481
|
+
const headers = request.headers;
|
|
482
|
+
const bodySchema = bindings.syntheticBodySchema;
|
|
483
|
+
let hasBodyValue = false;
|
|
484
|
+
let payload;
|
|
485
|
+
let eventStream;
|
|
486
|
+
let labels;
|
|
487
|
+
const names = Object.getOwnPropertyNames(input);
|
|
488
|
+
const prototype = Object.getPrototypeOf(input);
|
|
489
|
+
const sparse = (prototype === Object.prototype || prototype === null) &&
|
|
490
|
+
!bindings.hasIdempotency &&
|
|
491
|
+
!bindings.hasPrefixHeaders &&
|
|
492
|
+
names.length * 2 < bindings.memberBindings.length;
|
|
493
|
+
const length = sparse ? names.length : bindings.memberBindings.length;
|
|
494
|
+
for (let i = 0; i < length; ++i) {
|
|
495
|
+
const binding = sparse
|
|
496
|
+
? hasOwn(bindings.byName, names[i])
|
|
497
|
+
? bindings.byName[names[i]]
|
|
498
|
+
: undefined
|
|
499
|
+
: bindings.memberBindings[i];
|
|
500
|
+
if (!binding) {
|
|
501
|
+
continue;
|
|
502
|
+
}
|
|
503
|
+
const value = binding[1];
|
|
504
|
+
const memberName = binding[0];
|
|
505
|
+
const memberNs = value[0];
|
|
506
|
+
const flags = value[1];
|
|
507
|
+
const collectionValue = value[2];
|
|
508
|
+
const location = binding[2];
|
|
509
|
+
const wireName = binding[3];
|
|
273
510
|
const inputMemberValue = input[memberName];
|
|
274
|
-
if (inputMemberValue == null && !
|
|
275
|
-
if (memberTraits.httpLabel) {
|
|
276
|
-
if (request.path.includes(`{${memberName}+}`) || request.path.includes(`{${memberName}}`)) {
|
|
277
|
-
throw new Error(`No value provided for input HTTP label: ${memberName}.`);
|
|
278
|
-
}
|
|
279
|
-
}
|
|
511
|
+
if (inputMemberValue == null && !((flags >> 10) & 1)) {
|
|
280
512
|
continue;
|
|
281
513
|
}
|
|
282
|
-
if (
|
|
283
|
-
const
|
|
284
|
-
if (
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
if (input[memberName]) {
|
|
288
|
-
payload = await this.serializeEventStream({
|
|
289
|
-
eventStream: input[memberName],
|
|
290
|
-
requestSchema: ns,
|
|
291
|
-
});
|
|
292
|
-
}
|
|
514
|
+
if (location === 0b100_100) {
|
|
515
|
+
const stream = (flags >> 11) & 0b11;
|
|
516
|
+
if (stream) {
|
|
517
|
+
if (stream === 2) {
|
|
518
|
+
eventStream = inputMemberValue || undefined;
|
|
293
519
|
}
|
|
294
520
|
else {
|
|
295
521
|
payload = inputMemberValue;
|
|
296
522
|
}
|
|
297
523
|
}
|
|
298
524
|
else {
|
|
299
|
-
|
|
525
|
+
if (directSerializer) {
|
|
526
|
+
directSerializer.writeCodec(memberNs, inputMemberValue);
|
|
527
|
+
}
|
|
528
|
+
else {
|
|
529
|
+
serializer.write(memberNs, inputMemberValue);
|
|
530
|
+
}
|
|
300
531
|
payload = serializer.flush();
|
|
301
532
|
}
|
|
302
533
|
}
|
|
303
|
-
else if (
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
request.path = request.path.replace(`{${memberName}+}`, replacement.split("/").map(extendedEncodeURIComponent).join("/"));
|
|
534
|
+
else if (location === 0b100_001 || location === 0b100_110) {
|
|
535
|
+
const serialized = this.serializeHttpValue(value, inputMemberValue, location, directSerializer);
|
|
536
|
+
if (location === 0b100_001) {
|
|
537
|
+
(labels ??= Object.create(null))[memberName] = serialized;
|
|
308
538
|
}
|
|
309
|
-
else
|
|
310
|
-
|
|
539
|
+
else {
|
|
540
|
+
headers[wireName] = serialized;
|
|
311
541
|
}
|
|
312
542
|
}
|
|
313
|
-
else if (
|
|
314
|
-
serializer.write(memberNs, inputMemberValue);
|
|
315
|
-
headers[memberTraits.httpHeader.toLowerCase()] = String(serializer.flush());
|
|
316
|
-
}
|
|
317
|
-
else if (typeof memberTraits.httpPrefixHeaders === "string") {
|
|
543
|
+
else if (location === 0b100_111) {
|
|
318
544
|
for (const key in inputMemberValue) {
|
|
319
545
|
if (!hasOwn(inputMemberValue, key)) {
|
|
320
546
|
continue;
|
|
321
547
|
}
|
|
322
|
-
const
|
|
323
|
-
|
|
324
|
-
serializer.write([memberNs.getValueSchema(), { httpHeader: amalgam }], val);
|
|
325
|
-
headers[amalgam.toLowerCase()] = serializer.flush();
|
|
548
|
+
const amalgam = wireName + key;
|
|
549
|
+
headers[amalgam.toLowerCase()] = this.serializeHttpValue(collectionValue, inputMemberValue[key], 0b100_110, directSerializer, directSerializer ? collectionValue[0] : [collectionValue[0], { httpHeader: amalgam }]);
|
|
326
550
|
}
|
|
327
551
|
}
|
|
328
|
-
else if (
|
|
329
|
-
this.serializeQuery(
|
|
552
|
+
else if ((location & 0b111_110) === 0b100_010) {
|
|
553
|
+
this.serializeQuery(value, inputMemberValue, wireName, query, directSerializer);
|
|
330
554
|
}
|
|
331
555
|
else {
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
if (
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
name,
|
|
344
|
-
ns.getMergedTraits(),
|
|
345
|
-
payloadMemberNames,
|
|
346
|
-
payloadMemberSchemas,
|
|
347
|
-
undefined,
|
|
348
|
-
];
|
|
349
|
-
if (requiredMembers) {
|
|
350
|
-
payloadSchema[6] = requiredMembers;
|
|
556
|
+
hasBodyValue = true;
|
|
557
|
+
}
|
|
558
|
+
}
|
|
559
|
+
const operationPath = operation[1];
|
|
560
|
+
const pathSegments = operation[3];
|
|
561
|
+
if (operationPath && pathSegments && request.path.endsWith(operationPath)) {
|
|
562
|
+
request.path = request.path.slice(0, -operationPath.length) + this.serializePath(pathSegments, labels, bindings);
|
|
563
|
+
}
|
|
564
|
+
if (hasBodyValue && bodySchema) {
|
|
565
|
+
if (directSerializer) {
|
|
566
|
+
directSerializer.writeCodec(bodySchema, input);
|
|
351
567
|
}
|
|
352
568
|
else {
|
|
353
|
-
|
|
569
|
+
serializer.write(bodySchema, input);
|
|
354
570
|
}
|
|
355
|
-
serializer.write(payloadSchema, input);
|
|
356
571
|
payload = serializer.flush();
|
|
357
572
|
}
|
|
358
|
-
request.headers = headers;
|
|
359
|
-
request.query = query;
|
|
360
573
|
request.body = payload;
|
|
361
|
-
return
|
|
574
|
+
return eventStream;
|
|
362
575
|
}
|
|
363
|
-
serializeQuery(
|
|
364
|
-
const
|
|
365
|
-
const traits = ns.getMergedTraits();
|
|
366
|
-
if (
|
|
576
|
+
serializeQuery(value, data, wireName, query, directSerializer) {
|
|
577
|
+
const [ns, flags, collectionValue] = value;
|
|
578
|
+
const traits = directSerializer ? undefined : ns.getMergedTraits();
|
|
579
|
+
if (wireName === undefined) {
|
|
367
580
|
for (const key in data) {
|
|
368
|
-
if (!hasOwn(data, key)) {
|
|
581
|
+
if (!hasOwn(data, key) || key in query) {
|
|
369
582
|
continue;
|
|
370
583
|
}
|
|
371
|
-
if (!
|
|
372
|
-
|
|
373
|
-
const valueSchema = ns.getValueSchema();
|
|
374
|
-
Object.assign(valueSchema.getMergedTraits(), {
|
|
584
|
+
if (!directSerializer) {
|
|
585
|
+
Object.assign(collectionValue[0].getMergedTraits(), {
|
|
375
586
|
...traits,
|
|
376
587
|
httpQuery: key,
|
|
377
588
|
httpQueryParams: undefined,
|
|
378
589
|
});
|
|
379
|
-
this.serializeQuery(valueSchema, val, query);
|
|
380
590
|
}
|
|
591
|
+
this.serializeQuery(collectionValue, data[key], key, query, directSerializer);
|
|
381
592
|
}
|
|
382
593
|
return;
|
|
383
594
|
}
|
|
384
|
-
if (
|
|
385
|
-
const sparse = !!ns.getMergedTraits().sparse;
|
|
595
|
+
if ((flags & 0b1100_0000) === 0b0100_0000) {
|
|
386
596
|
const buffer = [];
|
|
387
597
|
for (const item of data) {
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
buffer.push(serializable);
|
|
598
|
+
const serialized = this.serializeHttpValue(collectionValue, item, 0b100_010, directSerializer, directSerializer ? collectionValue[0] : [collectionValue[0], traits]);
|
|
599
|
+
if ((flags >> 13) & 1 || serialized !== undefined) {
|
|
600
|
+
buffer.push(serialized);
|
|
392
601
|
}
|
|
393
602
|
}
|
|
394
|
-
query[
|
|
603
|
+
query[wireName] = buffer;
|
|
604
|
+
}
|
|
605
|
+
else {
|
|
606
|
+
query[wireName] = this.serializeHttpValue(value, data, 0b100_010, directSerializer, directSerializer ? ns : [ns, traits]);
|
|
607
|
+
}
|
|
608
|
+
}
|
|
609
|
+
serializeHttpValue(value, data, location, directSerializer, schema = value[0]) {
|
|
610
|
+
const flags = value[1];
|
|
611
|
+
const type = flags & 0xff;
|
|
612
|
+
if (directSerializer &&
|
|
613
|
+
!(flags & 0x700) &&
|
|
614
|
+
(type <= 2 ||
|
|
615
|
+
type === 17 ||
|
|
616
|
+
type === 19)) {
|
|
617
|
+
return String(data);
|
|
618
|
+
}
|
|
619
|
+
if (directSerializer) {
|
|
620
|
+
directSerializer.writeHttpBinding(value, data, location);
|
|
395
621
|
}
|
|
396
622
|
else {
|
|
397
|
-
serializer.write(
|
|
398
|
-
query[traits.httpQuery] = serializer.flush();
|
|
623
|
+
this.serializer.write(schema, data);
|
|
399
624
|
}
|
|
625
|
+
return this.serializer.flush();
|
|
626
|
+
}
|
|
627
|
+
serializePath(segments, labels, bindings) {
|
|
628
|
+
let path = "";
|
|
629
|
+
for (const [value, kind] of segments) {
|
|
630
|
+
if (kind === 0) {
|
|
631
|
+
path += value;
|
|
632
|
+
continue;
|
|
633
|
+
}
|
|
634
|
+
const replacement = labels?.[value];
|
|
635
|
+
if (replacement === undefined) {
|
|
636
|
+
if (hasOwn(bindings.byName, value) && bindings.byName[value][2] === 0b100_001) {
|
|
637
|
+
throw new Error(`No value provided for input HTTP label: ${value}.`);
|
|
638
|
+
}
|
|
639
|
+
path += `{${value}${kind === 2 ? "+" : ""}}`;
|
|
640
|
+
}
|
|
641
|
+
else {
|
|
642
|
+
path +=
|
|
643
|
+
kind === 2
|
|
644
|
+
? replacement.split("/").map(extendedEncodeURIComponent).join("/")
|
|
645
|
+
: extendedEncodeURIComponent(replacement);
|
|
646
|
+
}
|
|
647
|
+
}
|
|
648
|
+
return path;
|
|
400
649
|
}
|
|
401
650
|
async deserializeResponse(operationSchema, context, response) {
|
|
402
651
|
const deserializer = this.deserializer;
|
|
403
|
-
const
|
|
652
|
+
const directDeserializer = typeof deserializer.readCodec === "function"
|
|
653
|
+
? deserializer
|
|
654
|
+
: undefined;
|
|
655
|
+
const ns = HttpBindingNormalizedSchema.of(operationSchema.output);
|
|
656
|
+
const responseBindings = ns.getHttpBindings().response;
|
|
404
657
|
const dataObject = {};
|
|
405
658
|
if (response.statusCode >= 300) {
|
|
406
659
|
const bytes = await collectBody(response.body, context);
|
|
@@ -410,19 +663,13 @@ class HttpBindingProtocol extends HttpProtocol {
|
|
|
410
663
|
await this.handleError(operationSchema, context, response, dataObject, this.deserializeMetadata(response));
|
|
411
664
|
throw new Error("@smithy/core/protocols - HTTP Protocol error handler failed to throw.");
|
|
412
665
|
}
|
|
413
|
-
for (const header in response.headers) {
|
|
414
|
-
if (!hasOwn(response.headers, header)) {
|
|
415
|
-
continue;
|
|
416
|
-
}
|
|
417
|
-
const value = response.headers[header];
|
|
418
|
-
delete response.headers[header];
|
|
419
|
-
response.headers[header.toLowerCase()] = value;
|
|
420
|
-
}
|
|
421
666
|
const nonHttpBindingMembers = await this.deserializeHttpMessage(ns, context, response, dataObject);
|
|
422
667
|
if (nonHttpBindingMembers.length) {
|
|
423
668
|
const bytes = await collectBody(response.body, context);
|
|
424
669
|
if (bytes.byteLength > 0) {
|
|
425
|
-
const dataFromBody = await
|
|
670
|
+
const dataFromBody = await (directDeserializer
|
|
671
|
+
? directDeserializer.readCodec(responseBindings.syntheticBodySchema, bytes)
|
|
672
|
+
: deserializer.read(responseBindings.syntheticBodySchema, bytes));
|
|
426
673
|
for (const member of nonHttpBindingMembers) {
|
|
427
674
|
if (dataFromBody[member] != null) {
|
|
428
675
|
dataObject[member] = dataFromBody[member];
|
|
@@ -430,97 +677,95 @@ class HttpBindingProtocol extends HttpProtocol {
|
|
|
430
677
|
}
|
|
431
678
|
}
|
|
432
679
|
}
|
|
433
|
-
else if (
|
|
680
|
+
else if (!responseBindings.bindings.payload) {
|
|
434
681
|
await collectBody(response.body, context);
|
|
435
682
|
}
|
|
436
683
|
dataObject.$metadata = this.deserializeMetadata(response);
|
|
437
684
|
return dataObject;
|
|
438
685
|
}
|
|
439
686
|
async deserializeHttpMessage(schema, context, response, arg4, arg5) {
|
|
440
|
-
|
|
441
|
-
if (arg4 instanceof Set) {
|
|
442
|
-
dataObject = arg5;
|
|
443
|
-
}
|
|
444
|
-
else {
|
|
445
|
-
dataObject = arg4;
|
|
446
|
-
}
|
|
447
|
-
let discardResponseBody = true;
|
|
687
|
+
const dataObject = arg4 instanceof Set ? arg5 : arg4;
|
|
448
688
|
const deserializer = this.deserializer;
|
|
449
|
-
const
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
dataObject[memberName] = sdkStreamMixin(response.body);
|
|
466
|
-
}
|
|
689
|
+
const directDeserializer = typeof deserializer.readCodec === "function"
|
|
690
|
+
? deserializer
|
|
691
|
+
: undefined;
|
|
692
|
+
const ns = HttpBindingNormalizedSchema.of(schema);
|
|
693
|
+
const { bodyMemberNames, bindings: { payload, statusCode, headers: responseHeaders, prefixHeaders }, } = ns.getHttpBindings().response;
|
|
694
|
+
const headers = response.headers;
|
|
695
|
+
if (payload) {
|
|
696
|
+
const [memberName, value] = payload;
|
|
697
|
+
const [memberSchema, flags] = value;
|
|
698
|
+
const stream = (flags >> 11) & 0b11;
|
|
699
|
+
if (stream) {
|
|
700
|
+
if (stream === 2) {
|
|
701
|
+
dataObject[memberName] = await this.deserializeEventStream({
|
|
702
|
+
response,
|
|
703
|
+
responseSchema: ns,
|
|
704
|
+
});
|
|
467
705
|
}
|
|
468
|
-
else
|
|
469
|
-
|
|
470
|
-
if (bytes.byteLength > 0) {
|
|
471
|
-
dataObject[memberName] = await deserializer.read(memberSchema, bytes);
|
|
472
|
-
}
|
|
706
|
+
else {
|
|
707
|
+
dataObject[memberName] = sdkStreamMixin(response.body);
|
|
473
708
|
}
|
|
474
709
|
}
|
|
475
|
-
else if (
|
|
476
|
-
const
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
headerListValueSchema.getMergedTraits().httpHeader = key;
|
|
482
|
-
let sections;
|
|
483
|
-
if (headerListValueSchema.isTimestampSchema() &&
|
|
484
|
-
headerListValueSchema.getSchema() === 4) {
|
|
485
|
-
sections = splitEvery(value, ",", 2);
|
|
486
|
-
}
|
|
487
|
-
else {
|
|
488
|
-
sections = splitHeader(value);
|
|
489
|
-
}
|
|
490
|
-
const list = [];
|
|
491
|
-
for (const section of sections) {
|
|
492
|
-
list.push(await deserializer.read(headerListValueSchema, section.trim()));
|
|
493
|
-
}
|
|
494
|
-
dataObject[memberName] = list;
|
|
495
|
-
}
|
|
496
|
-
else {
|
|
497
|
-
dataObject[memberName] = await deserializer.read(memberSchema, value);
|
|
498
|
-
}
|
|
710
|
+
else if (response.body) {
|
|
711
|
+
const bytes = await collectBody(response.body, context);
|
|
712
|
+
if (bytes.byteLength > 0) {
|
|
713
|
+
dataObject[memberName] = await (directDeserializer
|
|
714
|
+
? directDeserializer.readPayload(value, bytes)
|
|
715
|
+
: deserializer.read(memberSchema, bytes));
|
|
499
716
|
}
|
|
500
717
|
}
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
continue;
|
|
506
|
-
}
|
|
507
|
-
if (header.startsWith(memberTraits.httpPrefixHeaders)) {
|
|
508
|
-
const value = response.headers[header];
|
|
509
|
-
const valueSchema = memberSchema.getValueSchema();
|
|
510
|
-
valueSchema.getMergedTraits().httpHeader = header;
|
|
511
|
-
dataObject[memberName][header.slice(memberTraits.httpPrefixHeaders.length)] = await deserializer.read(valueSchema, value);
|
|
512
|
-
}
|
|
513
|
-
}
|
|
718
|
+
}
|
|
719
|
+
for (const header in headers) {
|
|
720
|
+
if (!hasOwn(headers, header)) {
|
|
721
|
+
continue;
|
|
514
722
|
}
|
|
515
|
-
|
|
516
|
-
|
|
723
|
+
const lower = header.toLowerCase();
|
|
724
|
+
const headerValue = headers[header];
|
|
725
|
+
if (lower !== header) {
|
|
726
|
+
delete headers[header];
|
|
727
|
+
headers[lower] = headerValue;
|
|
728
|
+
}
|
|
729
|
+
const binding = hasOwn(responseHeaders, lower) ? responseHeaders[lower] : undefined;
|
|
730
|
+
if (!binding) {
|
|
731
|
+
continue;
|
|
732
|
+
}
|
|
733
|
+
const [memberName, [memberSchema, flags, collectionValue], , wireName] = binding;
|
|
734
|
+
if (collectionValue) {
|
|
735
|
+
const sections = (flags >> 16) & 1 ? splitEvery(headerValue, ",", 2) : splitHeader(headerValue);
|
|
736
|
+
const list = [];
|
|
737
|
+
for (const section of sections) {
|
|
738
|
+
list.push(directDeserializer
|
|
739
|
+
? directDeserializer.readHttpBinding(collectionValue, section.trim(), 0b100_110)
|
|
740
|
+
: await deserializer.read([collectionValue[0], { httpHeader: wireName }], section.trim()));
|
|
741
|
+
}
|
|
742
|
+
dataObject[memberName] = list;
|
|
517
743
|
}
|
|
518
744
|
else {
|
|
519
|
-
|
|
745
|
+
dataObject[memberName] = directDeserializer
|
|
746
|
+
? directDeserializer.readHttpBinding(binding[1], headerValue, 0b100_110)
|
|
747
|
+
: await deserializer.read(memberSchema, headerValue);
|
|
748
|
+
}
|
|
749
|
+
}
|
|
750
|
+
for (const [memberName, [, , collectionValue], , wireName] of prefixHeaders) {
|
|
751
|
+
dataObject[memberName] = {};
|
|
752
|
+
for (const header in headers) {
|
|
753
|
+
if (!hasOwn(headers, header)) {
|
|
754
|
+
continue;
|
|
755
|
+
}
|
|
756
|
+
if (!header.startsWith(wireName)) {
|
|
757
|
+
continue;
|
|
758
|
+
}
|
|
759
|
+
const headerValue = headers[header];
|
|
760
|
+
dataObject[memberName][header.slice(wireName.length)] = directDeserializer
|
|
761
|
+
? directDeserializer.readHttpBinding(collectionValue, headerValue, 0b100_110)
|
|
762
|
+
: await deserializer.read([collectionValue[0], { httpHeader: header }], headerValue);
|
|
520
763
|
}
|
|
521
764
|
}
|
|
522
|
-
|
|
523
|
-
|
|
765
|
+
if (statusCode) {
|
|
766
|
+
dataObject[statusCode[0]] = response.statusCode;
|
|
767
|
+
}
|
|
768
|
+
return bodyMemberNames;
|
|
524
769
|
}
|
|
525
770
|
}
|
|
526
771
|
|
|
@@ -738,26 +983,6 @@ class RequestBuilder {
|
|
|
738
983
|
}
|
|
739
984
|
}
|
|
740
985
|
|
|
741
|
-
function determineTimestampFormat(ns, settings) {
|
|
742
|
-
if (settings.timestampFormat.useTrait) {
|
|
743
|
-
if (ns.isTimestampSchema() &&
|
|
744
|
-
(ns.getSchema() === 5 ||
|
|
745
|
-
ns.getSchema() === 6 ||
|
|
746
|
-
ns.getSchema() === 7)) {
|
|
747
|
-
return ns.getSchema();
|
|
748
|
-
}
|
|
749
|
-
}
|
|
750
|
-
const { httpLabel, httpPrefixHeaders, httpHeader, httpQuery } = ns.getMergedTraits();
|
|
751
|
-
const bindingFormat = settings.httpBindings
|
|
752
|
-
? typeof httpPrefixHeaders === "string" || Boolean(httpHeader)
|
|
753
|
-
? 6
|
|
754
|
-
: Boolean(httpQuery) || Boolean(httpLabel)
|
|
755
|
-
? 5
|
|
756
|
-
: undefined
|
|
757
|
-
: undefined;
|
|
758
|
-
return bindingFormat ?? settings.timestampFormat.default;
|
|
759
|
-
}
|
|
760
|
-
|
|
761
986
|
class FromStringShapeDeserializer extends SerdeContext {
|
|
762
987
|
settings;
|
|
763
988
|
constructor(settings) {
|
|
@@ -765,57 +990,65 @@ class FromStringShapeDeserializer extends SerdeContext {
|
|
|
765
990
|
this.settings = settings;
|
|
766
991
|
}
|
|
767
992
|
read(_schema, data) {
|
|
768
|
-
const ns =
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
if (
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
993
|
+
const ns = HttpBindingNormalizedSchema.of(_schema);
|
|
994
|
+
const traits = ns.getMergedTraits();
|
|
995
|
+
const location = ns.getHttpBindingLocation(traits);
|
|
996
|
+
return this.readHttpBinding(ns.getHttpBindingValue(location, traits), data, location);
|
|
997
|
+
}
|
|
998
|
+
readHttpBinding([ns, flags, collectionValue], data, location) {
|
|
999
|
+
const schema = flags & 0xff;
|
|
1000
|
+
if ((schema & 0b1100_0000) === 0b0100_0000) {
|
|
1001
|
+
collectionValue ??= ns.getHttpBindingCollectionValue(location);
|
|
1002
|
+
return splitHeader(data).map((item) => this.readHttpBinding(collectionValue, item, location));
|
|
1003
|
+
}
|
|
1004
|
+
switch (schema) {
|
|
1005
|
+
case 21:
|
|
1006
|
+
case 42:
|
|
1007
|
+
return (this.serdeContext?.base64Decoder ?? fromBase64)(data);
|
|
1008
|
+
case 4:
|
|
1009
|
+
case 5:
|
|
1010
|
+
case 6:
|
|
1011
|
+
case 7: {
|
|
1012
|
+
const bindingFormat = this.settings.httpBindings ? (flags >> 14) & 0b11 : 0;
|
|
1013
|
+
const format = this.settings.timestampFormat.useTrait && schema > 4
|
|
1014
|
+
? schema
|
|
1015
|
+
: bindingFormat
|
|
1016
|
+
? bindingFormat + 4
|
|
1017
|
+
: this.settings.timestampFormat.default;
|
|
1018
|
+
switch (format) {
|
|
1019
|
+
case 5:
|
|
1020
|
+
return _parseRfc3339DateTimeWithOffset(data);
|
|
1021
|
+
case 6:
|
|
1022
|
+
return _parseRfc7231DateTime(data);
|
|
1023
|
+
case 7:
|
|
1024
|
+
return _parseEpochTimestamp(data);
|
|
1025
|
+
default:
|
|
1026
|
+
console.warn("Missing timestamp format, parsing value with Date constructor:", data);
|
|
1027
|
+
return new Date(data);
|
|
1028
|
+
}
|
|
787
1029
|
}
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
if (mediaType) {
|
|
793
|
-
if (ns.getMergedTraits().httpHeader) {
|
|
794
|
-
intermediateValue = this.base64ToUtf8(intermediateValue);
|
|
1030
|
+
case 0: {
|
|
1031
|
+
const media = (flags >> 8) & 0b11;
|
|
1032
|
+
if (!media) {
|
|
1033
|
+
return data;
|
|
795
1034
|
}
|
|
796
|
-
|
|
797
|
-
if (
|
|
798
|
-
intermediateValue =
|
|
1035
|
+
let intermediateValue = data;
|
|
1036
|
+
if ((location & 0b110) === 0b110) {
|
|
1037
|
+
intermediateValue = (this.serdeContext?.utf8Encoder ?? toUtf8)((this.serdeContext?.base64Decoder ?? fromBase64)(intermediateValue));
|
|
799
1038
|
}
|
|
800
|
-
return intermediateValue;
|
|
1039
|
+
return media === 2 ? LazyJsonString.from(intermediateValue) : intermediateValue;
|
|
801
1040
|
}
|
|
1041
|
+
case 1:
|
|
1042
|
+
return Number(data);
|
|
1043
|
+
case 2:
|
|
1044
|
+
return data.toLowerCase() === "true";
|
|
1045
|
+
case 17:
|
|
1046
|
+
return BigInt(data);
|
|
1047
|
+
case 19:
|
|
1048
|
+
return new NumericValue(data, "bigDecimal");
|
|
1049
|
+
default:
|
|
1050
|
+
return data;
|
|
802
1051
|
}
|
|
803
|
-
if (ns.isNumericSchema()) {
|
|
804
|
-
return Number(data);
|
|
805
|
-
}
|
|
806
|
-
if (ns.isBigIntegerSchema()) {
|
|
807
|
-
return BigInt(data);
|
|
808
|
-
}
|
|
809
|
-
if (ns.isBigDecimalSchema()) {
|
|
810
|
-
return new NumericValue(data, "bigDecimal");
|
|
811
|
-
}
|
|
812
|
-
if (ns.isBooleanSchema()) {
|
|
813
|
-
return String(data).toLowerCase() === "true";
|
|
814
|
-
}
|
|
815
|
-
return data;
|
|
816
|
-
}
|
|
817
|
-
base64ToUtf8(base64String) {
|
|
818
|
-
return (this.serdeContext?.utf8Encoder ?? toUtf8)((this.serdeContext?.base64Decoder ?? fromBase64)(base64String));
|
|
819
1052
|
}
|
|
820
1053
|
}
|
|
821
1054
|
|
|
@@ -833,28 +1066,33 @@ class HttpInterceptingShapeDeserializer extends SerdeContext {
|
|
|
833
1066
|
this.serdeContext = serdeContext;
|
|
834
1067
|
}
|
|
835
1068
|
read(schema, data) {
|
|
836
|
-
const ns =
|
|
1069
|
+
const ns = HttpBindingNormalizedSchema.of(schema);
|
|
837
1070
|
const traits = ns.getMergedTraits();
|
|
838
|
-
const toString = this.serdeContext?.utf8Encoder ?? toUtf8;
|
|
839
1071
|
if (traits.httpHeader || traits.httpResponseCode) {
|
|
840
|
-
|
|
1072
|
+
const value = ns.getHttpBindingValue(0b100_110, traits);
|
|
1073
|
+
return this.readHttpBinding(value, data, 0b100_110);
|
|
841
1074
|
}
|
|
842
1075
|
if (traits.httpPayload) {
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
}
|
|
1076
|
+
return this.readPayload(ns.getHttpBindingValue(0b100_100, traits), data);
|
|
1077
|
+
}
|
|
1078
|
+
return this.readCodec(ns, data);
|
|
1079
|
+
}
|
|
1080
|
+
readHttpBinding(binding, data, location) {
|
|
1081
|
+
const value = typeof data === "string" ? data : (this.serdeContext?.utf8Encoder ?? toUtf8)(data);
|
|
1082
|
+
return this.stringDeserializer.readHttpBinding(binding, value, location);
|
|
1083
|
+
}
|
|
1084
|
+
readPayload([schema, flags], data) {
|
|
1085
|
+
const type = flags & 0xff;
|
|
1086
|
+
if (type === 21 || type === 42) {
|
|
1087
|
+
return typeof data === "string" ? (this.serdeContext?.utf8Decoder ?? fromUtf8)(data) : data;
|
|
856
1088
|
}
|
|
857
|
-
|
|
1089
|
+
if (type === 0) {
|
|
1090
|
+
return typeof data === "string" ? data : (this.serdeContext?.utf8Encoder ?? toUtf8)(data);
|
|
1091
|
+
}
|
|
1092
|
+
return this.readCodec(schema, data);
|
|
1093
|
+
}
|
|
1094
|
+
readCodec(schema, data) {
|
|
1095
|
+
return this.codecDeserializer.read(schema, data);
|
|
858
1096
|
}
|
|
859
1097
|
}
|
|
860
1098
|
|
|
@@ -866,18 +1104,29 @@ class ToStringShapeSerializer extends SerdeContext {
|
|
|
866
1104
|
this.settings = settings;
|
|
867
1105
|
}
|
|
868
1106
|
write(schema, value) {
|
|
869
|
-
const ns =
|
|
1107
|
+
const ns = HttpBindingNormalizedSchema.of(schema);
|
|
1108
|
+
const traits = ns.getMergedTraits();
|
|
1109
|
+
const location = ns.getHttpBindingLocation(traits);
|
|
1110
|
+
this.writeHttpBinding(ns.getHttpBindingValue(location, traits), value, location);
|
|
1111
|
+
}
|
|
1112
|
+
writeHttpBinding([ns, flags, collectionValue], value, location) {
|
|
1113
|
+
const schema = flags & 0xff;
|
|
870
1114
|
switch (typeof value) {
|
|
871
1115
|
case "object":
|
|
872
1116
|
if (value === null) {
|
|
873
1117
|
this.stringBuffer = "null";
|
|
874
1118
|
return;
|
|
875
1119
|
}
|
|
876
|
-
if (
|
|
1120
|
+
if (schema >= 4 && schema <= 7) {
|
|
877
1121
|
if (!(value instanceof Date)) {
|
|
878
1122
|
throw new Error(`@smithy/core/protocols - received non-Date value ${value} when schema expected Date in ${ns.getName(true)}`);
|
|
879
1123
|
}
|
|
880
|
-
const
|
|
1124
|
+
const bindingFormat = this.settings.httpBindings ? (flags >> 14) & 0b11 : 0;
|
|
1125
|
+
const format = this.settings.timestampFormat.useTrait && schema > 4
|
|
1126
|
+
? schema
|
|
1127
|
+
: bindingFormat
|
|
1128
|
+
? bindingFormat + 4
|
|
1129
|
+
: this.settings.timestampFormat.default;
|
|
881
1130
|
switch (format) {
|
|
882
1131
|
case 5:
|
|
883
1132
|
this.stringBuffer = value.toISOString().replace(".000Z", "Z");
|
|
@@ -894,20 +1143,24 @@ class ToStringShapeSerializer extends SerdeContext {
|
|
|
894
1143
|
}
|
|
895
1144
|
return;
|
|
896
1145
|
}
|
|
897
|
-
if (
|
|
1146
|
+
if ((schema === 21 || schema === 42) &&
|
|
1147
|
+
"byteLength" in value) {
|
|
898
1148
|
this.stringBuffer = (this.serdeContext?.base64Encoder ?? toBase64)(value);
|
|
899
1149
|
return;
|
|
900
1150
|
}
|
|
901
|
-
if (
|
|
1151
|
+
if ((schema & 0b1100_0000) === 0b0100_0000 && Array.isArray(value)) {
|
|
1152
|
+
collectionValue ??= ns.getHttpBindingCollectionValue(location);
|
|
1153
|
+
const valueSchemaType = collectionValue[1] & 0xff;
|
|
1154
|
+
const isTimestamp = valueSchemaType >= 4 &&
|
|
1155
|
+
valueSchemaType <= 7;
|
|
902
1156
|
let buffer = "";
|
|
903
1157
|
for (const item of value) {
|
|
904
|
-
this.
|
|
1158
|
+
this.writeHttpBinding(collectionValue, item, location);
|
|
905
1159
|
const headerItem = this.flush();
|
|
906
|
-
|
|
907
|
-
if (buffer !== "") {
|
|
1160
|
+
if (buffer) {
|
|
908
1161
|
buffer += ", ";
|
|
909
1162
|
}
|
|
910
|
-
buffer +=
|
|
1163
|
+
buffer += isTimestamp ? headerItem : quoteHeader(headerItem);
|
|
911
1164
|
}
|
|
912
1165
|
this.stringBuffer = buffer;
|
|
913
1166
|
return;
|
|
@@ -915,27 +1168,19 @@ class ToStringShapeSerializer extends SerdeContext {
|
|
|
915
1168
|
this.stringBuffer = JSON.stringify(value, null, 2);
|
|
916
1169
|
break;
|
|
917
1170
|
case "string":
|
|
918
|
-
const
|
|
1171
|
+
const media = (flags >> 8) & 0b11;
|
|
919
1172
|
let intermediateValue = value;
|
|
920
|
-
if (
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
this.stringBuffer = (this.serdeContext?.base64Encoder ?? toBase64)(intermediateValue.toString());
|
|
927
|
-
return;
|
|
928
|
-
}
|
|
1173
|
+
if (media === 2) {
|
|
1174
|
+
intermediateValue = LazyJsonString.from(intermediateValue);
|
|
1175
|
+
}
|
|
1176
|
+
if (media && (location & 0b110) === 0b110) {
|
|
1177
|
+
this.stringBuffer = (this.serdeContext?.base64Encoder ?? toBase64)(intermediateValue.toString());
|
|
1178
|
+
return;
|
|
929
1179
|
}
|
|
930
1180
|
this.stringBuffer = value;
|
|
931
1181
|
break;
|
|
932
1182
|
default:
|
|
933
|
-
|
|
934
|
-
this.stringBuffer = generateIdempotencyToken();
|
|
935
|
-
}
|
|
936
|
-
else {
|
|
937
|
-
this.stringBuffer = String(value);
|
|
938
|
-
}
|
|
1183
|
+
this.stringBuffer = (flags >> 10) & 1 ? generateIdempotencyToken() : String(value);
|
|
939
1184
|
}
|
|
940
1185
|
}
|
|
941
1186
|
flush() {
|
|
@@ -958,14 +1203,21 @@ class HttpInterceptingShapeSerializer {
|
|
|
958
1203
|
this.stringSerializer.setSerdeContext(serdeContext);
|
|
959
1204
|
}
|
|
960
1205
|
write(schema, value) {
|
|
961
|
-
const ns =
|
|
1206
|
+
const ns = HttpBindingNormalizedSchema.of(schema);
|
|
962
1207
|
const traits = ns.getMergedTraits();
|
|
963
1208
|
if (traits.httpHeader || traits.httpLabel || traits.httpQuery) {
|
|
964
|
-
|
|
965
|
-
this.
|
|
1209
|
+
const location = ns.getHttpBindingLocation(traits);
|
|
1210
|
+
this.writeHttpBinding(ns.getHttpBindingValue(location, traits), value, location);
|
|
966
1211
|
return;
|
|
967
1212
|
}
|
|
968
|
-
|
|
1213
|
+
this.writeCodec(ns, value);
|
|
1214
|
+
}
|
|
1215
|
+
writeHttpBinding(binding, value, location) {
|
|
1216
|
+
this.stringSerializer.writeHttpBinding(binding, value, location);
|
|
1217
|
+
this.buffer = this.stringSerializer.flush();
|
|
1218
|
+
}
|
|
1219
|
+
writeCodec(schema, value) {
|
|
1220
|
+
this.codecSerializer.write(schema, value);
|
|
969
1221
|
}
|
|
970
1222
|
flush() {
|
|
971
1223
|
if (this.buffer !== undefined) {
|
|
@@ -977,6 +1229,26 @@ class HttpInterceptingShapeSerializer {
|
|
|
977
1229
|
}
|
|
978
1230
|
}
|
|
979
1231
|
|
|
1232
|
+
function determineTimestampFormat(ns, settings) {
|
|
1233
|
+
if (settings.timestampFormat.useTrait) {
|
|
1234
|
+
const schema = ns.getSchema();
|
|
1235
|
+
if (schema === 5 ||
|
|
1236
|
+
schema === 6 ||
|
|
1237
|
+
schema === 7) {
|
|
1238
|
+
return schema;
|
|
1239
|
+
}
|
|
1240
|
+
}
|
|
1241
|
+
const { httpLabel, httpPrefixHeaders, httpHeader, httpQuery } = ns.getMergedTraits();
|
|
1242
|
+
const bindingFormat = settings.httpBindings
|
|
1243
|
+
? typeof httpPrefixHeaders === "string" || Boolean(httpHeader)
|
|
1244
|
+
? 6
|
|
1245
|
+
: Boolean(httpQuery) || Boolean(httpLabel)
|
|
1246
|
+
? 5
|
|
1247
|
+
: undefined
|
|
1248
|
+
: undefined;
|
|
1249
|
+
return bindingFormat ?? settings.timestampFormat.default;
|
|
1250
|
+
}
|
|
1251
|
+
|
|
980
1252
|
class Field {
|
|
981
1253
|
name;
|
|
982
1254
|
kind;
|