UNPKG

failure-lambda

Version:

Failure injection for AWS Lambda - chaos engineering made simple

1,014 lines (999 loc) 34.5 kB
#!/usr/bin/env node import { FromStringShapeDeserializer, HttpProtocol, LazyJsonString, NormalizedSchema, NumericValue, ProtocolLib, SerdeContext, SerdeContextConfig, TypeRegistry, UnionSerde, collectBody, determineTimestampFormat, extendedEncodeURIComponent, splitHeader, translateTraits, v4 } from "./chunk-762XZWE7.js"; import { sdkStreamMixin } from "./chunk-VSWURCYJ.js"; import { dateToUtcString, fromBase64, parseEpochTimestamp, parseRfc3339DateTimeWithOffset, parseRfc7231DateTime, toBase64 } from "./chunk-W3M6RT2M.js"; import { HttpRequest } from "./chunk-XDZ73E2B.js"; import { fromUtf8, toUtf8 } from "./chunk-VACN7GDP.js"; // node_modules/@smithy/core/dist-es/submodules/serde/quote-header.js function quoteHeader(part) { if (part.includes(",") || part.includes('"')) { part = `"${part.replace(/"/g, '\\"')}"`; } return part; } // node_modules/@smithy/core/dist-es/submodules/serde/split-every.js function splitEvery(value, delimiter, numDelimiters) { if (numDelimiters <= 0 || !Number.isInteger(numDelimiters)) { throw new Error("Invalid number of delimiters (" + numDelimiters + ") for splitEvery."); } const segments = value.split(delimiter); if (numDelimiters === 1) { return segments; } const compoundSegments = []; let currentSegment = ""; for (let i = 0; i < segments.length; i++) { if (currentSegment === "") { currentSegment = segments[i]; } else { currentSegment += delimiter + segments[i]; } if ((i + 1) % numDelimiters === 0) { compoundSegments.push(currentSegment); currentSegment = ""; } } if (currentSegment !== "") { compoundSegments.push(currentSegment); } return compoundSegments; } // node_modules/@smithy/core/dist-es/submodules/protocols/HttpBindingProtocol.js var HttpBindingProtocol = class extends HttpProtocol { async serializeRequest(operationSchema, _input, context) { const input = { ..._input ?? {} }; const serializer = this.serializer; const query = {}; const headers = {}; const endpoint = await context.endpoint(); const ns = NormalizedSchema.of(operationSchema?.input); const schema = ns.getSchema(); let hasNonHttpBindingMember = false; let payload; const request = new HttpRequest({ protocol: "", hostname: "", port: void 0, path: "", fragment: void 0, query, headers, body: void 0 }); if (endpoint) { this.updateServiceEndpoint(request, endpoint); this.setHostPrefix(request, operationSchema, input); const opTraits = translateTraits(operationSchema.traits); if (opTraits.http) { request.method = opTraits.http[0]; const [path, search] = opTraits.http[1].split("?"); if (request.path == "/") { request.path = path; } else { request.path += path; } const traitSearchParams = new URLSearchParams(search ?? ""); Object.assign(query, Object.fromEntries(traitSearchParams)); } } for (const [memberName, memberNs] of ns.structIterator()) { const memberTraits = memberNs.getMergedTraits() ?? {}; const inputMemberValue = input[memberName]; if (inputMemberValue == null && !memberNs.isIdempotencyToken()) { if (memberTraits.httpLabel) { if (request.path.includes(`{${memberName}+}`) || request.path.includes(`{${memberName}}`)) { throw new Error(`No value provided for input HTTP label: ${memberName}.`); } } continue; } if (memberTraits.httpPayload) { const isStreaming = memberNs.isStreaming(); if (isStreaming) { const isEventStream = memberNs.isStructSchema(); if (isEventStream) { if (input[memberName]) { payload = await this.serializeEventStream({ eventStream: input[memberName], requestSchema: ns }); } } else { payload = inputMemberValue; } } else { serializer.write(memberNs, inputMemberValue); payload = serializer.flush(); } delete input[memberName]; } else if (memberTraits.httpLabel) { serializer.write(memberNs, inputMemberValue); const replacement = serializer.flush(); if (request.path.includes(`{${memberName}+}`)) { request.path = request.path.replace(`{${memberName}+}`, replacement.split("/").map(extendedEncodeURIComponent).join("/")); } else if (request.path.includes(`{${memberName}}`)) { request.path = request.path.replace(`{${memberName}}`, extendedEncodeURIComponent(replacement)); } delete input[memberName]; } else if (memberTraits.httpHeader) { serializer.write(memberNs, inputMemberValue); headers[memberTraits.httpHeader.toLowerCase()] = String(serializer.flush()); delete input[memberName]; } else if (typeof memberTraits.httpPrefixHeaders === "string") { for (const [key, val] of Object.entries(inputMemberValue)) { const amalgam = memberTraits.httpPrefixHeaders + key; serializer.write([memberNs.getValueSchema(), { httpHeader: amalgam }], val); headers[amalgam.toLowerCase()] = serializer.flush(); } delete input[memberName]; } else if (memberTraits.httpQuery || memberTraits.httpQueryParams) { this.serializeQuery(memberNs, inputMemberValue, query); delete input[memberName]; } else { hasNonHttpBindingMember = true; } } if (hasNonHttpBindingMember && input) { serializer.write(schema, input); payload = serializer.flush(); } request.headers = headers; request.query = query; request.body = payload; return request; } serializeQuery(ns, data, query) { const serializer = this.serializer; const traits = ns.getMergedTraits(); if (traits.httpQueryParams) { for (const [key, val] of Object.entries(data)) { if (!(key in query)) { const valueSchema = ns.getValueSchema(); Object.assign(valueSchema.getMergedTraits(), { ...traits, httpQuery: key, httpQueryParams: void 0 }); this.serializeQuery(valueSchema, val, query); } } return; } if (ns.isListSchema()) { const sparse = !!ns.getMergedTraits().sparse; const buffer = []; for (const item of data) { serializer.write([ns.getValueSchema(), traits], item); const serializable = serializer.flush(); if (sparse || serializable !== void 0) { buffer.push(serializable); } } query[traits.httpQuery] = buffer; } else { serializer.write([ns, traits], data); query[traits.httpQuery] = serializer.flush(); } } async deserializeResponse(operationSchema, context, response) { const deserializer = this.deserializer; const ns = NormalizedSchema.of(operationSchema.output); const dataObject = {}; if (response.statusCode >= 300) { const bytes = await collectBody(response.body, context); if (bytes.byteLength > 0) { Object.assign(dataObject, await deserializer.read(15, bytes)); } await this.handleError(operationSchema, context, response, dataObject, this.deserializeMetadata(response)); throw new Error("@smithy/core/protocols - HTTP Protocol error handler failed to throw."); } for (const header in response.headers) { const value = response.headers[header]; delete response.headers[header]; response.headers[header.toLowerCase()] = value; } const nonHttpBindingMembers = await this.deserializeHttpMessage(ns, context, response, dataObject); if (nonHttpBindingMembers.length) { const bytes = await collectBody(response.body, context); if (bytes.byteLength > 0) { const dataFromBody = await deserializer.read(ns, bytes); for (const member of nonHttpBindingMembers) { if (dataFromBody[member] != null) { dataObject[member] = dataFromBody[member]; } } } } else if (nonHttpBindingMembers.discardResponseBody) { await collectBody(response.body, context); } dataObject.$metadata = this.deserializeMetadata(response); return dataObject; } async deserializeHttpMessage(schema, context, response, arg4, arg5) { let dataObject; if (arg4 instanceof Set) { dataObject = arg5; } else { dataObject = arg4; } let discardResponseBody = true; const deserializer = this.deserializer; const ns = NormalizedSchema.of(schema); const nonHttpBindingMembers = []; for (const [memberName, memberSchema] of ns.structIterator()) { const memberTraits = memberSchema.getMemberTraits(); if (memberTraits.httpPayload) { discardResponseBody = false; const isStreaming = memberSchema.isStreaming(); if (isStreaming) { const isEventStream = memberSchema.isStructSchema(); if (isEventStream) { dataObject[memberName] = await this.deserializeEventStream({ response, responseSchema: ns }); } else { dataObject[memberName] = sdkStreamMixin(response.body); } } else if (response.body) { const bytes = await collectBody(response.body, context); if (bytes.byteLength > 0) { dataObject[memberName] = await deserializer.read(memberSchema, bytes); } } } else if (memberTraits.httpHeader) { const key = String(memberTraits.httpHeader).toLowerCase(); const value = response.headers[key]; if (null != value) { if (memberSchema.isListSchema()) { const headerListValueSchema = memberSchema.getValueSchema(); headerListValueSchema.getMergedTraits().httpHeader = key; let sections; if (headerListValueSchema.isTimestampSchema() && headerListValueSchema.getSchema() === 4) { sections = splitEvery(value, ",", 2); } else { sections = splitHeader(value); } const list = []; for (const section of sections) { list.push(await deserializer.read(headerListValueSchema, section.trim())); } dataObject[memberName] = list; } else { dataObject[memberName] = await deserializer.read(memberSchema, value); } } } else if (memberTraits.httpPrefixHeaders !== void 0) { dataObject[memberName] = {}; for (const [header, value] of Object.entries(response.headers)) { if (header.startsWith(memberTraits.httpPrefixHeaders)) { const valueSchema = memberSchema.getValueSchema(); valueSchema.getMergedTraits().httpHeader = header; dataObject[memberName][header.slice(memberTraits.httpPrefixHeaders.length)] = await deserializer.read(valueSchema, value); } } } else if (memberTraits.httpResponseCode) { dataObject[memberName] = response.statusCode; } else { nonHttpBindingMembers.push(memberName); } } nonHttpBindingMembers.discardResponseBody = discardResponseBody; return nonHttpBindingMembers; } }; // node_modules/@smithy/core/dist-es/submodules/protocols/serde/HttpInterceptingShapeDeserializer.js var HttpInterceptingShapeDeserializer = class extends SerdeContext { codecDeserializer; stringDeserializer; constructor(codecDeserializer, codecSettings) { super(); this.codecDeserializer = codecDeserializer; this.stringDeserializer = new FromStringShapeDeserializer(codecSettings); } setSerdeContext(serdeContext) { this.stringDeserializer.setSerdeContext(serdeContext); this.codecDeserializer.setSerdeContext(serdeContext); this.serdeContext = serdeContext; } read(schema, data) { const ns = NormalizedSchema.of(schema); const traits = ns.getMergedTraits(); const toString = this.serdeContext?.utf8Encoder ?? toUtf8; if (traits.httpHeader || traits.httpResponseCode) { return this.stringDeserializer.read(ns, toString(data)); } if (traits.httpPayload) { if (ns.isBlobSchema()) { const toBytes = this.serdeContext?.utf8Decoder ?? fromUtf8; if (typeof data === "string") { return toBytes(data); } return data; } else if (ns.isStringSchema()) { if ("byteLength" in data) { return toString(data); } return data; } } return this.codecDeserializer.read(ns, data); } }; // node_modules/@smithy/core/dist-es/submodules/protocols/serde/ToStringShapeSerializer.js var ToStringShapeSerializer = class extends SerdeContext { settings; stringBuffer = ""; constructor(settings) { super(); this.settings = settings; } write(schema, value) { const ns = NormalizedSchema.of(schema); switch (typeof value) { case "object": if (value === null) { this.stringBuffer = "null"; return; } 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)}`); } const format = determineTimestampFormat(ns, this.settings); switch (format) { case 5: this.stringBuffer = value.toISOString().replace(".000Z", "Z"); break; case 6: this.stringBuffer = dateToUtcString(value); break; case 7: this.stringBuffer = String(value.getTime() / 1e3); break; default: console.warn("Missing timestamp format, using epoch seconds", value); this.stringBuffer = String(value.getTime() / 1e3); } return; } if (ns.isBlobSchema() && "byteLength" in value) { this.stringBuffer = (this.serdeContext?.base64Encoder ?? toBase64)(value); return; } if (ns.isListSchema() && Array.isArray(value)) { let buffer = ""; for (const item of value) { this.write([ns.getValueSchema(), ns.getMergedTraits()], item); const headerItem = this.flush(); const serialized = ns.getValueSchema().isTimestampSchema() ? headerItem : quoteHeader(headerItem); if (buffer !== "") { buffer += ", "; } buffer += serialized; } this.stringBuffer = buffer; return; } this.stringBuffer = JSON.stringify(value, null, 2); break; case "string": const mediaType = ns.getMergedTraits().mediaType; let intermediateValue = value; if (mediaType) { const isJson = mediaType === "application/json" || mediaType.endsWith("+json"); if (isJson) { intermediateValue = LazyJsonString.from(intermediateValue); } if (ns.getMergedTraits().httpHeader) { this.stringBuffer = (this.serdeContext?.base64Encoder ?? toBase64)(intermediateValue.toString()); return; } } this.stringBuffer = value; break; default: if (ns.isIdempotencyToken()) { this.stringBuffer = v4(); } else { this.stringBuffer = String(value); } } } flush() { const buffer = this.stringBuffer; this.stringBuffer = ""; return buffer; } }; // node_modules/@smithy/core/dist-es/submodules/protocols/serde/HttpInterceptingShapeSerializer.js var HttpInterceptingShapeSerializer = class { codecSerializer; stringSerializer; buffer; constructor(codecSerializer, codecSettings, stringSerializer = new ToStringShapeSerializer(codecSettings)) { this.codecSerializer = codecSerializer; this.stringSerializer = stringSerializer; } setSerdeContext(serdeContext) { this.codecSerializer.setSerdeContext(serdeContext); this.stringSerializer.setSerdeContext(serdeContext); } write(schema, value) { const ns = NormalizedSchema.of(schema); const traits = ns.getMergedTraits(); if (traits.httpHeader || traits.httpLabel || traits.httpQuery) { this.stringSerializer.write(ns, value); this.buffer = this.stringSerializer.flush(); return; } return this.codecSerializer.write(ns, value); } flush() { if (this.buffer !== void 0) { const buffer = this.buffer; this.buffer = void 0; return buffer; } return this.codecSerializer.flush(); } }; // node_modules/@aws-sdk/core/dist-es/submodules/protocols/json/jsonReviver.js function jsonReviver(key, value, context) { if (context?.source) { const numericString = context.source; if (typeof value === "number") { if (value > Number.MAX_SAFE_INTEGER || value < Number.MIN_SAFE_INTEGER || numericString !== String(value)) { const isFractional = numericString.includes("."); if (isFractional) { return new NumericValue(numericString, "bigDecimal"); } else { return BigInt(numericString); } } } } return value; } // node_modules/@aws-sdk/core/dist-es/submodules/protocols/common.js var collectBodyString = (streamBody, context) => collectBody(streamBody, context).then((body) => (context?.utf8Encoder ?? toUtf8)(body)); // node_modules/@aws-sdk/core/dist-es/submodules/protocols/json/parseJsonBody.js var parseJsonBody = (streamBody, context) => collectBodyString(streamBody, context).then((encoded) => { if (encoded.length) { try { return JSON.parse(encoded); } catch (e) { if (e?.name === "SyntaxError") { Object.defineProperty(e, "$responseBodyText", { value: encoded }); } throw e; } } return {}; }); var loadRestJsonErrorCode = (output, data) => { const findKey = (object, key) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); const sanitizeErrorCode = (rawValue) => { let cleanValue = rawValue; if (typeof cleanValue === "number") { cleanValue = cleanValue.toString(); } if (cleanValue.indexOf(",") >= 0) { cleanValue = cleanValue.split(",")[0]; } if (cleanValue.indexOf(":") >= 0) { cleanValue = cleanValue.split(":")[0]; } if (cleanValue.indexOf("#") >= 0) { cleanValue = cleanValue.split("#")[1]; } return cleanValue; }; const headerKey = findKey(output.headers, "x-amzn-errortype"); if (headerKey !== void 0) { return sanitizeErrorCode(output.headers[headerKey]); } if (data && typeof data === "object") { const codeKey = findKey(data, "code"); if (codeKey && data[codeKey] !== void 0) { return sanitizeErrorCode(data[codeKey]); } if (data["__type"] !== void 0) { return sanitizeErrorCode(data["__type"]); } } }; // node_modules/@aws-sdk/core/dist-es/submodules/protocols/json/JsonShapeDeserializer.js var JsonShapeDeserializer = class extends SerdeContextConfig { settings; constructor(settings) { super(); this.settings = settings; } async read(schema, data) { return this._read(schema, typeof data === "string" ? JSON.parse(data, jsonReviver) : await parseJsonBody(data, this.serdeContext)); } readObject(schema, data) { return this._read(schema, data); } _read(schema, value) { const isObject = value !== null && typeof value === "object"; const ns = NormalizedSchema.of(schema); if (isObject) { if (ns.isStructSchema()) { const record = value; const union = ns.isUnionSchema(); const out = {}; let nameMap = void 0; const { jsonName } = this.settings; if (jsonName) { nameMap = {}; } let unionSerde; if (union) { unionSerde = new UnionSerde(record, out); } for (const [memberName, memberSchema] of ns.structIterator()) { let fromKey = memberName; if (jsonName) { fromKey = memberSchema.getMergedTraits().jsonName ?? fromKey; nameMap[fromKey] = memberName; } if (union) { unionSerde.mark(fromKey); } if (record[fromKey] != null) { out[memberName] = this._read(memberSchema, record[fromKey]); } } if (union) { unionSerde.writeUnknown(); } else if (typeof record.__type === "string") { for (const [k, v] of Object.entries(record)) { const t = jsonName ? nameMap[k] ?? k : k; if (!(t in out)) { out[t] = v; } } } return out; } if (Array.isArray(value) && ns.isListSchema()) { const listMember = ns.getValueSchema(); const out = []; const sparse = !!ns.getMergedTraits().sparse; for (const item of value) { if (sparse || item != null) { out.push(this._read(listMember, item)); } } return out; } if (ns.isMapSchema()) { const mapMember = ns.getValueSchema(); const out = {}; const sparse = !!ns.getMergedTraits().sparse; for (const [_k, _v] of Object.entries(value)) { if (sparse || _v != null) { out[_k] = this._read(mapMember, _v); } } return out; } } if (ns.isBlobSchema() && typeof value === "string") { return fromBase64(value); } const mediaType = ns.getMergedTraits().mediaType; if (ns.isStringSchema() && typeof value === "string" && mediaType) { const isJson = mediaType === "application/json" || mediaType.endsWith("+json"); if (isJson) { return LazyJsonString.from(value); } return value; } if (ns.isTimestampSchema() && value != null) { const format = determineTimestampFormat(ns, this.settings); switch (format) { case 5: return parseRfc3339DateTimeWithOffset(value); case 6: return parseRfc7231DateTime(value); case 7: return parseEpochTimestamp(value); default: console.warn("Missing timestamp format, parsing value with Date constructor:", value); return new Date(value); } } if (ns.isBigIntegerSchema() && (typeof value === "number" || typeof value === "string")) { return BigInt(value); } if (ns.isBigDecimalSchema() && value != void 0) { if (value instanceof NumericValue) { return value; } const untyped = value; if (untyped.type === "bigDecimal" && "string" in untyped) { return new NumericValue(untyped.string, untyped.type); } return new NumericValue(String(value), "bigDecimal"); } if (ns.isNumericSchema() && typeof value === "string") { switch (value) { case "Infinity": return Infinity; case "-Infinity": return -Infinity; case "NaN": return NaN; } return value; } if (ns.isDocumentSchema()) { if (isObject) { const out = Array.isArray(value) ? [] : {}; for (const [k, v] of Object.entries(value)) { if (v instanceof NumericValue) { out[k] = v; } else { out[k] = this._read(ns, v); } } return out; } else { return structuredClone(value); } } return value; } }; // node_modules/@aws-sdk/core/dist-es/submodules/protocols/json/jsonReplacer.js var NUMERIC_CONTROL_CHAR = String.fromCharCode(925); var JsonReplacer = class { values = /* @__PURE__ */ new Map(); counter = 0; stage = 0; createReplacer() { if (this.stage === 1) { throw new Error("@aws-sdk/core/protocols - JsonReplacer already created."); } if (this.stage === 2) { throw new Error("@aws-sdk/core/protocols - JsonReplacer exhausted."); } this.stage = 1; return (key, value) => { if (value instanceof NumericValue) { const v = `${NUMERIC_CONTROL_CHAR + "nv" + this.counter++}_` + value.string; this.values.set(`"${v}"`, value.string); return v; } if (typeof value === "bigint") { const s = value.toString(); const v = `${NUMERIC_CONTROL_CHAR + "b" + this.counter++}_` + s; this.values.set(`"${v}"`, s); return v; } return value; }; } replaceInJson(json) { if (this.stage === 0) { throw new Error("@aws-sdk/core/protocols - JsonReplacer not created yet."); } if (this.stage === 2) { throw new Error("@aws-sdk/core/protocols - JsonReplacer exhausted."); } this.stage = 2; if (this.counter === 0) { return json; } for (const [key, value] of this.values) { json = json.replace(key, value); } return json; } }; // node_modules/@aws-sdk/core/dist-es/submodules/protocols/json/JsonShapeSerializer.js var JsonShapeSerializer = class extends SerdeContextConfig { settings; buffer; useReplacer = false; rootSchema; constructor(settings) { super(); this.settings = settings; } write(schema, value) { this.rootSchema = NormalizedSchema.of(schema); this.buffer = this._write(this.rootSchema, value); } writeDiscriminatedDocument(schema, value) { this.write(schema, value); if (typeof this.buffer === "object") { this.buffer.__type = NormalizedSchema.of(schema).getName(true); } } flush() { const { rootSchema, useReplacer } = this; this.rootSchema = void 0; this.useReplacer = false; if (rootSchema?.isStructSchema() || rootSchema?.isDocumentSchema()) { if (!useReplacer) { return JSON.stringify(this.buffer); } const replacer = new JsonReplacer(); return replacer.replaceInJson(JSON.stringify(this.buffer, replacer.createReplacer(), 0)); } return this.buffer; } _write(schema, value, container) { const isObject = value !== null && typeof value === "object"; const ns = NormalizedSchema.of(schema); if (isObject) { if (ns.isStructSchema()) { const record = value; const out = {}; const { jsonName } = this.settings; let nameMap = void 0; if (jsonName) { nameMap = {}; } for (const [memberName, memberSchema] of ns.structIterator()) { const serializableValue = this._write(memberSchema, record[memberName], ns); if (serializableValue !== void 0) { let targetKey = memberName; if (jsonName) { targetKey = memberSchema.getMergedTraits().jsonName ?? memberName; nameMap[memberName] = targetKey; } out[targetKey] = serializableValue; } } if (ns.isUnionSchema() && Object.keys(out).length === 0) { const { $unknown } = record; if (Array.isArray($unknown)) { const [k, v] = $unknown; out[k] = this._write(15, v); } } else if (typeof record.__type === "string") { for (const [k, v] of Object.entries(record)) { const targetKey = jsonName ? nameMap[k] ?? k : k; if (!(targetKey in out)) { out[targetKey] = this._write(15, v); } } } return out; } if (Array.isArray(value) && ns.isListSchema()) { const listMember = ns.getValueSchema(); const out = []; const sparse = !!ns.getMergedTraits().sparse; for (const item of value) { if (sparse || item != null) { out.push(this._write(listMember, item)); } } return out; } if (ns.isMapSchema()) { const mapMember = ns.getValueSchema(); const out = {}; const sparse = !!ns.getMergedTraits().sparse; for (const [_k, _v] of Object.entries(value)) { if (sparse || _v != null) { out[_k] = this._write(mapMember, _v); } } return out; } if (value instanceof Uint8Array && (ns.isBlobSchema() || ns.isDocumentSchema())) { if (ns === this.rootSchema) { return value; } return (this.serdeContext?.base64Encoder ?? toBase64)(value); } if (value instanceof Date && (ns.isTimestampSchema() || ns.isDocumentSchema())) { const format = determineTimestampFormat(ns, this.settings); switch (format) { case 5: return value.toISOString().replace(".000Z", "Z"); case 6: return dateToUtcString(value); case 7: return value.getTime() / 1e3; default: console.warn("Missing timestamp format, using epoch seconds", value); return value.getTime() / 1e3; } } if (value instanceof NumericValue) { this.useReplacer = true; } } if (value === null && container?.isStructSchema()) { return void 0; } if (ns.isStringSchema()) { if (typeof value === "undefined" && ns.isIdempotencyToken()) { return v4(); } const mediaType = ns.getMergedTraits().mediaType; if (value != null && mediaType) { const isJson = mediaType === "application/json" || mediaType.endsWith("+json"); if (isJson) { return LazyJsonString.from(value); } } return value; } if (typeof value === "number" && ns.isNumericSchema()) { if (Math.abs(value) === Infinity || isNaN(value)) { return String(value); } return value; } if (typeof value === "string" && ns.isBlobSchema()) { if (ns === this.rootSchema) { return value; } return (this.serdeContext?.base64Encoder ?? toBase64)(value); } if (typeof value === "bigint") { this.useReplacer = true; } if (ns.isDocumentSchema()) { if (isObject) { const out = Array.isArray(value) ? [] : {}; for (const [k, v] of Object.entries(value)) { if (v instanceof NumericValue) { this.useReplacer = true; out[k] = v; } else { out[k] = this._write(ns, v); } } return out; } else { return structuredClone(value); } } return value; } }; // node_modules/@aws-sdk/core/dist-es/submodules/protocols/json/JsonCodec.js var JsonCodec = class extends SerdeContextConfig { settings; constructor(settings) { super(); this.settings = settings; } createSerializer() { const serializer = new JsonShapeSerializer(this.settings); serializer.setSerdeContext(this.serdeContext); return serializer; } createDeserializer() { const deserializer = new JsonShapeDeserializer(this.settings); deserializer.setSerdeContext(this.serdeContext); return deserializer; } }; // node_modules/@aws-sdk/core/dist-es/submodules/protocols/json/AwsRestJsonProtocol.js var AwsRestJsonProtocol = class extends HttpBindingProtocol { serializer; deserializer; codec; mixin = new ProtocolLib(); constructor({ defaultNamespace }) { super({ defaultNamespace }); const settings = { timestampFormat: { useTrait: true, default: 7 }, httpBindings: true, jsonName: true }; this.codec = new JsonCodec(settings); this.serializer = new HttpInterceptingShapeSerializer(this.codec.createSerializer(), settings); this.deserializer = new HttpInterceptingShapeDeserializer(this.codec.createDeserializer(), settings); } getShapeId() { return "aws.protocols#restJson1"; } getPayloadCodec() { return this.codec; } setSerdeContext(serdeContext) { this.codec.setSerdeContext(serdeContext); super.setSerdeContext(serdeContext); } async serializeRequest(operationSchema, input, context) { const request = await super.serializeRequest(operationSchema, input, context); const inputSchema = NormalizedSchema.of(operationSchema.input); if (!request.headers["content-type"]) { const contentType = this.mixin.resolveRestContentType(this.getDefaultContentType(), inputSchema); if (contentType) { request.headers["content-type"] = contentType; } } if (request.body == null && request.headers["content-type"] === this.getDefaultContentType()) { request.body = "{}"; } return request; } async deserializeResponse(operationSchema, context, response) { const output = await super.deserializeResponse(operationSchema, context, response); const outputSchema = NormalizedSchema.of(operationSchema.output); for (const [name, member] of outputSchema.structIterator()) { if (member.getMemberTraits().httpPayload && !(name in output)) { output[name] = null; } } return output; } async handleError(operationSchema, context, response, dataObject, metadata) { const errorIdentifier = loadRestJsonErrorCode(response, dataObject) ?? "Unknown"; const { errorSchema, errorMetadata } = await this.mixin.getErrorSchemaOrThrowBaseException(errorIdentifier, this.options.defaultNamespace, response, dataObject, metadata); const ns = NormalizedSchema.of(errorSchema); const message = dataObject.message ?? dataObject.Message ?? "Unknown"; const ErrorCtor = TypeRegistry.for(errorSchema[1]).getErrorCtor(errorSchema) ?? Error; const exception = new ErrorCtor(message); await this.deserializeHttpMessage(errorSchema, context, response, dataObject); const output = {}; for (const [name, member] of ns.structIterator()) { const target = member.getMergedTraits().jsonName ?? name; output[name] = this.codec.createDeserializer().readObject(member, dataObject[target]); } throw this.mixin.decorateServiceException(Object.assign(exception, errorMetadata, { $fault: ns.getMergedTraits().error, message }, output), dataObject); } getDefaultContentType() { return "application/json"; } }; export { AwsRestJsonProtocol }; //# sourceMappingURL=chunk-ZJL5KTIU.js.map