node-turbo 1.2.6 → 1.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/LICENSE +1 -1
- package/README.md +15 -15
- package/docs/API.md +20 -17
- package/docs/config.codekit3 +2925 -0
- package/lib/express/express-turbo-stream.js +1 -1
- package/lib/express/turbocharge-express.js +3 -2
- package/lib/koa/turbocharge-koa.js +4 -2
- package/lib/sse/sse-turbo-stream.js +44 -25
- package/lib/turbo-readable.js +3 -10
- package/lib/turbo-stream.js +50 -11
- package/lib/ws/ws-turbo-stream.js +1 -0
- package/package.json +12 -12
- package/test/end2end/server-koa.js +4 -3
- package/test/integration/sse.test.js +45 -33
- package/test/integration/ws.test.js +2 -3
- package/test/unit/core/turbo-readable.test.js +8 -11
- package/test/unit/core/turbo-stream.test.js +89 -19
- package/test/unit/express/turbocharge-express.test.js +2 -1
- package/test/unit/koa/turbocharge-koa.test.js +2 -1
- package/test/unit/sse/sse-turbo-stream.test.js +12 -4
package/LICENSE
CHANGED
package/README.md
CHANGED
|
@@ -55,11 +55,11 @@ node-turbo has been tested with 100% code coverage with the following engines/li
|
|
|
55
55
|
|
|
56
56
|
| Name | Version(s) |
|
|
57
57
|
| :--- | :--- |
|
|
58
|
-
| [Hotwire Turbo](https://turbo.hotwired.dev/) | 7.3.0 - 8.0.
|
|
58
|
+
| [Hotwire Turbo](https://turbo.hotwired.dev/) | 7.3.0 - 8.0.23 |
|
|
59
59
|
| [Node.js](https://nodejs.org/) | 16.6 - 22.20.0 |
|
|
60
|
-
| [Koa](https://koajs.com/) | 2.14.2 - 3.
|
|
61
|
-
| [Express](https://expressjs.com/) | 4.18.2 - 5.1
|
|
62
|
-
| [ws](https://github.com/websockets/ws) | 8.15.1 - 8.
|
|
60
|
+
| [Koa](https://koajs.com/) | 2.14.2 - 3.1.2 |
|
|
61
|
+
| [Express](https://expressjs.com/) | 4.18.2 - 5.2.1 |
|
|
62
|
+
| [ws](https://github.com/websockets/ws) | 8.15.1 - 8.19.0 |
|
|
63
63
|
|
|
64
64
|
## API docs
|
|
65
65
|
See [`/docs/API.md`](./docs/API.md) for a documentation of all node-turbo classes and functions.
|
|
@@ -216,15 +216,15 @@ Result:
|
|
|
216
216
|
|
|
217
217
|
##### Using the Node.js streams API
|
|
218
218
|
If you want to use the [Node.js streams API](https://nodejs.org/docs/latest/api/stream.html) with Turbo Streams, you can
|
|
219
|
-
create a
|
|
219
|
+
create a `PassThrough` stream instance which reads Turbo Stream messages.
|
|
220
220
|
|
|
221
221
|
```javascript
|
|
222
222
|
import { TurboStream } from 'node-turbo';
|
|
223
223
|
|
|
224
224
|
const ts = new TurboStream();
|
|
225
|
-
const
|
|
225
|
+
const nStream = ts.createNodeStream();
|
|
226
226
|
|
|
227
|
-
|
|
227
|
+
nStream.pipe(process.stdout);
|
|
228
228
|
|
|
229
229
|
// These elements get piped immediately:
|
|
230
230
|
ts
|
|
@@ -459,9 +459,9 @@ const wss = new WebSocketServer({ port: 8080 });
|
|
|
459
459
|
|
|
460
460
|
wss.on('connection', function connection(ws) {
|
|
461
461
|
const ts = new TurboStream();
|
|
462
|
-
const
|
|
462
|
+
const nStream = ts.createNodeStream();
|
|
463
463
|
const wsStream = createWebSocketStream(ws, { encoding: 'utf8' });
|
|
464
|
-
|
|
464
|
+
nStream.pipe(wsStream);
|
|
465
465
|
|
|
466
466
|
ts
|
|
467
467
|
.append('target-id', '<p>My content</p>')
|
|
@@ -508,8 +508,8 @@ const httpServer = http.createServer((req, res) => {
|
|
|
508
508
|
|
|
509
509
|
// You can also use the streams API.
|
|
510
510
|
setTimeout(() => {
|
|
511
|
-
const
|
|
512
|
-
|
|
511
|
+
const nStream = ssets.createNodeStream();
|
|
512
|
+
nStream.pipe(res);
|
|
513
513
|
ssets.prependAll('.stream', '<p>Prepend!</p>');
|
|
514
514
|
}, 2000);
|
|
515
515
|
|
|
@@ -529,7 +529,7 @@ const httpServer = http.createServer((req, res) => {
|
|
|
529
529
|
padding: 10px;
|
|
530
530
|
}
|
|
531
531
|
</style>
|
|
532
|
-
<script type="module" src="https://unpkg.com/@hotwired/turbo@8.0.
|
|
532
|
+
<script type="module" src="https://unpkg.com/@hotwired/turbo@8.0.23/dist/turbo.es2017-esm.js"></script>
|
|
533
533
|
<script>
|
|
534
534
|
var eventSource = new EventSource('/sse');
|
|
535
535
|
eventSource.onmessage = function(event) {
|
|
@@ -616,7 +616,7 @@ app.use(async (ctx, next) => {
|
|
|
616
616
|
padding: 10px;
|
|
617
617
|
}
|
|
618
618
|
</style>
|
|
619
|
-
<script type="module" src="https://unpkg.com/@hotwired/turbo@8.0.
|
|
619
|
+
<script type="module" src="https://unpkg.com/@hotwired/turbo@8.0.23/dist/turbo.es2017-esm.js"></script>
|
|
620
620
|
<script>
|
|
621
621
|
var eventSource = new EventSource('/sse');
|
|
622
622
|
eventSource.onmessage = function(event) {
|
|
@@ -693,7 +693,7 @@ app.get('/', async (req, res) => {
|
|
|
693
693
|
padding: 10px;
|
|
694
694
|
}
|
|
695
695
|
</style>
|
|
696
|
-
<script type="module" src="https://unpkg.com/@hotwired/turbo@8.0.
|
|
696
|
+
<script type="module" src="https://unpkg.com/@hotwired/turbo@8.0.23/dist/turbo.es2017-esm.js"></script>
|
|
697
697
|
<script>
|
|
698
698
|
var eventSource = new EventSource('/sse');
|
|
699
699
|
eventSource.onmessage = function(event) {
|
|
@@ -720,4 +720,4 @@ app.listen(config.port);
|
|
|
720
720
|
```
|
|
721
721
|
## License
|
|
722
722
|
|
|
723
|
-
node-turbo is © 2024-
|
|
723
|
+
node-turbo is © 2024-2026 Walter Krivanek and released under the [MIT license](https://mit-license.org).
|
package/docs/API.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# node-turbo API documentation
|
|
2
2
|
|
|
3
|
-
Version 1.
|
|
3
|
+
Version 1.3.0
|
|
4
4
|
|
|
5
5
|
## Table of Contents
|
|
6
6
|
|
|
@@ -26,7 +26,7 @@ Version 1.2.6
|
|
|
26
26
|
- [turbostream.flush()](#turbostreamflush)
|
|
27
27
|
- [turbostream.custom(action, target, content)](#turbostreamcustomaction-target-content)
|
|
28
28
|
- [turbostream.customAll(action, targets, content)](#turbostreamcustomallaction-targets-content)
|
|
29
|
-
- [turbostream.
|
|
29
|
+
- [turbostream.createNodeStream(opts, streamOptions)](#turbostreamcreatenodestreamopts-streamoptions)
|
|
30
30
|
- [turbostream.append(targetOrAttributes, content)](#turbostreamappendtargetorattributes-content)
|
|
31
31
|
- [turbostream.appendAll(targetsOrAttributes, content)](#turbostreamappendalltargetsorattributes-content)
|
|
32
32
|
- [turbostream.prepend(targetOrAttributes, content)](#turbostreamprependtargetorattributes-content)
|
|
@@ -54,7 +54,7 @@ Version 1.2.6
|
|
|
54
54
|
- [turboelement.renderAttributesAsHtml()](#turboelementrenderattributesashtml)
|
|
55
55
|
- [turboelement.validate()](#turboelementvalidate)
|
|
56
56
|
- [turboelement.render()](#turboelementrender)
|
|
57
|
-
- [Class: TurboReadable](#class-turboreadable)
|
|
57
|
+
- [Class: TurboReadable (deprecated)](#class-turboreadable)
|
|
58
58
|
- [new TurboReadable(turboStream[, opts])](#new-turboreadableturbostream-opts)
|
|
59
59
|
- [turboreadable._turboStream](#turboreadable_turbostream)
|
|
60
60
|
- [turboreadable._boundPush](#turboreadable_boundpush)
|
|
@@ -92,7 +92,7 @@ Version 1.2.6
|
|
|
92
92
|
- [sseturbostream.eventName](#sseturbostreameventname)
|
|
93
93
|
- [sseturbostream.render()](#sseturbostreamrender)
|
|
94
94
|
- [sseturbostream.renderSseEvent(raw)](#sseturbostreamrendersseeventraw)
|
|
95
|
-
- [sseturbostream.
|
|
95
|
+
- [sseturbostream.createNodeStream()](#sseturbostreamcreatenodestream)
|
|
96
96
|
- [sseturbostream.event(eventName)](#sseturbostreameventeventname)
|
|
97
97
|
- [node-turbo/errors](#node-turboerrors)
|
|
98
98
|
- [Class: ValidationError](#class-validationerror)
|
|
@@ -271,16 +271,16 @@ Adds a Turbo Stream Element with a custom action, targeting multiple DOM element
|
|
|
271
271
|
|
|
272
272
|
Returns: {TurboStream} The instance for chaining.
|
|
273
273
|
|
|
274
|
-
#### turbostream.
|
|
274
|
+
#### turbostream.createNodeStream(opts, streamOptions)
|
|
275
275
|
|
|
276
276
|
- `opts` {Object<String, String>} The options for stream creation.
|
|
277
|
-
- `opts.continuous` {Boolean} If true, a
|
|
278
|
-
If false, a
|
|
277
|
+
- `opts.continuous` {Boolean} If true, a {node:stream~PassThrough} instance is returned.
|
|
278
|
+
If false, a {node:stream~Readable} created from the buffered items is returned.
|
|
279
279
|
- `streamOptions` {Object<String, String>} The options for the readable stream itself.
|
|
280
280
|
|
|
281
|
-
Creates a
|
|
281
|
+
Creates either a {node:stream~Readable} or {node:stream~PassThrough} stream instance.
|
|
282
282
|
|
|
283
|
-
Returns: {stream
|
|
283
|
+
Returns: {node:stream~Readable | {node:stream~PassThrough}} Either a readable stream or a TurboReadable instance.
|
|
284
284
|
|
|
285
285
|
#### turbostream.append(targetOrAttributes, content)
|
|
286
286
|
|
|
@@ -510,6 +510,9 @@ Render function to implement.
|
|
|
510
510
|
|
|
511
511
|
### Class: TurboReadable
|
|
512
512
|
|
|
513
|
+
> [!WARNING]
|
|
514
|
+
> Deprecated since v1.3.0!
|
|
515
|
+
|
|
513
516
|
```javascript
|
|
514
517
|
import { TurboReadable } from 'node-turbo';
|
|
515
518
|
```
|
|
@@ -688,7 +691,7 @@ Adds the element to the buffer, if config.buffer === true.
|
|
|
688
691
|
Fires the event 'element' with the added element.
|
|
689
692
|
> - clear()
|
|
690
693
|
Clears the buffer.
|
|
691
|
-
> -
|
|
694
|
+
> - createNodeStream(opts, streamOptions)
|
|
692
695
|
Creates a readable stream.
|
|
693
696
|
> - custom(action, target, content)
|
|
694
697
|
Adds a Turbo Stream Element with a custom action.
|
|
@@ -752,7 +755,7 @@ Adds the element to the buffer, if config.buffer === true.
|
|
|
752
755
|
Fires the event 'element' with the added element.
|
|
753
756
|
> - clear()
|
|
754
757
|
Clears the buffer.
|
|
755
|
-
> -
|
|
758
|
+
> - createNodeStream(opts, streamOptions)
|
|
756
759
|
Creates a readable stream.
|
|
757
760
|
> - custom(action, target, content)
|
|
758
761
|
Adds a Turbo Stream Element with a custom action.
|
|
@@ -851,7 +854,7 @@ Adds the element to the buffer, if config.buffer === true.
|
|
|
851
854
|
Fires the event 'element' with the added element.
|
|
852
855
|
> - clear()
|
|
853
856
|
Clears the buffer.
|
|
854
|
-
> -
|
|
857
|
+
> - createNodeStream(opts, streamOptions)
|
|
855
858
|
Creates a readable stream.
|
|
856
859
|
> - custom(action, target, content)
|
|
857
860
|
Adds a Turbo Stream Element with a custom action.
|
|
@@ -942,15 +945,15 @@ Returns: {String | null} The rendered SSE or null if there were no elements in t
|
|
|
942
945
|
|
|
943
946
|
- `raw` {String} The raw HTML string.
|
|
944
947
|
|
|
945
|
-
Takes
|
|
948
|
+
Takes an HTML fragment string and converts it to an SSE event message.
|
|
946
949
|
|
|
947
950
|
Returns: {String | null} The converted SSE event message or null if no string has been passed.
|
|
948
951
|
|
|
949
|
-
#### sseturbostream.
|
|
952
|
+
#### sseturbostream.createNodeStream()
|
|
950
953
|
|
|
951
|
-
Creates a {
|
|
954
|
+
Creates a {node:stream~PassThrough} instance, which passes Turbo Stream elements through as SSE messages.
|
|
952
955
|
|
|
953
|
-
Returns: {node:stream
|
|
956
|
+
Returns: {node:stream~PassThrough} The PassThrough stream instance.
|
|
954
957
|
|
|
955
958
|
#### sseturbostream.event(eventName)
|
|
956
959
|
|
|
@@ -1050,4 +1053,4 @@ Gets thrown when invalid attributes are discovered.
|
|
|
1050
1053
|
|
|
1051
1054
|
***
|
|
1052
1055
|
|
|
1053
|
-
node-turbo is © 2024-
|
|
1056
|
+
node-turbo is © 2024-2026 by Walter Krivanek and released under the [MIT license](https://mit-license.org).
|