fix(ts): Fixed formatting issues in SmartDuplex class
This commit is contained in:
parent
c8465b82be
commit
a55b2548d7
35
changelog.md
Normal file
35
changelog.md
Normal file
@ -0,0 +1,35 @@
|
||||
# Changelog
|
||||
|
||||
## 2024-10-13 - 3.0.45 - fix(ts)
|
||||
Fixed formatting issues in SmartDuplex class
|
||||
|
||||
- Resolved inconsistent spacing in SmartDuplex class methods and constructor.
|
||||
- Ensured consistent formatting in the getWebStreams method.
|
||||
|
||||
## 2024-06-02 - 3.0.39 - smartduplex
|
||||
Add .getWebStreams method
|
||||
|
||||
- Introduced a new `.getWebStreams` method in the smartduplex module, providing compatibility with the web streams API.
|
||||
|
||||
## 2024-03-16 - 3.0.34 - configuration
|
||||
Update project configuration files
|
||||
|
||||
- Updated `tsconfig` for optimization.
|
||||
- Modified `npmextra.json` to set the `githost` attribute.
|
||||
|
||||
## 2023-11-03 - 3.0.0 to 3.0.8 - core
|
||||
Transition to major version 3.x
|
||||
|
||||
- Implemented breaking changes in the core system for better performance and feature set.
|
||||
- Continuous core updates to improve stability and performance across minor version increments.
|
||||
|
||||
## 2023-11-02 - 2.0.4 to 2.0.8 - core
|
||||
Core updates and a major fix
|
||||
|
||||
- Implemented core updates addressing minor bugs and enhancements.
|
||||
- A significant breaking change update transitioning from 2.0.x to 3.0.0.
|
||||
|
||||
## 2022-03-31 - 2.0.0 - core
|
||||
Major esm transition
|
||||
|
||||
- Implemented a breaking change by switching the core to ESM (ECMAScript Module) format for modernized module handling.
|
@ -1,8 +1,8 @@
|
||||
/**
|
||||
* autocreated commitinfo by @pushrocks/commitinfo
|
||||
* autocreated commitinfo by @push.rocks/commitinfo
|
||||
*/
|
||||
export const commitinfo = {
|
||||
name: '@push.rocks/smartstream',
|
||||
version: '3.0.44',
|
||||
version: '3.0.45',
|
||||
description: 'A library to simplify the creation and manipulation of Node.js streams, providing utilities for handling transform, duplex, and readable/writable streams effectively in TypeScript.'
|
||||
}
|
||||
|
@ -34,9 +34,9 @@ export interface ISmartDuplexOptions<TInput, TOutput> extends DuplexOptions {
|
||||
* it can push or return chunks (but does not have to) to be written to the readable side of the stream
|
||||
*/
|
||||
writeFunction?: IStreamWriteFunction<TInput, TOutput>;
|
||||
|
||||
|
||||
/**
|
||||
* a final function that is run at the end of the stream
|
||||
* a final function that is run at the end of the stream
|
||||
*/
|
||||
finalFunction?: IStreamFinalFunction<TOutput>;
|
||||
}
|
||||
@ -53,21 +53,29 @@ export class SmartDuplex<TInput = any, TOutput = any> extends Duplex {
|
||||
}
|
||||
|
||||
// INSTANCE
|
||||
private backpressuredArray: plugins.lik.BackpressuredArray<TOutput>;
|
||||
private backpressuredArray: plugins.lik.BackpressuredArray<TOutput>; // an array that only takes a defined amount of items
|
||||
public options: ISmartDuplexOptions<TInput, TOutput>;
|
||||
private observableSubscription?: plugins.smartrx.rxjs.Subscription;
|
||||
private debugLog(messageArg: string) {
|
||||
// optional debug log
|
||||
if (this.options.debug) {
|
||||
console.log(messageArg);
|
||||
}
|
||||
}
|
||||
|
||||
constructor(optionsArg?: ISmartDuplexOptions<TInput, TOutput>) {
|
||||
super(Object.assign({
|
||||
highWaterMark: 1,
|
||||
}, optionsArg));
|
||||
super(
|
||||
Object.assign(
|
||||
{
|
||||
highWaterMark: 1,
|
||||
},
|
||||
optionsArg
|
||||
)
|
||||
);
|
||||
this.options = optionsArg;
|
||||
this.backpressuredArray = new plugins.lik.BackpressuredArray<TOutput>(this.options.highWaterMark || 1)
|
||||
this.backpressuredArray = new plugins.lik.BackpressuredArray<TOutput>(
|
||||
this.options.highWaterMark || 1
|
||||
);
|
||||
}
|
||||
|
||||
public async _read(size: number): Promise<void> {
|
||||
@ -77,14 +85,14 @@ export class SmartDuplex<TInput = any, TOutput = any> extends Duplex {
|
||||
if (this.options.readFunction) {
|
||||
await this.options.readFunction();
|
||||
}
|
||||
let canPushMore = true;
|
||||
while(this.backpressuredArray.data.length > 0 && canPushMore) {
|
||||
let canPushMore = true;
|
||||
while (this.backpressuredArray.data.length > 0 && canPushMore) {
|
||||
const nextChunk = this.backpressuredArray.shift();
|
||||
canPushMore = this.push(nextChunk);
|
||||
}
|
||||
}
|
||||
|
||||
public async backpressuredPush (pushArg: TOutput) {
|
||||
public async backpressuredPush(pushArg: TOutput) {
|
||||
const canPushMore = this.backpressuredArray.push(pushArg);
|
||||
if (!canPushMore) {
|
||||
this.debugLog(`${this.options.name}: cannot push more`);
|
||||
@ -92,7 +100,7 @@ export class SmartDuplex<TInput = any, TOutput = any> extends Duplex {
|
||||
this.debugLog(`${this.options.name}: can push more again`);
|
||||
}
|
||||
return canPushMore;
|
||||
};
|
||||
}
|
||||
|
||||
private asyncWritePromiseObjectmap = new plugins.lik.ObjectMap<Promise<any>>();
|
||||
// Ensure the _write method types the chunk as TInput and encodes TOutput
|
||||
@ -110,7 +118,7 @@ export class SmartDuplex<TInput = any, TOutput = any> extends Duplex {
|
||||
},
|
||||
push: async (pushArg: TOutput) => {
|
||||
return await this.backpressuredPush(pushArg);
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
try {
|
||||
@ -158,7 +166,7 @@ export class SmartDuplex<TInput = any, TOutput = any> extends Duplex {
|
||||
callback();
|
||||
}
|
||||
|
||||
public async getWebStreams(): Promise<{ readable: ReadableStream, writable: WritableStream }> {
|
||||
public async getWebStreams(): Promise<{ readable: ReadableStream; writable: WritableStream }> {
|
||||
const duplex = this;
|
||||
const readable = new ReadableStream({
|
||||
start(controller) {
|
||||
@ -168,16 +176,16 @@ export class SmartDuplex<TInput = any, TOutput = any> extends Duplex {
|
||||
controller.enqueue(chunk);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
duplex.on('end', () => {
|
||||
controller.close();
|
||||
});
|
||||
},
|
||||
cancel(reason) {
|
||||
duplex.destroy(new Error(reason));
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
const writable = new WritableStream({
|
||||
write(chunk) {
|
||||
return new Promise<void>((resolve, reject) => {
|
||||
@ -188,7 +196,7 @@ export class SmartDuplex<TInput = any, TOutput = any> extends Duplex {
|
||||
resolve();
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
if (isBackpressured) {
|
||||
duplex.once('drain', resolve);
|
||||
}
|
||||
@ -201,9 +209,9 @@ export class SmartDuplex<TInput = any, TOutput = any> extends Duplex {
|
||||
},
|
||||
abort(reason) {
|
||||
duplex.destroy(new Error(reason));
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
return { readable, writable };
|
||||
}
|
||||
}
|
||||
|
@ -1,8 +1,8 @@
|
||||
/**
|
||||
* autocreated commitinfo by @pushrocks/commitinfo
|
||||
* autocreated commitinfo by @push.rocks/commitinfo
|
||||
*/
|
||||
export const commitinfo = {
|
||||
name: '@push.rocks/smartstream',
|
||||
version: '3.0.44',
|
||||
version: '3.0.45',
|
||||
description: 'A library to simplify the creation and manipulation of Node.js streams, providing utilities for handling transform, duplex, and readable/writable streams effectively in TypeScript.'
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user