@arc-js/config-manager 0.0.91 → 0.0.92
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/core/ConfigService.d.ts
CHANGED
|
@@ -7,7 +7,8 @@ interface ConfigOptions {
|
|
|
7
7
|
declare class ConfigService {
|
|
8
8
|
private resources;
|
|
9
9
|
private loadedModules;
|
|
10
|
-
|
|
10
|
+
private configs;
|
|
11
|
+
constructor(configs?: any);
|
|
11
12
|
initialize(): Promise<void>;
|
|
12
13
|
loadAllConfigs(): Promise<void>;
|
|
13
14
|
loadModule(moduleName: string): Promise<void>;
|
package/core/ConfigService.js
CHANGED
|
@@ -36,37 +36,6 @@ const mergeDeep = (target, source) => {
|
|
|
36
36
|
|
|
37
37
|
let configManagerConfig = null;
|
|
38
38
|
|
|
39
|
-
const loadBaseConfig = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
40
|
-
try {
|
|
41
|
-
if (!(configManagerConfig === null || configManagerConfig === void 0 ? void 0 : configManagerConfig.base)) {
|
|
42
|
-
console.warn('No base config found');
|
|
43
|
-
return {};
|
|
44
|
-
}
|
|
45
|
-
const baseConfigs = yield Promise.all(Object.entries(configManagerConfig.base).map((_a) => __awaiter(void 0, [_a], void 0, function* ([key, loader]) {
|
|
46
|
-
try {
|
|
47
|
-
const config = yield loader();
|
|
48
|
-
return { key, config };
|
|
49
|
-
}
|
|
50
|
-
catch (error) {
|
|
51
|
-
console.error(`Failed to load base config ${key}:`, error);
|
|
52
|
-
return { key, config: {} };
|
|
53
|
-
}
|
|
54
|
-
})));
|
|
55
|
-
return baseConfigs.reduce((acc, { key, config }) => {
|
|
56
|
-
return Object.assign(Object.assign({}, acc), config);
|
|
57
|
-
}, {});
|
|
58
|
-
}
|
|
59
|
-
catch (error) {
|
|
60
|
-
console.error('Failed to load base config:', error);
|
|
61
|
-
return {};
|
|
62
|
-
}
|
|
63
|
-
});
|
|
64
|
-
const loadModulesConfigs = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
65
|
-
const results = [];
|
|
66
|
-
{
|
|
67
|
-
return results;
|
|
68
|
-
}
|
|
69
|
-
});
|
|
70
39
|
const loadModuleConfig = (moduleName) => __awaiter(void 0, void 0, void 0, function* () {
|
|
71
40
|
var _a;
|
|
72
41
|
if (!((_a = void 0 ) === null || _a === void 0 ? void 0 : _a[moduleName])) {
|
|
@@ -87,7 +56,7 @@ const loadModuleConfig = (moduleName) => __awaiter(void 0, void 0, void 0, funct
|
|
|
87
56
|
});
|
|
88
57
|
|
|
89
58
|
class ConfigService {
|
|
90
|
-
constructor() {
|
|
59
|
+
constructor(configs) {
|
|
91
60
|
Object.defineProperty(this, "resources", {
|
|
92
61
|
enumerable: true,
|
|
93
62
|
configurable: true,
|
|
@@ -100,6 +69,13 @@ class ConfigService {
|
|
|
100
69
|
writable: true,
|
|
101
70
|
value: new Set()
|
|
102
71
|
});
|
|
72
|
+
Object.defineProperty(this, "configs", {
|
|
73
|
+
enumerable: true,
|
|
74
|
+
configurable: true,
|
|
75
|
+
writable: true,
|
|
76
|
+
value: null
|
|
77
|
+
});
|
|
78
|
+
this.configs = configs;
|
|
103
79
|
}
|
|
104
80
|
initialize() {
|
|
105
81
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -108,16 +84,45 @@ class ConfigService {
|
|
|
108
84
|
}
|
|
109
85
|
loadAllConfigs() {
|
|
110
86
|
return __awaiter(this, void 0, void 0, function* () {
|
|
111
|
-
|
|
112
|
-
console.log('
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
87
|
+
var _a, _b;
|
|
88
|
+
console.log('Configs available:', this.configs);
|
|
89
|
+
if ((_a = this.configs) === null || _a === void 0 ? void 0 : _a.base) {
|
|
90
|
+
const baseConfigs = yield Promise.all(Object.entries(this.configs.base).map((_a) => __awaiter(this, [_a], void 0, function* ([key, loader]) {
|
|
91
|
+
try {
|
|
92
|
+
const config = yield loader();
|
|
93
|
+
return { key, config };
|
|
94
|
+
}
|
|
95
|
+
catch (error) {
|
|
96
|
+
console.error(`Failed to load base config ${key}:`, error);
|
|
97
|
+
return { key, config: {} };
|
|
98
|
+
}
|
|
99
|
+
})));
|
|
100
|
+
const base = baseConfigs.reduce((acc, { key, config }) => {
|
|
101
|
+
return Object.assign(Object.assign({}, acc), config);
|
|
102
|
+
}, {});
|
|
103
|
+
console.log('Base config loaded:', base);
|
|
104
|
+
this.resources.base = base;
|
|
105
|
+
}
|
|
106
|
+
if ((_b = this.configs) === null || _b === void 0 ? void 0 : _b.modules) {
|
|
107
|
+
const modules = [];
|
|
108
|
+
for (const [moduleName, loader] of Object.entries(this.configs.modules)) {
|
|
109
|
+
try {
|
|
110
|
+
const config = yield loader();
|
|
111
|
+
modules.push({
|
|
112
|
+
moduleName,
|
|
113
|
+
config
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
catch (error) {
|
|
117
|
+
console.error(`Failed to load config for module "${moduleName}"`, error);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
console.log('Modules configs loaded:', modules);
|
|
121
|
+
modules.forEach(({ moduleName, config }) => {
|
|
122
|
+
this.resources[moduleName] = mergeDeep(this.resources[moduleName] || {}, config);
|
|
123
|
+
this.loadedModules.add(moduleName);
|
|
124
|
+
});
|
|
125
|
+
}
|
|
121
126
|
});
|
|
122
127
|
}
|
|
123
128
|
loadModule(moduleName) {
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
function __awaiter(e,a,
|
|
1
|
+
function __awaiter(e,s,a,l){return new(a=a||Promise)(function(o,i){function t(e){try{n(l.next(e))}catch(e){i(e)}}function r(e){try{n(l.throw(e))}catch(e){i(e)}}function n(e){var i;e.done?o(e.value):((i=e.value)instanceof a?i:new a(function(e){e(i)})).then(t,r)}n((l=l.apply(e,s||[])).next())})}let mergeDeep=(e,i)=>{if("object"!=typeof e||"object"!=typeof i)return i;var o,t=Object.assign({},e);for(o in i)i.hasOwnProperty(o)&&(e.hasOwnProperty(o)?t[o]=mergeDeep(e[o],i[o]):t[o]=i[o]);return t},configManagerConfig=null,loadModuleConfig=e=>__awaiter(void 0,void 0,void 0,function*(){});class ConfigService{constructor(e){Object.defineProperty(this,"resources",{enumerable:!0,configurable:!0,writable:!0,value:{}}),Object.defineProperty(this,"loadedModules",{enumerable:!0,configurable:!0,writable:!0,value:new Set}),Object.defineProperty(this,"configs",{enumerable:!0,configurable:!0,writable:!0,value:null}),this.configs=e}initialize(){return __awaiter(this,void 0,void 0,function*(){yield this.loadAllConfigs()})}loadAllConfigs(){return __awaiter(this,void 0,void 0,function*(){var e;if(null!=(e=this.configs)&&e.base&&(e=(yield Promise.all(Object.entries(this.configs.base).map(e=>__awaiter(this,[e],void 0,function*([i,e]){try{return{key:i,config:yield e()}}catch(e){return{key:i,config:{}}}})))).reduce((e,{config:i})=>Object.assign(Object.assign({},e),i),{}),this.resources.base=e),null!=(e=this.configs)&&e.modules){var i,o,t=[];for([i,o]of Object.entries(this.configs.modules))try{var r=yield o();t.push({moduleName:i,config:r})}catch(e){}t.forEach(({moduleName:e,config:i})=>{this.resources[e]=mergeDeep(this.resources[e]||{},i),this.loadedModules.add(e)})}})}loadModule(i){return __awaiter(this,void 0,void 0,function*(){var e;this.loadedModules.has(i)||null!=(e=yield loadModuleConfig(i))&&e.config&&(this.resources[i]=mergeDeep(this.resources[i]||{},e.config),this.loadedModules.add(i))})}get(e,i={}){var{moduleName:i="base",defaultValue:o=void 0,pathSeparator:t="."}=i,i=this.resources[i];return i&&void 0!==(e=e.split(t).reduce((e,i)=>e&&void 0!==e[i]?e[i]:void 0,i))?e:o}getConfig(e="base"){return this.resources[e]||{}}reload(){return this.loadAllConfigs()}}export{ConfigService};
|
|
2
2
|
//# sourceMappingURL=ConfigService.min.js.map
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"publishConfig": {
|
|
4
4
|
"access": "public"
|
|
5
5
|
},
|
|
6
|
-
"version": "0.0.
|
|
6
|
+
"version": "0.0.92",
|
|
7
7
|
"description": "CONFIG-MANAGER est un système de gestion de configuration modulaire pour les applications React avec TypeScript/JavaScript. Il fournit une gestion centralisée des configurations, un chargement dynamique des modules, et une intégration transparente avec les variables d'environnement.",
|
|
8
8
|
"main": "index.js",
|
|
9
9
|
"keywords": [],
|
|
@@ -1,14 +1,12 @@
|
|
|
1
1
|
import React from "react";
|
|
2
2
|
import { createContext, useContext, useState, useEffect, useCallback } from 'react';
|
|
3
3
|
import { ConfigService } from '../core/ConfigService';
|
|
4
|
-
import { setConfigManagerConfig } from '../config';
|
|
5
4
|
const ConfigManagerContext = createContext(null);
|
|
6
5
|
export const ConfigManagerProvider = ({
|
|
7
6
|
configs,
|
|
8
7
|
children
|
|
9
8
|
}) => {
|
|
10
|
-
|
|
11
|
-
const [service] = useState(() => new ConfigService());
|
|
9
|
+
const [service] = useState(() => new ConfigService(configs))
|
|
12
10
|
const [isLoading, setIsLoading] = useState(true);
|
|
13
11
|
useEffect(() => {
|
|
14
12
|
const initialize = async () => {
|
|
@@ -12,9 +12,7 @@ export const ConfigManagerProvider: React.FC<{
|
|
|
12
12
|
configs,
|
|
13
13
|
children,
|
|
14
14
|
}) => {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
const [service] = useState(() => new ConfigService());
|
|
15
|
+
const [service] = useState(() => new ConfigService(configs));
|
|
18
16
|
const [isLoading, setIsLoading] = useState(true);
|
|
19
17
|
|
|
20
18
|
useEffect(() => {
|