Skip to content

Commit

Permalink
feat(functions): typescript definitions for httpsCallable and httpsCa…
Browse files Browse the repository at this point in the history
…llableFromUrl (#7762)

* feat(functions): Enable specification of input and response types for httpsCallable and httpsCallableFromUrl functions

* lint

* update to match upstream typings
  • Loading branch information
skam22 authored May 3, 2024
1 parent 424b9d9 commit 3446ca3
Showing 1 changed file with 26 additions and 22 deletions.
48 changes: 26 additions & 22 deletions packages/functions/lib/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,8 @@ export namespace FirebaseFunctionsTypes {
/**
* An HttpsCallableResult wraps a single result from a function call.
*/
export interface HttpsCallableResult {
readonly data: any;
export interface HttpsCallableResult<ResponseData = unknown> {
readonly data: ResponseData;
}

/**
Expand All @@ -128,33 +128,33 @@ export namespace FirebaseFunctionsTypes {
* #### Example
*
* ```js
* // Create a HttpsCallable instance
* const instance = firebase.functions().httpsCallable('order');
* // Create an HttpsCallable reference
* const reference = firebase.functions().httpsCallable('order');
*
* try {
* const response = await instance({
* const response = await reference({
* id: '12345',
* });
* } catch (e) {
* console.error(e);
* }
* ```
*/
export interface HttpsCallable {
(data?: any): Promise<HttpsCallableResult>;
export interface HttpsCallable<RequestData = unknown, ResponseData = unknown> {
(data?: RequestData | null): Promise<HttpsCallableResult<ResponseData>>;
}

/**
* An HttpsCallableOptions object that can be passed as the second argument to `firebase.functions().httpsCallable(name, HttpsCallableOptions)`.
* An interface for metadata about how calls should be executed. An instance of HttpsCallableOptions can be passed as the second argument to `firebase.functions().httpsCallable(name, httpsCallableOptions)`.
**/
export interface HttpsCallableOptions {
/**
* The timeout property allows you to control how long the application will wait for the cloud function to respond in milliseconds.
* The timeout property is the time in milliseconds after which to cancel if there is no response. Default is 70000.
*
* #### Example
*
*```js
* // The below will wait 7 seconds for a response from the cloud function before an error is thrown
* // The below will wait 7 seconds for a response from the cloud function before an error is thrown.
* try {
* const instance = firebase.functions().httpsCallable('order', { timeout: 7000 });
* const response = await instance({
Expand Down Expand Up @@ -316,16 +316,15 @@ export namespace FirebaseFunctionsTypes {
*/
export class Module extends FirebaseModule {
/**
* Gets an `HttpsCallable` instance that refers to the function with the given
* name.
* Returns a reference to the callable HTTPS trigger with the given name.
*
* #### Example
*
* ```js
* const instance = firebase.functions().httpsCallable('order');
* const reference = firebase.functions().httpsCallable('order');
*
* try {
* const response = await instance({
* const response = await reference({
* id: '12345',
* });
* } catch (e) {
Expand All @@ -334,21 +333,23 @@ export namespace FirebaseFunctionsTypes {
* ```
*
* @param name The name of the https callable function.
* @return The `HttpsCallable` instance.
* @return The `HttpsCallable` reference.
*/
httpsCallable(name: string, options?: HttpsCallableOptions): HttpsCallable;
httpsCallable<RequestData = unknown, ResponseData = unknown>(
name: string,
options?: HttpsCallableOptions,
): HttpsCallable<RequestData, ResponseData>;

/**
* Gets an `HttpsCallable` instance that refers to the function with the given
* URL.
* Returns a reference to the callable HTTPS trigger with the specified url.
*
* #### Example
*
* ```js
* const instance = firebase.functions().httpsCallable('order');
* const reference = firebase.functions().httpsCallable('order');
*
* try {
* const response = await instance({
* const response = await reference({
* id: '12345',
* });
* } catch (e) {
Expand All @@ -357,9 +358,12 @@ export namespace FirebaseFunctionsTypes {
* ```
*
* @param name The name of the https callable function.
* @return The `HttpsCallable` instance.
* @return The `HttpsCallable` reference.
*/
httpsCallableFromUrl(url: string, options?: HttpsCallableOptions): HttpsCallable;
httpsCallableFromUrl<RequestData = unknown, ResponseData = unknown>(
url: string,
options?: HttpsCallableOptions,
): HttpsCallable<RequestData, ResponseData>;

/**
* Changes this instance to point to a Cloud Functions emulator running locally.
Expand Down

0 comments on commit 3446ca3

Please sign in to comment.