Feat/parse invitation

This commit is contained in:
Kuldeep
2026-10-05 12:59:22 +00:00
parent d907946804
commit 0c95b9b2b1
19 changed files with 1008 additions and 386 deletions
+10 -10
View File
@@ -79,7 +79,7 @@ export class SSEEventParser {
* @returns Zero or more complete parsed SSE events from this chunk.
*/
public parseEvents(chunk: Uint8Array): SSEvent[] {
const lines = this.getBufferedLines(chunk);
const lines = this.#getBufferedLines(chunk);
const eventLines = lines.slice(0, -1);
@@ -91,7 +91,7 @@ export class SSEEventParser {
// A blank line indicates the end of an event. If we have received data, we can complete the event
if (line === '') {
if (event.data !== undefined) {
events.push(this.completeEvent(event));
events.push(this.#completeEvent(event));
event = {};
processedLineCount = index + 1;
}
@@ -99,10 +99,10 @@ export class SSEEventParser {
continue;
}
this.parseLine(line, event);
this.#parseLine(line, event);
}
this.storeRemainingLines(lines, processedLineCount);
this.#storeRemainingLines(lines, processedLineCount);
return events;
}
@@ -114,7 +114,7 @@ export class SSEEventParser {
* Accepts `\r\n`, `\r`, and `\n` line endings so events parse correctly
* regardless of server or platform conventions.
*/
private getBufferedLines(chunk: Uint8Array): string[] {
#getBufferedLines(chunk: Uint8Array): string[] {
this.#messageBuffer += this.#textDecoder.decode(chunk, { stream: true });
return this.#messageBuffer.split(SSE_LINE_ENDINGS);
@@ -126,7 +126,7 @@ export class SSEEventParser {
* Lines without a colon are ignored. A single optional space after the colon
* is stripped from the field value, per the SSE spec.
*/
private parseLine(line: string, event: Partial<SSEvent>): void {
#parseLine(line: string, event: Partial<SSEvent>): void {
const colonIndex = line.indexOf(':');
if (colonIndex === -1) return;
@@ -150,7 +150,7 @@ export class SSEEventParser {
return;
case 'retry':
this.parseRetry(value, event);
this.#parseRetry(value, event);
return;
}
@@ -161,7 +161,7 @@ export class SSEEventParser {
*
* Non-numeric values are ignored rather than failing the parse.
*/
private parseRetry(value: string, event: Partial<SSEvent>): void {
#parseRetry(value: string, event: Partial<SSEvent>): void {
const retry = parseInt(value, 10);
if (!isNaN(retry)) {
@@ -175,7 +175,7 @@ export class SSEEventParser {
* Trims a trailing newline from multi-line `data` values so callers receive
* the payload without an extra line break at the end.
*/
private completeEvent(event: Partial<SSEvent>): SSEvent {
#completeEvent(event: Partial<SSEvent>): SSEvent {
return {
...event,
data: event.data?.replace(SSE_TRAILING_NEWLINE_REGEX, ''),
@@ -188,7 +188,7 @@ export class SSEEventParser {
* Only lines that were fully processed (through a completed event boundary)
* are discarded; the remainder is re-encoded into {@link messageBuffer}.
*/
private storeRemainingLines(lines: string[], processedLineCount: number): void {
#storeRemainingLines(lines: string[], processedLineCount: number): void {
this.#messageBuffer = lines.slice(processedLineCount).join(NEW_LINE);
}
}