/** * Default function name generator. Converts a relative file path into a * Firebase Cloud Functions-compatible name with dash-separated groups. * * Directory segments become function groups (separated by dashes). * Each segment is camelCased independently. * * @example * funcNameFromRelPathDefault('auth/on-create.func.ts') * // => 'auth-onCreate' * * @example * funcNameFromRelPathDefault('http/api/get-users.func.ts') * // => 'http-api-getUsers' */ declare function funcNameFromRelPathDefault(relPath: string): string; declare const BFF_BUILD_DISCOVERY_ENV_VAR = "BFF_BUILD_DISCOVERY"; declare const BFF_DISCOVERY_EXPORT_KEY = "__bff_discovery"; /** * Configuration object for `exportFunctions()`. * * Required properties: `__filename` and `exports`. * All other properties have sensible defaults. */ interface ExportFunctionsConfig { /** * Absolute path to the directory containing your entry point file. * Defaults to the directory of `__filename`. Override if your function * files live in a different root directory. */ __dirname?: string; /** * Absolute path to the file calling `exportFunctions()`. * Pass Node's `__filename`. Used to prevent the entry point from * exporting itself. */ __filename: string; /** * The `exports` (or `module.exports`) object from your entry point. * This is the object Firebase inspects to discover function triggers. */ exports: any; /** * Relative path from `__dirname` to the directory containing function files. * @default './' */ functionDirectoryPath?: string; /** * Glob pattern for matching function files. * NOTE: Match files as they appear AFTER compilation (`.js`) unless * your runtime supports TypeScript natively. During bundler build-discovery, * BFF automatically expands `.js`/`.cjs`/`.mjs` globs to match source * `.ts`/`.cts`/`.mts` files as well. * @default '** /*.{js,ts}' (without space) */ searchGlob?: string; /** * Custom function to convert a relative file path into a function name. * Dashes `-` in the output create function groups in Firebase. */ funcNameFromRelPath?: (relativePath: string) => string; /** * Custom function to extract the trigger from a loaded module. * @default (mod) => mod?.default */ extractTrigger?: (inputModule: any, currentFunctionName?: string) => any; /** Enable performance timing logs. */ enableLogger?: boolean; /** Custom logger (must have `time`, `timeEnd`, and `log` methods). */ logger?: { time(msg: string): void; timeEnd(msg: string): void; log(msg: string): void; [key: string]: any; }; /** * When true, exports relative file paths instead of actual triggers. * Useful for debugging runtime discovery, but bundler plugins now prefer the * dedicated build-discovery mode triggered via `BFF_BUILD_DISCOVERY=1`. */ exportPathMode?: boolean; } interface DiscoverFunctionPathsConfig { __dirname?: string; __filename: string; functionDirectoryPath?: string; searchGlob?: string; funcNameFromRelPath?: (relativePath: string) => string; enableLogger?: boolean; logger?: { time(msg: string): void; timeEnd(msg: string): void; log(msg: string): void; [key: string]: any; }; } interface BffDiscoveredFunction { absPath: string; sourceRelativePath: string; runtimeRelativePath: string; outputRelativePath: string; outputEntryName: string; } interface BffBuildDiscovery { functionDirectoryPath: string; entries: Record; } declare function discoverFunctionPaths({ __filename, __dirname, functionDirectoryPath, searchGlob, funcNameFromRelPath, enableLogger, logger, }: DiscoverFunctionPathsConfig): BffBuildDiscovery; declare function consumeBuildDiscovery(entryPoint: string): BffBuildDiscovery | undefined; /** * Automatically discovers, names, and exports Firebase Cloud Function triggers * from a directory of files. * * **Cold-start optimization**: During function invocation (when `FUNCTION_NAME` * or `K_SERVICE` env var is set), only the single matching module is loaded. * During deployment, all modules are loaded so Firebase can discover every * function trigger. * * Supports both Gen 1 (`FUNCTION_NAME`) and Gen 2 (`K_SERVICE`) functions. * * During bundler build-discovery (`BFF_BUILD_DISCOVERY=1`), BFF does not load * any trigger modules. It instead exposes a structured discovery result on * `exports.__bff_discovery` so bundlers can reuse the exact same runtime config * (glob, directory, name generator) without duplicating it in build tooling. * * @returns The populated `exports` object (also mutated in-place). */ declare function exportFunctions({ __filename, exports, functionDirectoryPath, searchGlob, funcNameFromRelPath, enableLogger, logger, extractTrigger, __dirname, exportPathMode, }: ExportFunctionsConfig): any; /** * Async version of `exportFunctions()` that uses dynamic `import()` for * loading function modules. Required for ESM-only function files. * * When using `import()` on CJS modules, Node.js wraps the module in a * namespace object. The default `extractTrigger` handles this automatically * by unwrapping the namespace. * * Use with top-level await in ESM entry points, or inside an async IIFE * in CJS entry points. */ declare function exportFunctionsAsync({ __filename, exports, functionDirectoryPath, searchGlob, funcNameFromRelPath, enableLogger, logger, extractTrigger, __dirname, exportPathMode, }: ExportFunctionsConfig): Promise; /** * Convert a string to camelCase. * Handles kebab-case, snake_case, and space-separated strings. * * @example * camelCase('my-function') // 'myFunction' * camelCase('my_function') // 'myFunction' * camelCase('MyFunction') // 'myFunction' */ declare function camelCase(str: string): string; /** * Set a deeply nested property on an object using an array path. * Creates intermediate objects as needed. * * @example * const obj = {}; * setPath(obj, ['auth', 'onCreate'], handler); * // obj = { auth: { onCreate: handler } } */ declare function setPath(obj: Record, path: string[], value: unknown): Record; export { BFF_BUILD_DISCOVERY_ENV_VAR, BFF_DISCOVERY_EXPORT_KEY, type BffBuildDiscovery, type BffDiscoveredFunction, type DiscoverFunctionPathsConfig, type ExportFunctionsConfig, camelCase, consumeBuildDiscovery, discoverFunctionPaths, exportFunctions, exportFunctionsAsync, funcNameFromRelPathDefault, setPath };