@smithy/eventstream-serde-universal
Advanced tools
Comparing version 2.0.16 to 2.1.0
@@ -1,27 +0,1 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.EventStreamMarshaller = void 0; | ||
const eventstream_codec_1 = require("@smithy/eventstream-codec"); | ||
const getChunkedStream_1 = require("./getChunkedStream"); | ||
const getUnmarshalledStream_1 = require("./getUnmarshalledStream"); | ||
class EventStreamMarshaller { | ||
constructor({ utf8Encoder, utf8Decoder }) { | ||
this.eventStreamCodec = new eventstream_codec_1.EventStreamCodec(utf8Encoder, utf8Decoder); | ||
this.utfEncoder = utf8Encoder; | ||
} | ||
deserialize(body, deserializer) { | ||
const inputStream = (0, getChunkedStream_1.getChunkedStream)(body); | ||
return new eventstream_codec_1.SmithyMessageDecoderStream({ | ||
messageStream: new eventstream_codec_1.MessageDecoderStream({ inputStream, decoder: this.eventStreamCodec }), | ||
deserializer: (0, getUnmarshalledStream_1.getMessageUnmarshaller)(deserializer, this.utfEncoder), | ||
}); | ||
} | ||
serialize(inputStream, serializer) { | ||
return new eventstream_codec_1.MessageEncoderStream({ | ||
messageStream: new eventstream_codec_1.SmithyMessageEncoderStream({ inputStream, serializer }), | ||
encoder: this.eventStreamCodec, | ||
includeEndFrame: true, | ||
}); | ||
} | ||
} | ||
exports.EventStreamMarshaller = EventStreamMarshaller; | ||
module.exports = require("./index.js"); |
@@ -1,7 +0,1 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.exception = exports.endEventMessage = exports.statsEventMessage = exports.recordEventMessage = void 0; | ||
exports.recordEventMessage = Buffer.from("AAAA0AAAAFX31gVLDTptZXNzYWdlLXR5cGUHAAVldmVudAs6ZXZlbnQtdHlwZQcAB1JlY29yZHMNOmNvbnRlbnQtdHlwZQcAGGFwcGxpY2F0aW9uL29jdGV0LXN0cmVhbTEsRm9vLFdoZW4gbGlmZSBnaXZlcyB5b3UgZm9vLi4uCjIsQmFyLG1ha2UgQmFyIQozLEZpenosU29tZXRpbWVzIHBhaXJlZCB3aXRoLi4uCjQsQnV6eix0aGUgaW5mYW1vdXMgQnV6eiEKzxKeSw==", "base64"); | ||
exports.statsEventMessage = Buffer.from("AAAA0QAAAEM+YpmqDTptZXNzYWdlLXR5cGUHAAVldmVudAs6ZXZlbnQtdHlwZQcABVN0YXRzDTpjb250ZW50LXR5cGUHAAh0ZXh0L3htbDxTdGF0cyB4bWxucz0iIj48Qnl0ZXNTY2FubmVkPjEyNjwvQnl0ZXNTY2FubmVkPjxCeXRlc1Byb2Nlc3NlZD4xMjY8L0J5dGVzUHJvY2Vzc2VkPjxCeXRlc1JldHVybmVkPjEwNzwvQnl0ZXNSZXR1cm5lZD48L1N0YXRzPiJ0pLk=", "base64"); | ||
exports.endEventMessage = Buffer.from("AAAAOAAAACjBxoTUDTptZXNzYWdlLXR5cGUHAAVldmVudAs6ZXZlbnQtdHlwZQcAA0VuZM+X05I=", "base64"); | ||
exports.exception = Buffer.from("AAAAtgAAAF8BcW64DTpjb250ZW50LXR5cGUHABhhcHBsaWNhdGlvbi9vY3RldC1zdHJlYW0NOm1lc3NhZ2UtdHlwZQcACWV4Y2VwdGlvbg86ZXhjZXB0aW9uLXR5cGUHAAlFeGNlcHRpb25UaGlzIGlzIGEgbW9kZWxlZCBleGNlcHRpb24gZXZlbnQgdGhhdCB3b3VsZCBiZSB0aHJvd24gaW4gZGVzZXJpYWxpemVyLj6Gc60=", "base64"); | ||
module.exports = require("../index.js"); |
@@ -1,34 +0,1 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.MockEventMessageSource = void 0; | ||
const stream_1 = require("stream"); | ||
class MockEventMessageSource extends stream_1.Readable { | ||
constructor(options) { | ||
super(options); | ||
this.readCount = 0; | ||
this.data = Buffer.concat(options.messages); | ||
this.emitSize = options.emitSize; | ||
this.throwError = options.throwError; | ||
} | ||
_read() { | ||
const self = this; | ||
if (this.readCount === this.data.length) { | ||
if (this.throwError) { | ||
process.nextTick(function () { | ||
self.emit("error", new Error("Throwing an error!")); | ||
}); | ||
return; | ||
} | ||
else { | ||
this.push(null); | ||
return; | ||
} | ||
} | ||
const bytesLeft = this.data.length - this.readCount; | ||
const numBytesToSend = Math.min(bytesLeft, this.emitSize); | ||
const chunk = this.data.slice(this.readCount, this.readCount + numBytesToSend); | ||
this.readCount += numBytesToSend; | ||
this.push(chunk); | ||
} | ||
} | ||
exports.MockEventMessageSource = MockEventMessageSource; | ||
module.exports = require("../index.js"); |
@@ -1,70 +0,1 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.getChunkedStream = void 0; | ||
function getChunkedStream(source) { | ||
let currentMessageTotalLength = 0; | ||
let currentMessagePendingLength = 0; | ||
let currentMessage = null; | ||
let messageLengthBuffer = null; | ||
const allocateMessage = (size) => { | ||
if (typeof size !== "number") { | ||
throw new Error("Attempted to allocate an event message where size was not a number: " + size); | ||
} | ||
currentMessageTotalLength = size; | ||
currentMessagePendingLength = 4; | ||
currentMessage = new Uint8Array(size); | ||
const currentMessageView = new DataView(currentMessage.buffer); | ||
currentMessageView.setUint32(0, size, false); | ||
}; | ||
const iterator = async function* () { | ||
const sourceIterator = source[Symbol.asyncIterator](); | ||
while (true) { | ||
const { value, done } = await sourceIterator.next(); | ||
if (done) { | ||
if (!currentMessageTotalLength) { | ||
return; | ||
} | ||
else if (currentMessageTotalLength === currentMessagePendingLength) { | ||
yield currentMessage; | ||
} | ||
else { | ||
throw new Error("Truncated event message received."); | ||
} | ||
return; | ||
} | ||
const chunkLength = value.length; | ||
let currentOffset = 0; | ||
while (currentOffset < chunkLength) { | ||
if (!currentMessage) { | ||
const bytesRemaining = chunkLength - currentOffset; | ||
if (!messageLengthBuffer) { | ||
messageLengthBuffer = new Uint8Array(4); | ||
} | ||
const numBytesForTotal = Math.min(4 - currentMessagePendingLength, bytesRemaining); | ||
messageLengthBuffer.set(value.slice(currentOffset, currentOffset + numBytesForTotal), currentMessagePendingLength); | ||
currentMessagePendingLength += numBytesForTotal; | ||
currentOffset += numBytesForTotal; | ||
if (currentMessagePendingLength < 4) { | ||
break; | ||
} | ||
allocateMessage(new DataView(messageLengthBuffer.buffer).getUint32(0, false)); | ||
messageLengthBuffer = null; | ||
} | ||
const numBytesToWrite = Math.min(currentMessageTotalLength - currentMessagePendingLength, chunkLength - currentOffset); | ||
currentMessage.set(value.slice(currentOffset, currentOffset + numBytesToWrite), currentMessagePendingLength); | ||
currentMessagePendingLength += numBytesToWrite; | ||
currentOffset += numBytesToWrite; | ||
if (currentMessageTotalLength && currentMessageTotalLength === currentMessagePendingLength) { | ||
yield currentMessage; | ||
currentMessage = null; | ||
currentMessageTotalLength = 0; | ||
currentMessagePendingLength = 0; | ||
} | ||
} | ||
} | ||
}; | ||
return { | ||
[Symbol.asyncIterator]: iterator, | ||
}; | ||
} | ||
exports.getChunkedStream = getChunkedStream; | ||
module.exports = require("./index.js"); |
@@ -1,52 +0,1 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.getMessageUnmarshaller = exports.getUnmarshalledStream = void 0; | ||
function getUnmarshalledStream(source, options) { | ||
const messageUnmarshaller = getMessageUnmarshaller(options.deserializer, options.toUtf8); | ||
return { | ||
[Symbol.asyncIterator]: async function* () { | ||
for await (const chunk of source) { | ||
const message = options.eventStreamCodec.decode(chunk); | ||
const type = await messageUnmarshaller(message); | ||
if (type === undefined) | ||
continue; | ||
yield type; | ||
} | ||
}, | ||
}; | ||
} | ||
exports.getUnmarshalledStream = getUnmarshalledStream; | ||
function getMessageUnmarshaller(deserializer, toUtf8) { | ||
return async function (message) { | ||
const { value: messageType } = message.headers[":message-type"]; | ||
if (messageType === "error") { | ||
const unmodeledError = new Error(message.headers[":error-message"].value || "UnknownError"); | ||
unmodeledError.name = message.headers[":error-code"].value; | ||
throw unmodeledError; | ||
} | ||
else if (messageType === "exception") { | ||
const code = message.headers[":exception-type"].value; | ||
const exception = { [code]: message }; | ||
const deserializedException = await deserializer(exception); | ||
if (deserializedException.$unknown) { | ||
const error = new Error(toUtf8(message.body)); | ||
error.name = code; | ||
throw error; | ||
} | ||
throw deserializedException[code]; | ||
} | ||
else if (messageType === "event") { | ||
const event = { | ||
[message.headers[":event-type"].value]: message, | ||
}; | ||
const deserialized = await deserializer(event); | ||
if (deserialized.$unknown) | ||
return; | ||
return deserialized; | ||
} | ||
else { | ||
throw Error(`Unrecognizable event type: ${message.headers[":event-type"].value}`); | ||
} | ||
}; | ||
} | ||
exports.getMessageUnmarshaller = getMessageUnmarshaller; | ||
module.exports = require("./index.js"); |
@@ -1,5 +0,180 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const tslib_1 = require("tslib"); | ||
tslib_1.__exportStar(require("./EventStreamMarshaller"), exports); | ||
tslib_1.__exportStar(require("./provider"), exports); | ||
var __defProp = Object.defineProperty; | ||
var __getOwnPropDesc = Object.getOwnPropertyDescriptor; | ||
var __getOwnPropNames = Object.getOwnPropertyNames; | ||
var __hasOwnProp = Object.prototype.hasOwnProperty; | ||
var __name = (target, value) => __defProp(target, "name", { value, configurable: true }); | ||
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 __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); | ||
// src/index.ts | ||
var src_exports = {}; | ||
__export(src_exports, { | ||
EventStreamMarshaller: () => EventStreamMarshaller, | ||
eventStreamSerdeProvider: () => eventStreamSerdeProvider | ||
}); | ||
module.exports = __toCommonJS(src_exports); | ||
// src/EventStreamMarshaller.ts | ||
var import_eventstream_codec = require("@smithy/eventstream-codec"); | ||
// src/getChunkedStream.ts | ||
function getChunkedStream(source) { | ||
let currentMessageTotalLength = 0; | ||
let currentMessagePendingLength = 0; | ||
let currentMessage = null; | ||
let messageLengthBuffer = null; | ||
const allocateMessage = /* @__PURE__ */ __name((size) => { | ||
if (typeof size !== "number") { | ||
throw new Error("Attempted to allocate an event message where size was not a number: " + size); | ||
} | ||
currentMessageTotalLength = size; | ||
currentMessagePendingLength = 4; | ||
currentMessage = new Uint8Array(size); | ||
const currentMessageView = new DataView(currentMessage.buffer); | ||
currentMessageView.setUint32(0, size, false); | ||
}, "allocateMessage"); | ||
const iterator = /* @__PURE__ */ __name(async function* () { | ||
const sourceIterator = source[Symbol.asyncIterator](); | ||
while (true) { | ||
const { value, done } = await sourceIterator.next(); | ||
if (done) { | ||
if (!currentMessageTotalLength) { | ||
return; | ||
} else if (currentMessageTotalLength === currentMessagePendingLength) { | ||
yield currentMessage; | ||
} else { | ||
throw new Error("Truncated event message received."); | ||
} | ||
return; | ||
} | ||
const chunkLength = value.length; | ||
let currentOffset = 0; | ||
while (currentOffset < chunkLength) { | ||
if (!currentMessage) { | ||
const bytesRemaining = chunkLength - currentOffset; | ||
if (!messageLengthBuffer) { | ||
messageLengthBuffer = new Uint8Array(4); | ||
} | ||
const numBytesForTotal = Math.min( | ||
4 - currentMessagePendingLength, | ||
// remaining bytes to fill the messageLengthBuffer | ||
bytesRemaining | ||
// bytes left in chunk | ||
); | ||
messageLengthBuffer.set( | ||
// @ts-ignore error TS2532: Object is possibly 'undefined' for value | ||
value.slice(currentOffset, currentOffset + numBytesForTotal), | ||
currentMessagePendingLength | ||
); | ||
currentMessagePendingLength += numBytesForTotal; | ||
currentOffset += numBytesForTotal; | ||
if (currentMessagePendingLength < 4) { | ||
break; | ||
} | ||
allocateMessage(new DataView(messageLengthBuffer.buffer).getUint32(0, false)); | ||
messageLengthBuffer = null; | ||
} | ||
const numBytesToWrite = Math.min( | ||
currentMessageTotalLength - currentMessagePendingLength, | ||
// number of bytes left to complete message | ||
chunkLength - currentOffset | ||
// number of bytes left in the original chunk | ||
); | ||
currentMessage.set( | ||
// @ts-ignore error TS2532: Object is possibly 'undefined' for value | ||
value.slice(currentOffset, currentOffset + numBytesToWrite), | ||
currentMessagePendingLength | ||
); | ||
currentMessagePendingLength += numBytesToWrite; | ||
currentOffset += numBytesToWrite; | ||
if (currentMessageTotalLength && currentMessageTotalLength === currentMessagePendingLength) { | ||
yield currentMessage; | ||
currentMessage = null; | ||
currentMessageTotalLength = 0; | ||
currentMessagePendingLength = 0; | ||
} | ||
} | ||
} | ||
}, "iterator"); | ||
return { | ||
[Symbol.asyncIterator]: iterator | ||
}; | ||
} | ||
__name(getChunkedStream, "getChunkedStream"); | ||
// src/getUnmarshalledStream.ts | ||
function getMessageUnmarshaller(deserializer, toUtf8) { | ||
return async function(message) { | ||
const { value: messageType } = message.headers[":message-type"]; | ||
if (messageType === "error") { | ||
const unmodeledError = new Error(message.headers[":error-message"].value || "UnknownError"); | ||
unmodeledError.name = message.headers[":error-code"].value; | ||
throw unmodeledError; | ||
} else if (messageType === "exception") { | ||
const code = message.headers[":exception-type"].value; | ||
const exception = { [code]: message }; | ||
const deserializedException = await deserializer(exception); | ||
if (deserializedException.$unknown) { | ||
const error = new Error(toUtf8(message.body)); | ||
error.name = code; | ||
throw error; | ||
} | ||
throw deserializedException[code]; | ||
} else if (messageType === "event") { | ||
const event = { | ||
[message.headers[":event-type"].value]: message | ||
}; | ||
const deserialized = await deserializer(event); | ||
if (deserialized.$unknown) | ||
return; | ||
return deserialized; | ||
} else { | ||
throw Error(`Unrecognizable event type: ${message.headers[":event-type"].value}`); | ||
} | ||
}; | ||
} | ||
__name(getMessageUnmarshaller, "getMessageUnmarshaller"); | ||
// src/EventStreamMarshaller.ts | ||
var _EventStreamMarshaller = class _EventStreamMarshaller { | ||
constructor({ utf8Encoder, utf8Decoder }) { | ||
this.eventStreamCodec = new import_eventstream_codec.EventStreamCodec(utf8Encoder, utf8Decoder); | ||
this.utfEncoder = utf8Encoder; | ||
} | ||
deserialize(body, deserializer) { | ||
const inputStream = getChunkedStream(body); | ||
return new import_eventstream_codec.SmithyMessageDecoderStream({ | ||
messageStream: new import_eventstream_codec.MessageDecoderStream({ inputStream, decoder: this.eventStreamCodec }), | ||
// @ts-expect-error Type 'T' is not assignable to type 'Record<string, any>' | ||
deserializer: getMessageUnmarshaller(deserializer, this.utfEncoder) | ||
}); | ||
} | ||
serialize(inputStream, serializer) { | ||
return new import_eventstream_codec.MessageEncoderStream({ | ||
messageStream: new import_eventstream_codec.SmithyMessageEncoderStream({ inputStream, serializer }), | ||
encoder: this.eventStreamCodec, | ||
includeEndFrame: true | ||
}); | ||
} | ||
}; | ||
__name(_EventStreamMarshaller, "EventStreamMarshaller"); | ||
var EventStreamMarshaller = _EventStreamMarshaller; | ||
// src/provider.ts | ||
var eventStreamSerdeProvider = /* @__PURE__ */ __name((options) => new EventStreamMarshaller(options), "eventStreamSerdeProvider"); | ||
// Annotate the CommonJS export names for ESM import in node: | ||
0 && (module.exports = { | ||
EventStreamMarshaller, | ||
eventStreamSerdeProvider | ||
}); |
@@ -1,6 +0,1 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.eventStreamSerdeProvider = void 0; | ||
const EventStreamMarshaller_1 = require("./EventStreamMarshaller"); | ||
const eventStreamSerdeProvider = (options) => new EventStreamMarshaller_1.EventStreamMarshaller(options); | ||
exports.eventStreamSerdeProvider = eventStreamSerdeProvider; | ||
module.exports = require("./index.js"); |
{ | ||
"name": "@smithy/eventstream-serde-universal", | ||
"version": "2.0.16", | ||
"version": "2.1.0", | ||
"scripts": { | ||
"build": "concurrently 'yarn:build:cjs' 'yarn:build:es' 'yarn:build:types && yarn build:types:downlevel'", | ||
"build:cjs": "yarn g:tsc -p tsconfig.cjs.json", | ||
"build:cjs": "node ../../scripts/inline eventstream-serde-universal", | ||
"build:es": "yarn g:tsc -p tsconfig.es.json", | ||
@@ -25,8 +25,8 @@ "build:types": "yarn g:tsc -p tsconfig.types.json", | ||
"dependencies": { | ||
"@smithy/eventstream-codec": "^2.0.16", | ||
"@smithy/types": "^2.8.0", | ||
"@smithy/eventstream-codec": "^2.1.0", | ||
"@smithy/types": "^2.9.0", | ||
"tslib": "^2.5.0" | ||
}, | ||
"devDependencies": { | ||
"@smithy/util-utf8": "^2.0.2", | ||
"@smithy/util-utf8": "^2.1.0", | ||
"@tsconfig/recommended": "1.0.1", | ||
@@ -33,0 +33,0 @@ "@types/node": "^14.14.31", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
35292
540
Updated@smithy/types@^2.9.0