@smithy/eventstream-serde-browser 1.0.1 → 1.0.2
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.
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { Decoder, Encoder, EventStreamMarshaller as IEventStreamMarshaller, Message } from "@smithy/types";
|
|
2
|
+
/**
|
|
3
|
+
* @internal
|
|
4
|
+
*/
|
|
5
|
+
export interface EventStreamMarshaller extends IEventStreamMarshaller {
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* @internal
|
|
9
|
+
*/
|
|
10
|
+
export interface EventStreamMarshallerOptions {
|
|
11
|
+
utf8Encoder: Encoder;
|
|
12
|
+
utf8Decoder: Decoder;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* @internal
|
|
16
|
+
*
|
|
17
|
+
* Utility class used to serialize and deserialize event streams in
|
|
18
|
+
* browsers and ReactNative.
|
|
19
|
+
*
|
|
20
|
+
* In browsers where ReadableStream API is available:
|
|
21
|
+
* * deserialize from ReadableStream to an async iterable of output structure
|
|
22
|
+
* * serialize from async iterable of input structure to ReadableStream
|
|
23
|
+
* In ReactNative where only async iterable API is available:
|
|
24
|
+
* * deserialize from async iterable of binaries to async iterable of output structure
|
|
25
|
+
* * serialize from async iterable of input structure to async iterable of binaries
|
|
26
|
+
*
|
|
27
|
+
* We use ReadableStream API in browsers because of the consistency with other
|
|
28
|
+
* streaming operations, where ReadableStream API is used to denote streaming data.
|
|
29
|
+
* Whereas in ReactNative, ReadableStream API is not available, we use async iterable
|
|
30
|
+
* for streaming data although it has lower throughput.
|
|
31
|
+
*/
|
|
32
|
+
export declare class EventStreamMarshaller {
|
|
33
|
+
private readonly universalMarshaller;
|
|
34
|
+
constructor({ utf8Encoder, utf8Decoder }: EventStreamMarshallerOptions);
|
|
35
|
+
deserialize<T>(body: ReadableStream<Uint8Array> | AsyncIterable<Uint8Array>, deserializer: (input: Record<string, Message>) => Promise<T>): AsyncIterable<T>;
|
|
36
|
+
/**
|
|
37
|
+
* Generate a stream that serialize events into stream of binary chunks;
|
|
38
|
+
*
|
|
39
|
+
* Caveat is that streaming request payload doesn't work on browser with native
|
|
40
|
+
* xhr or fetch handler currently because they don't support upload streaming.
|
|
41
|
+
* reference:
|
|
42
|
+
* * https://bugs.chromium.org/p/chromium/issues/detail?id=688906
|
|
43
|
+
* * https://bugzilla.mozilla.org/show_bug.cgi?id=1387483
|
|
44
|
+
*
|
|
45
|
+
*/
|
|
46
|
+
serialize<T>(input: AsyncIterable<T>, serializer: (event: T) => Message): ReadableStream | AsyncIterable<Uint8Array>;
|
|
47
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @internal
|
|
3
|
+
*
|
|
4
|
+
* A util function converting ReadableStream into an async iterable.
|
|
5
|
+
* Reference: https://jakearchibald.com/2017/async-iterators-and-generators/#making-streams-iterate
|
|
6
|
+
*/
|
|
7
|
+
export declare const readableStreamtoIterable: <T>(readableStream: ReadableStream<T>) => AsyncIterable<T>;
|
|
8
|
+
/**
|
|
9
|
+
* @internal
|
|
10
|
+
*
|
|
11
|
+
* A util function converting async iterable to a ReadableStream.
|
|
12
|
+
*/
|
|
13
|
+
export declare const iterableToReadableStream: <T>(asyncIterable: AsyncIterable<T>) => ReadableStream<T>;
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@smithy/eventstream-serde-browser",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2",
|
|
4
4
|
"scripts": {
|
|
5
|
-
"build": "concurrently 'yarn:build:cjs' 'yarn:build:es' 'yarn:build:types'",
|
|
5
|
+
"build": "concurrently 'yarn:build:cjs' 'yarn:build:es' 'yarn:build:types && yarn build:types:downlevel'",
|
|
6
6
|
"build:cjs": "tsc -p tsconfig.cjs.json",
|
|
7
7
|
"build:es": "tsc -p tsconfig.es.json",
|
|
8
8
|
"build:types": "tsc -p tsconfig.types.json",
|
|
@@ -22,8 +22,8 @@
|
|
|
22
22
|
},
|
|
23
23
|
"license": "Apache-2.0",
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@smithy/eventstream-serde-universal": "^1.0.
|
|
26
|
-
"@smithy/types": "^1.1.
|
|
25
|
+
"@smithy/eventstream-serde-universal": "^1.0.2",
|
|
26
|
+
"@smithy/types": "^1.1.1",
|
|
27
27
|
"tslib": "^2.5.0"
|
|
28
28
|
},
|
|
29
29
|
"engines": {
|