@smithy/core 3.14.0 → 3.16.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 +4 -16
- package/dist-cjs/submodules/event-streams/index.js +5 -3
- package/dist-cjs/submodules/protocols/index.js +48 -44
- package/dist-cjs/submodules/schema/index.js +273 -319
- package/dist-cjs/submodules/serde/index.js +126 -34
- package/dist-es/index.js +1 -1
- package/dist-es/submodules/cbor/CborCodec.js +6 -17
- package/dist-es/submodules/event-streams/EventStreamSerde.js +5 -3
- package/dist-es/submodules/protocols/HttpBindingProtocol.js +4 -4
- package/dist-es/submodules/protocols/HttpProtocol.js +6 -5
- package/dist-es/submodules/protocols/RpcProtocol.js +2 -2
- package/dist-es/submodules/protocols/SerdeContext.js +6 -0
- package/dist-es/submodules/protocols/index.js +1 -0
- package/dist-es/submodules/protocols/serde/FromStringShapeDeserializer.js +22 -22
- package/dist-es/submodules/protocols/serde/HttpInterceptingShapeDeserializer.js +3 -2
- package/dist-es/submodules/protocols/serde/ToStringShapeSerializer.js +7 -9
- package/dist-es/submodules/protocols/serde/determineTimestampFormat.js +5 -6
- package/dist-es/submodules/schema/TypeRegistry.js +4 -4
- package/dist-es/submodules/schema/index.js +1 -0
- package/dist-es/submodules/schema/middleware/schemaDeserializationMiddleware.js +5 -1
- package/dist-es/submodules/schema/middleware/schemaSerializationMiddleware.js +5 -1
- package/dist-es/submodules/schema/schemas/NormalizedSchema.js +104 -180
- package/dist-es/submodules/schema/schemas/translateTraits.js +22 -0
- package/dist-es/submodules/serde/index.js +1 -0
- package/dist-es/submodules/serde/schema-serde-lib/schema-date-utils.js +110 -0
- package/dist-es/submodules/serde/value/NumericValue.js +4 -26
- package/dist-types/index.d.ts +1 -1
- package/dist-types/submodules/cbor/CborCodec.d.ts +5 -10
- package/dist-types/submodules/protocols/HttpProtocol.d.ts +5 -2
- package/dist-types/submodules/protocols/SerdeContext.d.ts +8 -0
- package/dist-types/submodules/protocols/index.d.ts +1 -0
- package/dist-types/submodules/protocols/serde/FromStringShapeDeserializer.d.ts +3 -4
- package/dist-types/submodules/protocols/serde/HttpInterceptingShapeDeserializer.d.ts +5 -2
- package/dist-types/submodules/protocols/serde/HttpInterceptingShapeSerializer.d.ts +5 -2
- package/dist-types/submodules/protocols/serde/ToStringShapeSerializer.d.ts +3 -4
- package/dist-types/submodules/schema/TypeRegistry.d.ts +4 -4
- package/dist-types/submodules/schema/index.d.ts +1 -0
- package/dist-types/submodules/schema/schemas/NormalizedSchema.d.ts +26 -24
- package/dist-types/submodules/schema/schemas/sentinels.d.ts +2 -0
- package/dist-types/submodules/schema/schemas/translateTraits.d.ts +7 -0
- package/dist-types/submodules/serde/index.d.ts +1 -0
- package/dist-types/submodules/serde/schema-serde-lib/schema-date-utils.d.ts +47 -0
- package/dist-types/ts3.4/index.d.ts +1 -1
- package/dist-types/ts3.4/submodules/cbor/CborCodec.d.ts +5 -10
- package/dist-types/ts3.4/submodules/protocols/HttpProtocol.d.ts +5 -2
- package/dist-types/ts3.4/submodules/protocols/SerdeContext.d.ts +8 -0
- package/dist-types/ts3.4/submodules/protocols/index.d.ts +1 -0
- package/dist-types/ts3.4/submodules/protocols/serde/FromStringShapeDeserializer.d.ts +3 -4
- package/dist-types/ts3.4/submodules/protocols/serde/HttpInterceptingShapeDeserializer.d.ts +5 -2
- package/dist-types/ts3.4/submodules/protocols/serde/HttpInterceptingShapeSerializer.d.ts +5 -2
- package/dist-types/ts3.4/submodules/protocols/serde/ToStringShapeSerializer.d.ts +3 -4
- package/dist-types/ts3.4/submodules/schema/TypeRegistry.d.ts +4 -4
- package/dist-types/ts3.4/submodules/schema/index.d.ts +1 -0
- package/dist-types/ts3.4/submodules/schema/schemas/NormalizedSchema.d.ts +26 -24
- package/dist-types/ts3.4/submodules/schema/schemas/sentinels.d.ts +2 -0
- package/dist-types/ts3.4/submodules/schema/schemas/translateTraits.d.ts +7 -0
- package/dist-types/ts3.4/submodules/serde/index.d.ts +1 -0
- package/dist-types/ts3.4/submodules/serde/schema-serde-lib/schema-date-utils.d.ts +47 -0
- package/package.json +8 -8
- /package/dist-es/{protocols → request-builder}/requestBuilder.js +0 -0
- /package/dist-types/{protocols → request-builder}/requestBuilder.d.ts +0 -0
- /package/dist-types/ts3.4/{protocols → request-builder}/requestBuilder.d.ts +0 -0
|
@@ -10,103 +10,6 @@ const deref = (schemaRef) => {
|
|
|
10
10
|
return schemaRef;
|
|
11
11
|
};
|
|
12
12
|
|
|
13
|
-
const schemaDeserializationMiddleware = (config) => (next, context) => async (args) => {
|
|
14
|
-
const { response } = await next(args);
|
|
15
|
-
const { operationSchema } = utilMiddleware.getSmithyContext(context);
|
|
16
|
-
try {
|
|
17
|
-
const parsed = await config.protocol.deserializeResponse(operationSchema, {
|
|
18
|
-
...config,
|
|
19
|
-
...context,
|
|
20
|
-
}, response);
|
|
21
|
-
return {
|
|
22
|
-
response,
|
|
23
|
-
output: parsed,
|
|
24
|
-
};
|
|
25
|
-
}
|
|
26
|
-
catch (error) {
|
|
27
|
-
Object.defineProperty(error, "$response", {
|
|
28
|
-
value: response,
|
|
29
|
-
});
|
|
30
|
-
if (!("$metadata" in error)) {
|
|
31
|
-
const hint = `Deserialization error: to see the raw response, inspect the hidden field {error}.$response on this object.`;
|
|
32
|
-
try {
|
|
33
|
-
error.message += "\n " + hint;
|
|
34
|
-
}
|
|
35
|
-
catch (e) {
|
|
36
|
-
if (!context.logger || context.logger?.constructor?.name === "NoOpLogger") {
|
|
37
|
-
console.warn(hint);
|
|
38
|
-
}
|
|
39
|
-
else {
|
|
40
|
-
context.logger?.warn?.(hint);
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
if (typeof error.$responseBodyText !== "undefined") {
|
|
44
|
-
if (error.$response) {
|
|
45
|
-
error.$response.body = error.$responseBodyText;
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
try {
|
|
49
|
-
if (protocolHttp.HttpResponse.isInstance(response)) {
|
|
50
|
-
const { headers = {} } = response;
|
|
51
|
-
const headerEntries = Object.entries(headers);
|
|
52
|
-
error.$metadata = {
|
|
53
|
-
httpStatusCode: response.statusCode,
|
|
54
|
-
requestId: findHeader(/^x-[\w-]+-request-?id$/, headerEntries),
|
|
55
|
-
extendedRequestId: findHeader(/^x-[\w-]+-id-2$/, headerEntries),
|
|
56
|
-
cfId: findHeader(/^x-[\w-]+-cf-id$/, headerEntries),
|
|
57
|
-
};
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
catch (e) {
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
throw error;
|
|
64
|
-
}
|
|
65
|
-
};
|
|
66
|
-
const findHeader = (pattern, headers) => {
|
|
67
|
-
return (headers.find(([k]) => {
|
|
68
|
-
return k.match(pattern);
|
|
69
|
-
}) || [void 0, void 0])[1];
|
|
70
|
-
};
|
|
71
|
-
|
|
72
|
-
const schemaSerializationMiddleware = (config) => (next, context) => async (args) => {
|
|
73
|
-
const { operationSchema } = utilMiddleware.getSmithyContext(context);
|
|
74
|
-
const endpoint = context.endpointV2?.url && config.urlParser
|
|
75
|
-
? async () => config.urlParser(context.endpointV2.url)
|
|
76
|
-
: config.endpoint;
|
|
77
|
-
const request = await config.protocol.serializeRequest(operationSchema, args.input, {
|
|
78
|
-
...config,
|
|
79
|
-
...context,
|
|
80
|
-
endpoint,
|
|
81
|
-
});
|
|
82
|
-
return next({
|
|
83
|
-
...args,
|
|
84
|
-
request,
|
|
85
|
-
});
|
|
86
|
-
};
|
|
87
|
-
|
|
88
|
-
const deserializerMiddlewareOption = {
|
|
89
|
-
name: "deserializerMiddleware",
|
|
90
|
-
step: "deserialize",
|
|
91
|
-
tags: ["DESERIALIZER"],
|
|
92
|
-
override: true,
|
|
93
|
-
};
|
|
94
|
-
const serializerMiddlewareOption = {
|
|
95
|
-
name: "serializerMiddleware",
|
|
96
|
-
step: "serialize",
|
|
97
|
-
tags: ["SERIALIZER"],
|
|
98
|
-
override: true,
|
|
99
|
-
};
|
|
100
|
-
function getSchemaSerdePlugin(config) {
|
|
101
|
-
return {
|
|
102
|
-
applyToStack: (commandStack) => {
|
|
103
|
-
commandStack.add(schemaSerializationMiddleware(config), serializerMiddlewareOption);
|
|
104
|
-
commandStack.add(schemaDeserializationMiddleware(config), deserializerMiddlewareOption);
|
|
105
|
-
config.protocol.setSerdeContext(config);
|
|
106
|
-
},
|
|
107
|
-
};
|
|
108
|
-
}
|
|
109
|
-
|
|
110
13
|
class TypeRegistry {
|
|
111
14
|
namespace;
|
|
112
15
|
schemas;
|
|
@@ -134,11 +37,11 @@ class TypeRegistry {
|
|
|
134
37
|
}
|
|
135
38
|
return this.schemas.get(id);
|
|
136
39
|
}
|
|
137
|
-
registerError(
|
|
138
|
-
this.exceptions.set(
|
|
40
|
+
registerError(es, ctor) {
|
|
41
|
+
this.exceptions.set(es, ctor);
|
|
139
42
|
}
|
|
140
|
-
getErrorCtor(
|
|
141
|
-
return this.exceptions.get(
|
|
43
|
+
getErrorCtor(es) {
|
|
44
|
+
return this.exceptions.get(es);
|
|
142
45
|
}
|
|
143
46
|
getBaseException() {
|
|
144
47
|
for (const [id, schema] of this.schemas.entries()) {
|
|
@@ -188,6 +91,36 @@ class Schema {
|
|
|
188
91
|
}
|
|
189
92
|
}
|
|
190
93
|
|
|
94
|
+
class StructureSchema extends Schema {
|
|
95
|
+
static symbol = Symbol.for("@smithy/str");
|
|
96
|
+
name;
|
|
97
|
+
traits;
|
|
98
|
+
memberNames;
|
|
99
|
+
memberList;
|
|
100
|
+
symbol = StructureSchema.symbol;
|
|
101
|
+
}
|
|
102
|
+
const struct = (namespace, name, traits, memberNames, memberList) => Schema.assign(new StructureSchema(), {
|
|
103
|
+
name,
|
|
104
|
+
namespace,
|
|
105
|
+
traits,
|
|
106
|
+
memberNames,
|
|
107
|
+
memberList,
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
class ErrorSchema extends StructureSchema {
|
|
111
|
+
static symbol = Symbol.for("@smithy/err");
|
|
112
|
+
ctor;
|
|
113
|
+
symbol = ErrorSchema.symbol;
|
|
114
|
+
}
|
|
115
|
+
const error = (namespace, name, traits, memberNames, memberList, ctor) => Schema.assign(new ErrorSchema(), {
|
|
116
|
+
name,
|
|
117
|
+
namespace,
|
|
118
|
+
traits,
|
|
119
|
+
memberNames,
|
|
120
|
+
memberList,
|
|
121
|
+
ctor: null,
|
|
122
|
+
});
|
|
123
|
+
|
|
191
124
|
class ListSchema extends Schema {
|
|
192
125
|
static symbol = Symbol.for("@smithy/lis");
|
|
193
126
|
name;
|
|
@@ -234,53 +167,6 @@ const op = (namespace, name, traits, input, output) => Schema.assign(new Operati
|
|
|
234
167
|
output,
|
|
235
168
|
});
|
|
236
169
|
|
|
237
|
-
class StructureSchema extends Schema {
|
|
238
|
-
static symbol = Symbol.for("@smithy/str");
|
|
239
|
-
name;
|
|
240
|
-
traits;
|
|
241
|
-
memberNames;
|
|
242
|
-
memberList;
|
|
243
|
-
symbol = StructureSchema.symbol;
|
|
244
|
-
}
|
|
245
|
-
const struct = (namespace, name, traits, memberNames, memberList) => Schema.assign(new StructureSchema(), {
|
|
246
|
-
name,
|
|
247
|
-
namespace,
|
|
248
|
-
traits,
|
|
249
|
-
memberNames,
|
|
250
|
-
memberList,
|
|
251
|
-
});
|
|
252
|
-
|
|
253
|
-
class ErrorSchema extends StructureSchema {
|
|
254
|
-
static symbol = Symbol.for("@smithy/err");
|
|
255
|
-
ctor;
|
|
256
|
-
symbol = ErrorSchema.symbol;
|
|
257
|
-
}
|
|
258
|
-
const error = (namespace, name, traits, memberNames, memberList, ctor) => Schema.assign(new ErrorSchema(), {
|
|
259
|
-
name,
|
|
260
|
-
namespace,
|
|
261
|
-
traits,
|
|
262
|
-
memberNames,
|
|
263
|
-
memberList,
|
|
264
|
-
ctor: null,
|
|
265
|
-
});
|
|
266
|
-
|
|
267
|
-
const SCHEMA = {
|
|
268
|
-
BLOB: 0b0001_0101,
|
|
269
|
-
STREAMING_BLOB: 0b0010_1010,
|
|
270
|
-
BOOLEAN: 0b0000_0010,
|
|
271
|
-
STRING: 0b0000_0000,
|
|
272
|
-
NUMERIC: 0b0000_0001,
|
|
273
|
-
BIG_INTEGER: 0b0001_0001,
|
|
274
|
-
BIG_DECIMAL: 0b0001_0011,
|
|
275
|
-
DOCUMENT: 0b0000_1111,
|
|
276
|
-
TIMESTAMP_DEFAULT: 0b0000_0100,
|
|
277
|
-
TIMESTAMP_DATE_TIME: 0b0000_0101,
|
|
278
|
-
TIMESTAMP_HTTP_DATE: 0b0000_0110,
|
|
279
|
-
TIMESTAMP_EPOCH_SECONDS: 0b0000_0111,
|
|
280
|
-
LIST_MODIFIER: 0b0100_0000,
|
|
281
|
-
MAP_MODIFIER: 0b1000_0000,
|
|
282
|
-
};
|
|
283
|
-
|
|
284
170
|
class SimpleSchema extends Schema {
|
|
285
171
|
static symbol = Symbol.for("@smithy/sim");
|
|
286
172
|
name;
|
|
@@ -295,6 +181,29 @@ const sim = (namespace, name, schemaRef, traits) => Schema.assign(new SimpleSche
|
|
|
295
181
|
schemaRef,
|
|
296
182
|
});
|
|
297
183
|
|
|
184
|
+
function translateTraits(indicator) {
|
|
185
|
+
if (typeof indicator === "object") {
|
|
186
|
+
return indicator;
|
|
187
|
+
}
|
|
188
|
+
indicator = indicator | 0;
|
|
189
|
+
const traits = {};
|
|
190
|
+
let i = 0;
|
|
191
|
+
for (const trait of [
|
|
192
|
+
"httpLabel",
|
|
193
|
+
"idempotent",
|
|
194
|
+
"idempotencyToken",
|
|
195
|
+
"sensitive",
|
|
196
|
+
"httpPayload",
|
|
197
|
+
"httpResponseCode",
|
|
198
|
+
"httpQueryParams",
|
|
199
|
+
]) {
|
|
200
|
+
if (((indicator >> i++) & 1) === 1) {
|
|
201
|
+
traits[trait] = 1;
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
return traits;
|
|
205
|
+
}
|
|
206
|
+
|
|
298
207
|
class NormalizedSchema {
|
|
299
208
|
ref;
|
|
300
209
|
memberName;
|
|
@@ -313,17 +222,19 @@ class NormalizedSchema {
|
|
|
313
222
|
let _ref = ref;
|
|
314
223
|
let schema = ref;
|
|
315
224
|
this._isMemberSchema = false;
|
|
316
|
-
while (
|
|
225
|
+
while (isMemberSchema(_ref)) {
|
|
317
226
|
traitStack.push(_ref[1]);
|
|
318
227
|
_ref = _ref[0];
|
|
319
228
|
schema = deref(_ref);
|
|
320
229
|
this._isMemberSchema = true;
|
|
321
230
|
}
|
|
231
|
+
if (isStaticSchema(schema))
|
|
232
|
+
schema = hydrate(schema);
|
|
322
233
|
if (traitStack.length > 0) {
|
|
323
234
|
this.memberTraits = {};
|
|
324
235
|
for (let i = traitStack.length - 1; i >= 0; --i) {
|
|
325
236
|
const traitSet = traitStack[i];
|
|
326
|
-
Object.assign(this.memberTraits,
|
|
237
|
+
Object.assign(this.memberTraits, translateTraits(traitSet));
|
|
327
238
|
}
|
|
328
239
|
}
|
|
329
240
|
else {
|
|
@@ -344,8 +255,7 @@ class NormalizedSchema {
|
|
|
344
255
|
else {
|
|
345
256
|
this.traits = 0;
|
|
346
257
|
}
|
|
347
|
-
this.name =
|
|
348
|
-
(this.schema instanceof Schema ? this.schema.getName?.() : void 0) ?? this.memberName ?? this.getSchemaName();
|
|
258
|
+
this.name = (this.schema instanceof Schema ? this.schema.getName?.() : void 0) ?? this.memberName ?? String(schema);
|
|
349
259
|
if (this._isMemberSchema && !memberName) {
|
|
350
260
|
throw new Error(`@smithy/core/schema - NormalizedSchema member init ${this.getName(true)} missing member name.`);
|
|
351
261
|
}
|
|
@@ -354,138 +264,90 @@ class NormalizedSchema {
|
|
|
354
264
|
return Schema[Symbol.hasInstance].bind(this)(lhs);
|
|
355
265
|
}
|
|
356
266
|
static of(ref) {
|
|
357
|
-
|
|
358
|
-
|
|
267
|
+
const sc = deref(ref);
|
|
268
|
+
if (sc instanceof NormalizedSchema) {
|
|
269
|
+
return sc;
|
|
359
270
|
}
|
|
360
|
-
if (
|
|
361
|
-
const [ns, traits] =
|
|
271
|
+
if (isMemberSchema(sc)) {
|
|
272
|
+
const [ns, traits] = sc;
|
|
362
273
|
if (ns instanceof NormalizedSchema) {
|
|
363
|
-
Object.assign(ns.getMergedTraits(),
|
|
274
|
+
Object.assign(ns.getMergedTraits(), translateTraits(traits));
|
|
364
275
|
return ns;
|
|
365
276
|
}
|
|
366
277
|
throw new Error(`@smithy/core/schema - may not init unwrapped member schema=${JSON.stringify(ref, null, 2)}.`);
|
|
367
278
|
}
|
|
368
|
-
return new NormalizedSchema(
|
|
369
|
-
}
|
|
370
|
-
static translateTraits(indicator) {
|
|
371
|
-
if (typeof indicator === "object") {
|
|
372
|
-
return indicator;
|
|
373
|
-
}
|
|
374
|
-
indicator = indicator | 0;
|
|
375
|
-
const traits = {};
|
|
376
|
-
let i = 0;
|
|
377
|
-
for (const trait of [
|
|
378
|
-
"httpLabel",
|
|
379
|
-
"idempotent",
|
|
380
|
-
"idempotencyToken",
|
|
381
|
-
"sensitive",
|
|
382
|
-
"httpPayload",
|
|
383
|
-
"httpResponseCode",
|
|
384
|
-
"httpQueryParams",
|
|
385
|
-
]) {
|
|
386
|
-
if (((indicator >> i++) & 1) === 1) {
|
|
387
|
-
traits[trait] = 1;
|
|
388
|
-
}
|
|
389
|
-
}
|
|
390
|
-
return traits;
|
|
279
|
+
return new NormalizedSchema(sc);
|
|
391
280
|
}
|
|
392
281
|
getSchema() {
|
|
393
|
-
|
|
394
|
-
Object.assign(this, { schema: this.schema.getSchema() });
|
|
395
|
-
return this.schema;
|
|
396
|
-
}
|
|
397
|
-
if (this.schema instanceof SimpleSchema) {
|
|
398
|
-
return deref(this.schema.schemaRef);
|
|
399
|
-
}
|
|
400
|
-
return deref(this.schema);
|
|
282
|
+
return deref(this.schema?.schemaRef ?? this.schema);
|
|
401
283
|
}
|
|
402
284
|
getName(withNamespace = false) {
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
}
|
|
407
|
-
}
|
|
408
|
-
return this.name || undefined;
|
|
285
|
+
const { name } = this;
|
|
286
|
+
const short = !withNamespace && name && name.includes("#");
|
|
287
|
+
return short ? name.split("#")[1] : name || undefined;
|
|
409
288
|
}
|
|
410
289
|
getMemberName() {
|
|
411
|
-
if (!this.isMemberSchema()) {
|
|
412
|
-
throw new Error(`@smithy/core/schema - non-member schema: ${this.getName(true)}`);
|
|
413
|
-
}
|
|
414
290
|
return this.memberName;
|
|
415
291
|
}
|
|
416
292
|
isMemberSchema() {
|
|
417
293
|
return this._isMemberSchema;
|
|
418
294
|
}
|
|
419
|
-
isUnitSchema() {
|
|
420
|
-
return this.getSchema() === "unit";
|
|
421
|
-
}
|
|
422
295
|
isListSchema() {
|
|
423
|
-
const
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
return inner instanceof ListSchema;
|
|
296
|
+
const sc = this.getSchema();
|
|
297
|
+
return typeof sc === "number"
|
|
298
|
+
? sc >= 64 && sc < 128
|
|
299
|
+
: sc instanceof ListSchema;
|
|
428
300
|
}
|
|
429
301
|
isMapSchema() {
|
|
430
|
-
const
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
return inner instanceof MapSchema;
|
|
302
|
+
const sc = this.getSchema();
|
|
303
|
+
return typeof sc === "number"
|
|
304
|
+
? sc >= 128 && sc <= 0b1111_1111
|
|
305
|
+
: sc instanceof MapSchema;
|
|
435
306
|
}
|
|
436
307
|
isStructSchema() {
|
|
437
|
-
const
|
|
438
|
-
return (
|
|
308
|
+
const sc = this.getSchema();
|
|
309
|
+
return (sc !== null && typeof sc === "object" && "members" in sc) || sc instanceof StructureSchema;
|
|
439
310
|
}
|
|
440
311
|
isBlobSchema() {
|
|
441
|
-
|
|
312
|
+
const sc = this.getSchema();
|
|
313
|
+
return sc === 21 || sc === 42;
|
|
442
314
|
}
|
|
443
315
|
isTimestampSchema() {
|
|
444
|
-
const
|
|
445
|
-
return typeof
|
|
316
|
+
const sc = this.getSchema();
|
|
317
|
+
return (typeof sc === "number" &&
|
|
318
|
+
sc >= 4 &&
|
|
319
|
+
sc <= 7);
|
|
320
|
+
}
|
|
321
|
+
isUnitSchema() {
|
|
322
|
+
return this.getSchema() === "unit";
|
|
446
323
|
}
|
|
447
324
|
isDocumentSchema() {
|
|
448
|
-
return this.getSchema() ===
|
|
325
|
+
return this.getSchema() === 15;
|
|
449
326
|
}
|
|
450
327
|
isStringSchema() {
|
|
451
|
-
return this.getSchema() ===
|
|
328
|
+
return this.getSchema() === 0;
|
|
452
329
|
}
|
|
453
330
|
isBooleanSchema() {
|
|
454
|
-
return this.getSchema() ===
|
|
331
|
+
return this.getSchema() === 2;
|
|
455
332
|
}
|
|
456
333
|
isNumericSchema() {
|
|
457
|
-
return this.getSchema() ===
|
|
334
|
+
return this.getSchema() === 1;
|
|
458
335
|
}
|
|
459
336
|
isBigIntegerSchema() {
|
|
460
|
-
return this.getSchema() ===
|
|
337
|
+
return this.getSchema() === 17;
|
|
461
338
|
}
|
|
462
339
|
isBigDecimalSchema() {
|
|
463
|
-
return this.getSchema() ===
|
|
340
|
+
return this.getSchema() === 19;
|
|
464
341
|
}
|
|
465
342
|
isStreaming() {
|
|
466
|
-
const streaming =
|
|
467
|
-
|
|
468
|
-
return true;
|
|
469
|
-
}
|
|
470
|
-
return this.getSchema() === SCHEMA.STREAMING_BLOB;
|
|
343
|
+
const { streaming } = this.getMergedTraits();
|
|
344
|
+
return !!streaming || this.getSchema() === 42;
|
|
471
345
|
}
|
|
472
346
|
isIdempotencyToken() {
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
}
|
|
476
|
-
|
|
477
|
-
if (typeof traits === "number") {
|
|
478
|
-
if ((traits & 0b0100) === 0b0100) {
|
|
479
|
-
return true;
|
|
480
|
-
}
|
|
481
|
-
}
|
|
482
|
-
else if (typeof traits === "object") {
|
|
483
|
-
if (!!traits.idempotencyToken) {
|
|
484
|
-
return true;
|
|
485
|
-
}
|
|
486
|
-
}
|
|
487
|
-
}
|
|
488
|
-
return false;
|
|
347
|
+
const match = (traits) => (traits & 0b0100) === 0b0100 ||
|
|
348
|
+
!!traits?.idempotencyToken;
|
|
349
|
+
const { normalizedTraits, traits, memberTraits } = this;
|
|
350
|
+
return match(normalizedTraits) || match(traits) || match(memberTraits);
|
|
489
351
|
}
|
|
490
352
|
getMergedTraits() {
|
|
491
353
|
return (this.normalizedTraits ??
|
|
@@ -495,74 +357,48 @@ class NormalizedSchema {
|
|
|
495
357
|
}));
|
|
496
358
|
}
|
|
497
359
|
getMemberTraits() {
|
|
498
|
-
return
|
|
360
|
+
return translateTraits(this.memberTraits);
|
|
499
361
|
}
|
|
500
362
|
getOwnTraits() {
|
|
501
|
-
return
|
|
363
|
+
return translateTraits(this.traits);
|
|
502
364
|
}
|
|
503
365
|
getKeySchema() {
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
}
|
|
507
|
-
if (!this.isMapSchema()) {
|
|
366
|
+
const [isDoc, isMap] = [this.isDocumentSchema(), this.isMapSchema()];
|
|
367
|
+
if (!isDoc && !isMap) {
|
|
508
368
|
throw new Error(`@smithy/core/schema - cannot get key for non-map: ${this.getName(true)}`);
|
|
509
369
|
}
|
|
510
370
|
const schema = this.getSchema();
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
return
|
|
371
|
+
const memberSchema = isDoc
|
|
372
|
+
? 15
|
|
373
|
+
: schema?.keySchema ?? 0;
|
|
374
|
+
return member([memberSchema, 0], "key");
|
|
515
375
|
}
|
|
516
376
|
getValueSchema() {
|
|
517
|
-
const
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
if (
|
|
527
|
-
|
|
528
|
-
throw new Error(`may not getValueSchema() on structure ${this.getName(true)}`);
|
|
529
|
-
}
|
|
530
|
-
const collection = schema;
|
|
531
|
-
if ("valueSchema" in collection) {
|
|
532
|
-
if (this.isMapSchema()) {
|
|
533
|
-
return this.memberFrom([collection.valueSchema, 0], "value");
|
|
534
|
-
}
|
|
535
|
-
else if (this.isListSchema()) {
|
|
536
|
-
return this.memberFrom([collection.valueSchema, 0], "member");
|
|
537
|
-
}
|
|
538
|
-
}
|
|
539
|
-
}
|
|
540
|
-
if (this.isDocumentSchema()) {
|
|
541
|
-
return this.memberFrom([SCHEMA.DOCUMENT, 0], "value");
|
|
377
|
+
const sc = this.getSchema();
|
|
378
|
+
const [isDoc, isMap, isList] = [this.isDocumentSchema(), this.isMapSchema(), this.isListSchema()];
|
|
379
|
+
const memberSchema = typeof sc === "number"
|
|
380
|
+
? 0b0011_1111 & sc
|
|
381
|
+
: sc && typeof sc === "object" && (isMap || isList)
|
|
382
|
+
? sc.valueSchema
|
|
383
|
+
: isDoc
|
|
384
|
+
? 15
|
|
385
|
+
: void 0;
|
|
386
|
+
if (memberSchema != null) {
|
|
387
|
+
return member([memberSchema, 0], isMap ? "value" : "member");
|
|
542
388
|
}
|
|
543
389
|
throw new Error(`@smithy/core/schema - ${this.getName(true)} has no value member.`);
|
|
544
390
|
}
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
}
|
|
550
|
-
return false;
|
|
551
|
-
}
|
|
552
|
-
getMemberSchema(member) {
|
|
553
|
-
if (this.isStructSchema()) {
|
|
554
|
-
const struct = this.getSchema();
|
|
555
|
-
if (!struct.memberNames.includes(member)) {
|
|
556
|
-
throw new Error(`@smithy/core/schema - ${this.getName(true)} has no member=${member}.`);
|
|
557
|
-
}
|
|
558
|
-
const i = struct.memberNames.indexOf(member);
|
|
391
|
+
getMemberSchema(memberName) {
|
|
392
|
+
const struct = this.getSchema();
|
|
393
|
+
if (this.isStructSchema() && struct.memberNames.includes(memberName)) {
|
|
394
|
+
const i = struct.memberNames.indexOf(memberName);
|
|
559
395
|
const memberSchema = struct.memberList[i];
|
|
560
|
-
return
|
|
396
|
+
return member(isMemberSchema(memberSchema) ? memberSchema : [memberSchema, 0], memberName);
|
|
561
397
|
}
|
|
562
398
|
if (this.isDocumentSchema()) {
|
|
563
|
-
return
|
|
399
|
+
return member([15, 0], memberName);
|
|
564
400
|
}
|
|
565
|
-
throw new Error(`@smithy/core/schema - ${this.getName(true)} has no
|
|
401
|
+
throw new Error(`@smithy/core/schema - ${this.getName(true)} has no no member=${memberName}.`);
|
|
566
402
|
}
|
|
567
403
|
getMemberSchemas() {
|
|
568
404
|
const buffer = {};
|
|
@@ -593,39 +429,154 @@ class NormalizedSchema {
|
|
|
593
429
|
}
|
|
594
430
|
const struct = this.getSchema();
|
|
595
431
|
for (let i = 0; i < struct.memberNames.length; ++i) {
|
|
596
|
-
yield [struct.memberNames[i],
|
|
432
|
+
yield [struct.memberNames[i], member([struct.memberList[i], 0], struct.memberNames[i])];
|
|
597
433
|
}
|
|
598
434
|
}
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
}
|
|
606
|
-
return new NormalizedSchema(memberSchema, memberName);
|
|
435
|
+
}
|
|
436
|
+
function member(memberSchema, memberName) {
|
|
437
|
+
if (memberSchema instanceof NormalizedSchema) {
|
|
438
|
+
return Object.assign(memberSchema, {
|
|
439
|
+
memberName,
|
|
440
|
+
_isMemberSchema: true,
|
|
441
|
+
});
|
|
607
442
|
}
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
443
|
+
const internalCtorAccess = NormalizedSchema;
|
|
444
|
+
return new internalCtorAccess(memberSchema, memberName);
|
|
445
|
+
}
|
|
446
|
+
function hydrate(ss) {
|
|
447
|
+
const [id, ...rest] = ss;
|
|
448
|
+
return {
|
|
449
|
+
[0]: sim,
|
|
450
|
+
[1]: list,
|
|
451
|
+
[2]: map,
|
|
452
|
+
[3]: struct,
|
|
453
|
+
[-3]: error,
|
|
454
|
+
[9]: op,
|
|
455
|
+
}[id].call(null, ...rest);
|
|
456
|
+
}
|
|
457
|
+
const isMemberSchema = (sc) => Array.isArray(sc) && sc.length === 2;
|
|
458
|
+
const isStaticSchema = (sc) => Array.isArray(sc) && sc.length >= 5;
|
|
459
|
+
|
|
460
|
+
const schemaDeserializationMiddleware = (config) => (next, context) => async (args) => {
|
|
461
|
+
const { response } = await next(args);
|
|
462
|
+
let { operationSchema } = utilMiddleware.getSmithyContext(context);
|
|
463
|
+
if (isStaticSchema(operationSchema)) {
|
|
464
|
+
operationSchema = hydrate(operationSchema);
|
|
465
|
+
}
|
|
466
|
+
try {
|
|
467
|
+
const parsed = await config.protocol.deserializeResponse(operationSchema, {
|
|
468
|
+
...config,
|
|
469
|
+
...context,
|
|
470
|
+
}, response);
|
|
471
|
+
return {
|
|
472
|
+
response,
|
|
473
|
+
output: parsed,
|
|
474
|
+
};
|
|
475
|
+
}
|
|
476
|
+
catch (error) {
|
|
477
|
+
Object.defineProperty(error, "$response", {
|
|
478
|
+
value: response,
|
|
479
|
+
});
|
|
480
|
+
if (!("$metadata" in error)) {
|
|
481
|
+
const hint = `Deserialization error: to see the raw response, inspect the hidden field {error}.$response on this object.`;
|
|
482
|
+
try {
|
|
483
|
+
error.message += "\n " + hint;
|
|
484
|
+
}
|
|
485
|
+
catch (e) {
|
|
486
|
+
if (!context.logger || context.logger?.constructor?.name === "NoOpLogger") {
|
|
487
|
+
console.warn(hint);
|
|
488
|
+
}
|
|
489
|
+
else {
|
|
490
|
+
context.logger?.warn?.(hint);
|
|
491
|
+
}
|
|
492
|
+
}
|
|
493
|
+
if (typeof error.$responseBodyText !== "undefined") {
|
|
494
|
+
if (error.$response) {
|
|
495
|
+
error.$response.body = error.$responseBodyText;
|
|
496
|
+
}
|
|
497
|
+
}
|
|
498
|
+
try {
|
|
499
|
+
if (protocolHttp.HttpResponse.isInstance(response)) {
|
|
500
|
+
const { headers = {} } = response;
|
|
501
|
+
const headerEntries = Object.entries(headers);
|
|
502
|
+
error.$metadata = {
|
|
503
|
+
httpStatusCode: response.statusCode,
|
|
504
|
+
requestId: findHeader(/^x-[\w-]+-request-?id$/, headerEntries),
|
|
505
|
+
extendedRequestId: findHeader(/^x-[\w-]+-id-2$/, headerEntries),
|
|
506
|
+
cfId: findHeader(/^x-[\w-]+-cf-id$/, headerEntries),
|
|
507
|
+
};
|
|
508
|
+
}
|
|
509
|
+
}
|
|
510
|
+
catch (e) {
|
|
623
511
|
}
|
|
624
512
|
}
|
|
625
|
-
|
|
513
|
+
throw error;
|
|
514
|
+
}
|
|
515
|
+
};
|
|
516
|
+
const findHeader = (pattern, headers) => {
|
|
517
|
+
return (headers.find(([k]) => {
|
|
518
|
+
return k.match(pattern);
|
|
519
|
+
}) || [void 0, void 0])[1];
|
|
520
|
+
};
|
|
521
|
+
|
|
522
|
+
const schemaSerializationMiddleware = (config) => (next, context) => async (args) => {
|
|
523
|
+
let { operationSchema } = utilMiddleware.getSmithyContext(context);
|
|
524
|
+
if (isStaticSchema(operationSchema)) {
|
|
525
|
+
operationSchema = hydrate(operationSchema);
|
|
626
526
|
}
|
|
527
|
+
const endpoint = context.endpointV2?.url && config.urlParser
|
|
528
|
+
? async () => config.urlParser(context.endpointV2.url)
|
|
529
|
+
: config.endpoint;
|
|
530
|
+
const request = await config.protocol.serializeRequest(operationSchema, args.input, {
|
|
531
|
+
...config,
|
|
532
|
+
...context,
|
|
533
|
+
endpoint,
|
|
534
|
+
});
|
|
535
|
+
return next({
|
|
536
|
+
...args,
|
|
537
|
+
request,
|
|
538
|
+
});
|
|
539
|
+
};
|
|
540
|
+
|
|
541
|
+
const deserializerMiddlewareOption = {
|
|
542
|
+
name: "deserializerMiddleware",
|
|
543
|
+
step: "deserialize",
|
|
544
|
+
tags: ["DESERIALIZER"],
|
|
545
|
+
override: true,
|
|
546
|
+
};
|
|
547
|
+
const serializerMiddlewareOption = {
|
|
548
|
+
name: "serializerMiddleware",
|
|
549
|
+
step: "serialize",
|
|
550
|
+
tags: ["SERIALIZER"],
|
|
551
|
+
override: true,
|
|
552
|
+
};
|
|
553
|
+
function getSchemaSerdePlugin(config) {
|
|
554
|
+
return {
|
|
555
|
+
applyToStack: (commandStack) => {
|
|
556
|
+
commandStack.add(schemaSerializationMiddleware(config), serializerMiddlewareOption);
|
|
557
|
+
commandStack.add(schemaDeserializationMiddleware(config), deserializerMiddlewareOption);
|
|
558
|
+
config.protocol.setSerdeContext(config);
|
|
559
|
+
},
|
|
560
|
+
};
|
|
627
561
|
}
|
|
628
562
|
|
|
563
|
+
const SCHEMA = {
|
|
564
|
+
BLOB: 0b0001_0101,
|
|
565
|
+
STREAMING_BLOB: 0b0010_1010,
|
|
566
|
+
BOOLEAN: 0b0000_0010,
|
|
567
|
+
STRING: 0b0000_0000,
|
|
568
|
+
NUMERIC: 0b0000_0001,
|
|
569
|
+
BIG_INTEGER: 0b0001_0001,
|
|
570
|
+
BIG_DECIMAL: 0b0001_0011,
|
|
571
|
+
DOCUMENT: 0b0000_1111,
|
|
572
|
+
TIMESTAMP_DEFAULT: 0b0000_0100,
|
|
573
|
+
TIMESTAMP_DATE_TIME: 0b0000_0101,
|
|
574
|
+
TIMESTAMP_HTTP_DATE: 0b0000_0110,
|
|
575
|
+
TIMESTAMP_EPOCH_SECONDS: 0b0000_0111,
|
|
576
|
+
LIST_MODIFIER: 0b0100_0000,
|
|
577
|
+
MAP_MODIFIER: 0b1000_0000,
|
|
578
|
+
};
|
|
579
|
+
|
|
629
580
|
exports.ErrorSchema = ErrorSchema;
|
|
630
581
|
exports.ListSchema = ListSchema;
|
|
631
582
|
exports.MapSchema = MapSchema;
|
|
@@ -640,9 +591,12 @@ exports.deref = deref;
|
|
|
640
591
|
exports.deserializerMiddlewareOption = deserializerMiddlewareOption;
|
|
641
592
|
exports.error = error;
|
|
642
593
|
exports.getSchemaSerdePlugin = getSchemaSerdePlugin;
|
|
594
|
+
exports.hydrate = hydrate;
|
|
595
|
+
exports.isStaticSchema = isStaticSchema;
|
|
643
596
|
exports.list = list;
|
|
644
597
|
exports.map = map;
|
|
645
598
|
exports.op = op;
|
|
646
599
|
exports.serializerMiddlewareOption = serializerMiddlewareOption;
|
|
647
600
|
exports.sim = sim;
|
|
648
601
|
exports.struct = struct;
|
|
602
|
+
exports.translateTraits = translateTraits;
|