Installations
npm install stronger-typed-streams
Developer Guide
Typescript
No
Module System
CommonJS
Node Version
12.19.0
NPM Version
6.14.8
Score
76.7
Supply Chain
99.5
Quality
75.5
Maintenance
100
Vulnerability
100
License
Releases
Unable to fetch releases
Contributors
Unable to fetch Contributors
Languages
TypeScript (100%)
Love this project? Help keep it running — sponsor us today! 🚀
Developer
forbesmyester
Download Statistics
Total Downloads
527,506
Last Day
87
Last Week
1,524
Last Month
6,463
Last Year
114,815
GitHub Statistics
10 Stars
5 Commits
3 Forks
4 Watchers
1 Branches
1 Contributors
Updated on May 28, 2024
Bundle Size
1.54 kB
Minified
531.00 B
Minified + Gzipped
Package Meta Information
Latest Version
0.2.0
Package Id
stronger-typed-streams@0.2.0
Size
7.61 kB
NPM Version
6.14.8
Node Version
12.19.0
Published on
Oct 31, 2020
Total Downloads
Cumulative downloads
Total Downloads
527,506
Last Day
-32.6%
87
Compared to previous day
Last Week
-8.5%
1,524
Compared to previous week
Last Month
33.1%
6,463
Compared to previous month
Last Year
-48.3%
114,815
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
Dev Dependencies
4
stronger-typed-streams
While I am a fan of RxJS there are still advantages to using just plain NodeJS Streams, the main one for me being that back-pressure just works.
The TypeScript bindings for NodeJS Streams are perfectly adequate themselves but I felt that the typings could also ensure that the Readable is outputting to a compatible Writable or Transform.
This mini project, which really is pretty much just subclasses of the NodeJS Streams classes aims to address that deficiency. This means that if you have a model of the following:
`Farm` -> `Bakery` -> `Shop`
Where Flour
is the input to the Bakery, which converts it into Bread
for selling in the shop. Going from Farm
to Shop
directly is not allowed as customers of the shop wish to buy bread not flour.
In code the only valid way to join these should be:
let farm = new Farm({highWaterMark: 1});
let bakery = new Bakery({highWaterMark: 1});
let shop = new Shop({highWaterMark: 1}, stock);
let supplyChain = farm.pipe(bakery).pipe(shop);
But the core NodeJS TypeScript bindings would allow going directly from farm
to shop
.
Installation
npm install --save stronger-typed-streams
Usage
Create a subclass of to plant and sow grain:
class Farm extends Readable<Flour> {
private i: number = 0;
constructor(opts = {}) {
super(Object.assign({objectMode: true}, opts));
}
_read() {
let v = this.i++ < 8 ? new Flour(1) : null;
process.nextTick(() => {
this.push(v);
});
}
}
And a class that converts Flour to Bread:
class Bakery extends Transform<Flour, Bread> {
private flour: Flour[] = [];
constructor(opts = {}) {
super(Object.assign({objectMode: true}, opts));
}
_flush(cb) {
process.nextTick(() => {
if (this.flour.length) {
this.push(new Bread(this.flour));
}
this.flour = [];
cb();
});
}
_transform(flour: Flour, encoding, cb) {
process.nextTick(() => {
this.flour.push(flour);
if (this.flour.length >= 3) {
this._flush(cb);
return;
}
cb();
});
}
}
And something to sell the finished product to the consumers:
class Shop extends Writable<Bread> {
constructor(opts = {}, out) {
super(Object.assign({objectMode: true}, opts));
}
_write(bread: Bread, encoding, cb) {
process.nextTick(() => {
console.log("Bread for sale!);
cb();
});
}
}
Now create a supply chain by joining instances of all the classes together:
let farm = new Farm({highWaterMark: 1});
let bakery = new Bakery({highWaterMark: 1});
let shop = new Shop({highWaterMark: 1}, stock);
let supplyChain = farm.pipe(bakery).pipe(shop);
If you tried to attach a Farm directly to a Shop the TypeScript compiler would tell you:
TS2345: Argument of type 'Shop' is not assignable to parameter of type 'Writable<Flour>'.
Which is absolutely correct and allows you to catch errors at compile time instead of runtime, perhaps in the wild.
There is also a Duplex implementation, but this is only tested in Node versions >= 8 because in the tests I an API method that is only available in Node 8+.

No vulnerabilities found.
Reason
no binaries found in the repo
Reason
0 existing vulnerabilities detected
Reason
Found 0/5 approved changesets -- score normalized to 0
Reason
no SAST tool detected
Details
- Warn: no pull requests merged into dev branch
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
- Warn: no security policy file detected
- Warn: no security file to analyze
- Warn: no security file to analyze
- Warn: no security file to analyze
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
license file not detected
Details
- Warn: project does not have a license file
Reason
branch protection not enabled on development/release branches
Details
- Warn: branch protection not enabled for branch 'master'
Score
2.6
/10
Last Scanned on 2025-02-10
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More