@arc-js/config-manager 0.0.9 → 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.
@@ -7,7 +7,8 @@ interface ConfigOptions {
7
7
  declare class ConfigService {
8
8
  private resources;
9
9
  private loadedModules;
10
- constructor();
10
+ private configs;
11
+ constructor(configs?: any);
11
12
  initialize(): Promise<void>;
12
13
  loadAllConfigs(): Promise<void>;
13
14
  loadModule(moduleName: string): Promise<void>;
@@ -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
- const base = yield loadBaseConfig();
112
- console.log('Base config loaded:', base);
113
- const modules = yield loadModulesConfigs();
114
- console.log('Modules configs loaded:', modules);
115
- this.resources = modules.reduce((acc, { moduleName, config }) => {
116
- return mergeDeep(acc, { [moduleName]: config });
117
- }, { base });
118
- modules.forEach(({ moduleName }) => {
119
- this.loadedModules.add(moduleName);
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,d,l){return new(d=d||Promise)(function(i,o){function n(e){try{t(l.next(e))}catch(e){o(e)}}function r(e){try{t(l.throw(e))}catch(e){o(e)}}function t(e){var o;e.done?i(e.value):((o=e.value)instanceof d?o:new d(function(e){e(o)})).then(n,r)}t((l=l.apply(e,a||[])).next())})}let mergeDeep=(e,o)=>{if("object"!=typeof e||"object"!=typeof o)return o;var i,n=Object.assign({},e);for(i in o)o.hasOwnProperty(i)&&(e.hasOwnProperty(i)?n[i]=mergeDeep(e[i],o[i]):n[i]=o[i]);return n},configManagerConfig=null,loadBaseConfig=()=>__awaiter(void 0,void 0,void 0,function*(){try{return null!=configManagerConfig&&configManagerConfig.base?(yield Promise.all(Object.entries(configManagerConfig.base).map(e=>__awaiter(void 0,[e],void 0,function*([o,e]){try{return{key:o,config:yield e()}}catch(e){return{key:o,config:{}}}})))).reduce((e,{config:o})=>Object.assign(Object.assign({},e),o),{}):{}}catch(e){return{}}}),loadModulesConfigs=()=>__awaiter(void 0,void 0,void 0,function*(){return[]}),loadModuleConfig=e=>__awaiter(void 0,void 0,void 0,function*(){});class ConfigService{constructor(){Object.defineProperty(this,"resources",{enumerable:!0,configurable:!0,writable:!0,value:{}}),Object.defineProperty(this,"loadedModules",{enumerable:!0,configurable:!0,writable:!0,value:new Set})}initialize(){return __awaiter(this,void 0,void 0,function*(){yield this.loadAllConfigs()})}loadAllConfigs(){return __awaiter(this,void 0,void 0,function*(){var e=yield loadBaseConfig(),o=yield loadModulesConfigs();this.resources=o.reduce((e,{moduleName:o,config:i})=>mergeDeep(e,{[o]:i}),{base:e}),o.forEach(({moduleName:e})=>{this.loadedModules.add(e)})})}loadModule(o){return __awaiter(this,void 0,void 0,function*(){var e;this.loadedModules.has(o)||null!=(e=yield loadModuleConfig(o))&&e.config&&(this.resources[o]=mergeDeep(this.resources[o]||{},e.config),this.loadedModules.add(o))})}get(e,o={}){var{moduleName:o="base",defaultValue:i=void 0,pathSeparator:n="."}=o,o=this.resources[o];return o&&void 0!==(e=e.split(n).reduce((e,o)=>e&&void 0!==e[o]?e[o]:void 0,o))?e:i}getConfig(e="base"){return this.resources[e]||{}}reload(){return this.loadAllConfigs()}}export{ConfigService};
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.9",
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,17 +1,13 @@
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
- const [service] = useState(() => new ConfigService());
9
+ const [service] = useState(() => new ConfigService(configs))
11
10
  const [isLoading, setIsLoading] = useState(true);
12
- useEffect(() => {
13
- setConfigManagerConfig(configs);
14
- }, [configs]);
15
11
  useEffect(() => {
16
12
  const initialize = async () => {
17
13
  setIsLoading(true);
@@ -12,13 +12,9 @@ export const ConfigManagerProvider: React.FC<{
12
12
  configs,
13
13
  children,
14
14
  }) => {
15
- const [service] = useState(() => new ConfigService());
15
+ const [service] = useState(() => new ConfigService(configs));
16
16
  const [isLoading, setIsLoading] = useState(true);
17
17
 
18
- useEffect(() => {
19
- setConfigManagerConfig(configs);
20
- }, [configs]);
21
-
22
18
  useEffect(() => {
23
19
  const initialize = async () => {
24
20
  setIsLoading(true);