Compare commits

..

No commits in common. "master" and "v5.0.21" have entirely different histories.

4 changed files with 18 additions and 142 deletions

View File

@ -1,57 +0,0 @@
# Changelog
## 2024-11-06 - 5.1.2 - fix(appdata)
Fix iteration over overwriteObject in AppData class
- Corrected the for loop from in to of inside the AppData class for iterating over overwriteObject keys.
## 2024-11-05 - 5.1.1 - fix(AppData)
Fix issue with overwrite object handling in AppData class
- Corrected logic to handle cases when overwriteObject is undefined.
## 2024-11-05 - 5.1.0 - feat(appdata)
Add support for overwriting keys using the overwriteObject option in AppData
- Introduced the overwriteObject option in IAppDataOptions to allow overwriting specific keys in the AppData class.
## 2024-06-19 - 5.0.17 - 5.0.23 - Core Updates
Routine maintenance and updates to the core components.
- Multiple core updates and fixes improving stability
## 2024-06-12 - 5.0.13 - 5.0.16 - Core Updates
Maintenance focus on core systems with enhancements and problem resolutions.
- Enhancements and updates in the core functionality
## 2024-05-29 - 5.0.13 - Documentation Update
Descriptive improvements aligned with current features.
- Updated core description for better clarity in documentation
## 2024-04-01 - 5.0.10 - Configuration Update
Improved configuration management for build processes.
- Updated `npmextra.json` to reflect changes in git repository management
## 2024-02-12 - 5.0.0 - 5.0.9 - Major Core Enhancements
A series of critical updates with resolved issues in the core components.
- Introduction of new core features
- Several core system updates
## 2024-02-12 - 4.0.16 - Major Version Transition
Migration to the new major version with impactful changes.
- BREAKING CHANGE: Significant updates requiring attention for smooth transition
## 2023-08-24 - 3.0.9 - 4.0.16 - Organization Updates
Formatted updates with attention to organizational standards and practice.
- SWITCH to a new organizational scheme
## 2023-07-11 - 3.0.9 - Organizational Enhancement
Shifts aligning with contemporary structuring and logistics.
- Strategic realignment with organizational principles

View File

