Skip to content

Feature: implement streaming api reading in client#45

Merged
krishan711 merged 5 commits into
mainfrom
streamin
Mar 5, 2026
Merged

Feature: implement streaming api reading in client#45
krishan711 merged 5 commits into
mainfrom
streamin

Conversation

@krishan711
Copy link
Copy Markdown
Contributor

Description

Copilot AI review requested due to automatic review settings March 5, 2026 16:29
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds client-side support for consuming line-delimited JSON streaming responses end-to-end (ServiceClient → Requester → fetch stream reader).

Changes:

  • Replaces constructor-based response parsing with a ResponseDataClass.fromObject static factory contract.
  • Adds streaming request APIs in ServiceClient and Requester.
  • Implements streaming fetch handling that reads newline-delimited JSON items and invokes a callback per parsed item.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.

File Description
src/services/serviceClient.ts Introduces a static factory type for response parsing and adds a streaming request wrapper.
src/requester/requester.ts Adds streaming request plumbing and implements streaming fetch + NDJSON parsing.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/services/serviceClient.ts Outdated
Comment on lines +223 to +229
.catch((error): void => {
throw new KibaException(`The request was made but no response was received: [${error.code}] "${error.message}"`);
})
.then(async (response: Response | void): Promise<KibaResponse> => {
if (!response) {
throw new KibaException('The request was made but no response was received.');
}
Copy link

Copilot AI Mar 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Chaining .catch(...).then(...) forces the then handler to accept Response | void, which complicates typing and requires an additional !response guard. Consider rewriting this section with try/catch around an awaited fetch(...) so response stays a Response, simplifying control flow and types.

Suggested change
.catch((error): void => {
throw new KibaException(`The request was made but no response was received: [${error.code}] "${error.message}"`);
})
.then(async (response: Response | void): Promise<KibaResponse> => {
if (!response) {
throw new KibaException('The request was made but no response was received.');
}
.catch((error): never => {
throw new KibaException(`The request was made but no response was received: [${error.code}] "${error.message}"`);
})
.then(async (response: Response): Promise<KibaResponse> => {

Copilot uses AI. Check for mistakes.
Comment thread src/requester/requester.ts Outdated
Comment on lines +186 to +192
private makeStreamingFetchRequest = async <StreamItemType>(
request: KibaRequest,
parseItem: (obj: Record<string, unknown>) => StreamItemType,
onItem: (item: StreamItemType) => void,
): Promise<KibaResponse> => {
const url = new URL(request.url);
const headers = new Headers({ ...this.headers, ...(request.headers || {}) });
Copy link

Copilot AI Mar 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

makeStreamingFetchRequest appears to duplicate substantial logic from the existing non-streaming fetch path (URL/header construction, method/body handling, status error handling). This duplication increases the risk of behavioral drift (e.g., a bugfix applied to one path but not the other). Consider extracting shared helpers (e.g., building fetchConfig/URL/search params and mapping error responses into KibaException) used by both streaming and non-streaming implementations.

Copilot uses AI. Check for mistakes.
Comment on lines +294 to +295
const response = await (request.timeoutSeconds ? timeoutPromise(request.timeoutSeconds, fetchOperation) : fetchOperation);
return response;
Copy link

Copilot AI Mar 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The timeout mechanism (timeoutPromise) likely rejects without aborting the underlying fetch/stream read, meaning network and parsing work can continue in the background after a timeout. Consider integrating AbortController so timeouts actively cancel the in-flight fetch and release resources for streaming requests.

Copilot uses AI. Check for mistakes.
@krishan711 krishan711 merged commit 6e18ce2 into main Mar 5, 2026
3 checks passed
@krishan711 krishan711 deleted the streamin branch March 5, 2026 17:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants