@arc-js/config-manager 0.0.94 → 0.0.95
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/config.d.ts +12 -9
- package/config.js +902 -5
- package/config.min.js +1 -1
- package/core/ConfigService.d.ts +23 -7
- package/core/ConfigService.js +1018 -54
- package/core/ConfigService.min.js +1 -1
- package/{types.d.ts → core/types.d.ts} +7 -5
- package/hooks/useConfig.jsx +23 -16
- package/hooks/useConfig.tsx +26 -18
- package/index.d.ts +17 -0
- package/index.js +896 -0
- package/index.min.js +2 -0
- package/package.json +3 -2
- package/providers/ConfigProvider.jsx +61 -32
- package/providers/ConfigProvider.tsx +123 -79
- package/utils/loaders.d.ts +8 -11
- package/utils/loaders.js +21 -32
- package/utils/loaders.min.js +1 -1
- package/utils.d.ts +23 -0
- package/utils.js +94 -0
- package/utils.min.js +2 -0
- /package/{types.js → core/types.js} +0 -0
- /package/{types.min.js → core/types.min.js} +0 -0
|
@@ -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,t,s,o){return new(s=s||Promise)(function(i,t){function a(e){try{n(o.next(e))}catch(e){t(e)}}function r(e){try{n(o.throw(e))}catch(e){t(e)}}function n(e){var t;e.done?i(e.value):((t=e.value)instanceof s?t:new s(function(e){e(t)})).then(a,r)}n((o=o.apply(e,[])).next())})}var hasRequiredTimez,hasRequiredCooks,cooks={},timez={};function requireTimez(){if(!hasRequiredTimez){hasRequiredTimez=1,Object.defineProperty(timez,"__esModule",{value:!0});class g{constructor(e,t=!1){!1===this.dateChecker(e)?this._date=void 0:e instanceof g&&e&&null!=e&&e._date?this._date=new Date(null==e?void 0:e._date):e instanceof Date?this._date=new Date(e):"string"==typeof e?this._date=g.parseString(e,t):"number"==typeof e?this._date=new Date(e):null==e||"number"==typeof e&&isNaN(e)?this._date=new Date:this._date=void 0}static now(){return new g}static parse(e,t){return"string"==typeof t&&0<t.length&&(e instanceof g&&e&&null!=e&&e._date||e instanceof Date||"string"==typeof e||"number"==typeof e||null==e||"number"==typeof e&&isNaN(e))&&g.parseWithFormat(e,t)||new g(e)}static unix(e){return new g(1e3*e)}static utc(){var e=new Date;return new g(Date.UTC(e.getUTCFullYear(),e.getUTCMonth(),e.getUTCDate(),e.getUTCHours(),e.getUTCMinutes(),e.getUTCSeconds(),e.getUTCMilliseconds()))}year(){var e;return null==(e=this._date)?void 0:e.getFullYear()}month(){return this._date?this._date.getMonth()+1:void 0}date(){var e;return null==(e=this._date)?void 0:e.getDate()}hour(){var e;return null==(e=this._date)?void 0:e.getHours()}minute(){var e;return null==(e=this._date)?void 0:e.getMinutes()}second(){var e;return null==(e=this._date)?void 0:e.getSeconds()}millisecond(){var e;return null==(e=this._date)?void 0:e.getMilliseconds()}day(){var e;return null==(e=this._date)?void 0:e.getDay()}add(e,t){if(!this._date)return new g(void 0);var i=new Date(this._date);switch(t){case"years":i.setFullYear(i.getFullYear()+e);break;case"months":i.setMonth(i.getMonth()+e);break;case"days":i.setDate(i.getDate()+e);break;case"hours":i.setHours(i.getHours()+e);break;case"minutes":i.setMinutes(i.getMinutes()+e);break;case"seconds":i.setSeconds(i.getSeconds()+e);break;case"milliseconds":i.setMilliseconds(i.getMilliseconds()+e)}return new g(i)}subtract(e,t){return this.add(-e,t)}startOf(e){if(!this._date)return new g(void 0);var t=new Date(this._date);switch(e){case"year":t.setMonth(0,1),t.setHours(0,0,0,0);break;case"month":t.setDate(1),t.setHours(0,0,0,0);break;case"day":t.setHours(0,0,0,0);break;case"hour":t.setMinutes(0,0,0);break;case"minute":t.setSeconds(0,0);break;case"second":t.setMilliseconds(0)}return new g(t)}endOf(e){var t=this.startOf(e);switch(e){case"year":return t.add(1,"years").subtract(1,"milliseconds");case"month":return t.add(1,"months").subtract(1,"milliseconds");case"day":return t.add(1,"days").subtract(1,"milliseconds");case"hour":return t.add(1,"hours").subtract(1,"milliseconds");case"minute":return t.add(1,"minutes").subtract(1,"milliseconds");case"second":return t.add(1,"seconds").subtract(1,"milliseconds");default:return t}}isBefore(e,t="()"){t="]"===t[1],e=e instanceof g?e:new g(e);return!(!this._date||!e._date)&&(!t&&this._date<e._date||!!t&&this._date<=e._date)}isAfter(e,t="()"){t="["===t[0],e=e instanceof g?e:new g(e);return!(!this._date||!e._date)&&(!t&&this._date>e._date||!!t&&this._date>=e._date)}isSame(e,t){var i,e=e instanceof g?e:new g(e);return!t&&this._date&&e._date?this._date.getTime()===e._date.getTime():(i=t?this.startOf(t):void 0,e=t?e.startOf(t):void 0,!!(i&&null!=i&&i._date&&e&&null!=e&&e._date)&&i._date.getTime()===e._date.getTime())}isBetween(e,t,i="()"){var e=e instanceof g?e:new g(e),t=t instanceof g?t:new g(t),a="["===i[0],i="]"===i[1],a=a&&this.isSame(e)||this.isAfter(e),e=i&&this.isSame(t)||this.isBefore(t);return a&&e}format(e){if(!e)return this.toISOString();var t,i,a=g.PREDEFINED_FORMATS[e];if(a)return this.format(a);let r="",n=0;for(;n<e.length;)"["===e[n]?-1===(i=e.indexOf("]",n))?(r+=e[n],n++):(t=e.substring(n+1,i),r+=t,n=i+1):"%"===e[n]&&n+1<e.length?(t="%"+e[n+1],i=g.FORMAT_TOKENS[t],r+=i?i(this):t,n+=2):(r+=e[n],n++);return r}setTimezone(e){var t;return this._date?(t=this._date.getTimezoneOffset(),e=this.parseTimezoneOffset(e),e=new Date(this._date.getTime()+6e4*(e-t)),new g(e)):new g(void 0)}utc(){return this._date?new g(new Date(Date.UTC(this._date.getUTCFullYear(),this._date.getUTCMonth(),this._date.getUTCDate(),this._date.getUTCHours(),this._date.getUTCMinutes(),this._date.getUTCSeconds(),this._date.getUTCMilliseconds()))):new g(void 0)}local(){return this._date?new g(new Date(this._date.getFullYear(),this._date.getMonth(),this._date.getDate(),this._date.getHours(),this._date.getMinutes(),this._date.getSeconds(),this._date.getMilliseconds())):new g(void 0)}toString(){var e;return null==(e=this._date)?void 0:e.toString()}toISOString(){var e;return null==(e=this._date)?void 0:e.toISOString()}toDate(){return this._date?new Date(this._date):void 0}valueOf(){var e;return null==(e=this._date)?void 0:e.getTime()}unix(){return this._date?Math.floor(this._date.getTime()/1e3):void 0}utcOffset(){return this._date?-this._date.getTimezoneOffset():void 0}isCorrect(){return!!this._date&&!isNaN(this._date.getTime())}timezone(){if(this._date)try{return(new Intl.DateTimeFormat).resolvedOptions().timeZone||void 0}catch(e){return this.timezoneFromOffset()}}timezoneAbbr(){if(this._date)try{var e=new Intl.DateTimeFormat("en",{timeZoneName:"short"}).formatToParts(this._date).find(e=>"timeZoneName"===e.type);return(null==e?void 0:e.value)||void 0}catch(e){return this.timezoneAbbrFromOffset()}}timezoneName(){if(this._date)try{var e=new Intl.DateTimeFormat("en",{timeZoneName:"long"}).formatToParts(this._date).find(e=>"timeZoneName"===e.type);return(null==e?void 0:e.value)||void 0}catch(e){return this.timezoneNameFromOffset()}}timezoneOffsetString(){var e=this.utcOffset();if(void 0!==e)return(0<=e?"+":"-")+Math.floor(Math.abs(e)/60).toString().padStart(2,"0")+":"+(Math.abs(e)%60).toString().padStart(2,"0")}dateChecker(e){return e instanceof g&&!!e&&!(null==e||!e._date)||e instanceof Date||"string"==typeof e||"number"==typeof e||null==e||"number"==typeof e&&isNaN(e)}timezoneFromOffset(){var e=this.utcOffset();if(void 0!==e)return{0:"Etc/UTC",60:"Europe/Paris",120:"Europe/Athens",180:"Europe/Moscow",240:"Asia/Dubai",270:"Asia/Tehran",300:"Asia/Karachi",330:"Asia/Kolkata",345:"Asia/Rangoon",360:"Asia/Dhaka",390:"Asia/Yangon",420:"Asia/Bangkok",480:"Asia/Shanghai",525:"Asia/Kathmandu",540:"Asia/Tokyo",570:"Australia/Adelaide",600:"Australia/Sydney",630:"Australia/Lord_Howe",660:"Pacific/Noumea",675:"Australia/Eucla",720:"Pacific/Auckland",780:"Pacific/Chatham","-60":"Atlantic/Azores","-120":"America/Noronha","-180":"America/Argentina/Buenos_Aires","-210":"America/St_Johns","-240":"America/Halifax","-270":"America/Caracas","-300":"America/New_York","-360":"America/Chicago","-420":"America/Denver","-480":"America/Los_Angeles","-540":"America/Anchorage","-600":"Pacific/Honolulu","-660":"Pacific/Pago_Pago","-720":"Pacific/Kiritimati"}[e]||"Etc/GMT"+(0<=e?"-":"+")+Math.abs(e)/60}timezoneAbbrFromOffset(){var e=this.utcOffset();if(void 0!==e)return{0:"GMT",60:"CET","-300":"EST","-360":"CST","-420":"MST","-480":"PST"}[e]||"GMT"+(0<=e?"+":"")+e/60}timezoneNameFromOffset(){var e=this.utcOffset();if(void 0!==e)return{0:"Greenwich Mean Time",60:"Central European Time","-300":"Eastern Standard Time","-360":"Central Standard Time","-420":"Mountain Standard Time","-480":"Pacific Standard Time"}[e]||"GMT"+(0<=e?"+":"")+e/60}isDST(){if(this._date)try{var e=new Date(this._date.getFullYear(),0,1),t=new Date(this._date.getFullYear(),6,1),i=Math.max(e.getTimezoneOffset(),t.getTimezoneOffset());return this._date.getTimezoneOffset()<i}catch(e){}}static parseString(e,t=!1){var i=new Date(e);if(!isNaN(i.getTime()))return i;var a,r=[/^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})\.(\d{3})Z$/,/^(\d{4})-(\d{2})-(\d{2})$/,/^(\d{4})\/(\d{2})\/(\d{2}) (\d{2}):(\d{2}):(\d{2})$/,/^(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})$/];for(a of r){var n=e.match(a);if(n){n=n.slice(1).map(Number);if(a===r[0])return new Date(Date.UTC(n[0],n[1]-1,n[2],n[3],n[4],n[5],n[6]));if(a===r[1])return new Date(n[0],n[1]-1,n[2]);if(a===r[2])return new Date(n[0],n[1]-1,n[2],n[3],n[4],n[5]);if(a===r[3])return new Date(n[0],n[1]-1,n[2],n[3],n[4],n[5])}}i=new Date(e);if(!isNaN(i.getTime()))return i;if(t)throw new Error("Unable to parse date string: "+e)}static parseWithFormat(e,r){if(e&&r){var n=String(e).trim();if(n){var s={Y:{regex:/\d{4}/,extract:e=>parseInt(e,10)},y:{regex:/\d{2}/,extract:e=>{e=parseInt(e,10);return 70<=e?1900+e:2e3+e}},m:{regex:/\d{1,2}/,extract:e=>parseInt(e,10)},d:{regex:/\d{1,2}/,extract:e=>parseInt(e,10)},H:{regex:/\d{1,2}/,extract:e=>parseInt(e,10)},M:{regex:/\d{1,2}/,extract:e=>parseInt(e,10)},S:{regex:/\d{1,2}/,extract:e=>parseInt(e,10)},f:{regex:/\d{1,3}/,extract:e=>parseInt(e,10)}},o={year:(new Date).getFullYear(),month:1,day:1,hour:0,minute:0,second:0,millisecond:0};let e=0,t=0,i=!1,a="";for(;t<r.length&&e<n.length;){var d=r[t];if("["===d)i=!0,a="",t++;else if("]"===d&&i){if(n.substring(e,e+a.length)!==a)return;e+=a.length,i=!1,a="",t++}else if(i)a+=d,t++;else if("%"===d&&t+1<r.length){var u=r[t+1],c=s[u];if(c){var l=n.substring(e).match(c.regex);if(!l||0!==l.index)return;var l=l[0],f=c.extract(l);switch(u){case"Y":case"y":o.year=f;break;case"m":o.month=f;break;case"d":o.day=f;break;case"H":o.hour=f;break;case"M":o.minute=f;break;case"S":o.second=f;break;case"f":o.millisecond=f}e+=l.length}else e++;t+=2}else{if(d!==n[e])return;e++,t++}}if(!(o.month<1||12<o.month||o.day<1||31<o.day||o.hour<0||23<o.hour||o.minute<0||59<o.minute||o.second<0||59<o.second||o.millisecond<0||999<o.millisecond))try{var h=new Date(o.year,o.month-1,o.day,o.hour,o.minute,o.second,o.millisecond);if(!isNaN(h.getTime()))return new g(h)}catch(e){}}}}static getTokenLength(e){return{Y:4,y:2,m:2,d:2,H:2,M:2,S:2,f:3,z:5}[e]||1}parseTimezoneOffset(e){var t={UTC:0,EST:-300,EDT:-240,CST:-360,CDT:-300,PST:-480,PDT:-420};return void 0!==t[e.toUpperCase()]?t[e.toUpperCase()]:(t=e.match(/^([+-])(\d{1,2}):?(\d{2})?$/))?("+"===t[1]?1:-1)*(60*parseInt(t[2],10)+(t[3]?parseInt(t[3],10):0)):this._date?-this._date.getTimezoneOffset():0}static get FORMATS(){return Object.assign({},g.PREDEFINED_FORMATS)}static exposeToGlobal(){"undefined"!=typeof window&&(window.Timez=g)}}g.FORMAT_TOKENS={"%Y":e=>null==(e=e.year())?void 0:e.toString().padStart(4,"0"),"%y":e=>null==(e=e.year())?void 0:e.toString().slice(-2).padStart(2,"0"),"%m":e=>null==(e=e.month())?void 0:e.toString().padStart(2,"0"),"%d":e=>null==(e=e.date())?void 0:e.toString().padStart(2,"0"),"%H":e=>null==(e=e.hour())?void 0:e.toString().padStart(2,"0"),"%M":e=>null==(e=e.minute())?void 0:e.toString().padStart(2,"0"),"%S":e=>null==(e=e.second())?void 0:e.toString().padStart(2,"0"),"%f":e=>null==(e=e.millisecond())?void 0:e.toString().padStart(3,"0"),"%z":e=>{e=e.utcOffset();if(e)return(0<=e?"+":"-")+Math.floor(Math.abs(e)/60).toString().padStart(2,"0")+(Math.abs(e)%60).toString().padStart(2,"0")},"%s":e=>{e=e.valueOf();return e?Math.floor(e/1e3).toString():void 0}},g.PREDEFINED_FORMATS={ISO:"%Y-%m-%dT%H:%M:%S.%fZ",ISO_DATE:"%Y-%m-%d",ISO_TIME:"%H:%M:%S.%fZ",COMPACT:"%Y%m%d%H%M%S",SLASH_DATETIME:"%Y/%m/%d %H:%M:%S.%fZ",SLASH_DATETIME_SEC:"%Y/%m/%d %H:%M:%S",SLASH_DATETIME_MIN:"%Y/%m/%d %H:%M",EUROPEAN:"%d/%m/%Y %H:%M:%S GMT%z",SLASH_DATE:"%Y/%m/%d",TIME_MICRO:"%H:%M:%S.%fZ",TIME_SEC:"%H:%M:%S",CUSTOM_GREETING:"[Bonjour celestin, ][la date actuelle est:: le] %d/%m/%Y [à] %H:%M:%S.%f[Z]"},"undefined"!=typeof window&&(window.Timez=g),timez.Timez=g,timez.default=g}return timez}function requireCooks(){if(!hasRequiredCooks){hasRequiredCooks=1,Object.defineProperty(cooks,"__esModule",{value:!0});var r=requireTimez(),e=["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"];[...e,...e.map(e=>e.toUpperCase())];class t{static set(e,t,i={}){if(this.isBrowser())try{var a=this.serialize(t),r=encodeURIComponent(a),n=this.buildCookieString(e,r,i);document.cookie=n}catch(e){}}static get(e){if(!this.isBrowser())return null;try{var t,i=this.getAllCookies()[e];return i?(t=decodeURIComponent(i),this.deserialize(t)):null}catch(e){return null}}static remove(e,t="/",i){this.isBrowser()&&(t={expires:new Date(0),path:t,domain:i},this.set(e,"",t))}static has(e){return null!==this.get(e)}static keys(){var e;return this.isBrowser()?(e=this.getAllCookies(),Object.keys(e)):[]}static clear(){var e;this.isBrowser()&&(e=this.getAllCookies(),Object.keys(e).forEach(e=>{this.remove(e)}))}static serialize(e){return e instanceof Date?JSON.stringify({__type:"Date",__value:e.toISOString()}):JSON.stringify(e)}static deserialize(e){e=JSON.parse(e);return e&&"object"==typeof e&&"Date"===e.__type?new Date(e.__value):e}static buildCookieString(e,t,i){i=Object.assign(Object.assign({},this.DEFAULT_OPTIONS),i);let a=e+"="+t;if(void 0!==i.expires){let e;e="number"==typeof i.expires?(new r.Timez).add(i.expires,"seconds").toDate()||new Date:i.expires,a+="; expires="+e.toUTCString()}return i.path&&(a+="; path="+i.path),i.domain&&(a+="; domain="+i.domain),i.secure&&(a+="; secure"),i.sameSite&&(a+="; samesite="+i.sameSite),a}static getAllCookies(){return document.cookie.split(";").reduce((e,t)=>{var[t,i]=t.split("=").map(e=>e.trim());return t&&(e[t]=i||""),e},{})}static isBrowser(){return"undefined"!=typeof window&&"undefined"!=typeof document}static exposeToGlobal(){"undefined"!=typeof window&&(window.Cooks=t)}}t.DEFAULT_OPTIONS={path:"/",secure:!0,sameSite:"lax"},"undefined"!=typeof window&&(window.Cooks=t),cooks.Cooks=t,cooks.default=t}return cooks}requireCooks();let DEFAULT_SCOPE="app",mergeDeep=(e,t)=>{if("object"!=typeof e||"object"!=typeof t)return t;var i,a=Object.assign({},e);for(i in t)t.hasOwnProperty(i)&&(e.hasOwnProperty(i)?a[i]=mergeDeep(e[i],t[i]):a[i]=t[i]);return a},loadBaseConfig=(e,t)=>__awaiter(void 0,void 0,void 0,function*(){if(null==t||!t.base[e])return{};try{return yield(0,t.base[e])()}catch(e){return{}}}),loadModulesConfig=r=>__awaiter(void 0,void 0,void 0,function*(){var e=[];if(null!=r&&r.modules)for(var[t,i]of Object.entries(r.modules))try{var a=yield i();e.push({moduleName:t,config:a})}catch(e){}return e}),loadModuleConfig=(i,a)=>__awaiter(void 0,void 0,void 0,function*(){var e;if(null!=(e=null==a?void 0:a.modules)&&e[i])try{var t=yield(0,a.modules[i])();return{moduleName:i,config:t}}catch(e){}});class ConfigService{constructor(e=[DEFAULT_SCOPE],t){Object.defineProperty(this,"configs",{enumerable:!0,configurable:!0,writable:!0,value:{}}),Object.defineProperty(this,"currentScope",{enumerable:!0,configurable:!0,writable:!0,value:DEFAULT_SCOPE}),Object.defineProperty(this,"loadedModules",{enumerable:!0,configurable:!0,writable:!0,value:new Set}),Object.defineProperty(this,"supportedScopes",{enumerable:!0,configurable:!0,writable:!0,value:[DEFAULT_SCOPE]}),Object.defineProperty(this,"configManagerConfig",{enumerable:!0,configurable:!0,writable:!0,value:null}),this.supportedScopes=e,t&&(this.configManagerConfig=t)}setConfigManagerConfig(e){this.configManagerConfig=e}initialize(e){return __awaiter(this,void 0,void 0,function*(){if(!this.configManagerConfig)throw new Error("Config manager config not set");this.currentScope=e,yield this.loadScope(e)})}loadScope(i){return __awaiter(this,void 0,void 0,function*(){var e,t;this.supportedScopes.includes(i)&&this.configManagerConfig&&(e=yield loadBaseConfig(i,this.configManagerConfig),t=yield loadModulesConfig(this.configManagerConfig),this.configs[i]=t.reduce((e,{moduleName:t,config:i})=>mergeDeep(e,{[t]:i}),{app:e}))})}loadModule(i){return __awaiter(this,void 0,void 0,function*(){if(!this.loadedModules.has(i)&&this.configManagerConfig){var e=yield loadModuleConfig(i,this.configManagerConfig);if(null!=e&&e.config)for(var t of this.supportedScopes)this.configs[t]||(this.configs[t]={app:{}}),this.configs[t][i]=e.config;this.loadedModules.add(i)}})}get(e,t={}){var{moduleName:t="app",defaultValue:i=void 0}=t;return this.findConfig(e,t)||i}findConfig(e,t){var i=this.configs[this.currentScope];if(i&&i[t])return e.split(".").reduce((e,t)=>e&&void 0!==e[t]?e[t]:void 0,i[t])}setScope(e){this.supportedScopes.includes(e)&&(this.currentScope=e)}getCurrentScope(){return this.currentScope}getAllConfigs(){return this.configs[this.currentScope]||{}}}export{ConfigService};
|
|
2
2
|
//# sourceMappingURL=ConfigService.min.js.map
|
|
@@ -1,16 +1,18 @@
|
|
|
1
|
+
type ConfigScope = string;
|
|
2
|
+
|
|
1
3
|
type ConfigResource = Record<string, any>;
|
|
2
4
|
type NamespacedConfigs = Record<string, ConfigResource>;
|
|
5
|
+
type ScopeConfigs = Record<ConfigScope, NamespacedConfigs>;
|
|
3
6
|
interface ConfigOptions {
|
|
4
7
|
moduleName?: string;
|
|
5
8
|
defaultValue?: any;
|
|
6
|
-
pathSeparator?: string;
|
|
7
9
|
}
|
|
8
|
-
interface
|
|
10
|
+
interface ArcConfigContextValue {
|
|
9
11
|
get: (key: string, options?: ConfigOptions) => any;
|
|
10
|
-
|
|
11
|
-
|
|
12
|
+
changeScope: (scope: ConfigScope) => Promise<void>;
|
|
13
|
+
currentScope: ConfigScope;
|
|
12
14
|
isLoading: boolean;
|
|
13
15
|
loadModuleConfig: (moduleName: string) => Promise<void>;
|
|
14
16
|
}
|
|
15
17
|
|
|
16
|
-
export type {
|
|
18
|
+
export type { ArcConfigContextValue, ConfigOptions, ConfigResource, NamespacedConfigs, ScopeConfigs };
|
package/hooks/useConfig.jsx
CHANGED
|
@@ -1,33 +1,40 @@
|
|
|
1
1
|
import React from "react";
|
|
2
2
|
import { useEffect, useState, useCallback } from 'react';
|
|
3
|
-
import {
|
|
4
|
-
export
|
|
5
|
-
const
|
|
3
|
+
import { useArcConfig } from '../providers/ConfigProvider';
|
|
4
|
+
export function useConfig(moduleName) {
|
|
5
|
+
const arcConfig = useArcConfig();
|
|
6
6
|
const [isModuleLoading, setIsModuleLoading] = useState(false);
|
|
7
7
|
const [moduleLoaded, setModuleLoaded] = useState(!moduleName);
|
|
8
|
-
const
|
|
8
|
+
const get = useCallback((key, options) => {
|
|
9
|
+
if (moduleName && !moduleLoaded && !options?.moduleName) {
|
|
10
|
+
console.warn(`⚠️ Module ${moduleName} not loaded yet, using default value`);
|
|
11
|
+
return options?.defaultValue || undefined;
|
|
12
|
+
}
|
|
9
13
|
const finalOptions = {
|
|
10
14
|
...options,
|
|
11
|
-
moduleName: options?.moduleName || moduleName || '
|
|
15
|
+
moduleName: options?.moduleName || moduleName || 'app'
|
|
12
16
|
};
|
|
13
|
-
return
|
|
14
|
-
}, [
|
|
17
|
+
return arcConfig.get(key, finalOptions);
|
|
18
|
+
}, [arcConfig, moduleName, moduleLoaded]);
|
|
15
19
|
useEffect(() => {
|
|
16
|
-
if (moduleName && !moduleLoaded) {
|
|
20
|
+
if (moduleName && !moduleLoaded && !arcConfig.isLoading) {
|
|
17
21
|
setIsModuleLoading(true);
|
|
18
|
-
|
|
22
|
+
arcConfig.loadModuleConfig(moduleName).then(() => {
|
|
19
23
|
setModuleLoaded(true);
|
|
24
|
+
}).catch(error => {
|
|
25
|
+
console.error(`❌ Failed to load module ${moduleName}:`, error);
|
|
20
26
|
}).finally(() => {
|
|
21
27
|
setIsModuleLoading(false);
|
|
22
28
|
});
|
|
23
29
|
}
|
|
24
|
-
}, [moduleName, moduleLoaded,
|
|
30
|
+
}, [moduleName, moduleLoaded, arcConfig, arcConfig.isLoading]);
|
|
25
31
|
return {
|
|
26
|
-
cf,
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
isLoading:
|
|
32
|
+
cf: get,
|
|
33
|
+
changeScope: arcConfig.changeScope,
|
|
34
|
+
currentScope: arcConfig.currentScope,
|
|
35
|
+
isLoading: arcConfig.isLoading || isModuleLoading,
|
|
30
36
|
isModuleLoaded: moduleLoaded,
|
|
31
|
-
|
|
37
|
+
loadModule: arcConfig.loadModuleConfig,
|
|
38
|
+
isInitialized: arcConfig.isInitialized
|
|
32
39
|
};
|
|
33
|
-
}
|
|
40
|
+
}
|
package/hooks/useConfig.tsx
CHANGED
|
@@ -1,40 +1,48 @@
|
|
|
1
|
-
// @arc-js/config-manager/hooks/useConfig.tsx
|
|
2
1
|
import { useEffect, useState, useCallback } from 'react';
|
|
3
|
-
import {
|
|
2
|
+
import { useArcConfig } from '../providers/ConfigProvider';
|
|
4
3
|
|
|
5
|
-
export
|
|
6
|
-
const
|
|
4
|
+
export function useConfig(moduleName?: string) {
|
|
5
|
+
const arcConfig = useArcConfig();
|
|
7
6
|
const [isModuleLoading, setIsModuleLoading] = useState(false);
|
|
8
7
|
const [moduleLoaded, setModuleLoaded] = useState(!moduleName);
|
|
9
8
|
|
|
10
|
-
const
|
|
9
|
+
const get = useCallback((key: string, options?: any) => {
|
|
10
|
+
if (moduleName && !moduleLoaded && !options?.moduleName) {
|
|
11
|
+
console.warn(`⚠️ Module ${moduleName} not loaded yet, using default value`);
|
|
12
|
+
return options?.defaultValue || undefined;
|
|
13
|
+
}
|
|
14
|
+
|
|
11
15
|
const finalOptions = {
|
|
12
16
|
...options,
|
|
13
|
-
moduleName: options?.moduleName || moduleName || '
|
|
17
|
+
moduleName: options?.moduleName || moduleName || 'app'
|
|
14
18
|
};
|
|
15
|
-
|
|
16
|
-
return
|
|
17
|
-
}, [
|
|
19
|
+
|
|
20
|
+
return arcConfig.get(key, finalOptions);
|
|
21
|
+
}, [arcConfig, moduleName, moduleLoaded]);
|
|
18
22
|
|
|
19
23
|
useEffect(() => {
|
|
20
|
-
if (moduleName && !moduleLoaded) {
|
|
24
|
+
if (moduleName && !moduleLoaded && !arcConfig.isLoading) {
|
|
21
25
|
setIsModuleLoading(true);
|
|
22
|
-
|
|
26
|
+
arcConfig.loadModuleConfig(moduleName)
|
|
23
27
|
.then(() => {
|
|
24
28
|
setModuleLoaded(true);
|
|
25
29
|
})
|
|
30
|
+
.catch(error => {
|
|
31
|
+
console.error(`❌ Failed to load module ${moduleName}:`, error);
|
|
32
|
+
})
|
|
26
33
|
.finally(() => {
|
|
27
34
|
setIsModuleLoading(false);
|
|
28
35
|
});
|
|
29
36
|
}
|
|
30
|
-
}, [moduleName, moduleLoaded,
|
|
37
|
+
}, [moduleName, moduleLoaded, arcConfig, arcConfig.isLoading]);
|
|
31
38
|
|
|
32
39
|
return {
|
|
33
|
-
cf,
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
isLoading:
|
|
40
|
+
cf: get,
|
|
41
|
+
changeScope: arcConfig.changeScope,
|
|
42
|
+
currentScope: arcConfig.currentScope,
|
|
43
|
+
isLoading: arcConfig.isLoading || isModuleLoading,
|
|
37
44
|
isModuleLoaded: moduleLoaded,
|
|
38
|
-
|
|
45
|
+
loadModule: arcConfig.loadModuleConfig,
|
|
46
|
+
isInitialized: arcConfig.isInitialized,
|
|
39
47
|
};
|
|
40
|
-
}
|
|
48
|
+
}
|
package/index.d.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
declare const DEFAULT_SCOPE = "app";
|
|
2
|
+
type ConfigScope = string;
|
|
3
|
+
|
|
4
|
+
interface ConfigOptions {
|
|
5
|
+
moduleName?: string;
|
|
6
|
+
defaultValue?: any;
|
|
7
|
+
}
|
|
8
|
+
interface ArcConfigContextValue {
|
|
9
|
+
get: (key: string, options?: ConfigOptions) => any;
|
|
10
|
+
changeScope: (scope: ConfigScope) => Promise<void>;
|
|
11
|
+
currentScope: ConfigScope;
|
|
12
|
+
isLoading: boolean;
|
|
13
|
+
loadModuleConfig: (moduleName: string) => Promise<void>;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export { DEFAULT_SCOPE };
|
|
17
|
+
export type { ArcConfigContextValue, ConfigOptions };
|