@apistudio/apim-cli
Version:
CLI for API Management Products
46 lines (45 loc) • 1.28 kB
JavaScript
/**
* Copyright IBM Corp. 2024, 2025
*/
export class VariableContext {
constructor() {
this.variableStore = new Map();
this.envStore = new Map();
}
// This will be the highest priority
setVariable(key, value, isSecret = false) {
this.variableStore.set(key, { value, isSecret });
}
set(key, value, isSecret = false) {
this.setVariable(key, value, isSecret);
}
// This will be the least priority
setEnvVariable(key, value, isSecret = false) {
this.envStore.set(key, { value, isSecret });
}
get(key) {
return this.variableStore.get(key) ?? this.envStore.get(key);
}
getValue(key) {
return this.variableStore.get(key)?.value ?? this.envStore.get(key)?.value;
}
getAll() {
return {
...Object.fromEntries(this.envStore.entries()),
...Object.fromEntries(this.variableStore.entries()),
};
}
getEnvStore() {
return Object.fromEntries(this.envStore.entries());
}
getVarStore() {
return Object.fromEntries(this.variableStore.entries());
}
delete(key) {
this.variableStore.delete(key);
this.envStore.delete(key);
}
clear() {
this.variableStore.clear();
}
}