@smithy/eventstream-serde-universal 4.1.1 → 4.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist-cjs/index.js
CHANGED
|
@@ -1,182 +1,132 @@
|
|
|
1
|
-
|
|
2
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
-
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
1
|
+
'use strict';
|
|
19
2
|
|
|
20
|
-
|
|
21
|
-
var index_exports = {};
|
|
22
|
-
__export(index_exports, {
|
|
23
|
-
EventStreamMarshaller: () => EventStreamMarshaller,
|
|
24
|
-
eventStreamSerdeProvider: () => eventStreamSerdeProvider
|
|
25
|
-
});
|
|
26
|
-
module.exports = __toCommonJS(index_exports);
|
|
3
|
+
var eventstreamCodec = require('@smithy/eventstream-codec');
|
|
27
4
|
|
|
28
|
-
// src/EventStreamMarshaller.ts
|
|
29
|
-
var import_eventstream_codec = require("@smithy/eventstream-codec");
|
|
30
|
-
|
|
31
|
-
// src/getChunkedStream.ts
|
|
32
5
|
function getChunkedStream(source) {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
}
|
|
41
|
-
currentMessageTotalLength = size;
|
|
42
|
-
currentMessagePendingLength = 4;
|
|
43
|
-
currentMessage = new Uint8Array(size);
|
|
44
|
-
const currentMessageView = new DataView(currentMessage.buffer);
|
|
45
|
-
currentMessageView.setUint32(0, size, false);
|
|
46
|
-
}, "allocateMessage");
|
|
47
|
-
const iterator = /* @__PURE__ */ __name(async function* () {
|
|
48
|
-
const sourceIterator = source[Symbol.asyncIterator]();
|
|
49
|
-
while (true) {
|
|
50
|
-
const { value, done } = await sourceIterator.next();
|
|
51
|
-
if (done) {
|
|
52
|
-
if (!currentMessageTotalLength) {
|
|
53
|
-
return;
|
|
54
|
-
} else if (currentMessageTotalLength === currentMessagePendingLength) {
|
|
55
|
-
yield currentMessage;
|
|
56
|
-
} else {
|
|
57
|
-
throw new Error("Truncated event message received.");
|
|
6
|
+
let currentMessageTotalLength = 0;
|
|
7
|
+
let currentMessagePendingLength = 0;
|
|
8
|
+
let currentMessage = null;
|
|
9
|
+
let messageLengthBuffer = null;
|
|
10
|
+
const allocateMessage = (size) => {
|
|
11
|
+
if (typeof size !== "number") {
|
|
12
|
+
throw new Error("Attempted to allocate an event message where size was not a number: " + size);
|
|
58
13
|
}
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
14
|
+
currentMessageTotalLength = size;
|
|
15
|
+
currentMessagePendingLength = 4;
|
|
16
|
+
currentMessage = new Uint8Array(size);
|
|
17
|
+
const currentMessageView = new DataView(currentMessage.buffer);
|
|
18
|
+
currentMessageView.setUint32(0, size, false);
|
|
19
|
+
};
|
|
20
|
+
const iterator = async function* () {
|
|
21
|
+
const sourceIterator = source[Symbol.asyncIterator]();
|
|
22
|
+
while (true) {
|
|
23
|
+
const { value, done } = await sourceIterator.next();
|
|
24
|
+
if (done) {
|
|
25
|
+
if (!currentMessageTotalLength) {
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
else if (currentMessageTotalLength === currentMessagePendingLength) {
|
|
29
|
+
yield currentMessage;
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
throw new Error("Truncated event message received.");
|
|
33
|
+
}
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
const chunkLength = value.length;
|
|
37
|
+
let currentOffset = 0;
|
|
38
|
+
while (currentOffset < chunkLength) {
|
|
39
|
+
if (!currentMessage) {
|
|
40
|
+
const bytesRemaining = chunkLength - currentOffset;
|
|
41
|
+
if (!messageLengthBuffer) {
|
|
42
|
+
messageLengthBuffer = new Uint8Array(4);
|
|
43
|
+
}
|
|
44
|
+
const numBytesForTotal = Math.min(4 - currentMessagePendingLength, bytesRemaining);
|
|
45
|
+
messageLengthBuffer.set(value.slice(currentOffset, currentOffset + numBytesForTotal), currentMessagePendingLength);
|
|
46
|
+
currentMessagePendingLength += numBytesForTotal;
|
|
47
|
+
currentOffset += numBytesForTotal;
|
|
48
|
+
if (currentMessagePendingLength < 4) {
|
|
49
|
+
break;
|
|
50
|
+
}
|
|
51
|
+
allocateMessage(new DataView(messageLengthBuffer.buffer).getUint32(0, false));
|
|
52
|
+
messageLengthBuffer = null;
|
|
53
|
+
}
|
|
54
|
+
const numBytesToWrite = Math.min(currentMessageTotalLength - currentMessagePendingLength, chunkLength - currentOffset);
|
|
55
|
+
currentMessage.set(value.slice(currentOffset, currentOffset + numBytesToWrite), currentMessagePendingLength);
|
|
56
|
+
currentMessagePendingLength += numBytesToWrite;
|
|
57
|
+
currentOffset += numBytesToWrite;
|
|
58
|
+
if (currentMessageTotalLength && currentMessageTotalLength === currentMessagePendingLength) {
|
|
59
|
+
yield currentMessage;
|
|
60
|
+
currentMessage = null;
|
|
61
|
+
currentMessageTotalLength = 0;
|
|
62
|
+
currentMessagePendingLength = 0;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
87
65
|
}
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
// number of bytes left in the original chunk
|
|
93
|
-
);
|
|
94
|
-
currentMessage.set(
|
|
95
|
-
// @ts-ignore error TS2532: Object is possibly 'undefined' for value
|
|
96
|
-
value.slice(currentOffset, currentOffset + numBytesToWrite),
|
|
97
|
-
currentMessagePendingLength
|
|
98
|
-
);
|
|
99
|
-
currentMessagePendingLength += numBytesToWrite;
|
|
100
|
-
currentOffset += numBytesToWrite;
|
|
101
|
-
if (currentMessageTotalLength && currentMessageTotalLength === currentMessagePendingLength) {
|
|
102
|
-
yield currentMessage;
|
|
103
|
-
currentMessage = null;
|
|
104
|
-
currentMessageTotalLength = 0;
|
|
105
|
-
currentMessagePendingLength = 0;
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
}, "iterator");
|
|
110
|
-
return {
|
|
111
|
-
[Symbol.asyncIterator]: iterator
|
|
112
|
-
};
|
|
66
|
+
};
|
|
67
|
+
return {
|
|
68
|
+
[Symbol.asyncIterator]: iterator,
|
|
69
|
+
};
|
|
113
70
|
}
|
|
114
|
-
__name(getChunkedStream, "getChunkedStream");
|
|
115
71
|
|
|
116
|
-
// src/getUnmarshalledStream.ts
|
|
117
72
|
function getMessageUnmarshaller(deserializer, toUtf8) {
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
73
|
+
return async function (message) {
|
|
74
|
+
const { value: messageType } = message.headers[":message-type"];
|
|
75
|
+
if (messageType === "error") {
|
|
76
|
+
const unmodeledError = new Error(message.headers[":error-message"].value || "UnknownError");
|
|
77
|
+
unmodeledError.name = message.headers[":error-code"].value;
|
|
78
|
+
throw unmodeledError;
|
|
79
|
+
}
|
|
80
|
+
else if (messageType === "exception") {
|
|
81
|
+
const code = message.headers[":exception-type"].value;
|
|
82
|
+
const exception = { [code]: message };
|
|
83
|
+
const deserializedException = await deserializer(exception);
|
|
84
|
+
if (deserializedException.$unknown) {
|
|
85
|
+
const error = new Error(toUtf8(message.body));
|
|
86
|
+
error.name = code;
|
|
87
|
+
throw error;
|
|
88
|
+
}
|
|
89
|
+
throw deserializedException[code];
|
|
90
|
+
}
|
|
91
|
+
else if (messageType === "event") {
|
|
92
|
+
const event = {
|
|
93
|
+
[message.headers[":event-type"].value]: message,
|
|
94
|
+
};
|
|
95
|
+
const deserialized = await deserializer(event);
|
|
96
|
+
if (deserialized.$unknown)
|
|
97
|
+
return;
|
|
98
|
+
return deserialized;
|
|
99
|
+
}
|
|
100
|
+
else {
|
|
101
|
+
throw Error(`Unrecognizable event type: ${message.headers[":event-type"].value}`);
|
|
102
|
+
}
|
|
103
|
+
};
|
|
145
104
|
}
|
|
146
|
-
__name(getMessageUnmarshaller, "getMessageUnmarshaller");
|
|
147
105
|
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
});
|
|
171
|
-
}
|
|
172
|
-
};
|
|
173
|
-
|
|
174
|
-
// src/provider.ts
|
|
175
|
-
var eventStreamSerdeProvider = /* @__PURE__ */ __name((options) => new EventStreamMarshaller(options), "eventStreamSerdeProvider");
|
|
176
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
106
|
+
class EventStreamMarshaller {
|
|
107
|
+
eventStreamCodec;
|
|
108
|
+
utfEncoder;
|
|
109
|
+
constructor({ utf8Encoder, utf8Decoder }) {
|
|
110
|
+
this.eventStreamCodec = new eventstreamCodec.EventStreamCodec(utf8Encoder, utf8Decoder);
|
|
111
|
+
this.utfEncoder = utf8Encoder;
|
|
112
|
+
}
|
|
113
|
+
deserialize(body, deserializer) {
|
|
114
|
+
const inputStream = getChunkedStream(body);
|
|
115
|
+
return new eventstreamCodec.SmithyMessageDecoderStream({
|
|
116
|
+
messageStream: new eventstreamCodec.MessageDecoderStream({ inputStream, decoder: this.eventStreamCodec }),
|
|
117
|
+
deserializer: getMessageUnmarshaller(deserializer, this.utfEncoder),
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
serialize(inputStream, serializer) {
|
|
121
|
+
return new eventstreamCodec.MessageEncoderStream({
|
|
122
|
+
messageStream: new eventstreamCodec.SmithyMessageEncoderStream({ inputStream, serializer }),
|
|
123
|
+
encoder: this.eventStreamCodec,
|
|
124
|
+
includeEndFrame: true,
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
}
|
|
177
128
|
|
|
178
|
-
|
|
179
|
-
EventStreamMarshaller,
|
|
180
|
-
eventStreamSerdeProvider
|
|
181
|
-
});
|
|
129
|
+
const eventStreamSerdeProvider = (options) => new EventStreamMarshaller(options);
|
|
182
130
|
|
|
131
|
+
exports.EventStreamMarshaller = EventStreamMarshaller;
|
|
132
|
+
exports.eventStreamSerdeProvider = eventStreamSerdeProvider;
|
|
@@ -2,6 +2,8 @@ import { EventStreamCodec, MessageDecoderStream, MessageEncoderStream, SmithyMes
|
|
|
2
2
|
import { getChunkedStream } from "./getChunkedStream";
|
|
3
3
|
import { getMessageUnmarshaller } from "./getUnmarshalledStream";
|
|
4
4
|
export class EventStreamMarshaller {
|
|
5
|
+
eventStreamCodec;
|
|
6
|
+
utfEncoder;
|
|
5
7
|
constructor({ utf8Encoder, utf8Decoder }) {
|
|
6
8
|
this.eventStreamCodec = new EventStreamCodec(utf8Encoder, utf8Decoder);
|
|
7
9
|
this.utfEncoder = utf8Encoder;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@smithy/eventstream-serde-universal",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.2.1",
|
|
4
4
|
"scripts": {
|
|
5
5
|
"build": "concurrently 'yarn:build:cjs' 'yarn:build:es' 'yarn:build:types && yarn build:types:downlevel'",
|
|
6
6
|
"build:cjs": "node ../../scripts/inline eventstream-serde-universal",
|
|
@@ -12,7 +12,9 @@
|
|
|
12
12
|
"lint": "eslint -c ../../.eslintrc.js \"src/**/*.ts\"",
|
|
13
13
|
"format": "prettier --config ../../prettier.config.js --ignore-path ../../.prettierignore --write \"**/*.{ts,md,json}\"",
|
|
14
14
|
"test": "yarn g:vitest run",
|
|
15
|
-
"test:watch": "yarn g:vitest watch"
|
|
15
|
+
"test:watch": "yarn g:vitest watch",
|
|
16
|
+
"test:integration": "yarn g:vitest run -c vitest.config.integ.mts",
|
|
17
|
+
"test:integration:watch": "yarn g:vitest watch -c vitest.config.integ.mts"
|
|
16
18
|
},
|
|
17
19
|
"main": "./dist-cjs/index.js",
|
|
18
20
|
"module": "./dist-es/index.js",
|
|
@@ -24,12 +26,12 @@
|
|
|
24
26
|
"license": "Apache-2.0",
|
|
25
27
|
"sideEffects": false,
|
|
26
28
|
"dependencies": {
|
|
27
|
-
"@smithy/eventstream-codec": "^4.
|
|
28
|
-
"@smithy/types": "^4.
|
|
29
|
+
"@smithy/eventstream-codec": "^4.2.1",
|
|
30
|
+
"@smithy/types": "^4.7.0",
|
|
29
31
|
"tslib": "^2.6.2"
|
|
30
32
|
},
|
|
31
33
|
"devDependencies": {
|
|
32
|
-
"@smithy/util-utf8": "^4.
|
|
34
|
+
"@smithy/util-utf8": "^4.2.0",
|
|
33
35
|
"@types/node": "^18.11.9",
|
|
34
36
|
"concurrently": "7.0.0",
|
|
35
37
|
"downlevel-dts": "0.10.1",
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
module.exports = require("./index.js");
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
module.exports = require("./index.js");
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
module.exports = require("./index.js");
|
package/dist-cjs/provider.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
module.exports = require("./index.js");
|