mirror of
https://github.com/hanzoai/firebase-js-sdk.git
synced 2026-09-24 16:59:10 +00:00
The new .stream() API allows the client to consume streaming responses from the WIP streaming callable functions in Firebase Functions Node.js SDK.
When client makes a request to the callable function w/ header Accept: text/event-stream, the callable function responds with response chunks in Server-Sent Event format.
The sdk changes here abstracts over the wire-protocol by parsing the response chunks and returning an instance of a AsyncIterable to consume to data:
import { getFunctions, httpsCallable } from "firebase/functions";
const functions = getFunctions();
const generateText = httpsCallable(functions, 'generateText');
const resp = await generateText.stream(
{ text: 'What is your favorite Firebase service and why?' },
{ signal: AbortSignal.timeout(60_000) },
);
try {
for await (const message of resp.stream) {
console.log(message); // prints "foo", "bar"
}
console.log(await resp.data) // prints "foo bar"
} catch (e) {
// FirebaseError(code='cancelled', message='Request was cancelled.');
console.error(e)
}
2.6 KiB
2.6 KiB
API Report File for "@firebase/functions"
Do not edit this file. It is a report generated by API Extractor.
import { FirebaseApp } from '@firebase/app';
import { FirebaseError } from '@firebase/util';
// @public
export function connectFunctionsEmulator(functionsInstance: Functions, host: string, port: number): void;
// @public
export interface Functions {
app: FirebaseApp;
customDomain: string | null;
region: string;
}
// @public
export class FunctionsError extends FirebaseError {
constructor(
code: FunctionsErrorCodeCore, message?: string,
details?: unknown);
readonly details?: unknown;
}
// @public
export type FunctionsErrorCode = `functions/${FunctionsErrorCodeCore}`;
// @public
export type FunctionsErrorCodeCore = 'ok' | 'cancelled' | 'unknown' | 'invalid-argument' | 'deadline-exceeded' | 'not-found' | 'already-exists' | 'permission-denied' | 'resource-exhausted' | 'failed-precondition' | 'aborted' | 'out-of-range' | 'unimplemented' | 'internal' | 'unavailable' | 'data-loss' | 'unauthenticated';
// @public
export function getFunctions(app?: FirebaseApp, regionOrCustomDomain?: string): Functions;
// @public
export interface HttpsCallable<RequestData = unknown, ResponseData = unknown, StreamData = unknown> {
// (undocumented)
(data?: RequestData | null): Promise<HttpsCallableResult<ResponseData>>;
// (undocumented)
stream: (data?: RequestData | null, options?: HttpsCallableStreamOptions) => Promise<HttpsCallableStreamResult<ResponseData, StreamData>>;
}
// @public
export function httpsCallable<RequestData = unknown, ResponseData = unknown, StreamData = unknown>(functionsInstance: Functions, name: string, options?: HttpsCallableOptions): HttpsCallable<RequestData, ResponseData, StreamData>;
// @public
export function httpsCallableFromURL<RequestData = unknown, ResponseData = unknown, StreamData = unknown>(functionsInstance: Functions, url: string, options?: HttpsCallableOptions): HttpsCallable<RequestData, ResponseData, StreamData>;
// @public
export interface HttpsCallableOptions {
limitedUseAppCheckTokens?: boolean;
timeout?: number;
}
// @public
export interface HttpsCallableResult<ResponseData = unknown> {
readonly data: ResponseData;
}
// @public
export interface HttpsCallableStreamOptions {
limitedUseAppCheckTokens?: boolean;
signal?: AbortSignal;
}
// @public
export interface HttpsCallableStreamResult<ResponseData = unknown, StreamData = unknown> {
// (undocumented)
readonly data: Promise<ResponseData>;
// (undocumented)
readonly stream: AsyncIterable<StreamData>;
}