@ -1,6 +1,6 @@
{ {
"name": "@push.rocks/npmextra", "name": "@push.rocks/npmextra",
"version": "5.1.2", "version": "5.0.21",
"private": false, "private": false,
"description": "A utility to enhance npm with additional configuration, tool management capabilities, and a key-value store for project setups.", "description": "A utility to enhance npm with additional configuration, tool management capabilities, and a key-value store for project setups.",
"main": "dist_ts/index.js", "main": "dist_ts/index.js",

View File

@ -1,8 +1,8 @@
/** /**
* autocreated commitinfo by @push.rocks/commitinfo * autocreated commitinfo by @pushrocks/commitinfo
*/ */
export const commitinfo = { export const commitinfo = {
name: '@push.rocks/npmextra', name: '@push.rocks/npmextra',
version: '5.1.2', version: '5.0.21',
description: 'A utility to enhance npm with additional configuration, tool management capabilities, and a key-value store for project setups.' description: 'A utility to enhance npm with additional configuration, tool management capabilities, and a key-value store for project setups.'
} }

View File

@ -2,6 +2,7 @@ import * as plugins from './npmextra.plugins.js';
import * as paths from './npmextra.paths.js'; import * as paths from './npmextra.paths.js';
import { KeyValueStore } from './npmextra.classes.keyvaluestore.js'; import { KeyValueStore } from './npmextra.classes.keyvaluestore.js';
export interface IAppDataOptions<T = any> { export interface IAppDataOptions<T = any> {
dirPath?: string; dirPath?: string;
requiredKeys?: Array<keyof T>; requiredKeys?: Array<keyof T>;
@ -14,8 +15,7 @@ export interface IAppDataOptions<T = any> {
/** /**
* kvStoreKey: 'MY_ENV_VAR' * kvStoreKey: 'MY_ENV_VAR'
*/ */
envMapping?: plugins.tsclass.typeFest.PartialDeep<T>; envMapping?: plugins.tsclass.typeFest.PartialDeep<T>
overwriteObject?: plugins.tsclass.typeFest.PartialDeep<T>;
} }
export class AppData<T = any> { export class AppData<T = any> {
@ -25,9 +25,7 @@ export class AppData<T = any> {
* @param pathArg * @param pathArg
* @returns * @returns
*/ */
public static async createAndInit<T = any>( public static async createAndInit<T = any>(optionsArg: IAppDataOptions<T> = {}): Promise<AppData<T>> {
optionsArg: IAppDataOptions<T> = {}
): Promise<AppData<T>> {
const appData = new AppData<T>(optionsArg); const appData = new AppData<T>(optionsArg);
await appData.readyDeferred.promise; await appData.readyDeferred.promise;
return appData; return appData;
@ -70,85 +68,27 @@ export class AppData<T = any> {
typeArg: this.options.ephermal ? 'ephemeral' : 'custom', typeArg: this.options.ephermal ? 'ephemeral' : 'custom',
identityArg: 'appkv', identityArg: 'appkv',
customPath: this.options.dirPath, customPath: this.options.dirPath,
mandatoryKeys: this.options.requiredKeys as Array<keyof T>, mandatoryKeys: this.options.requiredKeys as Array<keyof T>
}); });
if (this.options.envMapping) { if (this.options.envMapping) {
const qenvInstance = new plugins.qenv.Qenv( const qenvInstance = new plugins.qenv.Qenv(process.cwd(), plugins.path.join(process.cwd(), '.nogit'));
process.cwd(),
plugins.path.join(process.cwd(), '.nogit')
);
// Recursive function to handle nested objects, now includes key parameter // Recursive function to handle nested objects, now includes key parameter
const processEnvMapping = async ( const processEnvMapping = async (key: keyof T, mappingValue: any, parentKey: keyof T | '' = ''): Promise<any> => {
key: keyof T,
mappingValue: any,
parentKey: keyof T | '' = ''
): Promise<any> => {
if (typeof mappingValue === 'string') { if (typeof mappingValue === 'string') {
let envValue: string | boolean | T[keyof T]; let envValue: string | T[keyof T];
let convert: 'none' | 'json' | 'base64' | 'boolean' = 'none'; if (mappingValue.startsWith('hard:')) {
switch (true) { envValue = mappingValue.replace('hard:', '') as T[keyof T];
case mappingValue.startsWith('hard:'): } else {
envValue = mappingValue.replace('hard:', '') as T[keyof T]; envValue = await qenvInstance.getEnvVarOnDemand(mappingValue) as T[keyof T];
break;
case mappingValue.startsWith('hard_boolean:'):
envValue = mappingValue.replace('hard_boolean:', '') === 'true';
convert = 'boolean';
break;
case mappingValue.startsWith('hard_json:'):
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'
).toString() as T[keyof T];
convert = 'base64';
break;
case mappingValue.startsWith('boolean:'):
envValue = (await qenvInstance.getEnvVarOnDemand(
mappingValue.replace('boolean:', '')
)) as T[keyof T];
convert = 'boolean';
break;
case mappingValue.startsWith('json:'):
envValue = (await qenvInstance.getEnvVarOnDemand(
mappingValue.replace('json:', '')
)) as T[keyof T];
convert = 'json';
break;
case mappingValue.startsWith('base64:'):
envValue = (await qenvInstance.getEnvVarOnDemand(
mappingValue.replace('base64:', '')
)) as T[keyof T];
convert = 'base64';
break;
default:
envValue = (await qenvInstance.getEnvVarOnDemand(mappingValue)) as T[keyof T];
break;
} }
// lets format the env value
if (envValue) { if (envValue) {
if (typeof envValue === 'string' && convert === 'boolean') { if (typeof envValue === 'string' && mappingValue.endsWith('_JSON')) {
envValue = envValue === 'true'; envValue = JSON.parse(envValue) as T[keyof T];
}
if (
typeof envValue === 'string' &&
(mappingValue.endsWith('_JSON') || convert === 'json')
) {
envValue = JSON.parse(envValue as string) as T[keyof T];
}
if (
typeof envValue === 'string' &&
(mappingValue.endsWith('_BASE64') || convert === 'base64')
) {
envValue = Buffer.from(envValue as string, 'base64').toString();
} }
if (!parentKey) { if (!parentKey) {
await this.kvStore.writeKey(key, envValue as any); await this.kvStore.writeKey(key, envValue);
} else { } else {
return envValue; return envValue;
} }
@ -176,13 +116,6 @@ export class AppData<T = any> {
for (const key in this.options.envMapping) { for (const key in this.options.envMapping) {
await processEnvMapping(key as keyof T, this.options.envMapping[key]); await processEnvMapping(key as keyof T, this.options.envMapping[key]);
} }
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]);
}
}
} }
this.readyDeferred.resolve(); this.readyDeferred.resolve();