@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.
Files changed (31) hide show
  1. package/dist-cjs/index.js +308 -412
  2. package/dist-cjs/submodules/cbor/index.js +957 -969
  3. package/dist-cjs/submodules/event-streams/index.js +198 -249
  4. package/dist-cjs/submodules/protocols/index.js +793 -895
  5. package/dist-cjs/submodules/schema/index.js +617 -811
  6. package/dist-cjs/submodules/serde/index.js +584 -680
  7. package/dist-es/submodules/cbor/CborCodec.js +4 -0
  8. package/dist-es/submodules/cbor/SmithyRpcV2CborProtocol.js +3 -3
  9. package/dist-es/submodules/cbor/cbor-decode.js +18 -18
  10. package/dist-es/submodules/cbor/cbor-encode.js +5 -5
  11. package/dist-es/submodules/event-streams/EventStreamSerde.js +5 -0
  12. package/dist-es/submodules/protocols/HttpProtocol.js +2 -0
  13. package/dist-es/submodules/protocols/requestBuilder.js +9 -7
  14. package/dist-es/submodules/protocols/serde/FromStringShapeDeserializer.js +2 -0
  15. package/dist-es/submodules/protocols/serde/HttpInterceptingShapeDeserializer.js +3 -0
  16. package/dist-es/submodules/protocols/serde/HttpInterceptingShapeSerializer.js +3 -0
  17. package/dist-es/submodules/protocols/serde/ToStringShapeSerializer.js +3 -2
  18. package/dist-es/submodules/schema/TypeRegistry.js +4 -1
  19. package/dist-es/submodules/schema/schemas/ErrorSchema.js +3 -5
  20. package/dist-es/submodules/schema/schemas/ListSchema.js +5 -5
  21. package/dist-es/submodules/schema/schemas/MapSchema.js +6 -5
  22. package/dist-es/submodules/schema/schemas/NormalizedSchema.js +16 -8
  23. package/dist-es/submodules/schema/schemas/OperationSchema.js +6 -5
  24. package/dist-es/submodules/schema/schemas/Schema.js +3 -0
  25. package/dist-es/submodules/schema/schemas/SimpleSchema.js +5 -5
  26. package/dist-es/submodules/schema/schemas/StructureSchema.js +6 -5
  27. package/dist-es/submodules/schema/schemas/sentinels.js +14 -14
  28. package/dist-es/submodules/serde/value/NumericValue.js +2 -0
  29. package/dist-es/util-identity-and-auth/DefaultIdentityProviderConfig.js +1 -1
  30. package/dist-es/util-identity-and-auth/memoizeIdentityProvider.js +4 -2
  31. package/package.json +11 -11
@@ -1,261 +1,210 @@
1
- var __defProp = Object.defineProperty;
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
- // src/submodules/event-streams/index.ts
20
- var index_exports = {};
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
- // src/submodules/event-streams/EventStreamSerde.ts
27
- var import_schema = require("@smithy/core/schema");
28
- var import_util_utf8 = require("@smithy/util-utf8");
29
- var EventStreamSerde = class {
30
- /**
31
- * Properties are injected by the HttpProtocol.
32
- */
33
- constructor({
34
- marshaller,
35
- serializer,
36
- deserializer,
37
- serdeContext,
38
- defaultContentType
39
- }) {
40
- this.marshaller = marshaller;
41
- this.serializer = serializer;
42
- this.deserializer = deserializer;
43
- this.serdeContext = serdeContext;
44
- this.defaultContentType = defaultContentType;
45
- }
46
- /**
47
- * @param eventStream - the iterable provided by the caller.
48
- * @param requestSchema - the schema of the event stream container (struct).
49
- * @param [initialRequest] - only provided if the initial-request is part of the event stream (RPC).
50
- *
51
- * @returns a stream suitable for the HTTP body of a request.
52
- */
53
- async serializeEventStream({
54
- eventStream,
55
- requestSchema,
56
- initialRequest
57
- }) {
58
- const marshaller = this.marshaller;
59
- const eventStreamMember = requestSchema.getEventStreamMember();
60
- const unionSchema = requestSchema.getMemberSchema(eventStreamMember);
61
- const memberSchemas = unionSchema.getMemberSchemas();
62
- const serializer = this.serializer;
63
- const defaultContentType = this.defaultContentType;
64
- const initialRequestMarker = Symbol("initialRequestMarker");
65
- const eventStreamIterable = {
66
- async *[Symbol.asyncIterator]() {
67
- if (initialRequest) {
68
- const headers = {
69
- ":event-type": { type: "string", value: "initial-request" },
70
- ":message-type": { type: "string", value: "event" },
71
- ":content-type": { type: "string", value: defaultContentType }
72
- };
73
- serializer.write(requestSchema, initialRequest);
74
- const body = serializer.flush();
75
- yield {
76
- [initialRequestMarker]: true,
77
- headers,
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
- for await (const page of eventStream) {
82
- yield page;
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
- [initialResponseMarker]: true,
139
- ...dataObject
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
- return {
168
- async *[Symbol.asyncIterator]() {
169
- if (!firstEvent?.value?.[initialResponseMarker]) {
170
- yield firstEvent.value;
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
- while (true) {
173
- const { done, value } = await asyncIterator.next();
174
- if (done) {
175
- break;
176
- }
177
- yield value;
178
- }
179
- }
180
- };
181
- }
182
- /**
183
- * @param unionMember - member name within the structure that contains an event stream union.
184
- * @param unionSchema - schema of the union.
185
- * @param event
186
- *
187
- * @returns the event body (bytes) and event type (string).
188
- */
189
- writeEventBody(unionMember, unionSchema, event) {
190
- const serializer = this.serializer;
191
- let eventType = unionMember;
192
- let explicitPayloadMember = null;
193
- let explicitPayloadContentType;
194
- const isKnownSchema = unionSchema.hasMemberSchema(unionMember);
195
- const additionalHeaders = {};
196
- if (!isKnownSchema) {
197
- const [type, value] = event[unionMember];
198
- eventType = type;
199
- serializer.write(import_schema.SCHEMA.DOCUMENT, value);
200
- } else {
201
- const eventSchema = unionSchema.getMemberSchema(unionMember);
202
- if (eventSchema.isStructSchema()) {
203
- for (const [memberName, memberSchema] of eventSchema.structIterator()) {
204
- const { eventHeader, eventPayload } = memberSchema.getMergedTraits();
205
- if (eventPayload) {
206
- explicitPayloadMember = memberName;
207
- break;
208
- } else if (eventHeader) {
209
- const value = event[unionMember][memberName];
210
- let type = "binary";
211
- if (memberSchema.isNumericSchema()) {
212
- if ((-2) ** 31 <= value && value <= 2 ** 31 - 1) {
213
- type = "integer";
214
- } else {
215
- type = "long";
216
- }
217
- } else if (memberSchema.isTimestampSchema()) {
218
- type = "timestamp";
219
- } else if (memberSchema.isStringSchema()) {
220
- type = "string";
221
- } else if (memberSchema.isBooleanSchema()) {
222
- type = "boolean";
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
- if (value != null) {
225
- additionalHeaders[memberName] = {
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
- } else {
245
- throw new Error("@smithy/core/event-streams - non-struct member not supported in event stream union.");
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
- const messageSerialization = serializer.flush();
249
- const body = typeof messageSerialization === "string" ? (this.serdeContext?.utf8Decoder ?? import_util_utf8.fromUtf8)(messageSerialization) : messageSerialization;
250
- return {
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;