UNPKG

1.13 kBTypeScriptView Raw
1import { Duration } from '@salesforce/kit';
2import { JsonMap, Nullable } from '@salesforce/ts-types';
3import { ConfigFile } from './configFile';
4/**
5 * A Time To Live configuration file where each entry is timestamped and removed once the TTL has expired.
6 *
7 * @example
8 * ```
9 * import { Duration } from '@salesforce/kit';
10 * const config = await TTLConfig.create({
11 * isGlobal: false,
12 * ttl: Duration.days(1)
13 * });
14 * ```
15 */
16export declare class TTLConfig<T extends TTLConfig.Options, P extends JsonMap> extends ConfigFile<T, TTLConfig.Contents<P>> {
17 set(key: string, value: Partial<TTLConfig.Entry<P>>): void;
18 getLatestEntry(): Nullable<[string, TTLConfig.Entry<P>]>;
19 getLatestKey(): Nullable<string>;
20 isExpired(dateTime: number, value: P & {
21 timestamp: string;
22 }): boolean;
23 protected init(): Promise<void>;
24 private timestamp;
25}
26export declare namespace TTLConfig {
27 type Options = ConfigFile.Options & {
28 ttl: Duration;
29 };
30 type Entry<T extends JsonMap> = T & {
31 timestamp: string;
32 };
33 type Contents<T extends JsonMap> = Record<string, Entry<T>>;
34}