@cdk8s/awscdk-resolver 0.0.347 → 0.0.349
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/.jsii +3 -3
- package/lib/resolve.js +1 -1
- package/node_modules/@aws-sdk/client-cloudformation/package.json +6 -6
- package/node_modules/@aws-sdk/client-sso/package.json +5 -5
- package/node_modules/@aws-sdk/core/dist-cjs/submodules/protocols/index.js +81 -48
- package/node_modules/@aws-sdk/core/dist-es/submodules/protocols/json/AwsJsonRpcProtocol.js +12 -8
- package/node_modules/@aws-sdk/core/dist-es/submodules/protocols/json/AwsRestJsonProtocol.js +12 -8
- package/node_modules/@aws-sdk/core/dist-es/submodules/protocols/query/AwsQueryProtocol.js +14 -10
- package/node_modules/@aws-sdk/core/dist-es/submodules/protocols/xml/AwsRestXmlProtocol.js +12 -15
- package/node_modules/@aws-sdk/core/dist-es/submodules/protocols/xml/XmlShapeSerializer.js +3 -3
- package/node_modules/@aws-sdk/core/package.json +1 -1
- package/node_modules/@aws-sdk/credential-provider-env/package.json +2 -2
- package/node_modules/@aws-sdk/credential-provider-http/package.json +2 -2
- package/node_modules/@aws-sdk/credential-provider-ini/package.json +8 -8
- package/node_modules/@aws-sdk/credential-provider-node/package.json +7 -7
- package/node_modules/@aws-sdk/credential-provider-process/package.json +2 -2
- package/node_modules/@aws-sdk/credential-provider-sso/package.json +4 -4
- package/node_modules/@aws-sdk/credential-provider-web-identity/package.json +3 -3
- package/node_modules/@aws-sdk/middleware-logger/dist-types/loggerMiddleware.d.ts +1 -1
- package/node_modules/@aws-sdk/middleware-logger/package.json +1 -1
- package/node_modules/@aws-sdk/middleware-user-agent/package.json +2 -2
- package/node_modules/@aws-sdk/nested-clients/package.json +5 -5
- package/node_modules/@aws-sdk/token-providers/package.json +3 -3
- package/node_modules/@aws-sdk/util-user-agent-node/package.json +2 -2
- package/node_modules/@smithy/core/dist-cjs/submodules/cbor/index.js +44 -15
- package/node_modules/@smithy/core/dist-cjs/submodules/event-streams/index.js +261 -0
- package/node_modules/@smithy/core/dist-cjs/submodules/protocols/index.js +129 -39
- package/node_modules/@smithy/core/dist-cjs/submodules/schema/index.js +25 -0
- package/node_modules/@smithy/core/dist-es/submodules/cbor/SmithyRpcV2CborProtocol.js +36 -15
- package/node_modules/@smithy/core/dist-es/submodules/event-streams/EventStreamSerde.js +200 -0
- package/node_modules/@smithy/core/dist-es/submodules/event-streams/index.js +1 -0
- package/node_modules/@smithy/core/dist-es/submodules/protocols/HttpBindingProtocol.js +11 -26
- package/node_modules/@smithy/core/dist-es/submodules/protocols/HttpProtocol.js +36 -0
- package/node_modules/@smithy/core/dist-es/submodules/protocols/RpcProtocol.js +36 -10
- package/node_modules/@smithy/core/dist-es/submodules/protocols/index.js +1 -0
- package/node_modules/@smithy/core/dist-es/submodules/schema/schemas/NormalizedSchema.js +17 -0
- package/node_modules/@smithy/core/dist-types/submodules/cbor/CborCodec.d.ts +6 -2
- package/node_modules/@smithy/core/dist-types/submodules/cbor/SmithyRpcV2CborProtocol.d.ts +1 -0
- package/node_modules/@smithy/core/dist-types/submodules/cbor/parseCborBody.d.ts +1 -1
- package/node_modules/@smithy/core/dist-types/submodules/event-streams/EventStreamSerde.d.ts +60 -0
- package/node_modules/@smithy/core/dist-types/submodules/event-streams/index.d.ts +1 -0
- package/node_modules/@smithy/core/dist-types/submodules/protocols/HttpBindingProtocol.d.ts +1 -1
- package/node_modules/@smithy/core/dist-types/submodules/protocols/HttpProtocol.d.ts +39 -1
- package/node_modules/@smithy/core/dist-types/submodules/protocols/RpcProtocol.d.ts +1 -1
- package/node_modules/@smithy/core/dist-types/submodules/protocols/index.d.ts +1 -0
- package/node_modules/@smithy/core/dist-types/submodules/protocols/serde/FromStringShapeDeserializer.d.ts +1 -1
- package/node_modules/@smithy/core/dist-types/submodules/protocols/serde/HttpInterceptingShapeDeserializer.d.ts +1 -1
- package/node_modules/@smithy/core/dist-types/submodules/protocols/serde/HttpInterceptingShapeSerializer.d.ts +1 -1
- package/node_modules/@smithy/core/dist-types/submodules/protocols/serde/ToStringShapeSerializer.d.ts +1 -1
- package/node_modules/@smithy/core/dist-types/submodules/protocols/serde/determineTimestampFormat.d.ts +1 -1
- package/node_modules/@smithy/core/dist-types/submodules/schema/middleware/getSchemaSerdePlugin.d.ts +1 -1
- package/node_modules/@smithy/core/dist-types/submodules/schema/middleware/schemaDeserializationMiddleware.d.ts +1 -1
- package/node_modules/@smithy/core/dist-types/submodules/schema/schemas/NormalizedSchema.d.ts +10 -0
- package/node_modules/@smithy/core/dist-types/submodules/schema/schemas/SimpleSchema.d.ts +1 -1
- package/node_modules/@smithy/core/dist-types/submodules/schema/schemas/sentinels.d.ts +1 -1
- package/node_modules/@smithy/core/dist-types/submodules/serde/copyDocumentWithTransform.d.ts +1 -1
- package/node_modules/@smithy/core/dist-types/ts3.4/submodules/cbor/CborCodec.d.ts +5 -1
- package/node_modules/@smithy/core/dist-types/ts3.4/submodules/cbor/SmithyRpcV2CborProtocol.d.ts +1 -0
- package/node_modules/@smithy/core/dist-types/ts3.4/submodules/event-streams/EventStreamSerde.d.ts +60 -0
- package/node_modules/@smithy/core/dist-types/ts3.4/submodules/event-streams/index.d.ts +1 -0
- package/node_modules/@smithy/core/dist-types/ts3.4/submodules/protocols/HttpProtocol.d.ts +39 -1
- package/node_modules/@smithy/core/dist-types/ts3.4/submodules/protocols/index.d.ts +1 -0
- package/node_modules/@smithy/core/dist-types/ts3.4/submodules/protocols/serde/determineTimestampFormat.d.ts +1 -1
- package/node_modules/@smithy/core/dist-types/ts3.4/submodules/schema/schemas/NormalizedSchema.d.ts +10 -0
- package/node_modules/@smithy/core/event-streams.d.ts +7 -0
- package/node_modules/@smithy/core/event-streams.js +6 -0
- package/node_modules/@smithy/core/package.json +11 -1
- package/node_modules/@smithy/middleware-endpoint/package.json +2 -2
- package/node_modules/@smithy/middleware-retry/package.json +4 -4
- package/node_modules/@smithy/smithy-client/dist-cjs/index.js +43 -6
- package/node_modules/@smithy/smithy-client/dist-cjs/schemaLogFilter.js +1 -0
- package/node_modules/@smithy/smithy-client/dist-es/command.js +7 -4
- package/node_modules/@smithy/smithy-client/dist-es/schemaLogFilter.js +34 -0
- package/node_modules/@smithy/smithy-client/dist-types/schemaLogFilter.d.ts +9 -0
- package/node_modules/@smithy/smithy-client/dist-types/ts3.4/schemaLogFilter.d.ts +9 -0
- package/node_modules/@smithy/smithy-client/package.json +3 -3
- package/node_modules/@smithy/util-defaults-mode-browser/package.json +2 -2
- package/node_modules/@smithy/util-defaults-mode-node/package.json +2 -2
- package/package.json +5 -5
@@ -1,6 +1,8 @@
|
|
1
|
+
var __create = Object.create;
|
1
2
|
var __defProp = Object.defineProperty;
|
2
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
3
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
4
6
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
5
7
|
var __export = (target, all) => {
|
6
8
|
for (var name in all)
|
@@ -14,6 +16,14 @@ var __copyProps = (to, from, except, desc) => {
|
|
14
16
|
}
|
15
17
|
return to;
|
16
18
|
};
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
20
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
21
|
+
// file that has been converted to a CommonJS file using a Babel-
|
22
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
23
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
24
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
25
|
+
mod
|
26
|
+
));
|
17
27
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
18
28
|
|
19
29
|
// src/submodules/protocols/index.ts
|
@@ -23,6 +33,7 @@ __export(protocols_exports, {
|
|
23
33
|
HttpBindingProtocol: () => HttpBindingProtocol,
|
24
34
|
HttpInterceptingShapeDeserializer: () => HttpInterceptingShapeDeserializer,
|
25
35
|
HttpInterceptingShapeSerializer: () => HttpInterceptingShapeSerializer,
|
36
|
+
HttpProtocol: () => HttpProtocol,
|
26
37
|
RequestBuilder: () => RequestBuilder,
|
27
38
|
RpcProtocol: () => RpcProtocol,
|
28
39
|
ToStringShapeSerializer: () => ToStringShapeSerializer,
|
@@ -136,9 +147,75 @@ var HttpProtocol = class {
|
|
136
147
|
cfId: output.headers["x-amz-cf-id"]
|
137
148
|
};
|
138
149
|
}
|
150
|
+
/**
|
151
|
+
* @param eventStream - the iterable provided by the caller.
|
152
|
+
* @param requestSchema - the schema of the event stream container (struct).
|
153
|
+
* @param [initialRequest] - only provided if the initial-request is part of the event stream (RPC).
|
154
|
+
*
|
155
|
+
* @returns a stream suitable for the HTTP body of a request.
|
156
|
+
*/
|
157
|
+
async serializeEventStream({
|
158
|
+
eventStream,
|
159
|
+
requestSchema,
|
160
|
+
initialRequest
|
161
|
+
}) {
|
162
|
+
const eventStreamSerde = await this.loadEventStreamCapability();
|
163
|
+
return eventStreamSerde.serializeEventStream({
|
164
|
+
eventStream,
|
165
|
+
requestSchema,
|
166
|
+
initialRequest
|
167
|
+
});
|
168
|
+
}
|
169
|
+
/**
|
170
|
+
* @param response - http response from which to read the event stream.
|
171
|
+
* @param unionSchema - schema of the event stream container (struct).
|
172
|
+
* @param [initialResponseContainer] - provided and written to only if the initial response is part of the event stream (RPC).
|
173
|
+
*
|
174
|
+
* @returns the asyncIterable of the event stream.
|
175
|
+
*/
|
176
|
+
async deserializeEventStream({
|
177
|
+
response,
|
178
|
+
responseSchema,
|
179
|
+
initialResponseContainer
|
180
|
+
}) {
|
181
|
+
const eventStreamSerde = await this.loadEventStreamCapability();
|
182
|
+
return eventStreamSerde.deserializeEventStream({
|
183
|
+
response,
|
184
|
+
responseSchema,
|
185
|
+
initialResponseContainer
|
186
|
+
});
|
187
|
+
}
|
188
|
+
/**
|
189
|
+
* Loads eventStream capability async (for chunking).
|
190
|
+
*/
|
191
|
+
async loadEventStreamCapability() {
|
192
|
+
const { EventStreamSerde } = await Promise.resolve().then(() => __toESM(require("@smithy/core/event-streams")));
|
193
|
+
return new EventStreamSerde({
|
194
|
+
marshaller: this.getEventStreamMarshaller(),
|
195
|
+
serializer: this.serializer,
|
196
|
+
deserializer: this.deserializer,
|
197
|
+
serdeContext: this.serdeContext,
|
198
|
+
defaultContentType: this.getDefaultContentType()
|
199
|
+
});
|
200
|
+
}
|
201
|
+
/**
|
202
|
+
* @returns content-type default header value for event stream events and other documents.
|
203
|
+
*/
|
204
|
+
getDefaultContentType() {
|
205
|
+
throw new Error(
|
206
|
+
`@smithy/core/protocols - ${this.constructor.name} getDefaultContentType() implementation missing.`
|
207
|
+
);
|
208
|
+
}
|
139
209
|
async deserializeHttpMessage(schema, context, response, arg4, arg5) {
|
140
210
|
return [];
|
141
211
|
}
|
212
|
+
getEventStreamMarshaller() {
|
213
|
+
const context = this.serdeContext;
|
214
|
+
if (!context.eventStreamMarshaller) {
|
215
|
+
throw new Error("@smithy/core - HttpProtocol: eventStreamMarshaller missing in serdeContext.");
|
216
|
+
}
|
217
|
+
return context.eventStreamMarshaller;
|
218
|
+
}
|
142
219
|
};
|
143
220
|
|
144
221
|
// src/submodules/protocols/HttpBindingProtocol.ts
|
@@ -192,7 +269,12 @@ var HttpBindingProtocol = class extends HttpProtocol {
|
|
192
269
|
if (isStreaming) {
|
193
270
|
const isEventStream = memberNs.isStructSchema();
|
194
271
|
if (isEventStream) {
|
195
|
-
|
272
|
+
if (input[memberName]) {
|
273
|
+
payload = await this.serializeEventStream({
|
274
|
+
eventStream: input[memberName],
|
275
|
+
requestSchema: ns
|
276
|
+
});
|
277
|
+
}
|
196
278
|
} else {
|
197
279
|
payload = inputMemberValue;
|
198
280
|
}
|
@@ -307,11 +389,8 @@ var HttpBindingProtocol = class extends HttpProtocol {
|
|
307
389
|
}
|
308
390
|
}
|
309
391
|
}
|
310
|
-
|
311
|
-
|
312
|
-
...dataObject
|
313
|
-
};
|
314
|
-
return output;
|
392
|
+
dataObject.$metadata = this.deserializeMetadata(response);
|
393
|
+
return dataObject;
|
315
394
|
}
|
316
395
|
async deserializeHttpMessage(schema, context, response, arg4, arg5) {
|
317
396
|
let dataObject;
|
@@ -330,25 +409,9 @@ var HttpBindingProtocol = class extends HttpProtocol {
|
|
330
409
|
if (isStreaming) {
|
331
410
|
const isEventStream = memberSchema.isStructSchema();
|
332
411
|
if (isEventStream) {
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
}
|
337
|
-
const memberSchemas = memberSchema.getMemberSchemas();
|
338
|
-
dataObject[memberName] = context2.eventStreamMarshaller.deserialize(response.body, async (event) => {
|
339
|
-
const unionMember = Object.keys(event).find((key) => {
|
340
|
-
return key !== "__type";
|
341
|
-
}) ?? "";
|
342
|
-
if (unionMember in memberSchemas) {
|
343
|
-
const eventStreamSchema = memberSchemas[unionMember];
|
344
|
-
return {
|
345
|
-
[unionMember]: await deserializer.read(eventStreamSchema, event[unionMember].body)
|
346
|
-
};
|
347
|
-
} else {
|
348
|
-
return {
|
349
|
-
$unknown: event
|
350
|
-
};
|
351
|
-
}
|
412
|
+
dataObject[memberName] = await this.deserializeEventStream({
|
413
|
+
response,
|
414
|
+
responseSchema: ns
|
352
415
|
});
|
353
416
|
} else {
|
354
417
|
dataObject[memberName] = (0, import_util_stream2.sdkStreamMixin)(response.body);
|
@@ -430,8 +493,26 @@ var RpcProtocol = class extends HttpProtocol {
|
|
430
493
|
...input
|
431
494
|
};
|
432
495
|
if (input) {
|
433
|
-
|
434
|
-
|
496
|
+
const eventStreamMember = ns.getEventStreamMember();
|
497
|
+
if (eventStreamMember) {
|
498
|
+
if (_input[eventStreamMember]) {
|
499
|
+
const initialRequest = {};
|
500
|
+
for (const [memberName, memberSchema] of ns.structIterator()) {
|
501
|
+
if (memberName !== eventStreamMember && _input[memberName]) {
|
502
|
+
serializer.write(memberSchema, _input[memberName]);
|
503
|
+
initialRequest[memberName] = serializer.flush();
|
504
|
+
}
|
505
|
+
}
|
506
|
+
payload = await this.serializeEventStream({
|
507
|
+
eventStream: _input[eventStreamMember],
|
508
|
+
requestSchema: ns,
|
509
|
+
initialRequest
|
510
|
+
});
|
511
|
+
}
|
512
|
+
} else {
|
513
|
+
serializer.write(schema, _input);
|
514
|
+
payload = serializer.flush();
|
515
|
+
}
|
435
516
|
}
|
436
517
|
request.headers = headers;
|
437
518
|
request.query = query;
|
@@ -444,9 +525,9 @@ var RpcProtocol = class extends HttpProtocol {
|
|
444
525
|
const ns = import_schema3.NormalizedSchema.of(operationSchema.output);
|
445
526
|
const dataObject = {};
|
446
527
|
if (response.statusCode >= 300) {
|
447
|
-
const
|
448
|
-
if (
|
449
|
-
Object.assign(dataObject, await deserializer.read(import_schema3.SCHEMA.DOCUMENT,
|
528
|
+
const bytes = await collectBody(response.body, context);
|
529
|
+
if (bytes.byteLength > 0) {
|
530
|
+
Object.assign(dataObject, await deserializer.read(import_schema3.SCHEMA.DOCUMENT, bytes));
|
450
531
|
}
|
451
532
|
await this.handleError(operationSchema, context, response, dataObject, this.deserializeMetadata(response));
|
452
533
|
throw new Error("@smithy/core/protocols - RPC Protocol error handler failed to throw.");
|
@@ -456,15 +537,21 @@ var RpcProtocol = class extends HttpProtocol {
|
|
456
537
|
delete response.headers[header];
|
457
538
|
response.headers[header.toLowerCase()] = value;
|
458
539
|
}
|
459
|
-
const
|
460
|
-
if (
|
461
|
-
|
540
|
+
const eventStreamMember = ns.getEventStreamMember();
|
541
|
+
if (eventStreamMember) {
|
542
|
+
dataObject[eventStreamMember] = await this.deserializeEventStream({
|
543
|
+
response,
|
544
|
+
responseSchema: ns,
|
545
|
+
initialResponseContainer: dataObject
|
546
|
+
});
|
547
|
+
} else {
|
548
|
+
const bytes = await collectBody(response.body, context);
|
549
|
+
if (bytes.byteLength > 0) {
|
550
|
+
Object.assign(dataObject, await deserializer.read(ns, bytes));
|
551
|
+
}
|
462
552
|
}
|
463
|
-
|
464
|
-
|
465
|
-
...dataObject
|
466
|
-
};
|
467
|
-
return output;
|
553
|
+
dataObject.$metadata = this.deserializeMetadata(response);
|
554
|
+
return dataObject;
|
468
555
|
}
|
469
556
|
};
|
470
557
|
|
@@ -721,7 +808,9 @@ var ToStringShapeSerializer = class {
|
|
721
808
|
if (ns.isTimestampSchema()) {
|
722
809
|
if (!(value instanceof Date)) {
|
723
810
|
throw new Error(
|
724
|
-
`@smithy/core/protocols - received non-Date value ${value} when schema expected Date in ${ns.getName(
|
811
|
+
`@smithy/core/protocols - received non-Date value ${value} when schema expected Date in ${ns.getName(
|
812
|
+
true
|
813
|
+
)}`
|
725
814
|
);
|
726
815
|
}
|
727
816
|
const format = determineTimestampFormat(ns, this.settings);
|
@@ -822,6 +911,7 @@ var HttpInterceptingShapeSerializer = class {
|
|
822
911
|
HttpBindingProtocol,
|
823
912
|
HttpInterceptingShapeDeserializer,
|
824
913
|
HttpInterceptingShapeSerializer,
|
914
|
+
HttpProtocol,
|
825
915
|
RequestBuilder,
|
826
916
|
RpcProtocol,
|
827
917
|
ToStringShapeSerializer,
|
@@ -748,6 +748,17 @@ var NormalizedSchema = class _NormalizedSchema {
|
|
748
748
|
}
|
749
749
|
throw new Error(`@smithy/core/schema - the schema ${this.getName(true)} does not have a value member.`);
|
750
750
|
}
|
751
|
+
/**
|
752
|
+
* @param member - to query.
|
753
|
+
* @returns whether there is a memberSchema with the given member name. False if not a structure (or union).
|
754
|
+
*/
|
755
|
+
hasMemberSchema(member) {
|
756
|
+
if (this.isStructSchema()) {
|
757
|
+
const struct2 = this.getSchema();
|
758
|
+
return member in struct2.members;
|
759
|
+
}
|
760
|
+
return false;
|
761
|
+
}
|
751
762
|
/**
|
752
763
|
* @returns the NormalizedSchema for the given member name. The returned instance will return true for `isMemberSchema()`
|
753
764
|
* and will have the member name given.
|
@@ -794,6 +805,20 @@ var NormalizedSchema = class _NormalizedSchema {
|
|
794
805
|
}
|
795
806
|
return {};
|
796
807
|
}
|
808
|
+
/**
|
809
|
+
* @returns member name of event stream or empty string indicating none exists or this
|
810
|
+
* isn't a structure schema.
|
811
|
+
*/
|
812
|
+
getEventStreamMember() {
|
813
|
+
if (this.isStructSchema()) {
|
814
|
+
for (const [memberName, memberSchema] of this.structIterator()) {
|
815
|
+
if (memberSchema.isStreaming() && memberSchema.isStructSchema()) {
|
816
|
+
return memberName;
|
817
|
+
}
|
818
|
+
}
|
819
|
+
}
|
820
|
+
return "";
|
821
|
+
}
|
797
822
|
/**
|
798
823
|
* Allows iteration over members of a structure schema.
|
799
824
|
* Each yield is a pair of the member name and member schema.
|
@@ -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";
|
@@ -56,7 +56,12 @@ export class HttpBindingProtocol extends HttpProtocol {
|
|
56
56
|
if (isStreaming) {
|
57
57
|
const isEventStream = memberNs.isStructSchema();
|
58
58
|
if (isEventStream) {
|
59
|
-
|
59
|
+
if (input[memberName]) {
|
60
|
+
payload = await this.serializeEventStream({
|
61
|
+
eventStream: input[memberName],
|
62
|
+
requestSchema: ns,
|
63
|
+
});
|
64
|
+
}
|
60
65
|
}
|
61
66
|
else {
|
62
67
|
payload = inputMemberValue;
|
@@ -171,11 +176,8 @@ export class HttpBindingProtocol extends HttpProtocol {
|
|
171
176
|
}
|
172
177
|
}
|
173
178
|
}
|
174
|
-
|
175
|
-
|
176
|
-
...dataObject,
|
177
|
-
};
|
178
|
-
return output;
|
179
|
+
dataObject.$metadata = this.deserializeMetadata(response);
|
180
|
+
return dataObject;
|
179
181
|
}
|
180
182
|
async deserializeHttpMessage(schema, context, response, arg4, arg5) {
|
181
183
|
let dataObject;
|
@@ -195,26 +197,9 @@ export class HttpBindingProtocol extends HttpProtocol {
|
|
195
197
|
if (isStreaming) {
|
196
198
|
const isEventStream = memberSchema.isStructSchema();
|
197
199
|
if (isEventStream) {
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
}
|
202
|
-
const memberSchemas = memberSchema.getMemberSchemas();
|
203
|
-
dataObject[memberName] = context.eventStreamMarshaller.deserialize(response.body, async (event) => {
|
204
|
-
const unionMember = Object.keys(event).find((key) => {
|
205
|
-
return key !== "__type";
|
206
|
-
}) ?? "";
|
207
|
-
if (unionMember in memberSchemas) {
|
208
|
-
const eventStreamSchema = memberSchemas[unionMember];
|
209
|
-
return {
|
210
|
-
[unionMember]: await deserializer.read(eventStreamSchema, event[unionMember].body),
|
211
|
-
};
|
212
|
-
}
|
213
|
-
else {
|
214
|
-
return {
|
215
|
-
$unknown: event,
|
216
|
-
};
|
217
|
-
}
|
200
|
+
dataObject[memberName] = await this.deserializeEventStream({
|
201
|
+
response,
|
202
|
+
responseSchema: ns,
|
218
203
|
});
|
219
204
|
}
|
220
205
|
else {
|
@@ -72,6 +72,35 @@ export class HttpProtocol {
|
|
72
72
|
cfId: output.headers["x-amz-cf-id"],
|
73
73
|
};
|
74
74
|
}
|
75
|
+
async serializeEventStream({ eventStream, requestSchema, initialRequest, }) {
|
76
|
+
const eventStreamSerde = await this.loadEventStreamCapability();
|
77
|
+
return eventStreamSerde.serializeEventStream({
|
78
|
+
eventStream,
|
79
|
+
requestSchema,
|
80
|
+
initialRequest,
|
81
|
+
});
|
82
|
+
}
|
83
|
+
async deserializeEventStream({ response, responseSchema, initialResponseContainer, }) {
|
84
|
+
const eventStreamSerde = await this.loadEventStreamCapability();
|
85
|
+
return eventStreamSerde.deserializeEventStream({
|
86
|
+
response,
|
87
|
+
responseSchema,
|
88
|
+
initialResponseContainer,
|
89
|
+
});
|
90
|
+
}
|
91
|
+
async loadEventStreamCapability() {
|
92
|
+
const { EventStreamSerde } = await import("@smithy/core/event-streams");
|
93
|
+
return new EventStreamSerde({
|
94
|
+
marshaller: this.getEventStreamMarshaller(),
|
95
|
+
serializer: this.serializer,
|
96
|
+
deserializer: this.deserializer,
|
97
|
+
serdeContext: this.serdeContext,
|
98
|
+
defaultContentType: this.getDefaultContentType(),
|
99
|
+
});
|
100
|
+
}
|
101
|
+
getDefaultContentType() {
|
102
|
+
throw new Error(`@smithy/core/protocols - ${this.constructor.name} getDefaultContentType() implementation missing.`);
|
103
|
+
}
|
75
104
|
async deserializeHttpMessage(schema, context, response, arg4, arg5) {
|
76
105
|
void schema;
|
77
106
|
void context;
|
@@ -80,4 +109,11 @@ export class HttpProtocol {
|
|
80
109
|
void arg5;
|
81
110
|
return [];
|
82
111
|
}
|
112
|
+
getEventStreamMarshaller() {
|
113
|
+
const context = this.serdeContext;
|
114
|
+
if (!context.eventStreamMarshaller) {
|
115
|
+
throw new Error("@smithy/core - HttpProtocol: eventStreamMarshaller missing in serdeContext.");
|
116
|
+
}
|
117
|
+
return context.eventStreamMarshaller;
|
118
|
+
}
|
83
119
|
}
|