import { type ClassLikeType, type Getter, type Maybe } from '@dereekb/util'; import { type Functions, type HttpsCallableOptions } from 'firebase/functions'; import { type FirebaseFunctionMap, type FirebaseFunctionTypeMap } from './function'; /** * Per-function configuration for creating `HttpsCallable` instances, allowing * custom `HttpsCallableOptions` (e.g., timeout) per function key. */ export interface FirebaseFunctionTypeConfig { readonly options?: HttpsCallableOptions; } /** * Maps each function key in a {@link FirebaseFunctionTypeMap} to its optional configuration. */ export type FirebaseFunctionTypeConfigMap = { readonly [K in keyof M]: Maybe; }; /** * Factory that creates a {@link FirebaseFunctionMap} for a given `Functions` instance. * * Call this with a live `Functions` instance to get a map of typed callable functions * ready to invoke. */ export type FirebaseFunctionMapFactory = (functionsInstance: Functions) => FirebaseFunctionMap; /** * Creates a {@link FirebaseFunctionMapFactory} from a configuration map. * * Each key in the config map becomes an `HttpsCallable` function wrapped with {@link directDataHttpsCallable} * for direct data access. Per-key options (e.g., timeout) are applied if provided. * * @param configMap - maps function keys to their optional configuration * @returns a {@link FirebaseFunctionMapFactory} that creates a typed callable function map for a given `Functions` instance * * @example * ```ts * const factory = firebaseFunctionMapFactory({ * createUser: { options: { timeout: 30000 } }, * deleteUser: null * }); * const functions = factory(getFunctions()); * const result = await functions.createUser({ name: 'Alice' }); * ``` */ export declare function firebaseFunctionMapFactory(configMap: FirebaseFunctionTypeConfigMap): FirebaseFunctionMapFactory; /** * String key used to identify a function group in the app-level functions map. * * @semanticType * @semanticTopic identifier * @semanticTopic string * @semanticTopic dereekb-firebase:functions */ export type FirebaseFunctionMapKey = string; /** * Lazy getter that also carries metadata about the function group's type and key. * * The `_type` property holds the class constructor for type identification (used by injection), * and `_key` holds the string key in the app-level {@link FirebaseFunctionsMap}. */ export type FirebaseFunctionGetter = Getter & { _type: ClassLikeType; _key: FirebaseFunctionMapKey; }; /** * Top-level map of all function groups in the app. Each key represents a logical function group * (e.g., `'notificationFunctions'`, `'developmentFunctions'`) mapped to its {@link FirebaseFunctionTypeMap}. */ export type FirebaseFunctionsMap = { readonly [key: FirebaseFunctionMapKey]: FirebaseFunctionTypeMap; }; /** * Configuration map for building a {@link LazyFirebaseFunctions} instance. * Each entry pairs a class type (for DI identification) with a factory function. */ export type FirebaseFunctionsConfigMap = { readonly [K in keyof M]: FirebaseFunctionsConfigMapEntry; }; /** * Tuple of `[ClassType, FactoryFunction]` for a single function group entry. */ export type FirebaseFunctionsConfigMapEntry = [ClassLikeType, FirebaseFunctionMapFactory]; /** * Factory that creates a {@link LazyFirebaseFunctions} map for a given `Functions` instance. */ export type LazyFirebaseFunctionsFactory = (functions: Functions) => LazyFirebaseFunctions; /** * Map of lazy-loaded function groups. Each group is a {@link FirebaseFunctionGetter} that * defers initialization until first access via `cachedGetter`, avoiding unnecessary * `httpsCallable` instantiation for unused function groups. */ export type LazyFirebaseFunctions = { readonly [K in keyof M]: FirebaseFunctionGetter>; }; /** * Creates a {@link LazyFirebaseFunctionsFactory} from a config map of function groups. * * Each function group is lazily initialized on first access using `cachedGetter`, * so `httpsCallable` instances are only created when actually needed. * * @param configMap - maps each function group key to its `[ClassType, Factory]` tuple * @returns a {@link LazyFirebaseFunctionsFactory} that creates a lazy-loaded function map for a given `Functions` instance * * @example * ```ts * const factory = lazyFirebaseFunctionsFactory({ * notificationFunctions: [NotificationFunctions, notificationFunctionMapFactory], * developmentFunctions: [DevelopmentFunctions, devFunctionMapFactory] * }); * * const lazyFns = factory(getFunctions()); * const notifFns = lazyFns.notificationFunctions(); // initialized on first call * ``` */ export declare function lazyFirebaseFunctionsFactory = FirebaseFunctionsConfigMap>(configMap: C): LazyFirebaseFunctionsFactory;