Skip to content

Commit

Permalink
Merge branch 'master' into inlined.onCallGenkit
Browse files Browse the repository at this point in the history
  • Loading branch information
inlined authored Jan 23, 2025
2 parents 57a0d29 + 01c1198 commit 0847de6
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
12 changes: 6 additions & 6 deletions spec/common/providers/https.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -778,7 +778,7 @@ describe("onCallHandler", () => {

const resp = await runHandler(fn, mockReq as any);
const data = [`data: {"message":"hello"}`, `data: {"result":"world"}`];
expect(resp.body).to.equal([...data, ""].join("\n"));
expect(resp.body).to.equal([...data, ""].join("\n\n"));
});

it("returns error in SSE format", async () => {
Expand All @@ -800,7 +800,7 @@ describe("onCallHandler", () => {

const resp = await runHandler(fn, mockReq as any);
const data = [`data: {"error":{"message":"INTERNAL","status":"INTERNAL"}}`];
expect(resp.body).to.equal([...data, ""].join("\n"));
expect(resp.body).to.equal([...data, ""].join("\n\n"));
});

it("always returns error for v1 callables", async () => {
Expand Down Expand Up @@ -851,7 +851,7 @@ describe("onCallHandler", () => {

const resp = await runHandler(fn, mockReq);

expect(resp.body).to.equal(`data: {"message":"initial message"}\n`);
expect(resp.body).to.equal(`data: {"message":"initial message"}\n\n`);
});

describe("Heartbeats", () => {
Expand Down Expand Up @@ -890,7 +890,7 @@ describe("onCallHandler", () => {
await clock.tickAsync(11_000);
const resp = await handlerPromise;
const data = [": ping", ": ping", `data: {"result":"done"}`];
expect(resp.body).to.equal([...data, ""].join("\n"));
expect(resp.body).to.equal([...data, ""].join("\n\n"));
});

it("doesn't send heartbeat messages if user writes data", async () => {
Expand Down Expand Up @@ -919,7 +919,7 @@ describe("onCallHandler", () => {
await clock.tickAsync(10_000);
const resp = await handlerPromise;
const data = [`data: {"message":"hello"}`, `data: {"result":"done"}`];
expect(resp.body).to.equal([...data, ""].join("\n"));
expect(resp.body).to.equal([...data, ""].join("\n\n"));
});

it("respects null heartbeatSeconds option", async () => {
Expand All @@ -945,7 +945,7 @@ describe("onCallHandler", () => {
const handlerPromise = runHandler(fn, mockReq as any);
await clock.tickAsync(31_000);
const resp = await handlerPromise;
expect(resp.body).to.equal('data: {"result":"done"}\n');
expect(resp.body).to.equal('data: {"result":"done"}\n\n');
});
});
});
Expand Down
16 changes: 8 additions & 8 deletions src/common/providers/https.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ export interface CallableRequest<T = any> {
data: T;

/**
* The result of decoding and verifying a Firebase AppCheck token.
* The result of decoding and verifying a Firebase App Check token.
*/
app?: AppCheckData;

Expand All @@ -145,15 +145,15 @@ export interface CallableRequest<T = any> {
/**
* Whether this is a streaming request.
* Code can be optimized by not trying to generate a stream of chunks to
* call response.sendChunk on if request.acceptsStreaming is false.
* It is always safe, however, to call response.sendChunk as this will
* noop if acceptsStreaming is false.
* call `response.sendChunk` if `request.acceptsStreaming` is false.
* It is always safe, however, to call `response.sendChunk` as this will
* noop if `acceptsStreaming` is false.
*/
acceptsStreaming: boolean;
}

/**
* CallableProxyResponse allows streaming response chunks and listening to signals
* `CallableProxyResponse` allows streaming response chunks and listening to signals
* triggered in events such as a disconnect.
*/
export interface CallableResponse<T = unknown> {
Expand All @@ -166,7 +166,7 @@ export interface CallableResponse<T = unknown> {
sendChunk: (chunk: T) => Promise<boolean>;

/**
* An AbortSignal that is triggered when the client disconnects or the
* An `AbortSignal` that is triggered when the client disconnects or the
* request is terminated prematurely.
*/
signal: AbortSignal;
Expand Down Expand Up @@ -738,7 +738,7 @@ export function onCallHandler<Req = any, Res = any, Stream = unknown>(
}

function encodeSSE(data: unknown): string {
return `data: ${JSON.stringify(data)}\n`;
return `data: ${JSON.stringify(data)}\n\n`;
}

/** @internal */
Expand Down Expand Up @@ -766,7 +766,7 @@ function wrapOnCallHandler<Req = any, Res = any, Stream = unknown>(
if (!abortController.signal.aborted) {
heartbeatInterval = setTimeout(() => {
if (!abortController.signal.aborted) {
res.write(": ping\n");
res.write(": ping\n\n");
scheduleHeartbeat();
}
}, heartbeatSeconds * 1000);
Expand Down

0 comments on commit 0847de6

Please sign in to comment.