@smithy/core 3.13.0 → 3.14.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/index.js +308 -412
- package/dist-cjs/submodules/cbor/index.js +957 -969
- package/dist-cjs/submodules/event-streams/index.js +198 -249
- package/dist-cjs/submodules/protocols/index.js +793 -895
- package/dist-cjs/submodules/schema/index.js +617 -811
- package/dist-cjs/submodules/serde/index.js +584 -680
- package/dist-es/submodules/cbor/CborCodec.js +4 -0
- package/dist-es/submodules/cbor/SmithyRpcV2CborProtocol.js +3 -3
- package/dist-es/submodules/cbor/cbor-decode.js +18 -18
- package/dist-es/submodules/cbor/cbor-encode.js +5 -5
- package/dist-es/submodules/event-streams/EventStreamSerde.js +5 -0
- package/dist-es/submodules/protocols/HttpProtocol.js +2 -0
- package/dist-es/submodules/protocols/requestBuilder.js +9 -7
- package/dist-es/submodules/protocols/serde/FromStringShapeDeserializer.js +2 -0
- package/dist-es/submodules/protocols/serde/HttpInterceptingShapeDeserializer.js +3 -0
- package/dist-es/submodules/protocols/serde/HttpInterceptingShapeSerializer.js +3 -0
- package/dist-es/submodules/protocols/serde/ToStringShapeSerializer.js +3 -2
- package/dist-es/submodules/schema/TypeRegistry.js +4 -1
- package/dist-es/submodules/schema/schemas/ErrorSchema.js +3 -5
- package/dist-es/submodules/schema/schemas/ListSchema.js +5 -5
- package/dist-es/submodules/schema/schemas/MapSchema.js +6 -5
- package/dist-es/submodules/schema/schemas/NormalizedSchema.js +16 -8
- package/dist-es/submodules/schema/schemas/OperationSchema.js +6 -5
- package/dist-es/submodules/schema/schemas/Schema.js +3 -0
- package/dist-es/submodules/schema/schemas/SimpleSchema.js +5 -5
- package/dist-es/submodules/schema/schemas/StructureSchema.js +6 -5
- package/dist-es/submodules/schema/schemas/sentinels.js +14 -14
- package/dist-es/submodules/serde/value/NumericValue.js +2 -0
- package/dist-es/util-identity-and-auth/DefaultIdentityProviderConfig.js +1 -1
- package/dist-es/util-identity-and-auth/memoizeIdentityProvider.js +4 -2
- package/package.json +11 -11
|
@@ -1,261 +1,210 @@
|
|
|
1
|
-
|
|
2
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
-
var __export = (target, all) => {
|
|
6
|
-
for (var name in all)
|
|
7
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
-
};
|
|
9
|
-
var __copyProps = (to, from, except, desc) => {
|
|
10
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
-
for (let key of __getOwnPropNames(from))
|
|
12
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
-
}
|
|
15
|
-
return to;
|
|
16
|
-
};
|
|
17
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
1
|
+
'use strict';
|
|
18
2
|
|
|
19
|
-
|
|
20
|
-
var
|
|
21
|
-
__export(index_exports, {
|
|
22
|
-
EventStreamSerde: () => EventStreamSerde
|
|
23
|
-
});
|
|
24
|
-
module.exports = __toCommonJS(index_exports);
|
|
3
|
+
var schema = require('@smithy/core/schema');
|
|
4
|
+
var utilUtf8 = require('@smithy/util-utf8');
|
|
25
5
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
body
|
|
79
|
-
|
|
6
|
+
class EventStreamSerde {
|
|
7
|
+
marshaller;
|
|
8
|
+
serializer;
|
|
9
|
+
deserializer;
|
|
10
|
+
serdeContext;
|
|
11
|
+
defaultContentType;
|
|
12
|
+
constructor({ marshaller, serializer, deserializer, serdeContext, defaultContentType, }) {
|
|
13
|
+
this.marshaller = marshaller;
|
|
14
|
+
this.serializer = serializer;
|
|
15
|
+
this.deserializer = deserializer;
|
|
16
|
+
this.serdeContext = serdeContext;
|
|
17
|
+
this.defaultContentType = defaultContentType;
|
|
18
|
+
}
|
|
19
|
+
async serializeEventStream({ eventStream, requestSchema, initialRequest, }) {
|
|
20
|
+
const marshaller = this.marshaller;
|
|
21
|
+
const eventStreamMember = requestSchema.getEventStreamMember();
|
|
22
|
+
const unionSchema = requestSchema.getMemberSchema(eventStreamMember);
|
|
23
|
+
unionSchema.getMemberSchemas();
|
|
24
|
+
const serializer = this.serializer;
|
|
25
|
+
const defaultContentType = this.defaultContentType;
|
|
26
|
+
const initialRequestMarker = Symbol("initialRequestMarker");
|
|
27
|
+
const eventStreamIterable = {
|
|
28
|
+
async *[Symbol.asyncIterator]() {
|
|
29
|
+
if (initialRequest) {
|
|
30
|
+
const headers = {
|
|
31
|
+
":event-type": { type: "string", value: "initial-request" },
|
|
32
|
+
":message-type": { type: "string", value: "event" },
|
|
33
|
+
":content-type": { type: "string", value: defaultContentType },
|
|
34
|
+
};
|
|
35
|
+
serializer.write(requestSchema, initialRequest);
|
|
36
|
+
const body = serializer.flush();
|
|
37
|
+
yield {
|
|
38
|
+
[initialRequestMarker]: true,
|
|
39
|
+
headers,
|
|
40
|
+
body,
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
for await (const page of eventStream) {
|
|
44
|
+
yield page;
|
|
45
|
+
}
|
|
46
|
+
},
|
|
47
|
+
};
|
|
48
|
+
return marshaller.serialize(eventStreamIterable, (event) => {
|
|
49
|
+
if (event[initialRequestMarker]) {
|
|
50
|
+
return {
|
|
51
|
+
headers: event.headers,
|
|
52
|
+
body: event.body,
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
const unionMember = Object.keys(event).find((key) => {
|
|
56
|
+
return key !== "__type";
|
|
57
|
+
}) ?? "";
|
|
58
|
+
const { additionalHeaders, body, eventType, explicitPayloadContentType } = this.writeEventBody(unionMember, unionSchema, event);
|
|
59
|
+
const headers = {
|
|
60
|
+
":event-type": { type: "string", value: eventType },
|
|
61
|
+
":message-type": { type: "string", value: "event" },
|
|
62
|
+
":content-type": { type: "string", value: explicitPayloadContentType ?? defaultContentType },
|
|
63
|
+
...additionalHeaders,
|
|
64
|
+
};
|
|
65
|
+
return {
|
|
66
|
+
headers,
|
|
67
|
+
body,
|
|
68
|
+
};
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
async deserializeEventStream({ response, responseSchema, initialResponseContainer, }) {
|
|
72
|
+
const marshaller = this.marshaller;
|
|
73
|
+
const eventStreamMember = responseSchema.getEventStreamMember();
|
|
74
|
+
const unionSchema = responseSchema.getMemberSchema(eventStreamMember);
|
|
75
|
+
const memberSchemas = unionSchema.getMemberSchemas();
|
|
76
|
+
const initialResponseMarker = Symbol("initialResponseMarker");
|
|
77
|
+
const asyncIterable = marshaller.deserialize(response.body, async (event) => {
|
|
78
|
+
const unionMember = Object.keys(event).find((key) => {
|
|
79
|
+
return key !== "__type";
|
|
80
|
+
}) ?? "";
|
|
81
|
+
if (unionMember === "initial-response") {
|
|
82
|
+
const dataObject = await this.deserializer.read(responseSchema, event[unionMember].body);
|
|
83
|
+
delete dataObject[eventStreamMember];
|
|
84
|
+
return {
|
|
85
|
+
[initialResponseMarker]: true,
|
|
86
|
+
...dataObject,
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
else if (unionMember in memberSchemas) {
|
|
90
|
+
const eventStreamSchema = memberSchemas[unionMember];
|
|
91
|
+
return {
|
|
92
|
+
[unionMember]: await this.deserializer.read(eventStreamSchema, event[unionMember].body),
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
else {
|
|
96
|
+
return {
|
|
97
|
+
$unknown: event,
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
const asyncIterator = asyncIterable[Symbol.asyncIterator]();
|
|
102
|
+
const firstEvent = await asyncIterator.next();
|
|
103
|
+
if (firstEvent.done) {
|
|
104
|
+
return asyncIterable;
|
|
80
105
|
}
|
|
81
|
-
|
|
82
|
-
|
|
106
|
+
if (firstEvent.value?.[initialResponseMarker]) {
|
|
107
|
+
if (!responseSchema) {
|
|
108
|
+
throw new Error("@smithy::core/protocols - initial-response event encountered in event stream but no response schema given.");
|
|
109
|
+
}
|
|
110
|
+
for (const [key, value] of Object.entries(firstEvent.value)) {
|
|
111
|
+
initialResponseContainer[key] = value;
|
|
112
|
+
}
|
|
83
113
|
}
|
|
84
|
-
}
|
|
85
|
-
};
|
|
86
|
-
return marshaller.serialize(eventStreamIterable, (event) => {
|
|
87
|
-
if (event[initialRequestMarker]) {
|
|
88
|
-
return {
|
|
89
|
-
headers: event.headers,
|
|
90
|
-
body: event.body
|
|
91
|
-
};
|
|
92
|
-
}
|
|
93
|
-
const unionMember = Object.keys(event).find((key) => {
|
|
94
|
-
return key !== "__type";
|
|
95
|
-
}) ?? "";
|
|
96
|
-
const { additionalHeaders, body, eventType, explicitPayloadContentType } = this.writeEventBody(
|
|
97
|
-
unionMember,
|
|
98
|
-
unionSchema,
|
|
99
|
-
event
|
|
100
|
-
);
|
|
101
|
-
const headers = {
|
|
102
|
-
":event-type": { type: "string", value: eventType },
|
|
103
|
-
":message-type": { type: "string", value: "event" },
|
|
104
|
-
":content-type": { type: "string", value: explicitPayloadContentType ?? defaultContentType },
|
|
105
|
-
...additionalHeaders
|
|
106
|
-
};
|
|
107
|
-
return {
|
|
108
|
-
headers,
|
|
109
|
-
body
|
|
110
|
-
};
|
|
111
|
-
});
|
|
112
|
-
}
|
|
113
|
-
/**
|
|
114
|
-
* @param response - http response from which to read the event stream.
|
|
115
|
-
* @param unionSchema - schema of the event stream container (struct).
|
|
116
|
-
* @param [initialResponseContainer] - provided and written to only if the initial response is part of the event stream (RPC).
|
|
117
|
-
*
|
|
118
|
-
* @returns the asyncIterable of the event stream for the end-user.
|
|
119
|
-
*/
|
|
120
|
-
async deserializeEventStream({
|
|
121
|
-
response,
|
|
122
|
-
responseSchema,
|
|
123
|
-
initialResponseContainer
|
|
124
|
-
}) {
|
|
125
|
-
const marshaller = this.marshaller;
|
|
126
|
-
const eventStreamMember = responseSchema.getEventStreamMember();
|
|
127
|
-
const unionSchema = responseSchema.getMemberSchema(eventStreamMember);
|
|
128
|
-
const memberSchemas = unionSchema.getMemberSchemas();
|
|
129
|
-
const initialResponseMarker = Symbol("initialResponseMarker");
|
|
130
|
-
const asyncIterable = marshaller.deserialize(response.body, async (event) => {
|
|
131
|
-
const unionMember = Object.keys(event).find((key) => {
|
|
132
|
-
return key !== "__type";
|
|
133
|
-
}) ?? "";
|
|
134
|
-
if (unionMember === "initial-response") {
|
|
135
|
-
const dataObject = await this.deserializer.read(responseSchema, event[unionMember].body);
|
|
136
|
-
delete dataObject[eventStreamMember];
|
|
137
114
|
return {
|
|
138
|
-
|
|
139
|
-
|
|
115
|
+
async *[Symbol.asyncIterator]() {
|
|
116
|
+
if (!firstEvent?.value?.[initialResponseMarker]) {
|
|
117
|
+
yield firstEvent.value;
|
|
118
|
+
}
|
|
119
|
+
while (true) {
|
|
120
|
+
const { done, value } = await asyncIterator.next();
|
|
121
|
+
if (done) {
|
|
122
|
+
break;
|
|
123
|
+
}
|
|
124
|
+
yield value;
|
|
125
|
+
}
|
|
126
|
+
},
|
|
140
127
|
};
|
|
141
|
-
} else if (unionMember in memberSchemas) {
|
|
142
|
-
const eventStreamSchema = memberSchemas[unionMember];
|
|
143
|
-
return {
|
|
144
|
-
[unionMember]: await this.deserializer.read(eventStreamSchema, event[unionMember].body)
|
|
145
|
-
};
|
|
146
|
-
} else {
|
|
147
|
-
return {
|
|
148
|
-
$unknown: event
|
|
149
|
-
};
|
|
150
|
-
}
|
|
151
|
-
});
|
|
152
|
-
const asyncIterator = asyncIterable[Symbol.asyncIterator]();
|
|
153
|
-
const firstEvent = await asyncIterator.next();
|
|
154
|
-
if (firstEvent.done) {
|
|
155
|
-
return asyncIterable;
|
|
156
|
-
}
|
|
157
|
-
if (firstEvent.value?.[initialResponseMarker]) {
|
|
158
|
-
if (!responseSchema) {
|
|
159
|
-
throw new Error(
|
|
160
|
-
"@smithy::core/protocols - initial-response event encountered in event stream but no response schema given."
|
|
161
|
-
);
|
|
162
|
-
}
|
|
163
|
-
for (const [key, value] of Object.entries(firstEvent.value)) {
|
|
164
|
-
initialResponseContainer[key] = value;
|
|
165
|
-
}
|
|
166
128
|
}
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
129
|
+
writeEventBody(unionMember, unionSchema, event) {
|
|
130
|
+
const serializer = this.serializer;
|
|
131
|
+
let eventType = unionMember;
|
|
132
|
+
let explicitPayloadMember = null;
|
|
133
|
+
let explicitPayloadContentType;
|
|
134
|
+
const isKnownSchema = unionSchema.hasMemberSchema(unionMember);
|
|
135
|
+
const additionalHeaders = {};
|
|
136
|
+
if (!isKnownSchema) {
|
|
137
|
+
const [type, value] = event[unionMember];
|
|
138
|
+
eventType = type;
|
|
139
|
+
serializer.write(schema.SCHEMA.DOCUMENT, value);
|
|
171
140
|
}
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
141
|
+
else {
|
|
142
|
+
const eventSchema = unionSchema.getMemberSchema(unionMember);
|
|
143
|
+
if (eventSchema.isStructSchema()) {
|
|
144
|
+
for (const [memberName, memberSchema] of eventSchema.structIterator()) {
|
|
145
|
+
const { eventHeader, eventPayload } = memberSchema.getMergedTraits();
|
|
146
|
+
if (eventPayload) {
|
|
147
|
+
explicitPayloadMember = memberName;
|
|
148
|
+
break;
|
|
149
|
+
}
|
|
150
|
+
else if (eventHeader) {
|
|
151
|
+
const value = event[unionMember][memberName];
|
|
152
|
+
let type = "binary";
|
|
153
|
+
if (memberSchema.isNumericSchema()) {
|
|
154
|
+
if ((-2) ** 31 <= value && value <= 2 ** 31 - 1) {
|
|
155
|
+
type = "integer";
|
|
156
|
+
}
|
|
157
|
+
else {
|
|
158
|
+
type = "long";
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
else if (memberSchema.isTimestampSchema()) {
|
|
162
|
+
type = "timestamp";
|
|
163
|
+
}
|
|
164
|
+
else if (memberSchema.isStringSchema()) {
|
|
165
|
+
type = "string";
|
|
166
|
+
}
|
|
167
|
+
else if (memberSchema.isBooleanSchema()) {
|
|
168
|
+
type = "boolean";
|
|
169
|
+
}
|
|
170
|
+
if (value != null) {
|
|
171
|
+
additionalHeaders[memberName] = {
|
|
172
|
+
type,
|
|
173
|
+
value,
|
|
174
|
+
};
|
|
175
|
+
delete event[unionMember][memberName];
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
if (explicitPayloadMember !== null) {
|
|
180
|
+
const payloadSchema = eventSchema.getMemberSchema(explicitPayloadMember);
|
|
181
|
+
if (payloadSchema.isBlobSchema()) {
|
|
182
|
+
explicitPayloadContentType = "application/octet-stream";
|
|
183
|
+
}
|
|
184
|
+
else if (payloadSchema.isStringSchema()) {
|
|
185
|
+
explicitPayloadContentType = "text/plain";
|
|
186
|
+
}
|
|
187
|
+
serializer.write(payloadSchema, event[unionMember][explicitPayloadMember]);
|
|
188
|
+
}
|
|
189
|
+
else {
|
|
190
|
+
serializer.write(eventSchema, event[unionMember]);
|
|
191
|
+
}
|
|
223
192
|
}
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
type,
|
|
227
|
-
value
|
|
228
|
-
};
|
|
229
|
-
delete event[unionMember][memberName];
|
|
193
|
+
else {
|
|
194
|
+
throw new Error("@smithy/core/event-streams - non-struct member not supported in event stream union.");
|
|
230
195
|
}
|
|
231
|
-
}
|
|
232
|
-
}
|
|
233
|
-
if (explicitPayloadMember !== null) {
|
|
234
|
-
const payloadSchema = eventSchema.getMemberSchema(explicitPayloadMember);
|
|
235
|
-
if (payloadSchema.isBlobSchema()) {
|
|
236
|
-
explicitPayloadContentType = "application/octet-stream";
|
|
237
|
-
} else if (payloadSchema.isStringSchema()) {
|
|
238
|
-
explicitPayloadContentType = "text/plain";
|
|
239
|
-
}
|
|
240
|
-
serializer.write(payloadSchema, event[unionMember][explicitPayloadMember]);
|
|
241
|
-
} else {
|
|
242
|
-
serializer.write(eventSchema, event[unionMember]);
|
|
243
196
|
}
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
197
|
+
const messageSerialization = serializer.flush();
|
|
198
|
+
const body = typeof messageSerialization === "string"
|
|
199
|
+
? (this.serdeContext?.utf8Decoder ?? utilUtf8.fromUtf8)(messageSerialization)
|
|
200
|
+
: messageSerialization;
|
|
201
|
+
return {
|
|
202
|
+
body,
|
|
203
|
+
eventType,
|
|
204
|
+
explicitPayloadContentType,
|
|
205
|
+
additionalHeaders,
|
|
206
|
+
};
|
|
247
207
|
}
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
body,
|
|
252
|
-
eventType,
|
|
253
|
-
explicitPayloadContentType,
|
|
254
|
-
additionalHeaders
|
|
255
|
-
};
|
|
256
|
-
}
|
|
257
|
-
};
|
|
258
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
259
|
-
0 && (module.exports = {
|
|
260
|
-
EventStreamSerde
|
|
261
|
-
});
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
exports.EventStreamSerde = EventStreamSerde;
|