@arc-js/config-manager 0.0.92 → 0.0.94

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,8 +7,7 @@ interface ConfigOptions {
7
7
  declare class ConfigService {
8
8
  private resources;
9
9
  private loadedModules;
10
- private configs;
11
- constructor(configs?: any);
10
+ constructor();
12
11
  initialize(): Promise<void>;
13
12
  loadAllConfigs(): Promise<void>;
14
13
  loadModule(moduleName: string): Promise<void>;
@@ -36,6 +36,37 @@ 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
+ });
39
70
  const loadModuleConfig = (moduleName) => __awaiter(void 0, void 0, void 0, function* () {
40
71
  var _a;
41
72
  if (!((_a = void 0 ) === null || _a === void 0 ? void 0 : _a[moduleName])) {
@@ -56,7 +87,7 @@ const loadModuleConfig = (moduleName) => __awaiter(void 0, void 0, void 0, funct
56
87
  });
57
88
 
58
89
  class ConfigService {
59
- constructor(configs) {
90
+ constructor() {
60
91
  Object.defineProperty(this, "resources", {
61
92
  enumerable: true,
62
93
  configurable: true,
@@ -69,13 +100,6 @@ class ConfigService {
69
100
  writable: true,
70
101
  value: new Set()
71
102
  });
72
- Object.defineProperty(this, "configs", {
73
- enumerable: true,
74
- configurable: true,
75
- writable: true,
76
- value: null
77
- });
78
- this.configs = configs;
79
103
  }
80
104
  initialize() {
81
105
  return __awaiter(this, void 0, void 0, function* () {
@@ -84,45 +108,14 @@ class ConfigService {
84
108
  }
85
109
  loadAllConfigs() {
86
110
  return __awaiter(this, void 0, void 0, function* () {
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
- }
111
+ const base = yield loadBaseConfig();
112
+ const modules = yield loadModulesConfigs();
113
+ this.resources = modules.reduce((acc, { moduleName, config }) => {
114
+ return mergeDeep(acc, { [moduleName]: config });
115
+ }, { base });
116
+ modules.forEach(({ moduleName }) => {
117
+ this.loadedModules.add(moduleName);
118
+ });
126
119
  });
127
120
  }
128
121
  loadModule(moduleName) {
@@ -1,2 +1,2 @@
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};
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};
2
2
  //# sourceMappingURL=ConfigService.min.js.map
@@ -1,3 +1,4 @@
1
+ // @arc-js/config-manager/hooks/useConfig.tsx
1
2
  import { useEffect, useState, useCallback } from 'react';
2
3
  import { useConfigManager } from '../providers/ConfigProvider';
3
4
 
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "0.0.92",
6
+ "version": "0.0.94",
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,13 +1,16 @@
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';
4
5
  const ConfigManagerContext = createContext(null);
5
- export const ConfigManagerProvider = ({
6
- configs,
7
- children
8
- }) => {
9
- const [service] = useState(() => new ConfigService(configs))
10
- const [isLoading, setIsLoading] = useState(true);
6
+ const useConfigManagerValue = configManagerConfig => {
7
+ const [service] = useState(() => new ConfigService());
8
+ const [isLoading, setIsLoading] = useState(true)
9
+
10
+ useEffect(() => {
11
+ setConfigManagerConfig(configManagerConfig);
12
+ }, [configManagerConfig])
13
+
11
14
  useEffect(() => {
12
15
  const initialize = async () => {
13
16
  setIsLoading(true);
@@ -47,21 +50,25 @@ export const ConfigManagerProvider = ({
47
50
  const getConfig = useCallback(moduleName => {
48
51
  return service.getConfig(moduleName);
49
52
  }, [service]);
50
- const value = {
53
+ return {
51
54
  get,
52
55
  getConfig,
53
56
  reloadConfig,
54
57
  isLoading,
55
58
  loadModuleConfig
56
59
  };
60
+ };
61
+ export const ConfigManagerProvider = ({
62
+ configs,
63
+ children
64
+ }) => {
65
+ const value = useConfigManagerValue(configs);
57
66
  return React.createElement(ConfigManagerContext.Provider, {
58
67
  value: value
59
68
  }, children);
60
69
  };
61
70
  export const useConfigManager = () => {
62
71
  const context = useContext(ConfigManagerContext);
63
- if (!context) {
64
- throw new Error('useConfigManager must be used within a ConfigManagerProvider');
65
- }
72
+ if (!context) throw new Error('useConfigManager must be used within a ConfigManagerProvider');
66
73
  return context;
67
74
  };
@@ -1,83 +1,90 @@
1
+ // @arc-js/config-manager/providers/ConfigProvider.tsx
1
2
  import { createContext, useContext, useState, useEffect, useCallback } from 'react';
2
3
  import { ConfigService } from '../core/ConfigService';
3
4
  import { setConfigManagerConfig } from '../config';
4
5
  import type { ConfigManagerConfig } from '../config';
5
6
 
6
- const ConfigManagerContext = createContext<any>(null);
7
+ const ConfigManagerContext = createContext<ReturnType<typeof useConfigManagerValue> | null>(null);
7
8
 
8
- export const ConfigManagerProvider: React.FC<{
9
- children: React.ReactNode
10
- configs: ConfigManagerConfig
11
- }> = ({
12
- configs,
13
- children,
14
- }) => {
15
- const [service] = useState(() => new ConfigService(configs));
16
- const [isLoading, setIsLoading] = useState(true);
9
+ const useConfigManagerValue = (
10
+ configManagerConfig: ConfigManagerConfig
11
+ ) => {
12
+ const [service] = useState(() => new ConfigService());
13
+ const [isLoading, setIsLoading] = useState(true);
17
14
 
18
- useEffect(() => {
19
- const initialize = async () => {
20
- setIsLoading(true);
21
- try {
22
- await service.initialize();
23
- } catch (error) {
24
- console.error('Failed to initialize config manager:', error);
25
- } finally {
26
- setIsLoading(false);
27
- }
28
- };
29
- initialize();
30
- }, [service]);
15
+
16
+ useEffect(() => {
17
+ setConfigManagerConfig(configManagerConfig);
18
+ }, [configManagerConfig]);
31
19
 
32
- const reloadConfig = useCallback(async () => {
20
+
21
+ useEffect(() => {
22
+ const initialize = async () => {
33
23
  setIsLoading(true);
34
24
  try {
35
- await service.reload();
25
+ await service.initialize();
36
26
  } catch (error) {
37
- console.error('Failed to reload config:', error);
27
+ console.error('Failed to initialize config manager:', error);
38
28
  } finally {
39
29
  setIsLoading(false);
40
30
  }
41
- }, [service]);
31
+ };
32
+ initialize();
33
+ }, [service]);
42
34
 
43
- const loadModuleConfig = useCallback(async (moduleName: string) => {
44
- setIsLoading(true);
45
- try {
46
- await service.loadModule(moduleName);
47
- } catch (error) {
48
- console.error(`Failed to load module config ${moduleName}:`, error);
49
- } finally {
50
- setIsLoading(false);
51
- }
52
- }, [service]);
35
+ const reloadConfig = useCallback(async () => {
36
+ setIsLoading(true);
37
+ try {
38
+ await service.reload();
39
+ } catch (error) {
40
+ console.error('Failed to reload config:', error);
41
+ } finally {
42
+ setIsLoading(false);
43
+ }
44
+ }, [service]);
53
45
 
54
- const get = useCallback((key: string, options?: any) => {
55
- return service.get(key, options);
56
- }, [service]);
46
+ const loadModuleConfig = useCallback(async (moduleName: string) => {
47
+ setIsLoading(true);
48
+ try {
49
+ await service.loadModule(moduleName);
50
+ } catch (error) {
51
+ console.error(`Failed to load module config ${moduleName}:`, error);
52
+ } finally {
53
+ setIsLoading(false);
54
+ }
55
+ }, [service]);
57
56
 
58
- const getConfig = useCallback((moduleName?: string) => {
59
- return service.getConfig(moduleName);
60
- }, [service]);
57
+ const get = useCallback((key: string, options?: any) => {
58
+ return service.get(key, options);
59
+ }, [service]);
61
60
 
62
- const value = {
63
- get,
64
- getConfig,
65
- reloadConfig,
66
- isLoading,
67
- loadModuleConfig,
68
- };
61
+ const getConfig = useCallback((moduleName?: string) => {
62
+ return service.getConfig(moduleName);
63
+ }, [service]);
69
64
 
70
- return (
71
- <ConfigManagerContext.Provider value={value}>
72
- {children}
73
- </ConfigManagerContext.Provider>
74
- );
65
+ return {
66
+ get,
67
+ getConfig,
68
+ reloadConfig,
69
+ isLoading,
70
+ loadModuleConfig,
75
71
  };
72
+ };
73
+
74
+ export const ConfigManagerProvider: React.FC<{
75
+ children: React.ReactNode
76
+ configs: ConfigManagerConfig
77
+ }> = ({
78
+ configs,
79
+ children,
80
+ }) => {
81
+ const value = useConfigManagerValue(configs);
82
+
83
+ return <ConfigManagerContext.Provider value={value}>{children}</ConfigManagerContext.Provider>;
84
+ };
76
85
 
77
86
  export const useConfigManager = () => {
78
87
  const context = useContext(ConfigManagerContext);
79
- if (!context) {
80
- throw new Error('useConfigManager must be used within a ConfigManagerProvider');
81
- }
88
+ if (!context) throw new Error('useConfigManager must be used within a ConfigManagerProvider');
82
89
  return context;
83
90
  };
package/index.d.ts DELETED
@@ -1,3 +0,0 @@
1
- declare const _default: {};
2
-
3
- export { _default as default };
package/index.js DELETED
@@ -1,3 +0,0 @@
1
- var index = {};
2
-
3
- export { index as default };
package/index.min.js DELETED
@@ -1,2 +0,0 @@
1
- var index={};export{index as default};
2
- //# sourceMappingURL=index.min.js.map