Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Support streaming streaming responses for callable functions. #8609

Merged
merged 37 commits into from
Dec 4, 2024
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
48eca40
Support streaming streaming responses for callable functions.
taeold Oct 25, 2024
21db516
Merge branch 'main' into dl-fn-streaming
taeold Oct 25, 2024
d28863c
Support AbortSignal
taeold Oct 25, 2024
a02b25f
Update API reports
taeold Oct 25, 2024
ab99970
Re-introduce fetchImpl.
taeold Oct 27, 2024
8ec2787
Merge branch 'dl-fn-streaming' of https://github.com/firebase/firebas…
taeold Oct 27, 2024
4aee03e
Add more tests.
taeold Oct 27, 2024
fdc70d8
Update API reports
taeold Oct 27, 2024
55d9266
Add comment.
taeold Oct 27, 2024
9a430cc
Merge branch 'dl-fn-streaming' of https://github.com/firebase/firebas…
taeold Oct 28, 2024
785e906
Allow reading multiple data chunks from single read() chunk.
taeold Nov 6, 2024
861edce
Fix lint errors.
taeold Nov 6, 2024
4b188d0
Don't swallow errors.
taeold Nov 6, 2024
39c44d5
Fix linter issues.
taeold Nov 6, 2024
1c1f533
Update API reports
taeold Nov 7, 2024
b481220
Merge remote-tracking branch 'origin/main' into dl-fn-streaming
taeold Nov 9, 2024
9f4c973
Merge branch 'dl-fn-streaming' of https://github.com/firebase/firebas…
taeold Nov 9, 2024
ebd74cb
Add changeset.
taeold Nov 9, 2024
cf56623
Update code to use pump() patter.
taeold Nov 22, 2024
cfbcd46
Refactor implementation for better readability.
taeold Nov 22, 2024
1801c53
Nits.
taeold Nov 22, 2024
bf4f5e9
More nits.
taeold Nov 22, 2024
c6ef6a0
Merge branch 'main' into dl-fn-streaming
taeold Nov 22, 2024
31998c2
Revert changes to the functions-type package.
taeold Nov 22, 2024
72e87b4
Remove duplicate entry in the package script for functions.
taeold Nov 22, 2024
d8ebbb8
Run formatter.
taeold Nov 22, 2024
fd2cb15
Generate updated docs.
taeold Nov 22, 2024
9a85bb2
Refactor code to make auth headers.
taeold Nov 23, 2024
f581b61
Fix misc.
taeold Nov 23, 2024
b9a42e5
Update API reports
taeold Nov 23, 2024
d0cc907
Revert uninteded changes to untouched test case.
taeold Dec 3, 2024
f773110
Add docstring comments to utility functions.
taeold Dec 3, 2024
aa993f0
Merge branch 'dl-fn-streaming' of https://github.com/firebase/firebas…
taeold Dec 3, 2024
9ae31c0
Correct documentation on AbortSignal.
taeold Dec 3, 2024
327c1cb
Run formatter
taeold Dec 3, 2024
5fb40f1
Update docs.
taeold Dec 3, 2024
9ea463d
Update docs per comments.
taeold Dec 3, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 19 additions & 3 deletions common/api-review/functions.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,16 @@ export type FunctionsErrorCodeCore = 'ok' | 'cancelled' | 'unknown' | 'invalid-a
export function getFunctions(app?: FirebaseApp, regionOrCustomDomain?: string): Functions;

// @public
export type HttpsCallable<RequestData = unknown, ResponseData = unknown> = (data?: RequestData | null) => Promise<HttpsCallableResult<ResponseData>>;
export type HttpsCallable<RequestData = unknown, ResponseData = unknown, StreamData = unknown> = {
(data?: RequestData | null): Promise<HttpsCallableResult<ResponseData>>;
stream: (data?: RequestData | null, options?: HttpsCallableStreamOptions) => Promise<HttpsCallableStreamResult<ResponseData, StreamData>>;
};

// @public
export function httpsCallable<RequestData = unknown, ResponseData = unknown>(functionsInstance: Functions, name: string, options?: HttpsCallableOptions): HttpsCallable<RequestData, ResponseData>;
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>(functionsInstance: Functions, url: string, options?: HttpsCallableOptions): HttpsCallable<RequestData, ResponseData>;
export function httpsCallableFromURL<RequestData = unknown, ResponseData = unknown, StreamData = unknown>(functionsInstance: Functions, url: string, options?: HttpsCallableOptions): HttpsCallable<RequestData, ResponseData, StreamData>;

