@intuitionrobotics/thunderstorm
Version:
52 lines • 2.66 kB
TypeScript
import { type Express, type Router } from "express";
import { type DeployableFunction, FirebaseFunction, type FirebaseFunctionOptions } from "@intuitionrobotics/firebase/backend-functions";
export type ApiFunctionArgs = {
/**
* A pre-built Express app (e.g. with app-specific middleware already added).
* ApiFunction still runs the framework server setup (compression/CORS/json)
* and mounts the router on it — AFTER anything already registered.
*
* Contract: a provided app carries MIDDLEWARE ONLY, never routes. Express is
* registration-order sensitive — a route registered on the app before this
* instance is built bypasses the framework chain (no CORS headers, no
* compression). Routes belong in the router; app-level extras (debug
* endpoints etc.) must be registered AFTER Storm.build(). And each instance
* needs its OWN app — never share one Express app between two instances.
*/
app?: Express;
/** The route table this API serves (an Express Router built by the app). */
router?: Router;
/** Runtime options: memory, timeoutSeconds, generation ("v1"/"v2"), region, ... */
options?: FirebaseFunctionOptions;
};
/**
* An Express-backed HTTPS Cloud Function as a *regular module* — registered via
* `Storm.addModules(...)` like any other function, named after the module
* (no more hardcoded "api"), and instantiable as many times as needed:
*
* const Api = new ApiFunction("api", {router: rootRouter});
* const ApiTest = new ApiFunction("api_test", {router: rootRouter, options: {generation: "v2"}});
* new Storm().addModules(Api, ApiTest, ...modules).build();
*
* `api_test` deploys the exact same code as a separate function
* (`firebase deploy --only functions:api_test`) — a deployed test environment,
* or a safe gen-2 canary, without touching the real `api`.
*
* Server config (baseUrl/bodyParserLimit/cors) resolves through the module
* config store: the shared "HttpServer" slice applies to every instance, and
* the instance's own slice (config[name]) layers on top.
*
* When no ApiFunction is registered, Storm builds an implicit default named
* "api" from its legacy builder methods (setApp/setRoutes/setApiFunctionOptions)
* — registering ANY instance disables that default.
*/
export declare class ApiFunction extends FirebaseFunction {
private readonly providedApp?;
private router?;
private _app?;
constructor(name: string, args?: ApiFunctionArgs);
setRoutes(router: Router): this;
private get app();
getFunction: () => DeployableFunction;
}
//# sourceMappingURL=ApiFunction.d.ts.map