feat(response): Add streamNode() method for Node.js stream support; update tests
This commit is contained in:
27
test/test.streamnode.ts
Normal file
27
test/test.streamnode.ts
Normal file
@@ -0,0 +1,27 @@
|
||||
import { tap, expect } from '@git.zone/tstest/tapbundle';
|
||||
import { SmartRequest } from '../ts/index.js';
|
||||
|
||||
tap.test('should have streamNode() method available', async () => {
|
||||
const response = await SmartRequest.create()
|
||||
.url('https://httpbin.org/get')
|
||||
.get();
|
||||
|
||||
// Verify streamNode() method exists
|
||||
expect(response.streamNode).toBeDefined();
|
||||
expect(typeof response.streamNode).toEqual('function');
|
||||
|
||||
// In Node.js, it should return a stream
|
||||
const nodeStream = response.streamNode();
|
||||
expect(nodeStream).toBeDefined();
|
||||
|
||||
// Verify it's a Node.js readable stream
|
||||
expect(typeof nodeStream.pipe).toEqual('function');
|
||||
expect(typeof nodeStream.on).toEqual('function');
|
||||
|
||||
// Consume the stream to avoid hanging
|
||||
nodeStream.resume();
|
||||
});
|
||||
|
||||
|
||||
|
||||
export default tap.start();
|
@@ -42,4 +42,9 @@ export abstract class CoreResponse<T = any> implements types.ICoreResponse<T> {
|
||||
* Get response as a web-style ReadableStream
|
||||
*/
|
||||
abstract stream(): ReadableStream<Uint8Array> | null;
|
||||
|
||||
/**
|
||||
* Get response as a Node.js stream (throws in browser)
|
||||
*/
|
||||
abstract streamNode(): NodeJS.ReadableStream | never;
|
||||
}
|
||||
|
@@ -86,4 +86,5 @@ export interface ICoreResponse<T = any> {
|
||||
text(): Promise<string>;
|
||||
arrayBuffer(): Promise<ArrayBuffer>;
|
||||
stream(): ReadableStream<Uint8Array> | null; // Always returns web-style stream
|
||||
streamNode(): NodeJS.ReadableStream | never; // Returns Node.js stream or throws in browser
|
||||
}
|
||||
|
@@ -7,9 +7,6 @@ export * from '../core_base/types.js';
|
||||
* Fetch-specific response extensions
|
||||
*/
|
||||
export interface IFetchResponse<T = any> extends baseTypes.ICoreResponse<T> {
|
||||
// Node.js stream method that throws in browser
|
||||
streamNode(): never;
|
||||
|
||||
// Access to raw Response object
|
||||
raw(): Response;
|
||||
}
|
||||
|
@@ -16,9 +16,6 @@ export interface IExtendedIncomingMessage<T = any>
|
||||
* Node.js specific response extensions
|
||||
*/
|
||||
export interface INodeResponse<T = any> extends baseTypes.ICoreResponse<T> {
|
||||
// Node.js specific methods
|
||||
streamNode(): NodeJS.ReadableStream; // Returns Node.js style stream
|
||||
|
||||
// Legacy compatibility
|
||||
raw(): plugins.http.IncomingMessage;
|
||||
}
|
||||
|
Reference in New Issue
Block a user