Skip to content

Commit e724a46

Browse files
authored
feat(functions): typescript definitions for modular functions API (#7777)
* typescript definitions for modular functions API * Add missing description for functionsInstance param
1 parent d874e15 commit e724a46

File tree

2 files changed

+79
-21
lines changed

2 files changed

+79
-21
lines changed
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import { FirebaseApp } from '@firebase/app';
2+
import { FirebaseFunctionsTypes } from '..';
3+
4+
import Functions = FirebaseFunctionsTypes.Module;
5+
import HttpsCallable = FirebaseFunctionsTypes.HttpsCallable;
6+
import HttpsCallableOptions = FirebaseFunctionsTypes.HttpsCallableOptions;
7+
/**
8+
* Get a {@link Functions} instance for the given app.
9+
* @param {FirebaseApp | undefined} app - The FirebaseApp to use. Optional.
10+
* @param {string | undefined} regionOrCustomDomain - One of: a) The region the callable functions are located in (ex: us-central1) b) A custom domain hosting the callable functions (ex: https://mydomain.com). optional
11+
* @returns {Functions} Returns a {@link Functions} instance for the given app.
12+
*/
13+
export declare function getFunctions(app?: FirebaseApp, regionOrCustomDomain?: string): Functions;
14+
15+
/**
16+
* Modify this instance to communicate with the Cloud Functions emulator.
17+
* Note: this must be called before this instance has been used to do any operations.
18+
* @param {Functions} functionsInstance
19+
* @param {string} host The emulator host. (ex: localhost)
20+
* @param {number} port The emulator port. (ex: 5001)
21+
*/
22+
export declare function connectFunctionsEmulator(
23+
functionsInstance: Functions,
24+
host: string,
25+
port: number,
26+
): void;
27+
28+
/**
29+
* Returns a reference to the {@link HttpsCallable} trigger with the given name.
30+
* @param {Functions} functionsInstance A functions instance.
31+
* @param {string} name The name of the trigger.
32+
* @param {HttpsCallableOptions | undefined} options An instance of {@link HttpsCallableOptions} containing metadata about how calls should be executed.
33+
* @returns {HttpsCallable}
34+
*/
35+
export declare function httpsCallable<RequestData = unknown, ResponseData = unknown>(
36+
functionsInstance: Functions,
37+
name: string,
38+
options?: HttpsCallableOptions,
39+
): HttpsCallable<RequestData, ResponseData>;
40+
41+
/**
42+
* Returns a reference to the {@link HttpsCallable} trigger with the specified url.
43+
* @param {Functions} functionsInstance A functions instance.
44+
* @param {string} url The url of the trigger.
45+
* @param {HttpsCallableOptions | undefined} options An instance of {@link HttpsCallableOptions} containing metadata about how calls should be executed.
46+
* @returns {HttpsCallable}
47+
*/
48+
export declare function httpsCallableFromURL<RequestData = unknown, ResponseData = unknown>(
49+
functionsInstance: Functions,
50+
url: string,
51+
options?: HttpsCallableOptions,
52+
): HttpsCallable<RequestData, ResponseData>;

packages/functions/lib/modular/index.js

Lines changed: 27 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,19 @@
1414
* limitations under the License.
1515
*
1616
*/
17+
/**
18+
* @typedef {import("..").FirebaseFunctionsTypes.Module} Functions
19+
* @typedef {import("..").FirebaseFunctionsTypes.HttpsCallable} HttpsCallable
20+
* @typedef {import("..").FirebaseFunctionsTypes.HttpsCallableOptions} HttpsCallableOptions
21+
* @typedef {import("@firebase/app").FirebaseApp} FirebaseApp
22+
*/
1723

1824
import { firebase } from '..';
1925

2026
/**
2127
* Returns a Functions instance for the given app.
22-
* @param app - FirebaseApp. Optional.
23-
* @param regionOrCustomDomain - A String of the region or domain of the Firebase Function you wish to call. Optional.
28+
* @param {FirebaseApp | undefined} app - The FirebaseApp to use. Optional.
29+
* @param {string | undefined} regionOrCustomDomain - One of: a) The region the callable functions are located in (ex: us-central1) b) A custom domain hosting the callable functions (ex: https://mydomain.com). Optional.
2430
* @returns {Functions}
2531
*/
2632
export function getFunctions(app, regionOrCustomDomain) {
@@ -32,34 +38,34 @@ export function getFunctions(app, regionOrCustomDomain) {
3238
}
3339

3440
/**
35-
* Returns nothing
36-
* @param functions - Functions instance
37-
* @param host - The domain host of the Functions emulator
38-
* @param port - The port of the Functions emulator
39-
* @returns {void}
41+
* Modify this instance to communicate with the Cloud Functions emulator.
42+
* Note: this must be called before this instance has been used to do any operations.
43+
* @param {Functions} functionsInstance A functions instance.
44+
* @param {string} host The emulator host. (ex: localhost)
45+
* @param {number} port The emulator port. (ex: 5001)
4046
*/
41-
export function connectFunctionsEmulator(functions, host, port) {
42-
return firebase.app(functions.app.name).functions().useEmulator(host, port);
47+
export function connectFunctionsEmulator(functionsInstance, host, port) {
48+
return firebase.app(functionsInstance.app.name).functions().useEmulator(host, port);
4349
}
4450

4551
/**
46-
* Returns a HttpsCallable instance
47-
* @param functions - Functions instance
48-
* @param name - The name of the trigger
49-
* @param options - An HttpsCallableOptions object
52+
* Returns a reference to the callable HTTPS trigger with the given name.
53+
* @param {Functions} functionsInstance A functions instance.
54+
* @param {string} name The name of the trigger.
55+
* @param {HttpsCallableOptions | undefined} options An interface for metadata about how calls should be executed.
5056
* @returns {HttpsCallable}
5157
*/
52-
export function httpsCallable(functions, name, options) {
53-
return firebase.app(functions.app.name).functions().httpsCallable(name, options);
58+
export function httpsCallable(functionsInstance, name, options) {
59+
return firebase.app(functionsInstance.app.name).functions().httpsCallable(name, options);
5460
}
5561

5662
/**
57-
* Returns a HttpsCallable instance
58-
* @param functions - Functions instance
59-
* @param url - The url of the trigger
60-
* @param options - An HttpsCallableOptions object
63+
* Returns a reference to the callable HTTPS trigger with the specified url.
64+
* @param {Functions} functionsInstance A functions instance.
65+
* @param {string} url The url of the trigger.
66+
* @param {HttpsCallableOptions | undefined} options An instance of {@link HttpsCallableOptions} containing metadata about how calls should be executed.
6167
* @returns {HttpsCallable}
6268
*/
63-
export function httpsCallableFromUrl(functions, url, options) {
64-
return firebase.app(functions.app.name).functions().httpsCallableFromUrl(url, options);
69+
export function httpsCallableFromUrl(functionsInstance, url, options) {
70+
return firebase.app(functionsInstance.app.name).functions().httpsCallableFromUrl(url, options);
6571
}

0 commit comments

Comments
 (0)