fix(appdata): Fix iteration over overwriteObject in AppData and update configuration for dependency and path handling
This commit is contained in:
@@ -26,7 +26,7 @@ export class AppData<T = any> {
|
||||
* @returns
|
||||
*/
|
||||
public static async createAndInit<T = any>(
|
||||
optionsArg: IAppDataOptions<T> = {}
|
||||
optionsArg: IAppDataOptions<T> = {},
|
||||
): Promise<AppData<T>> {
|
||||
const appData = new AppData<T>(optionsArg);
|
||||
await appData.readyDeferred.promise;
|
||||
@@ -76,14 +76,14 @@ export class AppData<T = any> {
|
||||
if (this.options.envMapping) {
|
||||
const qenvInstance = new plugins.qenv.Qenv(
|
||||
process.cwd(),
|
||||
plugins.path.join(process.cwd(), '.nogit')
|
||||
plugins.path.join(process.cwd(), '.nogit'),
|
||||
);
|
||||
|
||||
// Recursive function to handle nested objects, now includes key parameter
|
||||
const processEnvMapping = async (
|
||||
key: keyof T,
|
||||
mappingValue: any,
|
||||
parentKey: keyof T | '' = ''
|
||||
parentKey: keyof T | '' = '',
|
||||
): Promise<any> => {
|
||||
if (typeof mappingValue === 'string') {
|
||||
let envValue: string | boolean | T[keyof T];
|
||||
@@ -97,36 +97,40 @@ export class AppData<T = any> {
|
||||
convert = 'boolean';
|
||||
break;
|
||||
case mappingValue.startsWith('hard_json:'):
|
||||
envValue = JSON.parse(mappingValue.replace('hard_json:', '')) as T[keyof T];
|
||||
envValue = JSON.parse(
|
||||
mappingValue.replace('hard_json:', ''),
|
||||
) as T[keyof T];
|
||||
convert = 'json';
|
||||
break;
|
||||
case mappingValue.startsWith('hard_base64:'):
|
||||
envValue = Buffer.from(
|
||||
mappingValue.replace('hard_base64:', ''),
|
||||
'base64'
|
||||
'base64',
|
||||
).toString() as T[keyof T];
|
||||
convert = 'base64';
|
||||
break;
|
||||
case mappingValue.startsWith('boolean:'):
|
||||
envValue = (await qenvInstance.getEnvVarOnDemand(
|
||||
mappingValue.replace('boolean:', '')
|
||||
mappingValue.replace('boolean:', ''),
|
||||
)) as T[keyof T];
|
||||
convert = 'boolean';
|
||||
break;
|
||||
case mappingValue.startsWith('json:'):
|
||||
envValue = (await qenvInstance.getEnvVarOnDemand(
|
||||
mappingValue.replace('json:', '')
|
||||
mappingValue.replace('json:', ''),
|
||||
)) as T[keyof T];
|
||||
convert = 'json';
|
||||
break;
|
||||
case mappingValue.startsWith('base64:'):
|
||||
envValue = (await qenvInstance.getEnvVarOnDemand(
|
||||
mappingValue.replace('base64:', '')
|
||||
mappingValue.replace('base64:', ''),
|
||||
)) as T[keyof T];
|
||||
convert = 'base64';
|
||||
break;
|
||||
default:
|
||||
envValue = (await qenvInstance.getEnvVarOnDemand(mappingValue)) as T[keyof T];
|
||||
envValue = (await qenvInstance.getEnvVarOnDemand(
|
||||
mappingValue,
|
||||
)) as T[keyof T];
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -160,7 +164,11 @@ export class AppData<T = any> {
|
||||
for (const innerKey in mappingValue) {
|
||||
const nestedValue = mappingValue[innerKey];
|
||||
// For nested objects, call recursively but do not immediately write to kvStore
|
||||
const nestedResult = await processEnvMapping(innerKey as keyof T, nestedValue, key);
|
||||
const nestedResult = await processEnvMapping(
|
||||
innerKey as keyof T,
|
||||
nestedValue,
|
||||
key,
|
||||
);
|
||||
resultObject[innerKey as keyof T] = nestedResult;
|
||||
}
|
||||
if (parentKey === '') {
|
||||
@@ -179,8 +187,13 @@ export class AppData<T = any> {
|
||||
|
||||
if (this.options.overwriteObject) {
|
||||
for (const key of Object.keys(this.options.overwriteObject)) {
|
||||
console.log(`-> heads up: overwriting key ${key} from options.overwriteObject`);
|
||||
await this.kvStore.writeKey(key as keyof T, this.options.overwriteObject[key]);
|
||||
console.log(
|
||||
`-> heads up: overwriting key ${key} from options.overwriteObject`,
|
||||
);
|
||||
await this.kvStore.writeKey(
|
||||
key as keyof T,
|
||||
this.options.overwriteObject[key],
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -202,8 +215,8 @@ export class AppData<T = any> {
|
||||
if (missingMandatoryKeys.length > 0) {
|
||||
console.log(
|
||||
`The following mandatory keys are missing in the appdata:\n -> ${missingMandatoryKeys.join(
|
||||
',\n -> '
|
||||
)}`
|
||||
',\n -> ',
|
||||
)}`,
|
||||
);
|
||||
} else {
|
||||
console.log('All mandatory keys are present in the appdata');
|
||||
@@ -211,7 +224,9 @@ export class AppData<T = any> {
|
||||
return missingMandatoryKeys;
|
||||
}
|
||||
|
||||
public async waitForAndGetKey<K extends keyof T>(keyArg: K): Promise<T[K] | undefined> {
|
||||
public async waitForAndGetKey<K extends keyof T>(
|
||||
keyArg: K,
|
||||
): Promise<T[K] | undefined> {
|
||||
await this.readyDeferred.promise;
|
||||
await this.kvStore.waitForKeysPresent([keyArg]);
|
||||
return this.kvStore.readKey(keyArg);
|
||||
|
Reference in New Issue
Block a user