@cdk8s/awscdk-resolver 0.0.348 → 0.0.350

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.
Files changed (104) hide show
  1. package/.jsii +3 -3
  2. package/lib/resolve.js +1 -1
  3. package/node_modules/@aws-sdk/client-cloudformation/package.json +12 -12
  4. package/node_modules/@aws-sdk/client-sso/package.json +11 -11
  5. package/node_modules/@aws-sdk/core/dist-cjs/submodules/protocols/index.js +320 -216
  6. package/node_modules/@aws-sdk/core/dist-es/submodules/protocols/ProtocolLib.js +94 -0
  7. package/node_modules/@aws-sdk/core/dist-es/submodules/protocols/cbor/AwsSmithyRpcV2CborProtocol.js +39 -0
  8. package/node_modules/@aws-sdk/core/dist-es/submodules/protocols/common.js +2 -1
  9. package/node_modules/@aws-sdk/core/dist-es/submodules/protocols/index.js +1 -0
  10. package/node_modules/@aws-sdk/core/dist-es/submodules/protocols/json/AwsJson1_0Protocol.js +2 -1
  11. package/node_modules/@aws-sdk/core/dist-es/submodules/protocols/json/AwsJson1_1Protocol.js +2 -1
  12. package/node_modules/@aws-sdk/core/dist-es/submodules/protocols/json/AwsJsonRpcProtocol.js +17 -31
  13. package/node_modules/@aws-sdk/core/dist-es/submodules/protocols/json/AwsRestJsonProtocol.js +8 -56
  14. package/node_modules/@aws-sdk/core/dist-es/submodules/protocols/query/AwsQueryProtocol.js +5 -32
  15. package/node_modules/@aws-sdk/core/dist-es/submodules/protocols/xml/AwsRestXmlProtocol.js +9 -57
  16. package/node_modules/@aws-sdk/core/dist-types/submodules/protocols/ProtocolLib.d.ts +57 -0
  17. package/node_modules/@aws-sdk/core/dist-types/submodules/protocols/cbor/AwsSmithyRpcV2CborProtocol.d.ts +23 -0
  18. package/node_modules/@aws-sdk/core/dist-types/submodules/protocols/index.d.ts +1 -0
  19. package/node_modules/@aws-sdk/core/dist-types/submodules/protocols/json/AwsJson1_0Protocol.d.ts +2 -1
  20. package/node_modules/@aws-sdk/core/dist-types/submodules/protocols/json/AwsJson1_1Protocol.d.ts +2 -1
  21. package/node_modules/@aws-sdk/core/dist-types/submodules/protocols/json/AwsJsonRpcProtocol.d.ts +6 -3
  22. package/node_modules/@aws-sdk/core/dist-types/submodules/protocols/json/AwsRestJsonProtocol.d.ts +2 -1
  23. package/node_modules/@aws-sdk/core/dist-types/submodules/protocols/query/AwsQueryProtocol.d.ts +2 -2
  24. package/node_modules/@aws-sdk/core/dist-types/submodules/protocols/xml/AwsRestXmlProtocol.d.ts +1 -0
  25. package/node_modules/@aws-sdk/core/dist-types/ts3.4/submodules/protocols/ProtocolLib.d.ts +39 -0
  26. package/node_modules/@aws-sdk/core/dist-types/ts3.4/submodules/protocols/cbor/AwsSmithyRpcV2CborProtocol.d.ts +33 -0
  27. package/node_modules/@aws-sdk/core/dist-types/ts3.4/submodules/protocols/index.d.ts +1 -0
  28. package/node_modules/@aws-sdk/core/dist-types/ts3.4/submodules/protocols/json/AwsJson1_0Protocol.d.ts +2 -0
  29. package/node_modules/@aws-sdk/core/dist-types/ts3.4/submodules/protocols/json/AwsJson1_1Protocol.d.ts +2 -0
  30. package/node_modules/@aws-sdk/core/dist-types/ts3.4/submodules/protocols/json/AwsJsonRpcProtocol.d.ts +5 -1
  31. package/node_modules/@aws-sdk/core/dist-types/ts3.4/submodules/protocols/json/AwsRestJsonProtocol.d.ts +1 -0
  32. package/node_modules/@aws-sdk/core/dist-types/ts3.4/submodules/protocols/query/AwsQueryProtocol.d.ts +2 -1
  33. package/node_modules/@aws-sdk/core/dist-types/ts3.4/submodules/protocols/xml/AwsRestXmlProtocol.d.ts +1 -0
  34. package/node_modules/@aws-sdk/core/package.json +3 -3
  35. package/node_modules/@aws-sdk/credential-provider-env/package.json +2 -2
  36. package/node_modules/@aws-sdk/credential-provider-http/package.json +3 -3
  37. package/node_modules/@aws-sdk/credential-provider-ini/package.json +8 -8
  38. package/node_modules/@aws-sdk/credential-provider-node/package.json +7 -7
  39. package/node_modules/@aws-sdk/credential-provider-process/package.json +2 -2
  40. package/node_modules/@aws-sdk/credential-provider-sso/package.json +4 -4
  41. package/node_modules/@aws-sdk/credential-provider-web-identity/package.json +3 -3
  42. package/node_modules/@aws-sdk/middleware-user-agent/package.json +4 -4
  43. package/node_modules/@aws-sdk/nested-clients/package.json +11 -11
  44. package/node_modules/@aws-sdk/token-providers/package.json +3 -3
  45. package/node_modules/@aws-sdk/util-endpoints/dist-cjs/index.js +4 -1
  46. package/node_modules/@aws-sdk/util-endpoints/dist-cjs/lib/aws/partitions.json +4 -1
  47. package/node_modules/@aws-sdk/util-endpoints/dist-es/lib/aws/partitions.json +4 -1
  48. package/node_modules/@aws-sdk/util-endpoints/package.json +1 -1
  49. package/node_modules/@aws-sdk/util-user-agent-node/package.json +2 -2
  50. package/node_modules/@smithy/core/dist-cjs/submodules/cbor/index.js +44 -15
  51. package/node_modules/@smithy/core/dist-cjs/submodules/event-streams/index.js +261 -0
  52. package/node_modules/@smithy/core/dist-cjs/submodules/protocols/index.js +129 -39
  53. package/node_modules/@smithy/core/dist-cjs/submodules/schema/index.js +25 -0
  54. package/node_modules/@smithy/core/dist-es/submodules/cbor/SmithyRpcV2CborProtocol.js +36 -15
  55. package/node_modules/@smithy/core/dist-es/submodules/event-streams/EventStreamSerde.js +200 -0
  56. package/node_modules/@smithy/core/dist-es/submodules/event-streams/index.js +1 -0
  57. package/node_modules/@smithy/core/dist-es/submodules/protocols/HttpBindingProtocol.js +11 -26
  58. package/node_modules/@smithy/core/dist-es/submodules/protocols/HttpProtocol.js +36 -0
  59. package/node_modules/@smithy/core/dist-es/submodules/protocols/RpcProtocol.js +36 -10
  60. package/node_modules/@smithy/core/dist-es/submodules/protocols/index.js +1 -0
  61. package/node_modules/@smithy/core/dist-es/submodules/schema/schemas/NormalizedSchema.js +17 -0
  62. package/node_modules/@smithy/core/dist-types/submodules/cbor/CborCodec.d.ts +6 -2
  63. package/node_modules/@smithy/core/dist-types/submodules/cbor/SmithyRpcV2CborProtocol.d.ts +1 -0
  64. package/node_modules/@smithy/core/dist-types/submodules/cbor/parseCborBody.d.ts +1 -1
  65. package/node_modules/@smithy/core/dist-types/submodules/event-streams/EventStreamSerde.d.ts +60 -0
  66. package/node_modules/@smithy/core/dist-types/submodules/event-streams/index.d.ts +1 -0
  67. package/node_modules/@smithy/core/dist-types/submodules/protocols/HttpBindingProtocol.d.ts +1 -1
  68. package/node_modules/@smithy/core/dist-types/submodules/protocols/HttpProtocol.d.ts +39 -1
  69. package/node_modules/@smithy/core/dist-types/submodules/protocols/RpcProtocol.d.ts +1 -1
  70. package/node_modules/@smithy/core/dist-types/submodules/protocols/index.d.ts +1 -0
  71. package/node_modules/@smithy/core/dist-types/submodules/protocols/serde/FromStringShapeDeserializer.d.ts +1 -1
  72. package/node_modules/@smithy/core/dist-types/submodules/protocols/serde/HttpInterceptingShapeDeserializer.d.ts +1 -1
  73. package/node_modules/@smithy/core/dist-types/submodules/protocols/serde/HttpInterceptingShapeSerializer.d.ts +1 -1
  74. package/node_modules/@smithy/core/dist-types/submodules/protocols/serde/ToStringShapeSerializer.d.ts +1 -1
  75. package/node_modules/@smithy/core/dist-types/submodules/protocols/serde/determineTimestampFormat.d.ts +1 -1
  76. package/node_modules/@smithy/core/dist-types/submodules/schema/middleware/getSchemaSerdePlugin.d.ts +1 -1
  77. package/node_modules/@smithy/core/dist-types/submodules/schema/middleware/schemaDeserializationMiddleware.d.ts +1 -1
  78. package/node_modules/@smithy/core/dist-types/submodules/schema/schemas/NormalizedSchema.d.ts +10 -0
  79. package/node_modules/@smithy/core/dist-types/submodules/schema/schemas/SimpleSchema.d.ts +1 -1
  80. package/node_modules/@smithy/core/dist-types/submodules/schema/schemas/sentinels.d.ts +1 -1
  81. package/node_modules/@smithy/core/dist-types/submodules/serde/copyDocumentWithTransform.d.ts +1 -1
  82. package/node_modules/@smithy/core/dist-types/ts3.4/submodules/cbor/CborCodec.d.ts +5 -1
  83. package/node_modules/@smithy/core/dist-types/ts3.4/submodules/cbor/SmithyRpcV2CborProtocol.d.ts +1 -0
  84. package/node_modules/@smithy/core/dist-types/ts3.4/submodules/event-streams/EventStreamSerde.d.ts +60 -0
  85. package/node_modules/@smithy/core/dist-types/ts3.4/submodules/event-streams/index.d.ts +1 -0
  86. package/node_modules/@smithy/core/dist-types/ts3.4/submodules/protocols/HttpProtocol.d.ts +39 -1
  87. package/node_modules/@smithy/core/dist-types/ts3.4/submodules/protocols/index.d.ts +1 -0
  88. package/node_modules/@smithy/core/dist-types/ts3.4/submodules/protocols/serde/determineTimestampFormat.d.ts +1 -1
  89. package/node_modules/@smithy/core/dist-types/ts3.4/submodules/schema/schemas/NormalizedSchema.d.ts +10 -0
  90. package/node_modules/@smithy/core/event-streams.d.ts +7 -0
  91. package/node_modules/@smithy/core/event-streams.js +6 -0
  92. package/node_modules/@smithy/core/package.json +11 -1
  93. package/node_modules/@smithy/middleware-endpoint/package.json +2 -2
  94. package/node_modules/@smithy/middleware-retry/package.json +4 -4
  95. package/node_modules/@smithy/smithy-client/dist-cjs/index.js +43 -6
  96. package/node_modules/@smithy/smithy-client/dist-cjs/schemaLogFilter.js +1 -0
  97. package/node_modules/@smithy/smithy-client/dist-es/command.js +7 -4
  98. package/node_modules/@smithy/smithy-client/dist-es/schemaLogFilter.js +34 -0
  99. package/node_modules/@smithy/smithy-client/dist-types/schemaLogFilter.d.ts +9 -0
  100. package/node_modules/@smithy/smithy-client/dist-types/ts3.4/schemaLogFilter.d.ts +9 -0
  101. package/node_modules/@smithy/smithy-client/package.json +3 -3
  102. package/node_modules/@smithy/util-defaults-mode-browser/package.json +2 -2
  103. package/node_modules/@smithy/util-defaults-mode-node/package.json +2 -2
  104. package/package.json +4 -4
