@aws-lambda-powertools/parameters
Version:
The parameters package for the Powertools for AWS Lambda (TypeScript) library
79 lines • 3.9 kB
TypeScript
import { EnvironmentVariablesService } from '../config/EnvironmentVariablesService.js';
import type { BaseProviderConstructorOptions, BaseProviderInterface, GetMultipleOptionsInterface, GetOptionsInterface } from '../types/BaseProvider.js';
import { ExpirableValue } from './ExpirableValue.js';
/**
* Base class for all providers.
*
* As an abstract class, it should not be used directly, but rather extended by other providers.
*
* It implements the common logic for all providers, such as caching, transformation, etc.
* Each provider that extends this class must implement the `_get` and `_getMultiple` abstract methods.
*
* These methods are responsible for retrieving the values from the underlying parameter store. They are
* called by the `get` and `getMultiple` methods, which are responsible for caching and transformation.
*
* If there are multiple calls to the same parameter but in a different transform, they will be stored multiple times.
* This allows us to optimize by transforming the data only once per retrieval, thus there is no need to transform cached values multiple times.
*
* However, this means that we need to make multiple calls to the underlying parameter store if we need to return it in different transforms.
*
* Since the number of supported transform is small and the probability that a given parameter will always be used in a specific transform,
* this should be an acceptable tradeoff.
*/
declare abstract class BaseProvider implements BaseProviderInterface {
envVarsService: EnvironmentVariablesService;
protected client: unknown;
protected store: Map<string, ExpirableValue>;
constructor({ awsSdkV3Client, clientConfig, awsSdkV3ClientPrototype, }: BaseProviderConstructorOptions);
/**
* Add a value to the cache.
*
* @param {string} key - Key of the cached value
* @param {string | Uint8Array | Record<string, unknown>} value - Value to be cached
* @param {number} maxAge - Maximum age in seconds for the value to be cached
*/
addToCache(key: string, value: unknown, maxAge: number): void;
/**
* Clear the cache.
*/
clearCache(): void;
/**
* Retrieve a parameter value or return the cached value.
*
* @param {string} name - Parameter name
* @param {GetOptionsInterface} options - Options to configure maximum age, trasformation, AWS SDK options, or force fetch
*/
get(name: string, options?: GetOptionsInterface): Promise<unknown | undefined>;
/**
* Retrieve multiple parameter values or return the cached values.
*
* @param {string} path - Parameters path
* @param {GetMultipleOptionsInterface} options - Options to configure maximum age, trasformation, AWS SDK options, or force fetch
* @returns
*/
getMultiple(path: string, options?: GetMultipleOptionsInterface): Promise<unknown>;
/**
* Check whether a key has expired in the cache or not.
*
* It returns true if the key is expired or not present in the cache.
*
* @param {string} key - Stringified representation of the key to retrieve
*/
hasKeyExpiredInCache(key: string): boolean;
/**
* Retrieve parameter value from the underlying parameter store.
*
* @param {string} name - Parameter name
* @param {unknown} options - Options to pass to the underlying implemented method
*/
protected abstract _get(name: string, options?: unknown): Promise<unknown>;
/**
* Retrieve multiple parameter values from the underlying parameter store.
*
* @param {string} path - Parameter name
* @param {unknown} options - Options to pass to the underlying implementated method
*/
protected abstract _getMultiple(path: string, options?: unknown): Promise<Record<string, unknown> | undefined>;
}
export { BaseProvider };
//# sourceMappingURL=BaseProvider.d.ts.map