npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

firebase-functions-declarations

v1.0.5

Published

Creates declaration files for your firebase funcations

Downloads

10

Readme

firebase-functions-declarations

This simple tool creates declaration files (.d.ts) for your Firebase Functions.

When calling a firebase function you have no guarantee for the functions return value. This tool tries solving that.

When using this tool, instead of writing:

const x = (await firebase.functions().httpsCallable('myFunction')(someData)).data

And not knowing what x is, you write:

import { myFunction } from './firebase-functions';

// ...

const x = await myFunction(someData);

And x will be typed to be whatever myFunction returns!

Important: Read the prerequisites and note that the declarations only include the function's return value. Not the data passed to it.

Why?

So that in your app's code you can enjoy type safety when working with functions.

How it works

Using tsc (on functions/src/index.ts), this tool creates a declaration files for each one of your functions.

It then creates an index.ts, where per-each Firebase Function you declared, an exported function is created, that function uses firebase.functions().httpCallback to dispatch a call to the Firebase function and the function's return value type is set to be the return value type of the Firebase Function.

How to set it up

Inside your project's root folder, run:

yarn add firebase-functions-declarations

Then add the following script to your package.json's scripts:

  "scripts": {
    "create-functions-declarations": "createFunctionsDeclarations --output ./src/firebase-functions"
  }

Where ./src/firebase-functions is the path where you want the declarations and index files created.

Prerequisites

Because of several limitations, for this tool to work you have to declare your Firebase Function to be a module that export defaults the return value of functions.https.onCall and also exports a function named impl that is the function passed to functions.https.onCall.

For example:

// ... import statements

export async function impl(
  data: any,
  context: functions.https.CallableContext,
) {
  // firebase function body...
}

export default functions.https.onCall(impl);