@@ -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": "application/cbor",
22
+ "content-type": this.getDefaultContentType(),
23
23
  "smithy-protocol": "rpc-v2-cbor",
24
- accept: "application/cbor",
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 error = loadSmithyRpcV2CborErrorCode(response, dataObject) ?? "Unknown";
54
+ const errorName = loadSmithyRpcV2CborErrorCode(response, dataObject) ?? "Unknown";
55
55
  let namespace = this.options.defaultNamespace;
56
- if (error.includes("#")) {
57
- [namespace] = error.split("#");
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
- const errorSchema = registry.getSchema(error);
61
- if (!errorSchema) {
62
- throw new Error("schema not found for " + error);
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
- Object.assign(exception, {
67
- $metadata: metadata,
68
- $response: response,
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
- ...dataObject,
71
- });
72
- throw exception;
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
- throw new Error("serialization of event streams is not yet implemented");
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
- const output = {
175
- $metadata: this.deserializeMetadata(response),
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
- const context = this.serdeContext;
199
- if (!context.eventStreamMarshaller) {
200
- throw new Error("@smithy/core - HttpProtocol: eventStreamMarshaller missing in serdeContext.");
201
- }
202
- const memberSchemas = memberSchema.getMemberSchemas();
203
- dataObject[memberName] = context.eventStreamMarshaller.deserialize(response.body, async (event) => {
204
- const unionMember = Object.keys(event).find((key) => {
205
- return key !== "__type";
206
- }) ?? "";
207
- if (unionMember in memberSchemas) {
208
- const eventStreamSchema = memberSchemas[unionMember];
209
- return {
210
- [unionMember]: await deserializer.read(eventStreamSchema, event[unionMember].body),
211
- };
212
- }
213
- else {
214
- return {
215
- $unknown: event,
216
- };
217
- }
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
  }
@@ -29,8 +29,27 @@ export class RpcProtocol extends HttpProtocol {
29
29
  ...input,
30
30
  };
31
31
  if (input) {
32
- serializer.write(schema, _input);
33
- payload = serializer.flush();
32
+ const eventStreamMember = ns.getEventStreamMember();
33
+ if (eventStreamMember) {
34
+ if (_input[eventStreamMember]) {
35
+ const initialRequest = {};
36
+ for (const [memberName, memberSchema] of ns.structIterator()) {
37
+ if (memberName !== eventStreamMember && _input[memberName]) {
38
+ serializer.write(memberSchema, _input[memberName]);
39
+ initialRequest[memberName] = serializer.flush();
40
+ }
41
+ }
42
+ payload = await this.serializeEventStream({
43
+ eventStream: _input[eventStreamMember],
44
+ requestSchema: ns,
45
+ initialRequest,
46
+ });
47
+ }
48
+ }
49
+ else {
50
+ serializer.write(schema, _input);
51
+ payload = serializer.flush();
52
+ }
34
53
  }
35
54
  request.headers = headers;
36
55
  request.query = query;
@@ -55,14 +74,21 @@ export class RpcProtocol extends HttpProtocol {
55
74
  delete response.headers[header];
56
75
  response.headers[header.toLowerCase()] = value;
57
76
  }
58
- const bytes = await collectBody(response.body, context);
59
- if (bytes.byteLength > 0) {
60
- Object.assign(dataObject, await deserializer.read(ns, bytes));
77
+ const eventStreamMember = ns.getEventStreamMember();
78
+ if (eventStreamMember) {
79
+ dataObject[eventStreamMember] = await this.deserializeEventStream({
80
+ response,
81
+ responseSchema: ns,
82
+ initialResponseContainer: dataObject,
83
+ });
61
84
  }
62
- const output = {
63
- $metadata: this.deserializeMetadata(response),
64
- ...dataObject,
65
- };
66
- return output;
85
+ else {
86
+ const bytes = await collectBody(response.body, context);
87
+ if (bytes.byteLength > 0) {
88
+ Object.assign(dataObject, await deserializer.read(ns, bytes));
89
+ }
90
+ }
91
+ dataObject.$metadata = this.deserializeMetadata(response);
92
+ return dataObject;
67
93
  }
68
94
  }
@@ -1,6 +1,7 @@
1
1
  export * from "./collect-stream-body";
2
2
  export * from "./extended-encode-uri-component";
3
3
  export * from "./HttpBindingProtocol";
4
+ export * from "./HttpProtocol";
4
5
  export * from "./RpcProtocol";
5
6
  export * from "./requestBuilder";
6
7
  export * from "./resolve-path";
@@ -250,6 +250,13 @@ export class NormalizedSchema {
250
250
  }
251
251
  throw new Error(`@smithy/core/schema - the schema ${this.getName(true)} does not have a value member.`);
252
252
  }
253
+ hasMemberSchema(member) {
254
+ if (this.isStructSchema()) {
255
+ const struct = this.getSchema();
256
+ return member in struct.members;
257
+ }
258
+ return false;
259
+ }
253
260
  getMemberSchema(member) {
254
261
  if (this.isStructSchema()) {
255
262
  const struct = this.getSchema();
@@ -278,6 +285,16 @@ export class NormalizedSchema {
278
285
  }
279
286
  return {};
280
287
  }
288
+ getEventStreamMember() {
289
+ if (this.isStructSchema()) {
290
+ for (const [memberName, memberSchema] of this.structIterator()) {
291
+ if (memberSchema.isStreaming() && memberSchema.isStructSchema()) {
292
+ return memberName;
293
+ }
294
+ }
295
+ }
296
+ return "";
297
+ }
281
298
  *structIterator() {
282
299
  if (this.isUnitSchema()) {
283
300
  return;
@@ -1,4 +1,4 @@
1
- import { Codec, Schema, SerdeFunctions, ShapeDeserializer, ShapeSerializer } from "@smithy/types";
1
+ import type { Codec, Schema, SerdeFunctions, ShapeDeserializer, ShapeSerializer } from "@smithy/types";
2
2
  /**
3
3
  * @alpha
4
4
  */
@@ -30,5 +30,9 @@ export declare class CborShapeDeserializer implements ShapeDeserializer {
30
30
  private serdeContext?;
31
31
  setSerdeContext(serdeContext: SerdeFunctions): void;
32
32
  read(schema: Schema, bytes: Uint8Array): any;
33
- private readValue;
33
+ /**
34
+ * Public because it's called by the protocol implementation to deserialize errors.
35
+ * @internal
36
+ */
37
+ readValue(_schema: Schema, value: any): any;
34
38
  }
@@ -19,4 +19,5 @@ export declare class SmithyRpcV2CborProtocol extends RpcProtocol {
19
19
  serializeRequest<Input extends object>(operationSchema: OperationSchema, input: Input, context: HandlerExecutionContext & SerdeFunctions & EndpointBearer): Promise<IHttpRequest>;
20
20
  deserializeResponse<Output extends MetadataBearer>(operationSchema: OperationSchema, context: HandlerExecutionContext & SerdeFunctions, response: IHttpResponse): Promise<Output>;
21
21
  protected handleError(operationSchema: OperationSchema, context: HandlerExecutionContext & SerdeFunctions, response: IHttpResponse, dataObject: any, metadata: ResponseMetadata): Promise<never>;
22
+ protected getDefaultContentType(): string;
22
23
  }
@@ -1,5 +1,5 @@
1
1
  import { HttpRequest as __HttpRequest } from "@smithy/protocol-http";
2
- import { HeaderBag as __HeaderBag, HttpResponse, SerdeContext as __SerdeContext, SerdeContext } from "@smithy/types";
2
+ import type { HeaderBag as __HeaderBag, HttpResponse, SerdeContext as __SerdeContext, SerdeContext } from "@smithy/types";
3
3
  import { tagSymbol } from "./cbor-types";
4
4
  /**
5
5
  * @internal
@@ -0,0 +1,60 @@
1
+ import { NormalizedSchema } from "@smithy/core/schema";
2
+ import type { EventStreamMarshaller, HttpRequest as IHttpRequest, HttpResponse as IHttpResponse, SerdeFunctions, ShapeDeserializer, ShapeSerializer } from "@smithy/types";
3
+ /**
4
+ * Separated module for async mixin of EventStream serde capability.
5
+ * This is used by the HttpProtocol base class from \@smithy/core/protocols.
6
+ *
7
+ * @alpha
8
+ */
9
+ export declare class EventStreamSerde {
10
+ private readonly marshaller;
11
+ private readonly serializer;
12
+ private readonly deserializer;
13
+ private readonly serdeContext?;
14
+ private readonly defaultContentType;
15
+ /**
16
+ * Properties are injected by the HttpProtocol.
17
+ */
18
+ constructor({ marshaller, serializer, deserializer, serdeContext, defaultContentType, }: {
19
+ marshaller: EventStreamMarshaller;
20
+ serializer: ShapeSerializer<string | Uint8Array>;
21
+ deserializer: ShapeDeserializer<string | Uint8Array>;
22
+ serdeContext?: SerdeFunctions;
23
+ defaultContentType: string;
24
+ });
25
+ /**
26
+ * @param eventStream - the iterable provided by the caller.
27
+ * @param requestSchema - the schema of the event stream container (struct).
28
+ * @param [initialRequest] - only provided if the initial-request is part of the event stream (RPC).
29
+ *
30
+ * @returns a stream suitable for the HTTP body of a request.
31
+ */
32
+ serializeEventStream({ eventStream, requestSchema, initialRequest, }: {
33
+ eventStream: AsyncIterable<any>;
34
+ requestSchema: NormalizedSchema;
35
+ initialRequest?: any;
36
+ }): Promise<IHttpRequest["body"] | Uint8Array>;
37
+ /**
38
+ * @param response - http response from which to read the event stream.
39
+ * @param unionSchema - schema of the event stream container (struct).
40
+ * @param [initialResponseContainer] - provided and written to only if the initial response is part of the event stream (RPC).
41
+ *
42
+ * @returns the asyncIterable of the event stream for the end-user.
43
+ */
44
+ deserializeEventStream({ response, responseSchema, initialResponseContainer, }: {
45
+ response: IHttpResponse;
46
+ responseSchema: NormalizedSchema;
47
+ initialResponseContainer?: any;
48
+ }): Promise<AsyncIterable<{
49
+ [key: string]: any;
50
+ $unknown?: unknown;
51
+ }>>;
52
+ /**
53
+ * @param unionMember - member name within the structure that contains an event stream union.
54
+ * @param unionSchema - schema of the union.
55
+ * @param event
56
+ *
57
+ * @returns the event body (bytes) and event type (string).
58
+ */
59
+ private writeEventBody;
60
+ }
@@ -0,0 +1 @@
1
+ export * from "./EventStreamSerde";
@@ -1,6 +1,6 @@
1
1
  import { NormalizedSchema } from "@smithy/core/schema";
2
2
  import { HttpRequest } from "@smithy/protocol-http";
3
- import { EndpointBearer, HandlerExecutionContext, HttpRequest as IHttpRequest, HttpResponse as IHttpResponse, MetadataBearer, OperationSchema, Schema, SerdeFunctions } from "@smithy/types";
3
+ import type { EndpointBearer, HandlerExecutionContext, HttpRequest as IHttpRequest, HttpResponse as IHttpResponse, MetadataBearer, OperationSchema, Schema, SerdeFunctions } from "@smithy/types";
4
4
  import { HttpProtocol } from "./HttpProtocol";
5
5
  /**
6
6
  * Base for HTTP-binding protocols. Downstream examples
@@ -1,4 +1,6 @@
1
- import { ClientProtocol, Codec, Endpoint, EndpointBearer, EndpointV2, HandlerExecutionContext, HttpRequest as IHttpRequest, HttpResponse as IHttpResponse, MetadataBearer, OperationSchema, ResponseMetadata, Schema, SerdeFunctions, ShapeDeserializer, ShapeSerializer } from "@smithy/types";
1
+ import type { EventStreamSerde } from "@smithy/core/event-streams";
2
+ import { NormalizedSchema } from "@smithy/core/schema";
3
+ import type { ClientProtocol, Codec, Endpoint, EndpointBearer, EndpointV2, EventStreamMarshaller, HandlerExecutionContext, HttpRequest as IHttpRequest, HttpResponse as IHttpResponse, MetadataBearer, OperationSchema, ResponseMetadata, Schema, SerdeFunctions, ShapeDeserializer, ShapeSerializer } from "@smithy/types";
2
4
  /**
3
5
  * Abstract base for HTTP-based client protocols.
4
6
  *
@@ -25,6 +27,41 @@ export declare abstract class HttpProtocol implements ClientProtocol<IHttpReques
25
27
  protected setHostPrefix<Input extends object>(request: IHttpRequest, operationSchema: OperationSchema, input: Input): void;
26
28
  protected abstract handleError(operationSchema: OperationSchema, context: HandlerExecutionContext & SerdeFunctions, response: IHttpResponse, dataObject: any, metadata: ResponseMetadata): Promise<never>;
27
29
  protected deserializeMetadata(output: IHttpResponse): ResponseMetadata;
30
+ /**
31
+ * @param eventStream - the iterable provided by the caller.
32
+ * @param requestSchema - the schema of the event stream container (struct).
33
+ * @param [initialRequest] - only provided if the initial-request is part of the event stream (RPC).
34
+ *
35
+ * @returns a stream suitable for the HTTP body of a request.
36
+ */
37
+ protected serializeEventStream({ eventStream, requestSchema, initialRequest, }: {
38
+ eventStream: AsyncIterable<any>;
39
+ requestSchema: NormalizedSchema;
40
+ initialRequest?: any;
41
+ }): Promise<IHttpRequest["body"]>;
42
+ /**
43
+ * @param response - http response from which to read the event stream.
44
+ * @param unionSchema - schema of the event stream container (struct).
45
+ * @param [initialResponseContainer] - provided and written to only if the initial response is part of the event stream (RPC).
46
+ *
47
+ * @returns the asyncIterable of the event stream.
48
+ */
49
+ protected deserializeEventStream({ response, responseSchema, initialResponseContainer, }: {
50
+ response: IHttpResponse;
51
+ responseSchema: NormalizedSchema;
52
+ initialResponseContainer?: any;
53
+ }): Promise<AsyncIterable<{
54
+ [key: string]: any;
55
+ $unknown?: unknown;
56
+ }>>;
57
+ /**
58
+ * Loads eventStream capability async (for chunking).
59
+ */
60
+ protected loadEventStreamCapability(): Promise<EventStreamSerde>;
61
+ /**
62
+ * @returns content-type default header value for event stream events and other documents.
63
+ */
64
+ protected getDefaultContentType(): string;
28
65
  /**
29
66
  * For HTTP binding protocols, this method is overridden in {@link HttpBindingProtocol}.
30
67
  *
@@ -32,4 +69,5 @@ export declare abstract class HttpProtocol implements ClientProtocol<IHttpReques
32
69
  */
33
70
  protected deserializeHttpMessage(schema: Schema, context: HandlerExecutionContext & SerdeFunctions, response: IHttpResponse, headerBindings: Set<string>, dataObject: any): Promise<string[]>;
34
71
  protected deserializeHttpMessage(schema: Schema, context: HandlerExecutionContext & SerdeFunctions, response: IHttpResponse, dataObject: any): Promise<string[]>;
72
+ protected getEventStreamMarshaller(): EventStreamMarshaller;
35
73
  }
@@ -1,4 +1,4 @@
1
- import { EndpointBearer, HandlerExecutionContext, HttpRequest as IHttpRequest, HttpResponse as IHttpResponse, MetadataBearer, OperationSchema, SerdeFunctions } from "@smithy/types";
1
+ import type { EndpointBearer, HandlerExecutionContext, HttpRequest as IHttpRequest, HttpResponse as IHttpResponse, MetadataBearer, OperationSchema, SerdeFunctions } from "@smithy/types";
2
2
  import { HttpProtocol } from "./HttpProtocol";
3
3
  /**
4
4
  * Abstract base for RPC-over-HTTP protocols.