@smithy/eventstream-codec 4.2.14 → 4.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist-cjs/index.js CHANGED
@@ -1,401 +1,11 @@
1
- 'use strict';
2
-
3
- var crc32 = require('@aws-crypto/crc32');
4
- var utilHexEncoding = require('@smithy/util-hex-encoding');
5
-
6
- class Int64 {
7
- bytes;
8
- constructor(bytes) {
9
- this.bytes = bytes;
10
- if (bytes.byteLength !== 8) {
11
- throw new Error("Int64 buffers must be exactly 8 bytes");
12
- }
13
- }
14
- static fromNumber(number) {
15
- if (number > 9_223_372_036_854_775_807 || number < -9223372036854776e3) {
16
- throw new Error(`${number} is too large (or, if negative, too small) to represent as an Int64`);
17
- }
18
- const bytes = new Uint8Array(8);
19
- for (let i = 7, remaining = Math.abs(Math.round(number)); i > -1 && remaining > 0; i--, remaining /= 256) {
20
- bytes[i] = remaining;
21
- }
22
- if (number < 0) {
23
- negate(bytes);
24
- }
25
- return new Int64(bytes);
26
- }
27
- valueOf() {
28
- const bytes = this.bytes.slice(0);
29
- const negative = bytes[0] & 0b10000000;
30
- if (negative) {
31
- negate(bytes);
32
- }
33
- return parseInt(utilHexEncoding.toHex(bytes), 16) * (negative ? -1 : 1);
34
- }
35
- toString() {
36
- return String(this.valueOf());
37
- }
38
- }
39
- function negate(bytes) {
40
- for (let i = 0; i < 8; i++) {
41
- bytes[i] ^= 0xff;
42
- }
43
- for (let i = 7; i > -1; i--) {
44
- bytes[i]++;
45
- if (bytes[i] !== 0)
46
- break;
47
- }
48
- }
49
-
50
- class HeaderMarshaller {
51
- toUtf8;
52
- fromUtf8;
53
- constructor(toUtf8, fromUtf8) {
54
- this.toUtf8 = toUtf8;
55
- this.fromUtf8 = fromUtf8;
56
- }
57
- format(headers) {
58
- const chunks = [];
59
- for (const headerName of Object.keys(headers)) {
60
- const bytes = this.fromUtf8(headerName);
61
- chunks.push(Uint8Array.from([bytes.byteLength]), bytes, this.formatHeaderValue(headers[headerName]));
62
- }
63
- const out = new Uint8Array(chunks.reduce((carry, bytes) => carry + bytes.byteLength, 0));
64
- let position = 0;
65
- for (const chunk of chunks) {
66
- out.set(chunk, position);
67
- position += chunk.byteLength;
68
- }
69
- return out;
70
- }
71
- formatHeaderValue(header) {
72
- switch (header.type) {
73
- case "boolean":
74
- return Uint8Array.from([header.value ? 0 : 1]);
75
- case "byte":
76
- return Uint8Array.from([2, header.value]);
77
- case "short":
78
- const shortView = new DataView(new ArrayBuffer(3));
79
- shortView.setUint8(0, 3);
80
- shortView.setInt16(1, header.value, false);
81
- return new Uint8Array(shortView.buffer);
82
- case "integer":
83
- const intView = new DataView(new ArrayBuffer(5));
84
- intView.setUint8(0, 4);
85
- intView.setInt32(1, header.value, false);
86
- return new Uint8Array(intView.buffer);
87
- case "long":
88
- const longBytes = new Uint8Array(9);
89
- longBytes[0] = 5;
90
- longBytes.set(header.value.bytes, 1);
91
- return longBytes;
92
- case "binary":
93
- const binView = new DataView(new ArrayBuffer(3 + header.value.byteLength));
94
- binView.setUint8(0, 6);
95
- binView.setUint16(1, header.value.byteLength, false);
96
- const binBytes = new Uint8Array(binView.buffer);
97
- binBytes.set(header.value, 3);
98
- return binBytes;
99
- case "string":
100
- const utf8Bytes = this.fromUtf8(header.value);
101
- const strView = new DataView(new ArrayBuffer(3 + utf8Bytes.byteLength));
102
- strView.setUint8(0, 7);
103
- strView.setUint16(1, utf8Bytes.byteLength, false);
104
- const strBytes = new Uint8Array(strView.buffer);
105
- strBytes.set(utf8Bytes, 3);
106
- return strBytes;
107
- case "timestamp":
108
- const tsBytes = new Uint8Array(9);
109
- tsBytes[0] = 8;
110
- tsBytes.set(Int64.fromNumber(header.value.valueOf()).bytes, 1);
111
- return tsBytes;
112
- case "uuid":
113
- if (!UUID_PATTERN.test(header.value)) {
114
- throw new Error(`Invalid UUID received: ${header.value}`);
115
- }
116
- const uuidBytes = new Uint8Array(17);
117
- uuidBytes[0] = 9;
118
- uuidBytes.set(utilHexEncoding.fromHex(header.value.replace(/\-/g, "")), 1);
119
- return uuidBytes;
120
- }
121
- }
122
- parse(headers) {
123
- const out = {};
124
- let position = 0;
125
- while (position < headers.byteLength) {
126
- const nameLength = headers.getUint8(position++);
127
- const name = this.toUtf8(new Uint8Array(headers.buffer, headers.byteOffset + position, nameLength));
128
- position += nameLength;
129
- switch (headers.getUint8(position++)) {
130
- case 0:
131
- out[name] = {
132
- type: BOOLEAN_TAG,
133
- value: true,
134
- };
135
- break;
136
- case 1:
137
- out[name] = {
138
- type: BOOLEAN_TAG,
139
- value: false,
140
- };
141
- break;
142
- case 2:
143
- out[name] = {
144
- type: BYTE_TAG,
145
- value: headers.getInt8(position++),
146
- };
147
- break;
148
- case 3:
149
- out[name] = {
150
- type: SHORT_TAG,
151
- value: headers.getInt16(position, false),
152
- };
153
- position += 2;
154
- break;
155
- case 4:
156
- out[name] = {
157
- type: INT_TAG,
158
- value: headers.getInt32(position, false),
159
- };
160
- position += 4;
161
- break;
162
- case 5:
163
- out[name] = {
164
- type: LONG_TAG,
165
- value: new Int64(new Uint8Array(headers.buffer, headers.byteOffset + position, 8)),
166
- };
167
- position += 8;
168
- break;
169
- case 6:
170
- const binaryLength = headers.getUint16(position, false);
171
- position += 2;
172
- out[name] = {
173
- type: BINARY_TAG,
174
- value: new Uint8Array(headers.buffer, headers.byteOffset + position, binaryLength),
175
- };
176
- position += binaryLength;
177
- break;
178
- case 7:
179
- const stringLength = headers.getUint16(position, false);
180
- position += 2;
181
- out[name] = {
182
- type: STRING_TAG,
183
- value: this.toUtf8(new Uint8Array(headers.buffer, headers.byteOffset + position, stringLength)),
184
- };
185
- position += stringLength;
186
- break;
187
- case 8:
188
- out[name] = {
189
- type: TIMESTAMP_TAG,
190
- value: new Date(new Int64(new Uint8Array(headers.buffer, headers.byteOffset + position, 8)).valueOf()),
191
- };
192
- position += 8;
193
- break;
194
- case 9:
195
- const uuidBytes = new Uint8Array(headers.buffer, headers.byteOffset + position, 16);
196
- position += 16;
197
- out[name] = {
198
- type: UUID_TAG,
199
- value: `${utilHexEncoding.toHex(uuidBytes.subarray(0, 4))}-${utilHexEncoding.toHex(uuidBytes.subarray(4, 6))}-${utilHexEncoding.toHex(uuidBytes.subarray(6, 8))}-${utilHexEncoding.toHex(uuidBytes.subarray(8, 10))}-${utilHexEncoding.toHex(uuidBytes.subarray(10))}`,
200
- };
201
- break;
202
- default:
203
- throw new Error(`Unrecognized header type tag`);
204
- }
205
- }
206
- return out;
207
- }
208
- }
209
- var HEADER_VALUE_TYPE;
210
- (function (HEADER_VALUE_TYPE) {
211
- HEADER_VALUE_TYPE[HEADER_VALUE_TYPE["boolTrue"] = 0] = "boolTrue";
212
- HEADER_VALUE_TYPE[HEADER_VALUE_TYPE["boolFalse"] = 1] = "boolFalse";
213
- HEADER_VALUE_TYPE[HEADER_VALUE_TYPE["byte"] = 2] = "byte";
214
- HEADER_VALUE_TYPE[HEADER_VALUE_TYPE["short"] = 3] = "short";
215
- HEADER_VALUE_TYPE[HEADER_VALUE_TYPE["integer"] = 4] = "integer";
216
- HEADER_VALUE_TYPE[HEADER_VALUE_TYPE["long"] = 5] = "long";
217
- HEADER_VALUE_TYPE[HEADER_VALUE_TYPE["byteArray"] = 6] = "byteArray";
218
- HEADER_VALUE_TYPE[HEADER_VALUE_TYPE["string"] = 7] = "string";
219
- HEADER_VALUE_TYPE[HEADER_VALUE_TYPE["timestamp"] = 8] = "timestamp";
220
- HEADER_VALUE_TYPE[HEADER_VALUE_TYPE["uuid"] = 9] = "uuid";
221
- })(HEADER_VALUE_TYPE || (HEADER_VALUE_TYPE = {}));
222
- const BOOLEAN_TAG = "boolean";
223
- const BYTE_TAG = "byte";
224
- const SHORT_TAG = "short";
225
- const INT_TAG = "integer";
226
- const LONG_TAG = "long";
227
- const BINARY_TAG = "binary";
228
- const STRING_TAG = "string";
229
- const TIMESTAMP_TAG = "timestamp";
230
- const UUID_TAG = "uuid";
231
- const UUID_PATTERN = /^[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$/;
232
-
233
- const PRELUDE_MEMBER_LENGTH = 4;
234
- const PRELUDE_LENGTH = PRELUDE_MEMBER_LENGTH * 2;
235
- const CHECKSUM_LENGTH = 4;
236
- const MINIMUM_MESSAGE_LENGTH = PRELUDE_LENGTH + CHECKSUM_LENGTH * 2;
237
- function splitMessage({ byteLength, byteOffset, buffer }) {
238
- if (byteLength < MINIMUM_MESSAGE_LENGTH) {
239
- throw new Error("Provided message too short to accommodate event stream message overhead");
240
- }
241
- const view = new DataView(buffer, byteOffset, byteLength);
242
- const messageLength = view.getUint32(0, false);
243
- if (byteLength !== messageLength) {
244
- throw new Error("Reported message length does not match received message length");
245
- }
246
- const headerLength = view.getUint32(PRELUDE_MEMBER_LENGTH, false);
247
- const expectedPreludeChecksum = view.getUint32(PRELUDE_LENGTH, false);
248
- const expectedMessageChecksum = view.getUint32(byteLength - CHECKSUM_LENGTH, false);
249
- const checksummer = new crc32.Crc32().update(new Uint8Array(buffer, byteOffset, PRELUDE_LENGTH));
250
- if (expectedPreludeChecksum !== checksummer.digest()) {
251
- throw new Error(`The prelude checksum specified in the message (${expectedPreludeChecksum}) does not match the calculated CRC32 checksum (${checksummer.digest()})`);
252
- }
253
- checksummer.update(new Uint8Array(buffer, byteOffset + PRELUDE_LENGTH, byteLength - (PRELUDE_LENGTH + CHECKSUM_LENGTH)));
254
- if (expectedMessageChecksum !== checksummer.digest()) {
255
- throw new Error(`The message checksum (${checksummer.digest()}) did not match the expected value of ${expectedMessageChecksum}`);
256
- }
257
- return {
258
- headers: new DataView(buffer, byteOffset + PRELUDE_LENGTH + CHECKSUM_LENGTH, headerLength),
259
- body: new Uint8Array(buffer, byteOffset + PRELUDE_LENGTH + CHECKSUM_LENGTH + headerLength, messageLength - headerLength - (PRELUDE_LENGTH + CHECKSUM_LENGTH + CHECKSUM_LENGTH)),
260
- };
261
- }
262
-
263
- class EventStreamCodec {
264
- headerMarshaller;
265
- messageBuffer;
266
- isEndOfStream;
267
- constructor(toUtf8, fromUtf8) {
268
- this.headerMarshaller = new HeaderMarshaller(toUtf8, fromUtf8);
269
- this.messageBuffer = [];
270
- this.isEndOfStream = false;
271
- }
272
- feed(message) {
273
- this.messageBuffer.push(this.decode(message));
274
- }
275
- endOfStream() {
276
- this.isEndOfStream = true;
277
- }
278
- getMessage() {
279
- const message = this.messageBuffer.pop();
280
- const isEndOfStream = this.isEndOfStream;
281
- return {
282
- getMessage() {
283
- return message;
284
- },
285
- isEndOfStream() {
286
- return isEndOfStream;
287
- },
288
- };
289
- }
290
- getAvailableMessages() {
291
- const messages = this.messageBuffer;
292
- this.messageBuffer = [];
293
- const isEndOfStream = this.isEndOfStream;
294
- return {
295
- getMessages() {
296
- return messages;
297
- },
298
- isEndOfStream() {
299
- return isEndOfStream;
300
- },
301
- };
302
- }
303
- encode({ headers: rawHeaders, body }) {
304
- const headers = this.headerMarshaller.format(rawHeaders);
305
- const length = headers.byteLength + body.byteLength + 16;
306
- const out = new Uint8Array(length);
307
- const view = new DataView(out.buffer, out.byteOffset, out.byteLength);
308
- const checksum = new crc32.Crc32();
309
- view.setUint32(0, length, false);
310
- view.setUint32(4, headers.byteLength, false);
311
- view.setUint32(8, checksum.update(out.subarray(0, 8)).digest(), false);
312
- out.set(headers, 12);
313
- out.set(body, headers.byteLength + 12);
314
- view.setUint32(length - 4, checksum.update(out.subarray(8, length - 4)).digest(), false);
315
- return out;
316
- }
317
- decode(message) {
318
- const { headers, body } = splitMessage(message);
319
- return { headers: this.headerMarshaller.parse(headers), body };
320
- }
321
- formatHeaders(rawHeaders) {
322
- return this.headerMarshaller.format(rawHeaders);
323
- }
324
- }
325
-
326
- class MessageDecoderStream {
327
- options;
328
- constructor(options) {
329
- this.options = options;
330
- }
331
- [Symbol.asyncIterator]() {
332
- return this.asyncIterator();
333
- }
334
- async *asyncIterator() {
335
- for await (const bytes of this.options.inputStream) {
336
- const decoded = this.options.decoder.decode(bytes);
337
- yield decoded;
338
- }
339
- }
340
- }
341
-
342
- class MessageEncoderStream {
343
- options;
344
- constructor(options) {
345
- this.options = options;
346
- }
347
- [Symbol.asyncIterator]() {
348
- return this.asyncIterator();
349
- }
350
- async *asyncIterator() {
351
- for await (const msg of this.options.messageStream) {
352
- const encoded = this.options.encoder.encode(msg);
353
- yield encoded;
354
- }
355
- if (this.options.includeEndFrame) {
356
- yield new Uint8Array(0);
357
- }
358
- }
359
- }
360
-
361
- class SmithyMessageDecoderStream {
362
- options;
363
- constructor(options) {
364
- this.options = options;
365
- }
366
- [Symbol.asyncIterator]() {
367
- return this.asyncIterator();
368
- }
369
- async *asyncIterator() {
370
- for await (const message of this.options.messageStream) {
371
- const deserialized = await this.options.deserializer(message);
372
- if (deserialized === undefined)
373
- continue;
374
- yield deserialized;
375
- }
376
- }
377
- }
378
-
379
- class SmithyMessageEncoderStream {
380
- options;
381
- constructor(options) {
382
- this.options = options;
383
- }
384
- [Symbol.asyncIterator]() {
385
- return this.asyncIterator();
386
- }
387
- async *asyncIterator() {
388
- for await (const chunk of this.options.inputStream) {
389
- const payloadBuf = this.options.serializer(chunk);
390
- yield payloadBuf;
391
- }
392
- }
393
- }
394
-
395
- exports.EventStreamCodec = EventStreamCodec;
396
- exports.HeaderMarshaller = HeaderMarshaller;
397
- exports.Int64 = Int64;
398
- exports.MessageDecoderStream = MessageDecoderStream;
399
- exports.MessageEncoderStream = MessageEncoderStream;
400
- exports.SmithyMessageDecoderStream = SmithyMessageDecoderStream;
401
- exports.SmithyMessageEncoderStream = SmithyMessageEncoderStream;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SmithyMessageEncoderStream = exports.SmithyMessageDecoderStream = exports.MessageEncoderStream = exports.MessageDecoderStream = exports.Int64 = exports.HeaderMarshaller = exports.EventStreamCodec = void 0;
4
+ var event_streams_1 = require("@smithy/core/event-streams");
5
+ Object.defineProperty(exports, "EventStreamCodec", { enumerable: true, get: function () { return event_streams_1.EventStreamCodec; } });
6
+ Object.defineProperty(exports, "HeaderMarshaller", { enumerable: true, get: function () { return event_streams_1.HeaderMarshaller; } });
7
+ Object.defineProperty(exports, "Int64", { enumerable: true, get: function () { return event_streams_1.Int64; } });
8
+ Object.defineProperty(exports, "MessageDecoderStream", { enumerable: true, get: function () { return event_streams_1.MessageDecoderStream; } });
9
+ Object.defineProperty(exports, "MessageEncoderStream", { enumerable: true, get: function () { return event_streams_1.MessageEncoderStream; } });
10
+ Object.defineProperty(exports, "SmithyMessageDecoderStream", { enumerable: true, get: function () { return event_streams_1.SmithyMessageDecoderStream; } });
11
+ Object.defineProperty(exports, "SmithyMessageEncoderStream", { enumerable: true, get: function () { return event_streams_1.SmithyMessageEncoderStream; } });
package/dist-es/index.js CHANGED
@@ -1,8 +1 @@
1
- export * from "./EventStreamCodec";
2
- export * from "./HeaderMarshaller";
3
- export * from "./Int64";
4
- export * from "./Message";
5
- export * from "./MessageDecoderStream";
6
- export * from "./MessageEncoderStream";
7
- export * from "./SmithyMessageDecoderStream";
8
- export * from "./SmithyMessageEncoderStream";
1
+ export { EventStreamCodec, HeaderMarshaller, Int64, MessageDecoderStream, MessageEncoderStream, SmithyMessageDecoderStream, SmithyMessageEncoderStream, } from "@smithy/core/event-streams";
@@ -1,8 +1,3 @@
1
- export * from "./EventStreamCodec";
2
- export * from "./HeaderMarshaller";
3
- export * from "./Int64";
4
- export * from "./Message";
5
- export * from "./MessageDecoderStream";
6
- export * from "./MessageEncoderStream";
7
- export * from "./SmithyMessageDecoderStream";
8
- export * from "./SmithyMessageEncoderStream";
1
+ /** @deprecated Use @smithy/core/event-streams instead. */
2
+ export { EventStreamCodec, HeaderMarshaller, Int64, MessageDecoderStream, MessageEncoderStream, SmithyMessageDecoderStream, SmithyMessageEncoderStream, } from "@smithy/core/event-streams";
3
+ export type { BinaryHeaderValue, BooleanHeaderValue, ByteHeaderValue, IntegerHeaderValue, LongHeaderValue, Message, MessageDecoderStreamOptions, MessageEncoderStreamOptions, MessageHeaders, MessageHeaderValue, ShortHeaderValue, SmithyMessageDecoderStreamOptions, SmithyMessageEncoderStreamOptions, StringHeaderValue, TimestampHeaderValue, UuidHeaderValue, } from "@smithy/core/event-streams";
package/package.json CHANGED
@@ -1,17 +1,10 @@
1
1
  {
2
2
  "name": "@smithy/eventstream-codec",
3
- "version": "4.2.14",
3
+ "version": "4.3.0",
4
4
  "scripts": {
5
- "build": "concurrently 'yarn:build:types' 'yarn:build:es:cjs'",
6
- "build:es:cjs": "yarn g:tsc -p tsconfig.es.json && node ../../scripts/inline eventstream-codec",
7
- "build:types": "yarn g:tsc -p tsconfig.types.json",
8
- "build:types:downlevel": "premove dist-types/ts3.4 && downlevel-dts dist-types dist-types/ts3.4",
5
+ "build": "yarn g:tsc -p tsconfig.cjs.json && yarn g:tsc -p tsconfig.es.json && yarn g:tsc -p tsconfig.types.json",
9
6
  "clean": "premove dist-cjs dist-es dist-types tsconfig.cjs.tsbuildinfo tsconfig.es.tsbuildinfo tsconfig.types.tsbuildinfo",
10
- "format": "prettier --config ../../prettier.config.js --ignore-path ../../.prettierignore --write \"**/*.{ts,md,json}\"",
11
- "lint": "eslint -c ../../.eslintrc.js \"src/**/*.ts\"",
12
- "stage-release": "premove .release && yarn pack && mkdir ./.release && tar zxvf ./package.tgz --directory ./.release && rm ./package.tgz",
13
- "test": "yarn g:vitest run",
14
- "test:watch": "yarn g:vitest watch"
7
+ "stage-release": "premove .release && yarn pack && mkdir ./.release && tar zxvf ./package.tgz --directory ./.release && rm ./package.tgz"
15
8
  },
16
9
  "main": "./dist-cjs/index.js",
17
10
  "module": "./dist-es/index.js",
@@ -23,25 +16,11 @@
23
16
  "license": "Apache-2.0",
24
17
  "sideEffects": false,
25
18
  "dependencies": {
26
- "@aws-crypto/crc32": "5.2.0",
27
- "@smithy/types": "^4.14.1",
28
- "@smithy/util-hex-encoding": "^4.2.2",
19
+ "@smithy/core": "^3.24.0",
29
20
  "tslib": "^2.6.2"
30
21
  },
31
22
  "devDependencies": {
32
- "@smithy/util-utf8": "^4.2.2",
33
- "@types/node": "^18.11.9",
34
- "concurrently": "7.0.0",
35
- "downlevel-dts": "0.10.1",
36
- "premove": "4.0.0",
37
- "typedoc": "0.23.23"
38
- },
39
- "typesVersions": {
40
- "<4.5": {
41
- "dist-types/*": [
42
- "dist-types/ts3.4/*"
43
- ]
44
- }
23
+ "premove": "4.0.0"
45
24
  },
46
25
  "files": [
47
26
  "dist-*/**"
package/README.md DELETED
@@ -1,17 +0,0 @@
1
- # @smithy/eventstream-codec
2
-
3
- [![NPM version](https://img.shields.io/npm/v/@smithy/eventstream-codec/latest.svg)](https://www.npmjs.com/package/@smithy/eventstream-codec)
4
- [![NPM downloads](https://img.shields.io/npm/dm/@smithy/eventstream-codec.svg)](https://www.npmjs.com/package/@smithy/eventstream-codec)
5
-
6
- ### :warning: Internal API :warning:
7
-
8
- > This is an internal package.
9
- > That means this is used as a dependency for other, public packages, but
10
- > should not be taken directly as a dependency in your application's `package.json`.
11
-
12
- > If you are updating the version of this package, for example to bring in a
13
- > bug-fix, you should do so by updating your application lockfile with
14
- > e.g. `npm up @scope/package` or equivalent command in another
15
- > package manager, rather than taking a direct dependency.
16
-
17
- ---
@@ -1,65 +0,0 @@
1
- import { Crc32 } from "@aws-crypto/crc32";
2
- import { HeaderMarshaller } from "./HeaderMarshaller";
3
- import { splitMessage } from "./splitMessage";
4
- export class EventStreamCodec {
5
- headerMarshaller;
6
- messageBuffer;
7
- isEndOfStream;
8
- constructor(toUtf8, fromUtf8) {
9
- this.headerMarshaller = new HeaderMarshaller(toUtf8, fromUtf8);
10
- this.messageBuffer = [];
11
- this.isEndOfStream = false;
12
- }
13
- feed(message) {
14
- this.messageBuffer.push(this.decode(message));
15
- }
16
- endOfStream() {
17
- this.isEndOfStream = true;
18
- }
19
- getMessage() {
20
- const message = this.messageBuffer.pop();
21
- const isEndOfStream = this.isEndOfStream;
22
- return {
23
- getMessage() {
24
- return message;
25
- },
26
- isEndOfStream() {
27
- return isEndOfStream;
28
- },
29
- };
30
- }
31
- getAvailableMessages() {
32
- const messages = this.messageBuffer;
33
- this.messageBuffer = [];
34
- const isEndOfStream = this.isEndOfStream;
35
- return {
36
- getMessages() {
37
- return messages;
38
- },
39
- isEndOfStream() {
40
- return isEndOfStream;
41
- },
42
- };
43
- }
44
- encode({ headers: rawHeaders, body }) {
45
- const headers = this.headerMarshaller.format(rawHeaders);
46
- const length = headers.byteLength + body.byteLength + 16;
47
- const out = new Uint8Array(length);
48
- const view = new DataView(out.buffer, out.byteOffset, out.byteLength);
49
- const checksum = new Crc32();
50
- view.setUint32(0, length, false);
51
- view.setUint32(4, headers.byteLength, false);
52
- view.setUint32(8, checksum.update(out.subarray(0, 8)).digest(), false);
53
- out.set(headers, 12);
54
- out.set(body, headers.byteLength + 12);
55
- view.setUint32(length - 4, checksum.update(out.subarray(8, length - 4)).digest(), false);
56
- return out;
57
- }
58
- decode(message) {
59
- const { headers, body } = splitMessage(message);
60
- return { headers: this.headerMarshaller.parse(headers), body };
61
- }
62
- formatHeaders(rawHeaders) {
63
- return this.headerMarshaller.format(rawHeaders);
64
- }
65
- }
@@ -1,184 +0,0 @@
1
- import { fromHex, toHex } from "@smithy/util-hex-encoding";
2
- import { Int64 } from "./Int64";
3
- export class HeaderMarshaller {
4
- toUtf8;
5
- fromUtf8;
6
- constructor(toUtf8, fromUtf8) {
7
- this.toUtf8 = toUtf8;
8
- this.fromUtf8 = fromUtf8;
9
- }
10
- format(headers) {
11
- const chunks = [];
12
- for (const headerName of Object.keys(headers)) {
13
- const bytes = this.fromUtf8(headerName);
14
- chunks.push(Uint8Array.from([bytes.byteLength]), bytes, this.formatHeaderValue(headers[headerName]));
15
- }
16
- const out = new Uint8Array(chunks.reduce((carry, bytes) => carry + bytes.byteLength, 0));
17
- let position = 0;
18
- for (const chunk of chunks) {
19
- out.set(chunk, position);
20
- position += chunk.byteLength;
21
- }
22
- return out;
23
- }
24
- formatHeaderValue(header) {
25
- switch (header.type) {
26
- case "boolean":
27
- return Uint8Array.from([header.value ? 0 : 1]);
28
- case "byte":
29
- return Uint8Array.from([2, header.value]);
30
- case "short":
31
- const shortView = new DataView(new ArrayBuffer(3));
32
- shortView.setUint8(0, 3);
33
- shortView.setInt16(1, header.value, false);
34
- return new Uint8Array(shortView.buffer);
35
- case "integer":
36
- const intView = new DataView(new ArrayBuffer(5));
37
- intView.setUint8(0, 4);
38
- intView.setInt32(1, header.value, false);
39
- return new Uint8Array(intView.buffer);
40
- case "long":
41
- const longBytes = new Uint8Array(9);
42
- longBytes[0] = 5;
43
- longBytes.set(header.value.bytes, 1);
44
- return longBytes;
45
- case "binary":
46
- const binView = new DataView(new ArrayBuffer(3 + header.value.byteLength));
47
- binView.setUint8(0, 6);
48
- binView.setUint16(1, header.value.byteLength, false);
49
- const binBytes = new Uint8Array(binView.buffer);
50
- binBytes.set(header.value, 3);
51
- return binBytes;
52
- case "string":
53
- const utf8Bytes = this.fromUtf8(header.value);
54
- const strView = new DataView(new ArrayBuffer(3 + utf8Bytes.byteLength));
55
- strView.setUint8(0, 7);
56
- strView.setUint16(1, utf8Bytes.byteLength, false);
57
- const strBytes = new Uint8Array(strView.buffer);
58
- strBytes.set(utf8Bytes, 3);
59
- return strBytes;
60
- case "timestamp":
61
- const tsBytes = new Uint8Array(9);
62
- tsBytes[0] = 8;
63
- tsBytes.set(Int64.fromNumber(header.value.valueOf()).bytes, 1);
64
- return tsBytes;
65
- case "uuid":
66
- if (!UUID_PATTERN.test(header.value)) {
67
- throw new Error(`Invalid UUID received: ${header.value}`);
68
- }
69
- const uuidBytes = new Uint8Array(17);
70
- uuidBytes[0] = 9;
71
- uuidBytes.set(fromHex(header.value.replace(/\-/g, "")), 1);
72
- return uuidBytes;
73
- }
74
- }
75
- parse(headers) {
76
- const out = {};
77
- let position = 0;
78
- while (position < headers.byteLength) {
79
- const nameLength = headers.getUint8(position++);
80
- const name = this.toUtf8(new Uint8Array(headers.buffer, headers.byteOffset + position, nameLength));
81
- position += nameLength;
82
- switch (headers.getUint8(position++)) {
83
- case 0:
84
- out[name] = {
85
- type: BOOLEAN_TAG,
86
- value: true,
87
- };
88
- break;
89
- case 1:
90
- out[name] = {
91
- type: BOOLEAN_TAG,
92
- value: false,
93
- };
94
- break;
95
- case 2:
96
- out[name] = {
97
- type: BYTE_TAG,
98
- value: headers.getInt8(position++),
99
- };
100
- break;
101
- case 3:
102
- out[name] = {
103
- type: SHORT_TAG,
104
- value: headers.getInt16(position, false),
105
- };
106
- position += 2;
107
- break;
108
- case 4:
109
- out[name] = {
110
- type: INT_TAG,
111
- value: headers.getInt32(position, false),
112
- };
113
- position += 4;
114
- break;
115
- case 5:
116
- out[name] = {
117
- type: LONG_TAG,
118
- value: new Int64(new Uint8Array(headers.buffer, headers.byteOffset + position, 8)),
119
- };
120
- position += 8;
121
- break;
122
- case 6:
123
- const binaryLength = headers.getUint16(position, false);
124
- position += 2;
125
- out[name] = {
126
- type: BINARY_TAG,
127
- value: new Uint8Array(headers.buffer, headers.byteOffset + position, binaryLength),
128
- };
129
- position += binaryLength;
130
- break;
131
- case 7:
132
- const stringLength = headers.getUint16(position, false);
133
- position += 2;
134
- out[name] = {
135
- type: STRING_TAG,
136
- value: this.toUtf8(new Uint8Array(headers.buffer, headers.byteOffset + position, stringLength)),
137
- };
138
- position += stringLength;
139
- break;
140
- case 8:
141
- out[name] = {
142
- type: TIMESTAMP_TAG,
143
- value: new Date(new Int64(new Uint8Array(headers.buffer, headers.byteOffset + position, 8)).valueOf()),
144
- };
145
- position += 8;
146
- break;
147
- case 9:
148
- const uuidBytes = new Uint8Array(headers.buffer, headers.byteOffset + position, 16);
149
- position += 16;
150
- out[name] = {
151
- type: UUID_TAG,
152
- value: `${toHex(uuidBytes.subarray(0, 4))}-${toHex(uuidBytes.subarray(4, 6))}-${toHex(uuidBytes.subarray(6, 8))}-${toHex(uuidBytes.subarray(8, 10))}-${toHex(uuidBytes.subarray(10))}`,
153
- };
154
- break;
155
- default:
156
- throw new Error(`Unrecognized header type tag`);
157
- }
158
- }
159
- return out;
160
- }
161
- }
162
- var HEADER_VALUE_TYPE;
163
- (function (HEADER_VALUE_TYPE) {
164
- HEADER_VALUE_TYPE[HEADER_VALUE_TYPE["boolTrue"] = 0] = "boolTrue";
165
- HEADER_VALUE_TYPE[HEADER_VALUE_TYPE["boolFalse"] = 1] = "boolFalse";
166
- HEADER_VALUE_TYPE[HEADER_VALUE_TYPE["byte"] = 2] = "byte";
167
- HEADER_VALUE_TYPE[HEADER_VALUE_TYPE["short"] = 3] = "short";
168
- HEADER_VALUE_TYPE[HEADER_VALUE_TYPE["integer"] = 4] = "integer";
169
- HEADER_VALUE_TYPE[HEADER_VALUE_TYPE["long"] = 5] = "long";
170
- HEADER_VALUE_TYPE[HEADER_VALUE_TYPE["byteArray"] = 6] = "byteArray";
171
- HEADER_VALUE_TYPE[HEADER_VALUE_TYPE["string"] = 7] = "string";
172
- HEADER_VALUE_TYPE[HEADER_VALUE_TYPE["timestamp"] = 8] = "timestamp";
173
- HEADER_VALUE_TYPE[HEADER_VALUE_TYPE["uuid"] = 9] = "uuid";
174
- })(HEADER_VALUE_TYPE || (HEADER_VALUE_TYPE = {}));
175
- const BOOLEAN_TAG = "boolean";
176
- const BYTE_TAG = "byte";
177
- const SHORT_TAG = "short";
178
- const INT_TAG = "integer";
179
- const LONG_TAG = "long";
180
- const BINARY_TAG = "binary";
181
- const STRING_TAG = "string";
182
- const TIMESTAMP_TAG = "timestamp";
183
- const UUID_TAG = "uuid";
184
- const UUID_PATTERN = /^[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$/;
package/dist-es/Int64.js DELETED
@@ -1,44 +0,0 @@
1
- import { toHex } from "@smithy/util-hex-encoding";
2
- export class Int64 {
3
- bytes;
4
- constructor(bytes) {
5
- this.bytes = bytes;
6
- if (bytes.byteLength !== 8) {
7
- throw new Error("Int64 buffers must be exactly 8 bytes");
8
- }
9
- }
10
- static fromNumber(number) {
11
- if (number > 9_223_372_036_854_775_807 || number < -9_223_372_036_854_775_808) {
12
- throw new Error(`${number} is too large (or, if negative, too small) to represent as an Int64`);
13
- }
14
- const bytes = new Uint8Array(8);
15
- for (let i = 7, remaining = Math.abs(Math.round(number)); i > -1 && remaining > 0; i--, remaining /= 256) {
16
- bytes[i] = remaining;
17
- }
18
- if (number < 0) {
19
- negate(bytes);
20
- }
21
- return new Int64(bytes);
22
- }
23
- valueOf() {
24
- const bytes = this.bytes.slice(0);
25
- const negative = bytes[0] & 0b10000000;
26
- if (negative) {
27
- negate(bytes);
28
- }
29
- return parseInt(toHex(bytes), 16) * (negative ? -1 : 1);
30
- }
31
- toString() {
32
- return String(this.valueOf());
33
- }
34
- }
35
- function negate(bytes) {
36
- for (let i = 0; i < 8; i++) {
37
- bytes[i] ^= 0xff;
38
- }
39
- for (let i = 7; i > -1; i--) {
40
- bytes[i]++;
41
- if (bytes[i] !== 0)
42
- break;
43
- }
44
- }
@@ -1 +0,0 @@
1
- export {};
@@ -1,15 +0,0 @@
1
- export class MessageDecoderStream {
2
- options;
3
- constructor(options) {
4
- this.options = options;
5
- }
6
- [Symbol.asyncIterator]() {
7
- return this.asyncIterator();
8
- }
9
- async *asyncIterator() {
10
- for await (const bytes of this.options.inputStream) {
11
- const decoded = this.options.decoder.decode(bytes);
12
- yield decoded;
13
- }
14
- }
15
- }
@@ -1,18 +0,0 @@
1
- export class MessageEncoderStream {
2
- options;
3
- constructor(options) {
4
- this.options = options;
5
- }
6
- [Symbol.asyncIterator]() {
7
- return this.asyncIterator();
8
- }
9
- async *asyncIterator() {
10
- for await (const msg of this.options.messageStream) {
11
- const encoded = this.options.encoder.encode(msg);
12
- yield encoded;
13
- }
14
- if (this.options.includeEndFrame) {
15
- yield new Uint8Array(0);
16
- }
17
- }
18
- }
@@ -1,17 +0,0 @@
1
- export class SmithyMessageDecoderStream {
2
- options;
3
- constructor(options) {
4
- this.options = options;
5
- }
6
- [Symbol.asyncIterator]() {
7
- return this.asyncIterator();
8
- }
9
- async *asyncIterator() {
10
- for await (const message of this.options.messageStream) {
11
- const deserialized = await this.options.deserializer(message);
12
- if (deserialized === undefined)
13
- continue;
14
- yield deserialized;
15
- }
16
- }
17
- }
@@ -1,15 +0,0 @@
1
- export class SmithyMessageEncoderStream {
2
- options;
3
- constructor(options) {
4
- this.options = options;
5
- }
6
- [Symbol.asyncIterator]() {
7
- return this.asyncIterator();
8
- }
9
- async *asyncIterator() {
10
- for await (const chunk of this.options.inputStream) {
11
- const payloadBuf = this.options.serializer(chunk);
12
- yield payloadBuf;
13
- }
14
- }
15
- }
@@ -1,146 +0,0 @@
1
- import { Int64 } from "./Int64";
2
- export const vectors = {
3
- all_headers: {
4
- expectation: "success",
5
- encoded: Uint8Array.from([
6
- 0, 0, 0, 204, 0, 0, 0, 175, 15, 174, 100, 202, 10, 101, 118, 101, 110, 116, 45, 116, 121, 112, 101, 4, 0, 0, 160,
7
- 12, 12, 99, 111, 110, 116, 101, 110, 116, 45, 116, 121, 112, 101, 7, 0, 16, 97, 112, 112, 108, 105, 99, 97, 116,
8
- 105, 111, 110, 47, 106, 115, 111, 110, 10, 98, 111, 111, 108, 32, 102, 97, 108, 115, 101, 1, 9, 98, 111, 111, 108,
9
- 32, 116, 114, 117, 101, 0, 4, 98, 121, 116, 101, 2, 207, 8, 98, 121, 116, 101, 32, 98, 117, 102, 6, 0, 20, 73, 39,
10
- 109, 32, 97, 32, 108, 105, 116, 116, 108, 101, 32, 116, 101, 97, 112, 111, 116, 33, 9, 116, 105, 109, 101, 115,
11
- 116, 97, 109, 112, 8, 0, 0, 0, 0, 0, 132, 95, 237, 5, 105, 110, 116, 49, 54, 3, 0, 42, 5, 105, 110, 116, 54, 52,
12
- 5, 0, 0, 0, 0, 2, 135, 87, 178, 4, 117, 117, 105, 100, 9, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
13
- 123, 39, 102, 111, 111, 39, 58, 39, 98, 97, 114, 39, 125, 171, 165, 241, 12,
14
- ]),
15
- decoded: {
16
- headers: {
17
- "event-type": {
18
- type: "integer",
19
- value: 40972,
20
- },
21
- "content-type": {
22
- type: "string",
23
- value: "application/json",
24
- },
25
- "bool false": {
26
- type: "boolean",
27
- value: false,
28
- },
29
- "bool true": {
30
- type: "boolean",
31
- value: true,
32
- },
33
- byte: {
34
- type: "byte",
35
- value: -49,
36
- },
37
- "byte buf": {
38
- type: "binary",
39
- value: Uint8Array.from([
40
- 73, 39, 109, 32, 97, 32, 108, 105, 116, 116, 108, 101, 32, 116, 101, 97, 112, 111, 116, 33,
41
- ]),
42
- },
43
- timestamp: {
44
- type: "timestamp",
45
- value: new Date(8675309),
46
- },
47
- int16: {
48
- type: "short",
49
- value: 42,
50
- },
51
- int64: {
52
- type: "long",
53
- value: Int64.fromNumber(42424242),
54
- },
55
- uuid: {
56
- type: "uuid",
57
- value: "01020304-0506-0708-090a-0b0c0d0e0f10",
58
- },
59
- },
60
- body: Uint8Array.from([123, 39, 102, 111, 111, 39, 58, 39, 98, 97, 114, 39, 125]),
61
- },
62
- },
63
- empty_message: {
64
- expectation: "success",
65
- encoded: Uint8Array.from([0, 0, 0, 16, 0, 0, 0, 0, 5, 194, 72, 235, 125, 152, 200, 255]),
66
- decoded: {
67
- headers: {},
68
- body: Uint8Array.from([]),
69
- },
70
- },
71
- int32_header: {
72
- expectation: "success",
73
- encoded: Uint8Array.from([
74
- 0, 0, 0, 45, 0, 0, 0, 16, 65, 196, 36, 184, 10, 101, 118, 101, 110, 116, 45, 116, 121, 112, 101, 4, 0, 0, 160, 12,
75
- 123, 39, 102, 111, 111, 39, 58, 39, 98, 97, 114, 39, 125, 54, 244, 128, 160,
76
- ]),
77
- decoded: {
78
- headers: {
79
- "event-type": {
80
- type: "integer",
81
- value: 40972,
82
- },
83
- },
84
- body: Uint8Array.from([123, 39, 102, 111, 111, 39, 58, 39, 98, 97, 114, 39, 125]),
85
- },
86
- },
87
- payload_no_headers: {
88
- expectation: "success",
89
- encoded: Uint8Array.from([
90
- 0, 0, 0, 29, 0, 0, 0, 0, 253, 82, 140, 90, 123, 39, 102, 111, 111, 39, 58, 39, 98, 97, 114, 39, 125, 195, 101, 57,
91
- 54,
92
- ]),
93
- decoded: {
94
- headers: {},
95
- body: Uint8Array.from([123, 39, 102, 111, 111, 39, 58, 39, 98, 97, 114, 39, 125]),
96
- },
97
- },
98
- payload_one_str_header: {
99
- expectation: "success",
100
- encoded: Uint8Array.from([
101
- 0, 0, 0, 61, 0, 0, 0, 32, 7, 253, 131, 150, 12, 99, 111, 110, 116, 101, 110, 116, 45, 116, 121, 112, 101, 7, 0,
102
- 16, 97, 112, 112, 108, 105, 99, 97, 116, 105, 111, 110, 47, 106, 115, 111, 110, 123, 39, 102, 111, 111, 39, 58,
103
- 39, 98, 97, 114, 39, 125, 141, 156, 8, 177,
104
- ]),
105
- decoded: {
106
- headers: {
107
- "content-type": {
108
- type: "string",
109
- value: "application/json",
110
- },
111
- },
112
- body: Uint8Array.from([123, 39, 102, 111, 111, 39, 58, 39, 98, 97, 114, 39, 125]),
113
- },
114
- },
115
- corrupted_headers: {
116
- expectation: "failure",
117
- encoded: Uint8Array.from([
118
- 0, 0, 0, 61, 0, 0, 0, 32, 7, 253, 131, 150, 12, 99, 111, 110, 116, 101, 110, 116, 45, 116, 121, 112, 101, 7, 0,
119
- 16, 97, 112, 112, 108, 105, 99, 97, 116, 105, 111, 110, 47, 106, 115, 111, 110, 123, 97, 102, 111, 111, 39, 58,
120
- 39, 98, 97, 114, 39, 125, 141, 156, 8, 177,
121
- ]),
122
- },
123
- corrupted_header_len: {
124
- expectation: "failure",
125
- encoded: Uint8Array.from([
126
- 0, 0, 0, 61, 0, 0, 0, 33, 7, 253, 131, 150, 12, 99, 111, 110, 116, 101, 110, 116, 45, 116, 121, 112, 101, 7, 0,
127
- 16, 97, 112, 112, 108, 105, 99, 97, 116, 105, 111, 110, 47, 106, 115, 111, 110, 123, 39, 102, 111, 111, 39, 58,
128
- 39, 98, 97, 114, 39, 125, 141, 156, 8, 177,
129
- ]),
130
- },
131
- corrupted_length: {
132
- expectation: "failure",
133
- encoded: Uint8Array.from([
134
- 0, 0, 0, 62, 0, 0, 0, 32, 7, 253, 131, 150, 12, 99, 111, 110, 116, 101, 110, 116, 45, 116, 121, 112, 101, 7, 0,
135
- 16, 97, 112, 112, 108, 105, 99, 97, 116, 105, 111, 110, 47, 106, 115, 111, 110, 123, 39, 102, 111, 111, 39, 58,
136
- 39, 98, 97, 114, 39, 125, 141, 156, 8, 177,
137
- ]),
138
- },
139
- corrupted_payload: {
140
- expectation: "failure",
141
- encoded: Uint8Array.from([
142
- 0, 0, 0, 29, 0, 0, 0, 0, 253, 82, 140, 90, 91, 39, 102, 111, 111, 39, 58, 39, 98, 97, 114, 39, 125, 195, 101, 57,
143
- 54,
144
- ]),
145
- },
146
- };
@@ -1,30 +0,0 @@
1
- import { Crc32 } from "@aws-crypto/crc32";
2
- const PRELUDE_MEMBER_LENGTH = 4;
3
- const PRELUDE_LENGTH = PRELUDE_MEMBER_LENGTH * 2;
4
- const CHECKSUM_LENGTH = 4;
5
- const MINIMUM_MESSAGE_LENGTH = PRELUDE_LENGTH + CHECKSUM_LENGTH * 2;
6
- export function splitMessage({ byteLength, byteOffset, buffer }) {
7
- if (byteLength < MINIMUM_MESSAGE_LENGTH) {
8
- throw new Error("Provided message too short to accommodate event stream message overhead");
9
- }
10
- const view = new DataView(buffer, byteOffset, byteLength);
11
- const messageLength = view.getUint32(0, false);
12
- if (byteLength !== messageLength) {
13
- throw new Error("Reported message length does not match received message length");
14
- }
15
- const headerLength = view.getUint32(PRELUDE_MEMBER_LENGTH, false);
16
- const expectedPreludeChecksum = view.getUint32(PRELUDE_LENGTH, false);
17
- const expectedMessageChecksum = view.getUint32(byteLength - CHECKSUM_LENGTH, false);
18
- const checksummer = new Crc32().update(new Uint8Array(buffer, byteOffset, PRELUDE_LENGTH));
19
- if (expectedPreludeChecksum !== checksummer.digest()) {
20
- throw new Error(`The prelude checksum specified in the message (${expectedPreludeChecksum}) does not match the calculated CRC32 checksum (${checksummer.digest()})`);
21
- }
22
- checksummer.update(new Uint8Array(buffer, byteOffset + PRELUDE_LENGTH, byteLength - (PRELUDE_LENGTH + CHECKSUM_LENGTH)));
23
- if (expectedMessageChecksum !== checksummer.digest()) {
24
- throw new Error(`The message checksum (${checksummer.digest()}) did not match the expected value of ${expectedMessageChecksum}`);
25
- }
26
- return {
27
- headers: new DataView(buffer, byteOffset + PRELUDE_LENGTH + CHECKSUM_LENGTH, headerLength),
28
- body: new Uint8Array(buffer, byteOffset + PRELUDE_LENGTH + CHECKSUM_LENGTH + headerLength, messageLength - headerLength - (PRELUDE_LENGTH + CHECKSUM_LENGTH + CHECKSUM_LENGTH)),
29
- };
30
- }
@@ -1 +0,0 @@
1
- export {};
@@ -1,31 +0,0 @@
1
- import type { AvailableMessage, AvailableMessages, Message, MessageDecoder, MessageEncoder, MessageHeaders } from "@smithy/types";
2
- import type { Decoder, Encoder } from "@smithy/types";
3
- /**
4
- * A Codec that can convert binary-packed event stream messages into
5
- * JavaScript objects and back again into their binary format.
6
- */
7
- export declare class EventStreamCodec implements MessageEncoder, MessageDecoder {
8
- private readonly headerMarshaller;
9
- private messageBuffer;
10
- private isEndOfStream;
11
- constructor(toUtf8: Encoder, fromUtf8: Decoder);
12
- feed(message: ArrayBufferView): void;
13
- endOfStream(): void;
14
- getMessage(): AvailableMessage;
15
- getAvailableMessages(): AvailableMessages;
16
- /**
17
- * Convert a structured JavaScript object with tagged headers into a binary
18
- * event stream message.
19
- */
20
- encode({ headers: rawHeaders, body }: Message): Uint8Array;
21
- /**
22
- * Convert a binary event stream message into a JavaScript object with an
23
- * opaque, binary body and tagged, parsed headers.
24
- */
25
- decode(message: ArrayBufferView): Message;
26
- /**
27
- * Convert a structured JavaScript object with tagged headers into a binary
28
- * event stream message header.
29
- */
30
- formatHeaders(rawHeaders: MessageHeaders): Uint8Array;
31
- }
@@ -1,12 +0,0 @@
1
- import type { Decoder, Encoder, MessageHeaders } from "@smithy/types";
2
- /**
3
- * @internal
4
- */
5
- export declare class HeaderMarshaller {
6
- private readonly toUtf8;
7
- private readonly fromUtf8;
8
- constructor(toUtf8: Encoder, fromUtf8: Decoder);
9
- format(headers: MessageHeaders): Uint8Array;
10
- private formatHeaderValue;
11
- parse(headers: DataView): MessageHeaders;
12
- }
@@ -1,20 +0,0 @@
1
- import type { Int64 as IInt64 } from "@smithy/types";
2
- export interface Int64 extends IInt64 {
3
- }
4
- /**
5
- * A lossless representation of a signed, 64-bit integer. Instances of this
6
- * class may be used in arithmetic expressions as if they were numeric
7
- * primitives, but the binary representation will be preserved unchanged as the
8
- * `bytes` property of the object. The bytes should be encoded as big-endian,
9
- * two's complement integers.
10
- */
11
- export declare class Int64 {
12
- readonly bytes: Uint8Array;
13
- constructor(bytes: Uint8Array);
14
- static fromNumber(number: number): Int64;
15
- /**
16
- * Called implicitly by infix arithmetic operators.
17
- */
18
- valueOf(): number;
19
- toString(): string;
20
- }
@@ -1,26 +0,0 @@
1
- import type { Int64 } from "./Int64";
2
- /**
3
- * An event stream message. The headers and body properties will always be
4
- * defined, with empty headers represented as an object with no keys and an
5
- * empty body represented as a zero-length Uint8Array.
6
- */
7
- export interface Message {
8
- headers: MessageHeaders;
9
- body: Uint8Array;
10
- }
11
- export type MessageHeaders = Record<string, MessageHeaderValue>;
12
- type HeaderValue<K extends string, V> = {
13
- type: K;
14
- value: V;
15
- };
16
- export type BooleanHeaderValue = HeaderValue<"boolean", boolean>;
17
- export type ByteHeaderValue = HeaderValue<"byte", number>;
18
- export type ShortHeaderValue = HeaderValue<"short", number>;
19
- export type IntegerHeaderValue = HeaderValue<"integer", number>;
20
- export type LongHeaderValue = HeaderValue<"long", Int64>;
21
- export type BinaryHeaderValue = HeaderValue<"binary", Uint8Array>;
22
- export type StringHeaderValue = HeaderValue<"string", string>;
23
- export type TimestampHeaderValue = HeaderValue<"timestamp", Date>;
24
- export type UuidHeaderValue = HeaderValue<"uuid", string>;
25
- export type MessageHeaderValue = BooleanHeaderValue | ByteHeaderValue | ShortHeaderValue | IntegerHeaderValue | LongHeaderValue | BinaryHeaderValue | StringHeaderValue | TimestampHeaderValue | UuidHeaderValue;
26
- export {};
@@ -1,17 +0,0 @@
1
- import type { Message, MessageDecoder } from "@smithy/types";
2
- /**
3
- * @internal
4
- */
5
- export interface MessageDecoderStreamOptions {
6
- inputStream: AsyncIterable<Uint8Array>;
7
- decoder: MessageDecoder;
8
- }
9
- /**
10
- * @internal
11
- */
12
- export declare class MessageDecoderStream implements AsyncIterable<Message> {
13
- private readonly options;
14
- constructor(options: MessageDecoderStreamOptions);
15
- [Symbol.asyncIterator](): AsyncIterator<Message>;
16
- private asyncIterator;
17
- }
@@ -1,18 +0,0 @@
1
- import type { Message, MessageEncoder } from "@smithy/types";
2
- /**
3
- * @internal
4
- */
5
- export interface MessageEncoderStreamOptions {
6
- messageStream: AsyncIterable<Message>;
7
- encoder: MessageEncoder;
8
- includeEndFrame?: boolean;
9
- }
10
- /**
11
- * @internal
12
- */
13
- export declare class MessageEncoderStream implements AsyncIterable<Uint8Array> {
14
- private readonly options;
15
- constructor(options: MessageEncoderStreamOptions);
16
- [Symbol.asyncIterator](): AsyncIterator<Uint8Array>;
17
- private asyncIterator;
18
- }
@@ -1,17 +0,0 @@
1
- import type { Message } from "@smithy/types";
2
- /**
3
- * @internal
4
- */
5
- export interface SmithyMessageDecoderStreamOptions<T> {
6
- readonly messageStream: AsyncIterable<Message>;
7
- readonly deserializer: (input: Message) => Promise<T | undefined>;
8
- }
9
- /**
10
- * @internal
11
- */
12
- export declare class SmithyMessageDecoderStream<T> implements AsyncIterable<T> {
13
- private readonly options;
14
- constructor(options: SmithyMessageDecoderStreamOptions<T>);
15
- [Symbol.asyncIterator](): AsyncIterator<T>;
16
- private asyncIterator;
17
- }
@@ -1,17 +0,0 @@
1
- import type { Message } from "@smithy/types";
2
- /**
3
- * @internal
4
- */
5
- export interface SmithyMessageEncoderStreamOptions<T> {
6
- inputStream: AsyncIterable<T>;
7
- serializer: (event: T) => Message;
8
- }
9
- /**
10
- * @internal
11
- */
12
- export declare class SmithyMessageEncoderStream<T> implements AsyncIterable<Message> {
13
- private readonly options;
14
- constructor(options: SmithyMessageEncoderStreamOptions<T>);
15
- [Symbol.asyncIterator](): AsyncIterator<Message>;
16
- private asyncIterator;
17
- }
@@ -1,2 +0,0 @@
1
- import type { TestVectors } from "./vectorTypes.fixture";
2
- export declare const vectors: TestVectors;
@@ -1,11 +0,0 @@
1
- /**
2
- * @internal
3
- */
4
- export interface MessageParts {
5
- headers: DataView;
6
- body: Uint8Array;
7
- }
8
- /**
9
- * @internal
10
- */
11
- export declare function splitMessage({ byteLength, byteOffset, buffer }: ArrayBufferView): MessageParts;
@@ -1,12 +0,0 @@
1
- import type { Message } from "./Message";
2
- export interface NegativeTestVector {
3
- expectation: "failure";
4
- encoded: Uint8Array;
5
- }
6
- export interface PositiveTestVector {
7
- expectation: "success";
8
- encoded: Uint8Array;
9
- decoded: Message;
10
- }
11
- export type TestVector = NegativeTestVector | PositiveTestVector;
12
- export type TestVectors = Record<string, TestVector>;