turbo-stream 2.4.0 → 3.0.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/README.md +40 -10
- package/dist/decode.d.ts +7 -0
- package/dist/decode.js +636 -0
- package/dist/encode.d.ts +27 -0
- package/dist/encode.js +395 -0
- package/dist/shared.d.ts +107 -0
- package/dist/shared.js +324 -0
- package/dist/turbo-stream.d.ts +4 -13
- package/dist/turbo-stream.js +4 -204
- package/dist/turbo-stream.mjs +1175 -597
- package/package.json +53 -48
- package/dist/flatten.d.ts +0 -2
- package/dist/flatten.js +0 -203
- package/dist/unflatten.d.ts +0 -2
- package/dist/unflatten.js +0 -243
- package/dist/utils.d.ts +0 -44
- package/dist/utils.js +0 -55
package/README.md
CHANGED
|
@@ -4,11 +4,6 @@ A streaming data transport format that aims to support built-in features such as
|
|
|
4
4
|
|
|
5
5
|
Decode runtime size: [](https://bundlejs.com/?q=turbo-stream&treeshake=%5B%7B+decode+%7D%5D)
|
|
6
6
|
|
|
7
|
-
## Shout Out!
|
|
8
|
-
|
|
9
|
-
Shout out to Rich Harris and his https://github.com/rich-harris/devalue project. Devalue has heavily influenced this project and portions
|
|
10
|
-
of the code have been directly lifted from it. I highly recommend checking it out if you need something more cusomizable or without streaming support.
|
|
11
|
-
|
|
12
7
|
## Installation
|
|
13
8
|
|
|
14
9
|
```bash
|
|
@@ -22,10 +17,45 @@ import { decode, encode } from "turbo-stream";
|
|
|
22
17
|
|
|
23
18
|
const encodedStream = encode(Promise.resolve(42));
|
|
24
19
|
const decoded = await decode(encodedStream);
|
|
25
|
-
console.log(decoded
|
|
26
|
-
|
|
27
|
-
|
|
20
|
+
console.log(decoded); // 42
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## Benchmarks
|
|
24
|
+
|
|
25
|
+
Run them yourself with `pnpm bench`
|
|
26
|
+
|
|
28
27
|
```
|
|
28
|
+
• realistic payload
|
|
29
|
+
------------------------------------------- -------------------------------
|
|
30
|
+
JSON 2.80 µs/iter 2.71 µs █▆
|
|
31
|
+
(2.59 µs … 5.61 µs) 5.55 µs ██
|
|
32
|
+
( 2.91 kb … 2.91 kb) 2.91 kb ██▁▂▁▁▁▁▁▂▁▁▁▁▁▁▁▁▁▁▂
|
|
33
|
+
turbo encode 16.71 µs/iter 16.47 µs █
|
|
34
|
+
(16.04 µs … 19.47 µs) 18.38 µs ███
|
|
35
|
+
( 2.80 kb … 2.81 kb) 2.80 kb ██████▁▁▁▁▁▁▁▁▁▁▁▁▁▁█
|
|
36
|
+
turbo full 35.30 µs/iter 36.33 µs █
|
|
37
|
+
(31.38 µs … 202.79 µs) 52.50 µs █▃ ▄
|
|
38
|
+
( 2.47 kb … 454.32 kb) 104.44 kb ▂██▃▅█▂▂▂▂▁▁▁▁▁▁▁▁▁▁▁
|
|
39
|
+
|
|
40
|
+
┌ ┐
|
|
41
|
+
┬ ╷
|
|
42
|
+
JSON │──┤
|
|
43
|
+
┴ ╵
|
|
44
|
+
┌┬╷
|
|
45
|
+
turbo encode ││┤
|
|
46
|
+
└┴╵
|
|
47
|
+
╷┌─┬┐ ╷
|
|
48
|
+
turbo full ├┤ │├──────────────┤
|
|
49
|
+
╵└─┴┘ ╵
|
|
50
|
+
└ ┘
|
|
51
|
+
2.59 µs 27.55 µs 52.50 µs
|
|
52
|
+
|
|
53
|
+
summary
|
|
54
|
+
turbo encode
|
|
55
|
+
5.97x slower than JSON
|
|
56
|
+
2.11x faster than turbo full
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
## Legacy
|
|
29
60
|
|
|
30
|
-
|
|
31
|
-
React SSR Example: https://github.com/jacob-ebey/turbo-stream-react-example
|
|
61
|
+
Shout out to Rich Harris and his https://github.com/rich-harris/devalue project. Devalue has heavily influenced this project and portions of the original code was directly lifted from it. I highly recommend checking it out if you need something more cusomizable or without streaming support. This new version has been re-written from the ground up and no longer resembles devalue.
|
package/dist/decode.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export type DecodePlugin = (type: string, ...data: unknown[]) => {
|
|
2
|
+
value: unknown;
|
|
3
|
+
} | false | null | undefined;
|
|
4
|
+
export type DecodeOptions = {
|
|
5
|
+
plugins?: DecodePlugin[];
|
|
6
|
+
};
|
|
7
|
+
export declare function decode<T>(stream: ReadableStream<string>, { plugins }?: DecodeOptions): Promise<T>;
|