UNPKG

5.24 kBTypeScriptView Raw
1import { AsyncCreatable } from '@salesforce/kit';
2import { AnyJson, Dictionary, JsonMap, Optional } from '@salesforce/ts-types';
3/**
4 * The allowed types stored in a config store.
5 */
6export declare type ConfigValue = AnyJson;
7/**
8 * The type of entries in a config store defined by the key and value type of {@link ConfigContents}.
9 */
10export declare type ConfigEntry = [string, ConfigValue];
11/**
12 * The type of content a config stores.
13 */
14export declare type ConfigContents = Dictionary<ConfigValue>;
15/**
16 * An interface for a config object with a persistent store.
17 */
18export interface ConfigStore {
19 entries(): ConfigEntry[];
20 get(key: string): Optional<ConfigValue>;
21 getKeysByValue(value: ConfigValue): string[];
22 has(key: string): boolean;
23 keys(): string[];
24 set(key: string, value: ConfigValue): ConfigContents;
25 unset(key: string): boolean;
26 unsetAll(keys: string[]): boolean;
27 clear(): void;
28 values(): ConfigValue[];
29 forEach(actionFn: (key: string, value: ConfigValue) => void): void;
30 awaitEach(actionFn: (key: string, value: ConfigValue) => Promise<void>): Promise<void>;
31 getContents(): ConfigContents;
32 setContents(contents?: ConfigContents): void;
33}
34/**
35 * An abstract class that implements all the config management functions but
36 * none of the storage functions.
37 *
38 * **Note:** To see the interface, look in typescripts autocomplete help or the npm package's ConfigStore.d.ts file.
39 */
40export declare abstract class BaseConfigStore<T extends BaseConfigStore.Options> extends AsyncCreatable<T> implements ConfigStore {
41 protected options: T;
42 private contents;
43 /**
44 * Constructor.
45 *
46 * @param options The options for the class instance.
47 * @ignore
48 */
49 constructor(options: T);
50 /**
51 * Returns an array of {@link ConfigEntry} for each element in the config.
52 */
53 entries(): ConfigEntry[];
54 /**
55 * Returns the value associated to the key, or undefined if there is none.
56 *
57 * @param key The key.
58 */
59 get(key: string): Optional<ConfigValue>;
60 /**
61 * Returns the list of keys that contain a value.
62 *
63 * @param value The value to filter keys on.
64 */
65 getKeysByValue(value: ConfigValue): string[];
66 /**
67 * Returns a boolean asserting whether a value has been associated to the key in the config object or not.
68 *
69 * @param key The key.
70 */
71 has(key: string): boolean;
72 /**
73 * Returns an array that contains the keys for each element in the config object.
74 */
75 keys(): string[];
76 /**
77 * Sets the value for the key in the config object.
78 *
79 * @param key The Key.
80 * @param value The value.
81 */
82 set(key: string, value: ConfigValue): ConfigContents;
83 /**
84 * Returns `true` if an element in the config object existed and has been removed, or `false` if the element does not
85 * exist. {@link BaseConfigStore.has} will return false afterwards.
86 *
87 * @param key The key.
88 */
89 unset(key: string): boolean;
90 /**
91 * Returns `true` if all elements in the config object existed and have been removed, or `false` if all the elements
92 * do not exist (some may have been removed). {@link BaseConfigStore.has(key)} will return false afterwards.
93 *
94 * @param keys The keys.
95 */
96 unsetAll(keys: string[]): boolean;
97 /**
98 * Removes all key/value pairs from the config object.
99 */
100 clear(): void;
101 /**
102 * Returns an array that contains the values for each element in the config object.
103 */
104 values(): ConfigValue[];
105 /**
106 * Returns the entire config contents.
107 */
108 getContents(): ConfigContents;
109 /**
110 * Sets the entire config contents.
111 *
112 * @param contents The contents.
113 */
114 setContents(contents?: ConfigContents): void;
115 /**
116 * Invokes `actionFn` once for each key-value pair present in the config object.
117 *
118 * @param {function} actionFn The function `(key: string, value: ConfigValue) => void` to be called for each element.
119 */
120 forEach(actionFn: (key: string, value: ConfigValue) => void): void;
121 /**
122 * Asynchronously invokes `actionFn` once for each key-value pair present in the config object.
123 *
124 * @param {function} actionFn The function `(key: string, value: ConfigValue) => Promise<void>` to be called for
125 * each element.
126 * @returns {Promise<void>}
127 */
128 awaitEach(actionFn: (key: string, value: ConfigValue) => Promise<void>): Promise<void>;
129 /**
130 * Convert the config object to a JSON object. Returns the config contents.
131 * Same as calling {@link ConfigStore.getContents}
132 */
133 toObject(): JsonMap;
134 /**
135 * Convert an object to a {@link ConfigContents} and set it as the config contents.
136 *
137 * @param obj The object.
138 */
139 setContentsFromObject<U extends object>(obj: U): void;
140 protected setMethod(contents: ConfigContents, key: string, value?: ConfigValue): void;
141}
142/**
143 * @ignore
144 */
145export declare namespace BaseConfigStore {
146 /**
147 * Options for the config store.
148 */
149 interface Options {
150 /**
151 * Initial contents for the config.
152 */
153 contents?: ConfigContents;
154 }
155}