// @public
export interface HttpsCallableOptions {
Expand All @@ -54,5 +57,18 @@ export interface HttpsCallableResult<ResponseData = unknown> {
readonly data: ResponseData;
}

// @public
export interface HttpsCallableStreamOptions {
signal?: AbortSignal;
}

// @public
export interface HttpsCallableStreamResult<ResponseData = unknown, StreamData = unknown> {
// (undocumented)
readonly data: Promise<ResponseData>;
// (undocumented)
readonly stream: AsyncIterable<StreamData>;
}


```
9 changes: 9 additions & 0 deletions packages/functions-types/index.d.ts
taeold marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,21 @@ export interface HttpsCallableResult {
readonly data: any;
}

/**
* An HttpsCallableStreamResult wraps a single streaming result from a function call.
*/
export interface HttpsCallableStreamResult {
readonly data: Promise<any>;
readonly stream: AsyncIterable<any>;
}

/**
* An HttpsCallable is a reference to a "callable" http trigger in
* Google Cloud Functions.
*/
export interface HttpsCallable {
(data?: {} | null): Promise<HttpsCallableResult>;
stream(data?: {} | null): Promise<HttpsCallableStreamResult>;
}

/**
Expand Down
3 changes: 2 additions & 1 deletion packages/functions/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@
"test:browser": "karma start",
"test:browser:debug": "karma start --browsers=Chrome --auto-watch",
"test:node": "TS_NODE_COMPILER_OPTIONS='{\"module\":\"commonjs\"}' nyc --reporter lcovonly -- mocha 'src/{,!(browser)/**/}*.test.ts' --file src/index.ts --config ../../config/mocharc.node.js",
"test:emulator": "env FIREBASE_FUNCTIONS_EMULATOR_ORIGIN=http://localhost:5005 run-p --npm-path npm test:node",
"test:emulator": "env FIREBASE_FUNCTIONS_EMULATOR_ORIGIN=http://127.0.0.1:5005 run-p test:node",
"test:emulator": "env FIREBASE_FUNCTIONS_EMULATOR_ORIGIN=http://127.0.0.1:5005 run-p --npm-path npm test:node",
Copy link
Contributor

Choose a reason for hiding this comment

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

Is my github diff wonky or are these two lines with the same script name?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

whoops i think this is an artifact of a merge gone wrong. Reverted.

Copy link
Contributor

Choose a reason for hiding this comment

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

Should this change to use 127.0.0.1 instead of localhost still be here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

On my dev machine, only 127.0.0.1 works (due to changes in recent Mac version that resolves localhost to ipv6), but I can revert the change if preferred.

"trusted-type-check": "tsec -p tsconfig.json --noEmit",
"api-report": "api-extractor run --local --verbose",
"doc": "api-documenter markdown --input temp --output docs",
Expand Down
13 changes: 7 additions & 6 deletions packages/functions/src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,12 @@ export function connectFunctionsEmulator(
* @param name - The name of the trigger.
* @public
*/
export function httpsCallable<RequestData = unknown, ResponseData = unknown>(
export function httpsCallable<RequestData = unknown, ResponseData = unknown, StreamData = unknown>(
functionsInstance: Functions,
name: string,
options?: HttpsCallableOptions
): HttpsCallable<RequestData, ResponseData> {
return _httpsCallable<RequestData, ResponseData>(
): HttpsCallable<RequestData, ResponseData, StreamData> {
return _httpsCallable<RequestData, ResponseData, StreamData>(
getModularInstance<FunctionsService>(functionsInstance as FunctionsService),
name,
options
Expand All @@ -107,13 +107,14 @@ export function httpsCallable<RequestData = unknown, ResponseData = unknown>(
*/
export function httpsCallableFromURL<
RequestData = unknown,
ResponseData = unknown
ResponseData = unknown,
StreamData = unknown,
>(
functionsInstance: Functions,
url: string,
options?: HttpsCallableOptions
): HttpsCallable<RequestData, ResponseData> {
return _httpsCallableFromURL<RequestData, ResponseData>(
): HttpsCallable<RequestData, ResponseData, StreamData> {
return _httpsCallableFromURL<RequestData, ResponseData, StreamData>(
getModularInstance<FunctionsService>(functionsInstance as FunctionsService),
url,
options
Expand Down
Loading
Loading