From cf5f2acba3ed5c403d00f6f9531a2dc3a5ef8d9a Mon Sep 17 00:00:00 2001 From: GitHub Actions Date: Wed, 3 Sep 2025 18:25:19 +0000 Subject: [PATCH] chore: Update dist --- dist/cleanup/index.js | 513 ++++++++++++++++++++++++++++++++++++++---- dist/index.js | 513 ++++++++++++++++++++++++++++++++++++++---- 2 files changed, 930 insertions(+), 96 deletions(-) diff --git a/dist/cleanup/index.js b/dist/cleanup/index.js index 5773279..e8e4d31 100644 --- a/dist/cleanup/index.js +++ b/dist/cleanup/index.js @@ -14146,7 +14146,7 @@ var memoizeIdentityProvider = /* @__PURE__ */ __name((provider, isExpired, requi /***/ }), -/***/ 3422: +/***/ 6579: /***/ ((module, __unused_webpack_exports, __nccwpck_require__) => { var __defProp = Object.defineProperty; @@ -14167,6 +14167,282 @@ var __copyProps = (to, from, except, desc) => { }; var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); +// src/submodules/event-streams/index.ts +var event_streams_exports = {}; +__export(event_streams_exports, { + EventStreamSerde: () => EventStreamSerde +}); +module.exports = __toCommonJS(event_streams_exports); + +// src/submodules/event-streams/EventStreamSerde.ts +var import_schema = __nccwpck_require__(6890); +var import_util_utf8 = __nccwpck_require__(1577); +var EventStreamSerde = class { + /** + * Properties are injected by the HttpProtocol. + */ + constructor({ + marshaller, + serializer, + deserializer, + serdeContext, + defaultContentType + }) { + this.marshaller = marshaller; + this.serializer = serializer; + this.deserializer = deserializer; + this.serdeContext = serdeContext; + this.defaultContentType = defaultContentType; + } + /** + * @param eventStream - the iterable provided by the caller. + * @param requestSchema - the schema of the event stream container (struct). + * @param [initialRequest] - only provided if the initial-request is part of the event stream (RPC). + * + * @returns a stream suitable for the HTTP body of a request. + */ + async serializeEventStream({ + eventStream, + requestSchema, + initialRequest + }) { + const marshaller = this.marshaller; + const eventStreamMember = requestSchema.getEventStreamMember(); + const unionSchema = requestSchema.getMemberSchema(eventStreamMember); + const memberSchemas = unionSchema.getMemberSchemas(); + const serializer = this.serializer; + const defaultContentType = this.defaultContentType; + const initialRequestMarker = Symbol("initialRequestMarker"); + const eventStreamIterable = { + async *[Symbol.asyncIterator]() { + if (initialRequest) { + const headers = { + ":event-type": { type: "string", value: "initial-request" }, + ":message-type": { type: "string", value: "event" }, + ":content-type": { type: "string", value: defaultContentType } + }; + serializer.write(requestSchema, initialRequest); + const body = serializer.flush(); + yield { + [initialRequestMarker]: true, + headers, + body + }; + } + for await (const page of eventStream) { + yield page; + } + } + }; + return marshaller.serialize(eventStreamIterable, (event) => { + if (event[initialRequestMarker]) { + return { + headers: event.headers, + body: event.body + }; + } + const unionMember = Object.keys(event).find((key) => { + return key !== "__type"; + }) ?? ""; + const { additionalHeaders, body, eventType, explicitPayloadContentType } = this.writeEventBody( + unionMember, + unionSchema, + event + ); + const headers = { + ":event-type": { type: "string", value: eventType }, + ":message-type": { type: "string", value: "event" }, + ":content-type": { type: "string", value: explicitPayloadContentType ?? defaultContentType }, + ...additionalHeaders + }; + return { + headers, + body + }; + }); + } + /** + * @param response - http response from which to read the event stream. + * @param unionSchema - schema of the event stream container (struct). + * @param [initialResponseContainer] - provided and written to only if the initial response is part of the event stream (RPC). + * + * @returns the asyncIterable of the event stream for the end-user. + */ + async deserializeEventStream({ + response, + responseSchema, + initialResponseContainer + }) { + const marshaller = this.marshaller; + const eventStreamMember = responseSchema.getEventStreamMember(); + const unionSchema = responseSchema.getMemberSchema(eventStreamMember); + const memberSchemas = unionSchema.getMemberSchemas(); + const initialResponseMarker = Symbol("initialResponseMarker"); + const asyncIterable = marshaller.deserialize(response.body, async (event) => { + const unionMember = Object.keys(event).find((key) => { + return key !== "__type"; + }) ?? ""; + if (unionMember === "initial-response") { + const dataObject = await this.deserializer.read(responseSchema, event[unionMember].body); + delete dataObject[eventStreamMember]; + return { + [initialResponseMarker]: true, + ...dataObject + }; + } else if (unionMember in memberSchemas) { + const eventStreamSchema = memberSchemas[unionMember]; + return { + [unionMember]: await this.deserializer.read(eventStreamSchema, event[unionMember].body) + }; + } else { + return { + $unknown: event + }; + } + }); + const asyncIterator = asyncIterable[Symbol.asyncIterator](); + const firstEvent = await asyncIterator.next(); + if (firstEvent.done) { + return asyncIterable; + } + if (firstEvent.value?.[initialResponseMarker]) { + if (!responseSchema) { + throw new Error( + "@smithy::core/protocols - initial-response event encountered in event stream but no response schema given." + ); + } + for (const [key, value] of Object.entries(firstEvent.value)) { + initialResponseContainer[key] = value; + } + } + return { + async *[Symbol.asyncIterator]() { + if (!firstEvent?.value?.[initialResponseMarker]) { + yield firstEvent.value; + } + while (true) { + const { done, value } = await asyncIterator.next(); + if (done) { + break; + } + yield value; + } + } + }; + } + /** + * @param unionMember - member name within the structure that contains an event stream union. + * @param unionSchema - schema of the union. + * @param event + * + * @returns the event body (bytes) and event type (string). + */ + writeEventBody(unionMember, unionSchema, event) { + const serializer = this.serializer; + let eventType = unionMember; + let explicitPayloadMember = null; + let explicitPayloadContentType; + const isKnownSchema = unionSchema.hasMemberSchema(unionMember); + const additionalHeaders = {}; + if (!isKnownSchema) { + const [type, value] = event[unionMember]; + eventType = type; + serializer.write(import_schema.SCHEMA.DOCUMENT, value); + } else { + const eventSchema = unionSchema.getMemberSchema(unionMember); + if (eventSchema.isStructSchema()) { + for (const [memberName, memberSchema] of eventSchema.structIterator()) { + const { eventHeader, eventPayload } = memberSchema.getMergedTraits(); + if (eventPayload) { + explicitPayloadMember = memberName; + break; + } else if (eventHeader) { + const value = event[unionMember][memberName]; + let type = "binary"; + if (memberSchema.isNumericSchema()) { + if ((-2) ** 31 <= value && value <= 2 ** 31 - 1) { + type = "integer"; + } else { + type = "long"; + } + } else if (memberSchema.isTimestampSchema()) { + type = "timestamp"; + } else if (memberSchema.isStringSchema()) { + type = "string"; + } else if (memberSchema.isBooleanSchema()) { + type = "boolean"; + } + if (value != null) { + additionalHeaders[memberName] = { + type, + value + }; + delete event[unionMember][memberName]; + } + } + } + if (explicitPayloadMember !== null) { + const payloadSchema = eventSchema.getMemberSchema(explicitPayloadMember); + if (payloadSchema.isBlobSchema()) { + explicitPayloadContentType = "application/octet-stream"; + } else if (payloadSchema.isStringSchema()) { + explicitPayloadContentType = "text/plain"; + } + serializer.write(payloadSchema, event[unionMember][explicitPayloadMember]); + } else { + serializer.write(eventSchema, event[unionMember]); + } + } else { + throw new Error("@smithy/core/event-streams - non-struct member not supported in event stream union."); + } + } + const messageSerialization = serializer.flush(); + const body = typeof messageSerialization === "string" ? (this.serdeContext?.utf8Decoder ?? import_util_utf8.fromUtf8)(messageSerialization) : messageSerialization; + return { + body, + eventType, + explicitPayloadContentType, + additionalHeaders + }; + } +}; +// Annotate the CommonJS export names for ESM import in node: +0 && (0); + + +/***/ }), + +/***/ 3422: +/***/ ((module, __unused_webpack_exports, __nccwpck_require__) => { + +var __create = Object.create; +var __defProp = Object.defineProperty; +var __getOwnPropDesc = Object.getOwnPropertyDescriptor; +var __getOwnPropNames = Object.getOwnPropertyNames; +var __getProtoOf = Object.getPrototypeOf; +var __hasOwnProp = Object.prototype.hasOwnProperty; +var __export = (target, all) => { + for (var name in all) + __defProp(target, name, { get: all[name], enumerable: true }); +}; +var __copyProps = (to, from, except, desc) => { + if (from && typeof from === "object" || typeof from === "function") { + for (let key of __getOwnPropNames(from)) + if (!__hasOwnProp.call(to, key) && key !== except) + __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); + } + return to; +}; +var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps( + // If the importer is in node compatibility mode or this is not an ESM + // file that has been converted to a CommonJS file using a Babel- + // compatible transform (i.e. "__esModule" has not been set), then set + // "default" to the CommonJS "module.exports" for node compatibility. + isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, + mod +)); +var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); + // src/submodules/protocols/index.ts var protocols_exports = {}; __export(protocols_exports, { @@ -14174,6 +14450,7 @@ __export(protocols_exports, { HttpBindingProtocol: () => HttpBindingProtocol, HttpInterceptingShapeDeserializer: () => HttpInterceptingShapeDeserializer, HttpInterceptingShapeSerializer: () => HttpInterceptingShapeSerializer, + HttpProtocol: () => HttpProtocol, RequestBuilder: () => RequestBuilder, RpcProtocol: () => RpcProtocol, ToStringShapeSerializer: () => ToStringShapeSerializer, @@ -14287,9 +14564,75 @@ var HttpProtocol = class { cfId: output.headers["x-amz-cf-id"] }; } + /** + * @param eventStream - the iterable provided by the caller. + * @param requestSchema - the schema of the event stream container (struct). + * @param [initialRequest] - only provided if the initial-request is part of the event stream (RPC). + * + * @returns a stream suitable for the HTTP body of a request. + */ + async serializeEventStream({ + eventStream, + requestSchema, + initialRequest + }) { + const eventStreamSerde = await this.loadEventStreamCapability(); + return eventStreamSerde.serializeEventStream({ + eventStream, + requestSchema, + initialRequest + }); + } + /** + * @param response - http response from which to read the event stream. + * @param unionSchema - schema of the event stream container (struct). + * @param [initialResponseContainer] - provided and written to only if the initial response is part of the event stream (RPC). + * + * @returns the asyncIterable of the event stream. + */ + async deserializeEventStream({ + response, + responseSchema, + initialResponseContainer + }) { + const eventStreamSerde = await this.loadEventStreamCapability(); + return eventStreamSerde.deserializeEventStream({ + response, + responseSchema, + initialResponseContainer + }); + } + /** + * Loads eventStream capability async (for chunking). + */ + async loadEventStreamCapability() { + const { EventStreamSerde } = await Promise.resolve().then(() => __toESM(__nccwpck_require__(6579))); + return new EventStreamSerde({ + marshaller: this.getEventStreamMarshaller(), + serializer: this.serializer, + deserializer: this.deserializer, + serdeContext: this.serdeContext, + defaultContentType: this.getDefaultContentType() + }); + } + /** + * @returns content-type default header value for event stream events and other documents. + */ + getDefaultContentType() { + throw new Error( + `@smithy/core/protocols - ${this.constructor.name} getDefaultContentType() implementation missing.` + ); + } async deserializeHttpMessage(schema, context, response, arg4, arg5) { return []; } + getEventStreamMarshaller() { + const context = this.serdeContext; + if (!context.eventStreamMarshaller) { + throw new Error("@smithy/core - HttpProtocol: eventStreamMarshaller missing in serdeContext."); + } + return context.eventStreamMarshaller; + } }; // src/submodules/protocols/HttpBindingProtocol.ts @@ -14343,7 +14686,12 @@ var HttpBindingProtocol = class extends HttpProtocol { if (isStreaming) { const isEventStream = memberNs.isStructSchema(); if (isEventStream) { - throw new Error("serialization of event streams is not yet implemented"); + if (input[memberName]) { + payload = await this.serializeEventStream({ + eventStream: input[memberName], + requestSchema: ns + }); + } } else { payload = inputMemberValue; } @@ -14458,11 +14806,8 @@ var HttpBindingProtocol = class extends HttpProtocol { } } } - const output = { - $metadata: this.deserializeMetadata(response), - ...dataObject - }; - return output; + dataObject.$metadata = this.deserializeMetadata(response); + return dataObject; } async deserializeHttpMessage(schema, context, response, arg4, arg5) { let dataObject; @@ -14481,25 +14826,9 @@ var HttpBindingProtocol = class extends HttpProtocol { if (isStreaming) { const isEventStream = memberSchema.isStructSchema(); if (isEventStream) { - const context2 = this.serdeContext; - if (!context2.eventStreamMarshaller) { - throw new Error("@smithy/core - HttpProtocol: eventStreamMarshaller missing in serdeContext."); - } - const memberSchemas = memberSchema.getMemberSchemas(); - dataObject[memberName] = context2.eventStreamMarshaller.deserialize(response.body, async (event) => { - const unionMember = Object.keys(event).find((key) => { - return key !== "__type"; - }) ?? ""; - if (unionMember in memberSchemas) { - const eventStreamSchema = memberSchemas[unionMember]; - return { - [unionMember]: await deserializer.read(eventStreamSchema, event[unionMember].body) - }; - } else { - return { - $unknown: event - }; - } + dataObject[memberName] = await this.deserializeEventStream({ + response, + responseSchema: ns }); } else { dataObject[memberName] = (0, import_util_stream2.sdkStreamMixin)(response.body); @@ -14581,8 +14910,26 @@ var RpcProtocol = class extends HttpProtocol { ...input }; if (input) { - serializer.write(schema, _input); - payload = serializer.flush(); + const eventStreamMember = ns.getEventStreamMember(); + if (eventStreamMember) { + if (_input[eventStreamMember]) { + const initialRequest = {}; + for (const [memberName, memberSchema] of ns.structIterator()) { + if (memberName !== eventStreamMember && _input[memberName]) { + serializer.write(memberSchema, _input[memberName]); + initialRequest[memberName] = serializer.flush(); + } + } + payload = await this.serializeEventStream({ + eventStream: _input[eventStreamMember], + requestSchema: ns, + initialRequest + }); + } + } else { + serializer.write(schema, _input); + payload = serializer.flush(); + } } request.headers = headers; request.query = query; @@ -14595,9 +14942,9 @@ var RpcProtocol = class extends HttpProtocol { const ns = import_schema3.NormalizedSchema.of(operationSchema.output); const dataObject = {}; if (response.statusCode >= 300) { - const bytes2 = await collectBody(response.body, context); - if (bytes2.byteLength > 0) { - Object.assign(dataObject, await deserializer.read(import_schema3.SCHEMA.DOCUMENT, bytes2)); + const bytes = await collectBody(response.body, context); + if (bytes.byteLength > 0) { + Object.assign(dataObject, await deserializer.read(import_schema3.SCHEMA.DOCUMENT, bytes)); } await this.handleError(operationSchema, context, response, dataObject, this.deserializeMetadata(response)); throw new Error("@smithy/core/protocols - RPC Protocol error handler failed to throw."); @@ -14607,15 +14954,21 @@ var RpcProtocol = class extends HttpProtocol { delete response.headers[header]; response.headers[header.toLowerCase()] = value; } - const bytes = await collectBody(response.body, context); - if (bytes.byteLength > 0) { - Object.assign(dataObject, await deserializer.read(ns, bytes)); + const eventStreamMember = ns.getEventStreamMember(); + if (eventStreamMember) { + dataObject[eventStreamMember] = await this.deserializeEventStream({ + response, + responseSchema: ns, + initialResponseContainer: dataObject + }); + } else { + const bytes = await collectBody(response.body, context); + if (bytes.byteLength > 0) { + Object.assign(dataObject, await deserializer.read(ns, bytes)); + } } - const output = { - $metadata: this.deserializeMetadata(response), - ...dataObject - }; - return output; + dataObject.$metadata = this.deserializeMetadata(response); + return dataObject; } }; @@ -14872,7 +15225,9 @@ var ToStringShapeSerializer = class { if (ns.isTimestampSchema()) { if (!(value instanceof Date)) { throw new Error( - `@smithy/core/protocols - received non-Date value ${value} when schema expected Date in ${ns.getName(true)}` + `@smithy/core/protocols - received non-Date value ${value} when schema expected Date in ${ns.getName( + true + )}` ); } const format = determineTimestampFormat(ns, this.settings); @@ -15726,6 +16081,17 @@ var NormalizedSchema = class _NormalizedSchema { } throw new Error(`@smithy/core/schema - the schema ${this.getName(true)} does not have a value member.`); } + /** + * @param member - to query. + * @returns whether there is a memberSchema with the given member name. False if not a structure (or union). + */ + hasMemberSchema(member) { + if (this.isStructSchema()) { + const struct2 = this.getSchema(); + return member in struct2.members; + } + return false; + } /** * @returns the NormalizedSchema for the given member name. The returned instance will return true for `isMemberSchema()` * and will have the member name given. @@ -15772,6 +16138,20 @@ var NormalizedSchema = class _NormalizedSchema { } return {}; } + /** + * @returns member name of event stream or empty string indicating none exists or this + * isn't a structure schema. + */ + getEventStreamMember() { + if (this.isStructSchema()) { + for (const [memberName, memberSchema] of this.structIterator()) { + if (memberSchema.isStreaming() && memberSchema.isStructSchema()) { + return memberName; + } + } + } + return ""; + } /** * Allows iteration over members of a structure schema. * Each yield is a pair of the member name and member schema. @@ -16477,11 +16857,11 @@ var NumericValue = class _NumericValue { return false; } const _nv = object; - const prototypeMatch = _NumericValue.prototype.isPrototypeOf(object.constructor?.prototype); + const prototypeMatch = _NumericValue.prototype.isPrototypeOf(object); if (prototypeMatch) { return prototypeMatch; } - if (typeof _nv.string === "string" && typeof _nv.type === "string" && _nv.constructor?.name === "NumericValue") { + if (typeof _nv.string === "string" && typeof _nv.type === "string" && _nv.constructor?.name?.endsWith("NumericValue")) { return true; } return prototypeMatch; @@ -21170,7 +21550,7 @@ __export(src_exports, { Client: () => Client, Command: () => Command, NoOpLogger: () => NoOpLogger, - SENSITIVE_STRING: () => SENSITIVE_STRING, + SENSITIVE_STRING: () => SENSITIVE_STRING2, ServiceException: () => ServiceException, _json: () => _json, collectBody: () => import_protocols.collectBody, @@ -21252,6 +21632,43 @@ var import_protocols = __nccwpck_require__(3422); // src/command.ts var import_types = __nccwpck_require__(690); + +// src/schemaLogFilter.ts +var import_schema = __nccwpck_require__(6890); +var SENSITIVE_STRING = "***SensitiveInformation***"; +function schemaLogFilter(schema, data) { + if (data == null) { + return data; + } + const ns = import_schema.NormalizedSchema.of(schema); + if (ns.getMergedTraits().sensitive) { + return SENSITIVE_STRING; + } + if (ns.isListSchema()) { + const isSensitive = !!ns.getValueSchema().getMergedTraits().sensitive; + if (isSensitive) { + return SENSITIVE_STRING; + } + } else if (ns.isMapSchema()) { + const isSensitive = !!ns.getKeySchema().getMergedTraits().sensitive || !!ns.getValueSchema().getMergedTraits().sensitive; + if (isSensitive) { + return SENSITIVE_STRING; + } + } else if (ns.isStructSchema() && typeof data === "object") { + const object = data; + const newObject = {}; + for (const [member, memberNs] of ns.structIterator()) { + if (object[member] != null) { + newObject[member] = schemaLogFilter(memberNs, object[member]); + } + } + return newObject; + } + return data; +} +__name(schemaLogFilter, "schemaLogFilter"); + +// src/command.ts var Command = class { constructor() { this.middlewareStack = (0, import_middleware_stack.constructStack)(); @@ -21313,8 +21730,8 @@ var ClassBuilder = class { this._clientName = ""; this._additionalContext = {}; this._smithyContext = {}; - this._inputFilterSensitiveLog = (_) => _; - this._outputFilterSensitiveLog = (_) => _; + this._inputFilterSensitiveLog = void 0; + this._outputFilterSensitiveLog = void 0; this._serializer = null; this._deserializer = null; } @@ -21441,8 +21858,8 @@ var ClassBuilder = class { middlewareFn: closure._middlewareFn, clientName: closure._clientName, commandName: closure._commandName, - inputFilterSensitiveLog: closure._inputFilterSensitiveLog, - outputFilterSensitiveLog: closure._outputFilterSensitiveLog, + inputFilterSensitiveLog: closure._inputFilterSensitiveLog ?? (closure._operationSchema ? schemaLogFilter.bind(null, closure._operationSchema.input) : (_) => _), + outputFilterSensitiveLog: closure._outputFilterSensitiveLog ?? (closure._operationSchema ? schemaLogFilter.bind(null, closure._operationSchema.output) : (_) => _), smithyContext: closure._smithyContext, additionalContext: closure._additionalContext }); @@ -21452,7 +21869,7 @@ var ClassBuilder = class { }; // src/constants.ts -var SENSITIVE_STRING = "***SensitiveInformation***"; +var SENSITIVE_STRING2 = "***SensitiveInformation***"; // src/create-aggregated-client.ts var createAggregatedClient = /* @__PURE__ */ __name((commands, Client2) => { diff --git a/dist/index.js b/dist/index.js index e4b821d..72d136a 100644 --- a/dist/index.js +++ b/dist/index.js @@ -14889,7 +14889,7 @@ var memoizeIdentityProvider = /* @__PURE__ */ __name((provider, isExpired, requi /***/ }), -/***/ 3422: +/***/ 6579: /***/ ((module, __unused_webpack_exports, __nccwpck_require__) => { var __defProp = Object.defineProperty; @@ -14910,6 +14910,282 @@ var __copyProps = (to, from, except, desc) => { }; var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); +// src/submodules/event-streams/index.ts +var event_streams_exports = {}; +__export(event_streams_exports, { + EventStreamSerde: () => EventStreamSerde +}); +module.exports = __toCommonJS(event_streams_exports); + +// src/submodules/event-streams/EventStreamSerde.ts +var import_schema = __nccwpck_require__(6890); +var import_util_utf8 = __nccwpck_require__(1577); +var EventStreamSerde = class { + /** + * Properties are injected by the HttpProtocol. + */ + constructor({ + marshaller, + serializer, + deserializer, + serdeContext, + defaultContentType + }) { + this.marshaller = marshaller; + this.serializer = serializer; + this.deserializer = deserializer; + this.serdeContext = serdeContext; + this.defaultContentType = defaultContentType; + } + /** + * @param eventStream - the iterable provided by the caller. + * @param requestSchema - the schema of the event stream container (struct). + * @param [initialRequest] - only provided if the initial-request is part of the event stream (RPC). + * + * @returns a stream suitable for the HTTP body of a request. + */ + async serializeEventStream({ + eventStream, + requestSchema, + initialRequest + }) { + const marshaller = this.marshaller; + const eventStreamMember = requestSchema.getEventStreamMember(); + const unionSchema = requestSchema.getMemberSchema(eventStreamMember); + const memberSchemas = unionSchema.getMemberSchemas(); + const serializer = this.serializer; + const defaultContentType = this.defaultContentType; + const initialRequestMarker = Symbol("initialRequestMarker"); + const eventStreamIterable = { + async *[Symbol.asyncIterator]() { + if (initialRequest) { + const headers = { + ":event-type": { type: "string", value: "initial-request" }, + ":message-type": { type: "string", value: "event" }, + ":content-type": { type: "string", value: defaultContentType } + }; + serializer.write(requestSchema, initialRequest); + const body = serializer.flush(); + yield { + [initialRequestMarker]: true, + headers, + body + }; + } + for await (const page of eventStream) { + yield page; + } + } + }; + return marshaller.serialize(eventStreamIterable, (event) => { + if (event[initialRequestMarker]) { + return { + headers: event.headers, + body: event.body + }; + } + const unionMember = Object.keys(event).find((key) => { + return key !== "__type"; + }) ?? ""; + const { additionalHeaders, body, eventType, explicitPayloadContentType } = this.writeEventBody( + unionMember, + unionSchema, + event + ); + const headers = { + ":event-type": { type: "string", value: eventType }, + ":message-type": { type: "string", value: "event" }, + ":content-type": { type: "string", value: explicitPayloadContentType ?? defaultContentType }, + ...additionalHeaders + }; + return { + headers, + body + }; + }); + } + /** + * @param response - http response from which to read the event stream. + * @param unionSchema - schema of the event stream container (struct). + * @param [initialResponseContainer] - provided and written to only if the initial response is part of the event stream (RPC). + * + * @returns the asyncIterable of the event stream for the end-user. + */ + async deserializeEventStream({ + response, + responseSchema, + initialResponseContainer + }) { + const marshaller = this.marshaller; + const eventStreamMember = responseSchema.getEventStreamMember(); + const unionSchema = responseSchema.getMemberSchema(eventStreamMember); + const memberSchemas = unionSchema.getMemberSchemas(); + const initialResponseMarker = Symbol("initialResponseMarker"); + const asyncIterable = marshaller.deserialize(response.body, async (event) => { + const unionMember = Object.keys(event).find((key) => { + return key !== "__type"; + }) ?? ""; + if (unionMember === "initial-response") { + const dataObject = await this.deserializer.read(responseSchema, event[unionMember].body); + delete dataObject[eventStreamMember]; + return { + [initialResponseMarker]: true, + ...dataObject + }; + } else if (unionMember in memberSchemas) { + const eventStreamSchema = memberSchemas[unionMember]; + return { + [unionMember]: await this.deserializer.read(eventStreamSchema, event[unionMember].body) + }; + } else { + return { + $unknown: event + }; + } + }); + const asyncIterator = asyncIterable[Symbol.asyncIterator](); + const firstEvent = await asyncIterator.next(); + if (firstEvent.done) { + return asyncIterable; + } + if (firstEvent.value?.[initialResponseMarker]) { + if (!responseSchema) { + throw new Error( + "@smithy::core/protocols - initial-response event encountered in event stream but no response schema given." + ); + } + for (const [key, value] of Object.entries(firstEvent.value)) { + initialResponseContainer[key] = value; + } + } + return { + async *[Symbol.asyncIterator]() { + if (!firstEvent?.value?.[initialResponseMarker]) { + yield firstEvent.value; + } + while (true) { + const { done, value } = await asyncIterator.next(); + if (done) { + break; + } + yield value; + } + } + }; + } + /** + * @param unionMember - member name within the structure that contains an event stream union. + * @param unionSchema - schema of the union. + * @param event + * + * @returns the event body (bytes) and event type (string). + */ + writeEventBody(unionMember, unionSchema, event) { + const serializer = this.serializer; + let eventType = unionMember; + let explicitPayloadMember = null; + let explicitPayloadContentType; + const isKnownSchema = unionSchema.hasMemberSchema(unionMember); + const additionalHeaders = {}; + if (!isKnownSchema) { + const [type, value] = event[unionMember]; + eventType = type; + serializer.write(import_schema.SCHEMA.DOCUMENT, value); + } else { + const eventSchema = unionSchema.getMemberSchema(unionMember); + if (eventSchema.isStructSchema()) { + for (const [memberName, memberSchema] of eventSchema.structIterator()) { + const { eventHeader, eventPayload } = memberSchema.getMergedTraits(); + if (eventPayload) { + explicitPayloadMember = memberName; + break; + } else if (eventHeader) { + const value = event[unionMember][memberName]; + let type = "binary"; + if (memberSchema.isNumericSchema()) { + if ((-2) ** 31 <= value && value <= 2 ** 31 - 1) { + type = "integer"; + } else { + type = "long"; + } + } else if (memberSchema.isTimestampSchema()) { + type = "timestamp"; + } else if (memberSchema.isStringSchema()) { + type = "string"; + } else if (memberSchema.isBooleanSchema()) { + type = "boolean"; + } + if (value != null) { + additionalHeaders[memberName] = { + type, + value + }; + delete event[unionMember][memberName]; + } + } + } + if (explicitPayloadMember !== null) { + const payloadSchema = eventSchema.getMemberSchema(explicitPayloadMember); + if (payloadSchema.isBlobSchema()) { + explicitPayloadContentType = "application/octet-stream"; + } else if (payloadSchema.isStringSchema()) { + explicitPayloadContentType = "text/plain"; + } + serializer.write(payloadSchema, event[unionMember][explicitPayloadMember]); + } else { + serializer.write(eventSchema, event[unionMember]); + } + } else { + throw new Error("@smithy/core/event-streams - non-struct member not supported in event stream union."); + } + } + const messageSerialization = serializer.flush(); + const body = typeof messageSerialization === "string" ? (this.serdeContext?.utf8Decoder ?? import_util_utf8.fromUtf8)(messageSerialization) : messageSerialization; + return { + body, + eventType, + explicitPayloadContentType, + additionalHeaders + }; + } +}; +// Annotate the CommonJS export names for ESM import in node: +0 && (0); + + +/***/ }), + +/***/ 3422: +/***/ ((module, __unused_webpack_exports, __nccwpck_require__) => { + +var __create = Object.create; +var __defProp = Object.defineProperty; +var __getOwnPropDesc = Object.getOwnPropertyDescriptor; +var __getOwnPropNames = Object.getOwnPropertyNames; +var __getProtoOf = Object.getPrototypeOf; +var __hasOwnProp = Object.prototype.hasOwnProperty; +var __export = (target, all) => { + for (var name in all) + __defProp(target, name, { get: all[name], enumerable: true }); +}; +var __copyProps = (to, from, except, desc) => { + if (from && typeof from === "object" || typeof from === "function") { + for (let key of __getOwnPropNames(from)) + if (!__hasOwnProp.call(to, key) && key !== except) + __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); + } + return to; +}; +var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps( + // If the importer is in node compatibility mode or this is not an ESM + // file that has been converted to a CommonJS file using a Babel- + // compatible transform (i.e. "__esModule" has not been set), then set + // "default" to the CommonJS "module.exports" for node compatibility. + isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, + mod +)); +var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); + // src/submodules/protocols/index.ts var protocols_exports = {}; __export(protocols_exports, { @@ -14917,6 +15193,7 @@ __export(protocols_exports, { HttpBindingProtocol: () => HttpBindingProtocol, HttpInterceptingShapeDeserializer: () => HttpInterceptingShapeDeserializer, HttpInterceptingShapeSerializer: () => HttpInterceptingShapeSerializer, + HttpProtocol: () => HttpProtocol, RequestBuilder: () => RequestBuilder, RpcProtocol: () => RpcProtocol, ToStringShapeSerializer: () => ToStringShapeSerializer, @@ -15030,9 +15307,75 @@ var HttpProtocol = class { cfId: output.headers["x-amz-cf-id"] }; } + /** + * @param eventStream - the iterable provided by the caller. + * @param requestSchema - the schema of the event stream container (struct). + * @param [initialRequest] - only provided if the initial-request is part of the event stream (RPC). + * + * @returns a stream suitable for the HTTP body of a request. + */ + async serializeEventStream({ + eventStream, + requestSchema, + initialRequest + }) { + const eventStreamSerde = await this.loadEventStreamCapability(); + return eventStreamSerde.serializeEventStream({ + eventStream, + requestSchema, + initialRequest + }); + } + /** + * @param response - http response from which to read the event stream. + * @param unionSchema - schema of the event stream container (struct). + * @param [initialResponseContainer] - provided and written to only if the initial response is part of the event stream (RPC). + * + * @returns the asyncIterable of the event stream. + */ + async deserializeEventStream({ + response, + responseSchema, + initialResponseContainer + }) { + const eventStreamSerde = await this.loadEventStreamCapability(); + return eventStreamSerde.deserializeEventStream({ + response, + responseSchema, + initialResponseContainer + }); + } + /** + * Loads eventStream capability async (for chunking). + */ + async loadEventStreamCapability() { + const { EventStreamSerde } = await Promise.resolve().then(() => __toESM(__nccwpck_require__(6579))); + return new EventStreamSerde({ + marshaller: this.getEventStreamMarshaller(), + serializer: this.serializer, + deserializer: this.deserializer, + serdeContext: this.serdeContext, + defaultContentType: this.getDefaultContentType() + }); + } + /** + * @returns content-type default header value for event stream events and other documents. + */ + getDefaultContentType() { + throw new Error( + `@smithy/core/protocols - ${this.constructor.name} getDefaultContentType() implementation missing.` + ); + } async deserializeHttpMessage(schema, context, response, arg4, arg5) { return []; } + getEventStreamMarshaller() { + const context = this.serdeContext; + if (!context.eventStreamMarshaller) { + throw new Error("@smithy/core - HttpProtocol: eventStreamMarshaller missing in serdeContext."); + } + return context.eventStreamMarshaller; + } }; // src/submodules/protocols/HttpBindingProtocol.ts @@ -15086,7 +15429,12 @@ var HttpBindingProtocol = class extends HttpProtocol { if (isStreaming) { const isEventStream = memberNs.isStructSchema(); if (isEventStream) { - throw new Error("serialization of event streams is not yet implemented"); + if (input[memberName]) { + payload = await this.serializeEventStream({ + eventStream: input[memberName], + requestSchema: ns + }); + } } else { payload = inputMemberValue; } @@ -15201,11 +15549,8 @@ var HttpBindingProtocol = class extends HttpProtocol { } } } - const output = { - $metadata: this.deserializeMetadata(response), - ...dataObject - }; - return output; + dataObject.$metadata = this.deserializeMetadata(response); + return dataObject; } async deserializeHttpMessage(schema, context, response, arg4, arg5) { let dataObject; @@ -15224,25 +15569,9 @@ var HttpBindingProtocol = class extends HttpProtocol { if (isStreaming) { const isEventStream = memberSchema.isStructSchema(); if (isEventStream) { - const context2 = this.serdeContext; - if (!context2.eventStreamMarshaller) { - throw new Error("@smithy/core - HttpProtocol: eventStreamMarshaller missing in serdeContext."); - } - const memberSchemas = memberSchema.getMemberSchemas(); - dataObject[memberName] = context2.eventStreamMarshaller.deserialize(response.body, async (event) => { - const unionMember = Object.keys(event).find((key) => { - return key !== "__type"; - }) ?? ""; - if (unionMember in memberSchemas) { - const eventStreamSchema = memberSchemas[unionMember]; - return { - [unionMember]: await deserializer.read(eventStreamSchema, event[unionMember].body) - }; - } else { - return { - $unknown: event - }; - } + dataObject[memberName] = await this.deserializeEventStream({ + response, + responseSchema: ns }); } else { dataObject[memberName] = (0, import_util_stream2.sdkStreamMixin)(response.body); @@ -15324,8 +15653,26 @@ var RpcProtocol = class extends HttpProtocol { ...input }; if (input) { - serializer.write(schema, _input); - payload = serializer.flush(); + const eventStreamMember = ns.getEventStreamMember(); + if (eventStreamMember) { + if (_input[eventStreamMember]) { + const initialRequest = {}; + for (const [memberName, memberSchema] of ns.structIterator()) { + if (memberName !== eventStreamMember && _input[memberName]) { + serializer.write(memberSchema, _input[memberName]); + initialRequest[memberName] = serializer.flush(); + } + } + payload = await this.serializeEventStream({ + eventStream: _input[eventStreamMember], + requestSchema: ns, + initialRequest + }); + } + } else { + serializer.write(schema, _input); + payload = serializer.flush(); + } } request.headers = headers; request.query = query; @@ -15338,9 +15685,9 @@ var RpcProtocol = class extends HttpProtocol { const ns = import_schema3.NormalizedSchema.of(operationSchema.output); const dataObject = {}; if (response.statusCode >= 300) { - const bytes2 = await collectBody(response.body, context); - if (bytes2.byteLength > 0) { - Object.assign(dataObject, await deserializer.read(import_schema3.SCHEMA.DOCUMENT, bytes2)); + const bytes = await collectBody(response.body, context); + if (bytes.byteLength > 0) { + Object.assign(dataObject, await deserializer.read(import_schema3.SCHEMA.DOCUMENT, bytes)); } await this.handleError(operationSchema, context, response, dataObject, this.deserializeMetadata(response)); throw new Error("@smithy/core/protocols - RPC Protocol error handler failed to throw."); @@ -15350,15 +15697,21 @@ var RpcProtocol = class extends HttpProtocol { delete response.headers[header]; response.headers[header.toLowerCase()] = value; } - const bytes = await collectBody(response.body, context); - if (bytes.byteLength > 0) { - Object.assign(dataObject, await deserializer.read(ns, bytes)); + const eventStreamMember = ns.getEventStreamMember(); + if (eventStreamMember) { + dataObject[eventStreamMember] = await this.deserializeEventStream({ + response, + responseSchema: ns, + initialResponseContainer: dataObject + }); + } else { + const bytes = await collectBody(response.body, context); + if (bytes.byteLength > 0) { + Object.assign(dataObject, await deserializer.read(ns, bytes)); + } } - const output = { - $metadata: this.deserializeMetadata(response), - ...dataObject - }; - return output; + dataObject.$metadata = this.deserializeMetadata(response); + return dataObject; } }; @@ -15615,7 +15968,9 @@ var ToStringShapeSerializer = class { if (ns.isTimestampSchema()) { if (!(value instanceof Date)) { throw new Error( - `@smithy/core/protocols - received non-Date value ${value} when schema expected Date in ${ns.getName(true)}` + `@smithy/core/protocols - received non-Date value ${value} when schema expected Date in ${ns.getName( + true + )}` ); } const format = determineTimestampFormat(ns, this.settings); @@ -16469,6 +16824,17 @@ var NormalizedSchema = class _NormalizedSchema { } throw new Error(`@smithy/core/schema - the schema ${this.getName(true)} does not have a value member.`); } + /** + * @param member - to query. + * @returns whether there is a memberSchema with the given member name. False if not a structure (or union). + */ + hasMemberSchema(member) { + if (this.isStructSchema()) { + const struct2 = this.getSchema(); + return member in struct2.members; + } + return false; + } /** * @returns the NormalizedSchema for the given member name. The returned instance will return true for `isMemberSchema()` * and will have the member name given. @@ -16515,6 +16881,20 @@ var NormalizedSchema = class _NormalizedSchema { } return {}; } + /** + * @returns member name of event stream or empty string indicating none exists or this + * isn't a structure schema. + */ + getEventStreamMember() { + if (this.isStructSchema()) { + for (const [memberName, memberSchema] of this.structIterator()) { + if (memberSchema.isStreaming() && memberSchema.isStructSchema()) { + return memberName; + } + } + } + return ""; + } /** * Allows iteration over members of a structure schema. * Each yield is a pair of the member name and member schema. @@ -17220,11 +17600,11 @@ var NumericValue = class _NumericValue { return false; } const _nv = object; - const prototypeMatch = _NumericValue.prototype.isPrototypeOf(object.constructor?.prototype); + const prototypeMatch = _NumericValue.prototype.isPrototypeOf(object); if (prototypeMatch) { return prototypeMatch; } - if (typeof _nv.string === "string" && typeof _nv.type === "string" && _nv.constructor?.name === "NumericValue") { + if (typeof _nv.string === "string" && typeof _nv.type === "string" && _nv.constructor?.name?.endsWith("NumericValue")) { return true; } return prototypeMatch; @@ -21913,7 +22293,7 @@ __export(src_exports, { Client: () => Client, Command: () => Command, NoOpLogger: () => NoOpLogger, - SENSITIVE_STRING: () => SENSITIVE_STRING, + SENSITIVE_STRING: () => SENSITIVE_STRING2, ServiceException: () => ServiceException, _json: () => _json, collectBody: () => import_protocols.collectBody, @@ -21995,6 +22375,43 @@ var import_protocols = __nccwpck_require__(3422); // src/command.ts var import_types = __nccwpck_require__(690); + +// src/schemaLogFilter.ts +var import_schema = __nccwpck_require__(6890); +var SENSITIVE_STRING = "***SensitiveInformation***"; +function schemaLogFilter(schema, data) { + if (data == null) { + return data; + } + const ns = import_schema.NormalizedSchema.of(schema); + if (ns.getMergedTraits().sensitive) { + return SENSITIVE_STRING; + } + if (ns.isListSchema()) { + const isSensitive = !!ns.getValueSchema().getMergedTraits().sensitive; + if (isSensitive) { + return SENSITIVE_STRING; + } + } else if (ns.isMapSchema()) { + const isSensitive = !!ns.getKeySchema().getMergedTraits().sensitive || !!ns.getValueSchema().getMergedTraits().sensitive; + if (isSensitive) { + return SENSITIVE_STRING; + } + } else if (ns.isStructSchema() && typeof data === "object") { + const object = data; + const newObject = {}; + for (const [member, memberNs] of ns.structIterator()) { + if (object[member] != null) { + newObject[member] = schemaLogFilter(memberNs, object[member]); + } + } + return newObject; + } + return data; +} +__name(schemaLogFilter, "schemaLogFilter"); + +// src/command.ts var Command = class { constructor() { this.middlewareStack = (0, import_middleware_stack.constructStack)(); @@ -22056,8 +22473,8 @@ var ClassBuilder = class { this._clientName = ""; this._additionalContext = {}; this._smithyContext = {}; - this._inputFilterSensitiveLog = (_) => _; - this._outputFilterSensitiveLog = (_) => _; + this._inputFilterSensitiveLog = void 0; + this._outputFilterSensitiveLog = void 0; this._serializer = null; this._deserializer = null; } @@ -22184,8 +22601,8 @@ var ClassBuilder = class { middlewareFn: closure._middlewareFn, clientName: closure._clientName, commandName: closure._commandName, - inputFilterSensitiveLog: closure._inputFilterSensitiveLog, - outputFilterSensitiveLog: closure._outputFilterSensitiveLog, + inputFilterSensitiveLog: closure._inputFilterSensitiveLog ?? (closure._operationSchema ? schemaLogFilter.bind(null, closure._operationSchema.input) : (_) => _), + outputFilterSensitiveLog: closure._outputFilterSensitiveLog ?? (closure._operationSchema ? schemaLogFilter.bind(null, closure._operationSchema.output) : (_) => _), smithyContext: closure._smithyContext, additionalContext: closure._additionalContext }); @@ -22195,7 +22612,7 @@ var ClassBuilder = class { }; // src/constants.ts -var SENSITIVE_STRING = "***SensitiveInformation***"; +var SENSITIVE_STRING2 = "***SensitiveInformation***"; // src/create-aggregated-client.ts var createAggregatedClient = /* @__PURE__ */ __name((commands, Client2) => {