@vlian/framework 1.2.59 → 1.2.60
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/dist/analytics/index.cjs +1 -22
- package/dist/analytics.umd.js +1 -1
- package/dist/components/LocaleSwitch.cjs +1 -116
- package/dist/components/ThemeSwitch.cjs +1 -115
- package/dist/components/index.cjs +1 -20
- package/dist/components/persistence.cjs +1 -58
- package/dist/core/Test.cjs +1 -64
- package/dist/core/app/AppContext.cjs +1 -348
- package/dist/core/app/AppContext.types.cjs +1 -4
- package/dist/core/app/BasicLayout.cjs +1 -122
- package/dist/core/app/DefaultApp.cjs +1 -150
- package/dist/core/app/index.cjs +1 -41
- package/dist/core/config/AppConfig.cjs +1 -139
- package/dist/core/config/ConfigLoader.cjs +1 -323
- package/dist/core/config/ConfigValidator.cjs +2 -133
- package/dist/core/config/index.cjs +1 -28
- package/dist/core/dev/DevTools.cjs +1 -226
- package/dist/core/error/ErrorBoundary.cjs +1 -401
- package/dist/core/error/ErrorHandler.cjs +1 -275
- package/dist/core/error/index.cjs +1 -34
- package/dist/core/event/AppEventBus.cjs +1 -444
- package/dist/core/event/frameworkEvents.cjs +1 -141
- package/dist/core/event/hooks.cjs +1 -69
- package/dist/core/event/index.cjs +1 -41
- package/dist/core/event/types.cjs +1 -62
- package/dist/core/event/useEventBus.cjs +1 -25
- package/dist/core/index.cjs +1 -140
- package/dist/core/initialization/InitializationErrorThrower.cjs +1 -75
- package/dist/core/initialization/index.cjs +1 -26
- package/dist/core/initialization/initialization.cjs +1 -64
- package/dist/core/initialization/initializationErrorState.cjs +1 -66
- package/dist/core/kernel/defaultAdapters.cjs +1 -184
- package/dist/core/kernel/errors.cjs +1 -69
- package/dist/core/kernel/index.cjs +1 -20
- package/dist/core/kernel/startKernel.cjs +1 -200
- package/dist/core/kernel/types.cjs +1 -4
- package/dist/core/middleware.cjs +1 -73
- package/dist/core/plugin/PluginEventBus.cjs +1 -298
- package/dist/core/plugin/PluginSandbox.cjs +1 -137
- package/dist/core/plugin.cjs +1 -494
- package/dist/core/router/RouterManager.cjs +1 -286
- package/dist/core/router/adapter/AdapterManager.cjs +1 -235
- package/dist/core/router/adapter/index.cjs +1 -22
- package/dist/core/router/adapter/react-router/ReactRouterAdapter.cjs +1 -128
- package/dist/core/router/adapter/react-router/index.cjs +1 -20
- package/dist/core/router/adapter/types.cjs +1 -6
- package/dist/core/router/dev/RouterDevTools.cjs +1 -260
- package/dist/core/router/dev/index.cjs +1 -20
- package/dist/core/router/dynamic/DynamicRouteManager.cjs +1 -193
- package/dist/core/router/dynamic/index.cjs +1 -20
- package/dist/core/router/errors/RouterError.cjs +1 -61
- package/dist/core/router/errors/index.cjs +1 -20
- package/dist/core/router/index.cjs +1 -36
- package/dist/core/router/lifecycle/RouterLifecycleManager.cjs +1 -144
- package/dist/core/router/lifecycle/index.cjs +1 -20
- package/dist/core/router/middleware/RouterMiddlewareManager.cjs +1 -193
- package/dist/core/router/middleware/auth.cjs +1 -66
- package/dist/core/router/middleware/index.cjs +1 -22
- package/dist/core/router/middleware/types.cjs +1 -6
- package/dist/core/router/monitoring/RouterMonitoring.cjs +1 -227
- package/dist/core/router/monitoring/index.cjs +1 -20
- package/dist/core/router/navigation/RouterNavigation.cjs +1 -239
- package/dist/core/router/navigation/index.cjs +1 -20
- package/dist/core/router/performance/RouteCache.cjs +1 -305
- package/dist/core/router/performance/RoutePreloader.cjs +1 -292
- package/dist/core/router/performance/index.cjs +1 -21
- package/dist/core/router/plugin/RouterPluginManager.cjs +1 -262
- package/dist/core/router/plugin/index.cjs +1 -21
- package/dist/core/router/plugin/types.cjs +1 -39
- package/dist/core/router/types.cjs +1 -4
- package/dist/core/router/utils/adapters/react-router/RouteErrorBoundary.cjs +1 -129
- package/dist/core/router/utils/adapters/react-router/transform.cjs +1 -250
- package/dist/core/router/utils/transform.cjs +1 -780
- package/dist/core/router/validation/RouterConfigValidator.cjs +2 -83
- package/dist/core/router/validation/index.cjs +1 -21
- package/dist/core/router/validation/schema.cjs +1 -159
- package/dist/core/router/version/RouteVersionManager.cjs +1 -205
- package/dist/core/router/version/index.cjs +1 -20
- package/dist/core/splash/SplashScreen.cjs +1 -341
- package/dist/core/splash/index.cjs +1 -22
- package/dist/core/splash/splashScreenUtils.cjs +1 -38
- package/dist/core/startup/AppInstance.cjs +1 -239
- package/dist/core/startup/environment.cjs +1 -169
- package/dist/core/startup/index.cjs +1 -23
- package/dist/core/startup/initializeServices.cjs +1 -226
- package/dist/core/startup/performanceTracker.cjs +1 -179
- package/dist/core/startup/renderApp.cjs +1 -314
- package/dist/core/startup/startApp.cjs +1 -317
- package/dist/core/types.cjs +1 -4
- package/dist/index.cjs +1 -52
- package/dist/index.umd.cjs +1 -27
- package/dist/index.umd.js +1 -1
- package/dist/kernel/constants.cjs +1 -65
- package/dist/kernel/index.cjs +1 -38
- package/dist/kernel/kernel.cjs +1 -295
- package/dist/kernel/manager/cacheManager.cjs +1 -46
- package/dist/kernel/manager/i18n/I18nManager.cjs +1 -91
- package/dist/kernel/manager/i18n/i18n.persistence.cjs +1 -60
- package/dist/kernel/manager/i18n/i18n.schema.cjs +1 -86
- package/dist/kernel/manager/i18n/index.cjs +1 -11
- package/dist/kernel/manager/i18nManager.cjs +1 -11
- package/dist/kernel/manager/index.cjs +1 -28
- package/dist/kernel/manager/logger/LoggerManager.cjs +1 -107
- package/dist/kernel/manager/logger/index.cjs +1 -11
- package/dist/kernel/manager/logger/logger.persistence.cjs +1 -62
- package/dist/kernel/manager/logger/logger.schema.cjs +1 -74
- package/dist/kernel/manager/loggerManager.cjs +1 -11
- package/dist/kernel/manager/theme/ThemeManager.cjs +1 -84
- package/dist/kernel/manager/theme/index.cjs +1 -11
- package/dist/kernel/manager/theme/theme.dom.cjs +1 -61
- package/dist/kernel/manager/theme/theme.persistence.cjs +1 -57
- package/dist/kernel/manager/theme/theme.schema.cjs +1 -122
- package/dist/kernel/manager/themeManager.cjs +1 -11
- package/dist/kernel/types.cjs +1 -4
- package/dist/library/index.cjs +1 -19
- package/dist/library/locale/index.cjs +1 -39
- package/dist/library/locale/langs/en-us/index.cjs +1 -32
- package/dist/library/locale/langs/zh-cn/index.cjs +1 -32
- package/dist/library/locale/types.cjs +1 -4
- package/dist/library/storage/cache.cjs +1 -243
- package/dist/library/storage/encryption.cjs +1 -147
- package/dist/library/storage/index.cjs +1 -124
- package/dist/state/StateManager.cjs +1 -166
- package/dist/state/adapters/AdapterFactory.cjs +1 -89
- package/dist/state/adapters/DefaultAdapter.cjs +1 -75
- package/dist/state/adapters/ReduxAdapter.cjs +1 -443
- package/dist/state/adapters/ZustandAdapter.cjs +1 -69
- package/dist/state/adapters/index.cjs +1 -44
- package/dist/state/adapters/types.cjs +1 -20
- package/dist/state/core/DerivedStateInstance.cjs +1 -174
- package/dist/state/core/StateInstance.cjs +1 -170
- package/dist/state/core/StateRegistry.cjs +1 -110
- package/dist/state/core/StateScope.cjs +1 -137
- package/dist/state/core/index.cjs +1 -30
- package/dist/state/index.cjs +1 -30
- package/dist/state/types.cjs +1 -12
- package/dist/state.umd.js +1 -1
- package/dist/types.cjs +1 -4
- package/dist/utils/analytics.cjs +1 -217
- package/dist/utils/configSecurity.cjs +3 -182
- package/dist/utils/csrf.cjs +1 -18
- package/dist/utils/errors/ErrorCodes.cjs +1 -25
- package/dist/utils/errors.cjs +1 -111
- package/dist/utils/index.cjs +1 -135
- package/dist/utils/logger.cjs +1 -25
- package/dist/utils/logger.types.cjs +1 -11
- package/dist/utils/monitoring.cjs +1 -18
- package/dist/utils/performance.cjs +1 -22
- package/dist/utils/resourceLoader.cjs +1 -22
- package/dist/utils/runtimeSecurity.cjs +1 -11
- package/dist/utils/security.cjs +1 -19
- package/dist/utils/traceId.cjs +1 -37
- package/dist/utils/validation.cjs +1 -19
- package/package.json +7 -3
package/dist/core/app/index.cjs
CHANGED
|
@@ -1,41 +1 @@
|
|
|
1
|
-
|
|
2
|
-
* 应用核心模块
|
|
3
|
-
*/ "use strict";
|
|
4
|
-
Object.defineProperty(exports, "__esModule", {
|
|
5
|
-
value: true
|
|
6
|
-
});
|
|
7
|
-
function _export(target, all) {
|
|
8
|
-
for(var name in all)Object.defineProperty(target, name, {
|
|
9
|
-
enumerable: true,
|
|
10
|
-
get: Object.getOwnPropertyDescriptor(all, name).get
|
|
11
|
-
});
|
|
12
|
-
}
|
|
13
|
-
_export(exports, {
|
|
14
|
-
get AppContextProvider () {
|
|
15
|
-
return _AppContext.AppContextProvider;
|
|
16
|
-
},
|
|
17
|
-
get BasicLayout () {
|
|
18
|
-
return _BasicLayout.BasicLayout;
|
|
19
|
-
},
|
|
20
|
-
get DefaultApp () {
|
|
21
|
-
return _DefaultApp.DefaultApp;
|
|
22
|
-
},
|
|
23
|
-
get useAppContext () {
|
|
24
|
-
return _AppContext.useAppContext;
|
|
25
|
-
},
|
|
26
|
-
get useConfig () {
|
|
27
|
-
return _AppContext.useConfig;
|
|
28
|
-
},
|
|
29
|
-
get useLocale () {
|
|
30
|
-
return _AppContext.useLocale;
|
|
31
|
-
},
|
|
32
|
-
get useStateManager () {
|
|
33
|
-
return _AppContext.useStateManager;
|
|
34
|
-
},
|
|
35
|
-
get useTheme () {
|
|
36
|
-
return _AppContext.useTheme;
|
|
37
|
-
}
|
|
38
|
-
});
|
|
39
|
-
const _AppContext = require("./AppContext");
|
|
40
|
-
const _DefaultApp = require("./DefaultApp");
|
|
41
|
-
const _BasicLayout = require("./BasicLayout");
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:true});function _export(target,all){for(var name in all)Object.defineProperty(target,name,{enumerable:true,get:Object.getOwnPropertyDescriptor(all,name).get})}_export(exports,{get AppContextProvider(){return _AppContext.AppContextProvider},get BasicLayout(){return _BasicLayout.BasicLayout},get DefaultApp(){return _DefaultApp.DefaultApp},get useAppContext(){return _AppContext.useAppContext},get useConfig(){return _AppContext.useConfig},get useLocale(){return _AppContext.useLocale},get useStateManager(){return _AppContext.useStateManager},get useTheme(){return _AppContext.useTheme}});const _AppContext=require("./AppContext");const _DefaultApp=require("./DefaultApp");const _BasicLayout=require("./BasicLayout");
|
|
@@ -1,139 +1 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
value: true
|
|
4
|
-
});
|
|
5
|
-
Object.defineProperty(exports, "appConfig", {
|
|
6
|
-
enumerable: true,
|
|
7
|
-
get: function() {
|
|
8
|
-
return appConfig;
|
|
9
|
-
}
|
|
10
|
-
});
|
|
11
|
-
function _define_property(obj, key, value) {
|
|
12
|
-
if (key in obj) {
|
|
13
|
-
Object.defineProperty(obj, key, {
|
|
14
|
-
value: value,
|
|
15
|
-
enumerable: true,
|
|
16
|
-
configurable: true,
|
|
17
|
-
writable: true
|
|
18
|
-
});
|
|
19
|
-
} else {
|
|
20
|
-
obj[key] = value;
|
|
21
|
-
}
|
|
22
|
-
return obj;
|
|
23
|
-
}
|
|
24
|
-
/**
|
|
25
|
-
* 应用配置单例
|
|
26
|
-
*
|
|
27
|
-
* 用于在非 React 代码中访问全局配置
|
|
28
|
-
*/ let AppConfigManager = class AppConfigManager {
|
|
29
|
-
/**
|
|
30
|
-
* 获取单例实例
|
|
31
|
-
*
|
|
32
|
-
* @returns 单例实例
|
|
33
|
-
*/ static getInstance() {
|
|
34
|
-
if (!AppConfigManager.instance) {
|
|
35
|
-
AppConfigManager.instance = new AppConfigManager();
|
|
36
|
-
}
|
|
37
|
-
return AppConfigManager.instance;
|
|
38
|
-
}
|
|
39
|
-
/**
|
|
40
|
-
* 初始化配置
|
|
41
|
-
*
|
|
42
|
-
* @param config - 应用配置
|
|
43
|
-
*/ initialize(config) {
|
|
44
|
-
this._config = {
|
|
45
|
-
theme: config.theme || {
|
|
46
|
-
mode: 'light'
|
|
47
|
-
},
|
|
48
|
-
locale: config.locale || 'zh-CN',
|
|
49
|
-
antdConfig: config.antdConfig,
|
|
50
|
-
initializationContext: config.initializationContext
|
|
51
|
-
};
|
|
52
|
-
}
|
|
53
|
-
/**
|
|
54
|
-
* 获取完整配置
|
|
55
|
-
*
|
|
56
|
-
* @returns 应用配置
|
|
57
|
-
*/ getConfig() {
|
|
58
|
-
return {
|
|
59
|
-
...this._config
|
|
60
|
-
};
|
|
61
|
-
}
|
|
62
|
-
/**
|
|
63
|
-
* 获取主题配置
|
|
64
|
-
*
|
|
65
|
-
* @returns 主题配置
|
|
66
|
-
*/ getTheme() {
|
|
67
|
-
return {
|
|
68
|
-
...this._config.theme
|
|
69
|
-
};
|
|
70
|
-
}
|
|
71
|
-
/**
|
|
72
|
-
* 更新主题配置
|
|
73
|
-
*
|
|
74
|
-
* @param theme - 主题配置或更新函数
|
|
75
|
-
*/ setTheme(theme) {
|
|
76
|
-
if (typeof theme === 'function') {
|
|
77
|
-
this._config.theme = theme(this._config.theme);
|
|
78
|
-
} else {
|
|
79
|
-
this._config.theme = {
|
|
80
|
-
...theme
|
|
81
|
-
};
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
/**
|
|
85
|
-
* 获取当前语言
|
|
86
|
-
*
|
|
87
|
-
* @returns 当前语言
|
|
88
|
-
*/ getLocale() {
|
|
89
|
-
return this._config.locale;
|
|
90
|
-
}
|
|
91
|
-
/**
|
|
92
|
-
* 更新语言
|
|
93
|
-
*
|
|
94
|
-
* @param locale - 语言类型
|
|
95
|
-
*/ setLocale(locale) {
|
|
96
|
-
this._config.locale = locale;
|
|
97
|
-
}
|
|
98
|
-
/**
|
|
99
|
-
* 获取 Ant Design 配置
|
|
100
|
-
*
|
|
101
|
-
* @returns Ant Design 配置
|
|
102
|
-
*/ getAntdConfig() {
|
|
103
|
-
return this._config.antdConfig;
|
|
104
|
-
}
|
|
105
|
-
/**
|
|
106
|
-
* 更新 Ant Design 配置
|
|
107
|
-
*
|
|
108
|
-
* @param config - Ant Design 配置
|
|
109
|
-
*/ setAntdConfig(config) {
|
|
110
|
-
this._config.antdConfig = config;
|
|
111
|
-
}
|
|
112
|
-
/**
|
|
113
|
-
* 获取初始化上下文
|
|
114
|
-
*
|
|
115
|
-
* @returns 初始化上下文
|
|
116
|
-
*/ getInitializationContext() {
|
|
117
|
-
return this._config.initializationContext;
|
|
118
|
-
}
|
|
119
|
-
/**
|
|
120
|
-
* 更新初始化上下文
|
|
121
|
-
*
|
|
122
|
-
* @param context - 初始化上下文
|
|
123
|
-
*/ setInitializationContext(context) {
|
|
124
|
-
this._config.initializationContext = context;
|
|
125
|
-
}
|
|
126
|
-
/**
|
|
127
|
-
* 私有构造函数,防止外部直接实例化
|
|
128
|
-
*/ constructor(){
|
|
129
|
-
_define_property(this, "_config", void 0);
|
|
130
|
-
this._config = {
|
|
131
|
-
theme: {
|
|
132
|
-
mode: 'light'
|
|
133
|
-
},
|
|
134
|
-
locale: 'zh-CN'
|
|
135
|
-
};
|
|
136
|
-
}
|
|
137
|
-
};
|
|
138
|
-
_define_property(AppConfigManager, "instance", null);
|
|
139
|
-
const appConfig = AppConfigManager.getInstance();
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:true});Object.defineProperty(exports,"appConfig",{enumerable:true,get:function(){return appConfig}});function _define_property(obj,key,value){if(key in obj){Object.defineProperty(obj,key,{value:value,enumerable:true,configurable:true,writable:true})}else{obj[key]=value}return obj}let AppConfigManager=class AppConfigManager{static getInstance(){if(!AppConfigManager.instance){AppConfigManager.instance=new AppConfigManager}return AppConfigManager.instance}initialize(config){this._config={theme:config.theme||{mode:"light"},locale:config.locale||"zh-CN",antdConfig:config.antdConfig,initializationContext:config.initializationContext}}getConfig(){return{...this._config}}getTheme(){return{...this._config.theme}}setTheme(theme){if(typeof theme==="function"){this._config.theme=theme(this._config.theme)}else{this._config.theme={...theme}}}getLocale(){return this._config.locale}setLocale(locale){this._config.locale=locale}getAntdConfig(){return this._config.antdConfig}setAntdConfig(config){this._config.antdConfig=config}getInitializationContext(){return this._config.initializationContext}setInitializationContext(context){this._config.initializationContext=context}constructor(){_define_property(this,"_config",void 0);this._config={theme:{mode:"light"},locale:"zh-CN"}}};_define_property(AppConfigManager,"instance",null);const appConfig=AppConfigManager.getInstance();
|
|
@@ -1,323 +1 @@
|
|
|
1
|
-
|
|
2
|
-
* 配置文件加载模块
|
|
3
|
-
* 支持从JSON/YAML文件加载配置
|
|
4
|
-
* 优化:支持环境变量配置、配置热更新
|
|
5
|
-
*/ "use strict";
|
|
6
|
-
Object.defineProperty(exports, "__esModule", {
|
|
7
|
-
value: true
|
|
8
|
-
});
|
|
9
|
-
function _export(target, all) {
|
|
10
|
-
for(var name in all)Object.defineProperty(target, name, {
|
|
11
|
-
enumerable: true,
|
|
12
|
-
get: Object.getOwnPropertyDescriptor(all, name).get
|
|
13
|
-
});
|
|
14
|
-
}
|
|
15
|
-
_export(exports, {
|
|
16
|
-
get ConfigFileFormat () {
|
|
17
|
-
return ConfigFileFormat;
|
|
18
|
-
},
|
|
19
|
-
get ConfigLoader () {
|
|
20
|
-
return ConfigLoader;
|
|
21
|
-
}
|
|
22
|
-
});
|
|
23
|
-
const _logger = require("@vlian/logger");
|
|
24
|
-
function _define_property(obj, key, value) {
|
|
25
|
-
if (key in obj) {
|
|
26
|
-
Object.defineProperty(obj, key, {
|
|
27
|
-
value: value,
|
|
28
|
-
enumerable: true,
|
|
29
|
-
configurable: true,
|
|
30
|
-
writable: true
|
|
31
|
-
});
|
|
32
|
-
} else {
|
|
33
|
-
obj[key] = value;
|
|
34
|
-
}
|
|
35
|
-
return obj;
|
|
36
|
-
}
|
|
37
|
-
var ConfigFileFormat = /*#__PURE__*/ function(ConfigFileFormat) {
|
|
38
|
-
ConfigFileFormat["JSON"] = "json";
|
|
39
|
-
ConfigFileFormat["YAML"] = "yaml";
|
|
40
|
-
return ConfigFileFormat;
|
|
41
|
-
}({});
|
|
42
|
-
/**
|
|
43
|
-
* 配置变更通知管理器
|
|
44
|
-
*/ let ConfigChangeNotifier = class ConfigChangeNotifier {
|
|
45
|
-
/**
|
|
46
|
-
* 添加配置变更监听器
|
|
47
|
-
*/ addListener(listener) {
|
|
48
|
-
this.listeners.add(listener);
|
|
49
|
-
// 返回取消监听的函数
|
|
50
|
-
return ()=>{
|
|
51
|
-
this.listeners.delete(listener);
|
|
52
|
-
};
|
|
53
|
-
}
|
|
54
|
-
/**
|
|
55
|
-
* 移除配置变更监听器
|
|
56
|
-
*/ removeListener(listener) {
|
|
57
|
-
this.listeners.delete(listener);
|
|
58
|
-
}
|
|
59
|
-
/**
|
|
60
|
-
* 通知配置变更
|
|
61
|
-
*/ notify(newConfig, oldConfig) {
|
|
62
|
-
this.listeners.forEach((listener)=>{
|
|
63
|
-
try {
|
|
64
|
-
listener(newConfig, oldConfig);
|
|
65
|
-
} catch (error) {
|
|
66
|
-
_logger.logger.warn('配置变更监听器执行失败:', error);
|
|
67
|
-
}
|
|
68
|
-
});
|
|
69
|
-
}
|
|
70
|
-
/**
|
|
71
|
-
* 清除所有监听器
|
|
72
|
-
*/ clear() {
|
|
73
|
-
this.listeners.clear();
|
|
74
|
-
}
|
|
75
|
-
constructor(){
|
|
76
|
-
_define_property(this, "listeners", new Set());
|
|
77
|
-
}
|
|
78
|
-
};
|
|
79
|
-
/**
|
|
80
|
-
* 全局配置变更通知器实例
|
|
81
|
-
*/ const configChangeNotifier = new ConfigChangeNotifier();
|
|
82
|
-
let ConfigLoader = class ConfigLoader {
|
|
83
|
-
/**
|
|
84
|
-
* 从JSON文件加载配置
|
|
85
|
-
*
|
|
86
|
-
* @param path - 文件路径
|
|
87
|
-
* @returns 配置对象
|
|
88
|
-
*/ static async loadFromJSON(path) {
|
|
89
|
-
try {
|
|
90
|
-
// 在浏览器环境中,需要通过网络请求加载
|
|
91
|
-
if (typeof window !== 'undefined') {
|
|
92
|
-
const response = await fetch(path);
|
|
93
|
-
if (!response.ok) {
|
|
94
|
-
throw new Error(`无法加载配置文件: ${path} (${response.status})`);
|
|
95
|
-
}
|
|
96
|
-
return await response.json();
|
|
97
|
-
}
|
|
98
|
-
// 在Node.js环境中,使用fs模块
|
|
99
|
-
if (typeof require !== 'undefined') {
|
|
100
|
-
const fs = require('fs');
|
|
101
|
-
const content = fs.readFileSync(path, 'utf-8');
|
|
102
|
-
return JSON.parse(content);
|
|
103
|
-
}
|
|
104
|
-
throw new Error('不支持的环境:无法加载配置文件');
|
|
105
|
-
} catch (error) {
|
|
106
|
-
_logger.logger.error(`加载JSON配置文件失败: ${path}`, error);
|
|
107
|
-
throw error;
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
/**
|
|
111
|
-
* 从YAML文件加载配置
|
|
112
|
-
*
|
|
113
|
-
* @param path - 文件路径
|
|
114
|
-
* @returns 配置对象
|
|
115
|
-
*/ static async loadFromYAML(path) {
|
|
116
|
-
try {
|
|
117
|
-
// 在浏览器环境中,需要通过网络请求加载
|
|
118
|
-
if (typeof window !== 'undefined') {
|
|
119
|
-
const response = await fetch(path);
|
|
120
|
-
if (!response.ok) {
|
|
121
|
-
throw new Error(`无法加载配置文件: ${path} (${response.status})`);
|
|
122
|
-
}
|
|
123
|
-
const text = await response.text();
|
|
124
|
-
// 需要YAML解析库,这里假设有yaml库
|
|
125
|
-
// 如果没有,可以提示用户安装
|
|
126
|
-
if (typeof window.YAML !== 'undefined') {
|
|
127
|
-
return window.YAML.parse(text);
|
|
128
|
-
}
|
|
129
|
-
// 降级:尝试作为JSON解析(如果YAML格式简单)
|
|
130
|
-
try {
|
|
131
|
-
return JSON.parse(text);
|
|
132
|
-
} catch {
|
|
133
|
-
throw new Error('需要YAML解析库,请安装 yaml 包');
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
// 在Node.js环境中,使用fs模块和yaml库
|
|
137
|
-
if (typeof require !== 'undefined') {
|
|
138
|
-
const fs = require('fs');
|
|
139
|
-
const yaml = require('yaml');
|
|
140
|
-
const content = fs.readFileSync(path, 'utf-8');
|
|
141
|
-
return yaml.parse(content);
|
|
142
|
-
}
|
|
143
|
-
throw new Error('不支持的环境:无法加载配置文件');
|
|
144
|
-
} catch (error) {
|
|
145
|
-
_logger.logger.error(`加载YAML配置文件失败: ${path}`, error);
|
|
146
|
-
throw error;
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
/**
|
|
150
|
-
* 从文件加载配置
|
|
151
|
-
*
|
|
152
|
-
* @param options - 加载选项
|
|
153
|
-
* @returns 配置对象
|
|
154
|
-
*/ static async loadFromFile(options) {
|
|
155
|
-
const { path, format = "json", required = false, defaultConfig = {} } = options;
|
|
156
|
-
if (!path) {
|
|
157
|
-
if (required) {
|
|
158
|
-
throw new Error('配置文件路径未指定');
|
|
159
|
-
}
|
|
160
|
-
return defaultConfig;
|
|
161
|
-
}
|
|
162
|
-
try {
|
|
163
|
-
let config;
|
|
164
|
-
switch(format){
|
|
165
|
-
case "json":
|
|
166
|
-
config = await this.loadFromJSON(path);
|
|
167
|
-
break;
|
|
168
|
-
case "yaml":
|
|
169
|
-
config = await this.loadFromYAML(path);
|
|
170
|
-
break;
|
|
171
|
-
default:
|
|
172
|
-
throw new Error(`不支持的配置文件格式: ${format}`);
|
|
173
|
-
}
|
|
174
|
-
_logger.logger.info(`成功加载配置文件: ${path}`);
|
|
175
|
-
return config;
|
|
176
|
-
} catch (error) {
|
|
177
|
-
if (required) {
|
|
178
|
-
throw error;
|
|
179
|
-
}
|
|
180
|
-
_logger.logger.warn(`配置文件加载失败,使用默认配置: ${path}`, error);
|
|
181
|
-
return defaultConfig;
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
/**
|
|
185
|
-
* 合并配置(深度合并)
|
|
186
|
-
*
|
|
187
|
-
* @param base - 基础配置
|
|
188
|
-
* @param override - 覆盖配置
|
|
189
|
-
* @returns 合并后的配置
|
|
190
|
-
*/ static mergeConfig(base, override) {
|
|
191
|
-
const merged = {
|
|
192
|
-
...base
|
|
193
|
-
};
|
|
194
|
-
for(const key in override){
|
|
195
|
-
if (!Object.prototype.hasOwnProperty.call(override, key)) {
|
|
196
|
-
continue;
|
|
197
|
-
}
|
|
198
|
-
const baseValue = merged[key];
|
|
199
|
-
const overrideValue = override[key];
|
|
200
|
-
if (baseValue && overrideValue && typeof baseValue === 'object' && typeof overrideValue === 'object' && !Array.isArray(baseValue) && !Array.isArray(overrideValue)) {
|
|
201
|
-
// 深度合并对象
|
|
202
|
-
merged[key] = this.mergeConfig(baseValue, overrideValue);
|
|
203
|
-
} else {
|
|
204
|
-
// 直接覆盖
|
|
205
|
-
merged[key] = overrideValue;
|
|
206
|
-
}
|
|
207
|
-
}
|
|
208
|
-
return merged;
|
|
209
|
-
}
|
|
210
|
-
/**
|
|
211
|
-
* 从多个源加载并合并配置
|
|
212
|
-
*
|
|
213
|
-
* @param sources - 配置源列表(按优先级从低到高)
|
|
214
|
-
* @returns 合并后的配置
|
|
215
|
-
*/ static async loadFromMultipleSources(sources) {
|
|
216
|
-
let merged = {};
|
|
217
|
-
for (const source of sources){
|
|
218
|
-
if ('path' in source && 'format' in source) {
|
|
219
|
-
// 配置文件
|
|
220
|
-
const fileConfig = await this.loadFromFile(source);
|
|
221
|
-
merged = this.mergeConfig(merged, fileConfig);
|
|
222
|
-
} else if (!('path' in source) && !('format' in source)) {
|
|
223
|
-
// 配置对象
|
|
224
|
-
merged = this.mergeConfig(merged, source);
|
|
225
|
-
}
|
|
226
|
-
}
|
|
227
|
-
return merged;
|
|
228
|
-
}
|
|
229
|
-
/**
|
|
230
|
-
* 从环境变量加载配置
|
|
231
|
-
*
|
|
232
|
-
* 支持以下环境变量格式:
|
|
233
|
-
* - FRAMEWORK_LOGGER_LEVEL=DEBUG
|
|
234
|
-
* - FRAMEWORK_SHOW_SPLASH_SCREEN=always
|
|
235
|
-
* - FRAMEWORK_MIN_SPLASH_SCREEN_TIME=1000
|
|
236
|
-
*
|
|
237
|
-
* @param prefix - 环境变量前缀,默认为 'FRAMEWORK_'
|
|
238
|
-
* @returns 配置对象
|
|
239
|
-
*/ static loadFromEnv(prefix = 'FRAMEWORK_') {
|
|
240
|
-
const config = {};
|
|
241
|
-
if (typeof process === 'undefined' || !process.env) {
|
|
242
|
-
return config;
|
|
243
|
-
}
|
|
244
|
-
// 遍历所有环境变量
|
|
245
|
-
for (const [key, value] of Object.entries(process.env)){
|
|
246
|
-
if (!key.startsWith(prefix)) {
|
|
247
|
-
continue;
|
|
248
|
-
}
|
|
249
|
-
// 移除前缀并转换为驼峰命名
|
|
250
|
-
const configKey = key.slice(prefix.length).toLowerCase().split('_').map((part, index)=>index === 0 ? part : part.charAt(0).toUpperCase() + part.slice(1)).join('');
|
|
251
|
-
// 尝试解析值
|
|
252
|
-
let parsedValue = value;
|
|
253
|
-
if (value === 'true' || value === 'false') {
|
|
254
|
-
parsedValue = value === 'true';
|
|
255
|
-
} else if (!isNaN(Number(value))) {
|
|
256
|
-
parsedValue = Number(value);
|
|
257
|
-
} else if (value?.startsWith('{') || value?.startsWith('[')) {
|
|
258
|
-
try {
|
|
259
|
-
parsedValue = JSON.parse(value);
|
|
260
|
-
} catch {
|
|
261
|
-
// 解析失败,使用原始值
|
|
262
|
-
}
|
|
263
|
-
}
|
|
264
|
-
// 设置配置值
|
|
265
|
-
config[configKey] = parsedValue;
|
|
266
|
-
}
|
|
267
|
-
_logger.logger.debug('从环境变量加载配置:', config);
|
|
268
|
-
return config;
|
|
269
|
-
}
|
|
270
|
-
/**
|
|
271
|
-
* 从多个源加载配置(包括环境变量)
|
|
272
|
-
*
|
|
273
|
-
* 优化:明确优先级,从低到高:
|
|
274
|
-
* 1. 默认配置
|
|
275
|
-
* 2. 配置文件
|
|
276
|
-
* 3. 环境变量
|
|
277
|
-
* 4. 代码配置(通过 sources 参数传入)
|
|
278
|
-
*
|
|
279
|
-
* @param sources - 配置源列表(代码配置,优先级最高)
|
|
280
|
-
* @param defaultConfig - 默认配置(优先级最低)
|
|
281
|
-
* @param includeEnv - 是否包含环境变量,默认为 true
|
|
282
|
-
* @param envPrefix - 环境变量前缀,默认为 'FRAMEWORK_'
|
|
283
|
-
* @returns 合并后的配置
|
|
284
|
-
*/ static async loadFromAllSources(sources = [], defaultConfig = {}, includeEnv = true, envPrefix = 'FRAMEWORK_') {
|
|
285
|
-
// 保存旧配置用于变更通知
|
|
286
|
-
const oldConfig = {
|
|
287
|
-
...defaultConfig
|
|
288
|
-
};
|
|
289
|
-
// 1. 从默认配置开始
|
|
290
|
-
let merged = {
|
|
291
|
-
...defaultConfig
|
|
292
|
-
};
|
|
293
|
-
// 2. 加载配置文件(优先级高于默认配置)
|
|
294
|
-
const fileConfigs = await this.loadFromMultipleSources(sources.filter((source)=>typeof source === 'object' && 'path' in source));
|
|
295
|
-
merged = this.mergeConfig(merged, fileConfigs);
|
|
296
|
-
// 3. 加载环境变量(优先级高于配置文件)
|
|
297
|
-
if (includeEnv) {
|
|
298
|
-
const envConfig = this.loadFromEnv(envPrefix);
|
|
299
|
-
merged = this.mergeConfig(merged, envConfig);
|
|
300
|
-
}
|
|
301
|
-
// 4. 合并代码配置(优先级最高)
|
|
302
|
-
const codeConfigs = sources.filter((source)=>typeof source === 'object' && !('path' in source));
|
|
303
|
-
for (const codeConfig of codeConfigs){
|
|
304
|
-
merged = this.mergeConfig(merged, codeConfig);
|
|
305
|
-
}
|
|
306
|
-
// 通知配置变更
|
|
307
|
-
configChangeNotifier.notify(merged, oldConfig);
|
|
308
|
-
return merged;
|
|
309
|
-
}
|
|
310
|
-
/**
|
|
311
|
-
* 添加配置变更监听器
|
|
312
|
-
*
|
|
313
|
-
* @param listener - 配置变更监听器
|
|
314
|
-
* @returns 取消监听的函数
|
|
315
|
-
*/ static onConfigChange(listener) {
|
|
316
|
-
return configChangeNotifier.addListener(listener);
|
|
317
|
-
}
|
|
318
|
-
/**
|
|
319
|
-
* 移除配置变更监听器
|
|
320
|
-
*/ static removeConfigChangeListener(listener) {
|
|
321
|
-
configChangeNotifier.removeListener(listener);
|
|
322
|
-
}
|
|
323
|
-
};
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:true});function _export(target,all){for(var name in all)Object.defineProperty(target,name,{enumerable:true,get:Object.getOwnPropertyDescriptor(all,name).get})}_export(exports,{get ConfigFileFormat(){return ConfigFileFormat},get ConfigLoader(){return ConfigLoader}});const _logger=require("@vlian/logger");function _define_property(obj,key,value){if(key in obj){Object.defineProperty(obj,key,{value:value,enumerable:true,configurable:true,writable:true})}else{obj[key]=value}return obj}var ConfigFileFormat=/*#__PURE__*/function(ConfigFileFormat){ConfigFileFormat["JSON"]="json";ConfigFileFormat["YAML"]="yaml";return ConfigFileFormat}({});let ConfigChangeNotifier=class ConfigChangeNotifier{addListener(listener){this.listeners.add(listener);return()=>{this.listeners.delete(listener)}}removeListener(listener){this.listeners.delete(listener)}notify(newConfig,oldConfig){this.listeners.forEach(listener=>{try{listener(newConfig,oldConfig)}catch(error){_logger.logger.warn("配置变更监听器执行失败:",error)}})}clear(){this.listeners.clear()}constructor(){_define_property(this,"listeners",new Set)}};const configChangeNotifier=new ConfigChangeNotifier;let ConfigLoader=class ConfigLoader{static async loadFromJSON(path){try{if(typeof window!=="undefined"){const response=await fetch(path);if(!response.ok){throw new Error(`无法加载配置文件: ${path} (${response.status})`)}return await response.json()}if(typeof require!=="undefined"){const fs=require("fs");const content=fs.readFileSync(path,"utf-8");return JSON.parse(content)}throw new Error("不支持的环境:无法加载配置文件")}catch(error){_logger.logger.error(`加载JSON配置文件失败: ${path}`,error);throw error}}static async loadFromYAML(path){try{if(typeof window!=="undefined"){const response=await fetch(path);if(!response.ok){throw new Error(`无法加载配置文件: ${path} (${response.status})`)}const text=await response.text();if(typeof window.YAML!=="undefined"){return window.YAML.parse(text)}try{return JSON.parse(text)}catch{throw new Error("需要YAML解析库,请安装 yaml 包")}}if(typeof require!=="undefined"){const fs=require("fs");const yaml=require("yaml");const content=fs.readFileSync(path,"utf-8");return yaml.parse(content)}throw new Error("不支持的环境:无法加载配置文件")}catch(error){_logger.logger.error(`加载YAML配置文件失败: ${path}`,error);throw error}}static async loadFromFile(options){const{path,format="json",required=false,defaultConfig={}}=options;if(!path){if(required){throw new Error("配置文件路径未指定")}return defaultConfig}try{let config;switch(format){case"json":config=await this.loadFromJSON(path);break;case"yaml":config=await this.loadFromYAML(path);break;default:throw new Error(`不支持的配置文件格式: ${format}`)}_logger.logger.info(`成功加载配置文件: ${path}`);return config}catch(error){if(required){throw error}_logger.logger.warn(`配置文件加载失败,使用默认配置: ${path}`,error);return defaultConfig}}static mergeConfig(base,override){const merged={...base};for(const key in override){if(!Object.prototype.hasOwnProperty.call(override,key)){continue}const baseValue=merged[key];const overrideValue=override[key];if(baseValue&&overrideValue&&typeof baseValue==="object"&&typeof overrideValue==="object"&&!Array.isArray(baseValue)&&!Array.isArray(overrideValue)){merged[key]=this.mergeConfig(baseValue,overrideValue)}else{merged[key]=overrideValue}}return merged}static async loadFromMultipleSources(sources){let merged={};for(const source of sources){if("path"in source&&"format"in source){const fileConfig=await this.loadFromFile(source);merged=this.mergeConfig(merged,fileConfig)}else if(!("path"in source)&&!("format"in source)){merged=this.mergeConfig(merged,source)}}return merged}static loadFromEnv(prefix="FRAMEWORK_"){const config={};if(typeof process==="undefined"||!process.env){return config}for(const[key,value]of Object.entries(process.env)){if(!key.startsWith(prefix)){continue}const configKey=key.slice(prefix.length).toLowerCase().split("_").map((part,index)=>index===0?part:part.charAt(0).toUpperCase()+part.slice(1)).join("");let parsedValue=value;if(value==="true"||value==="false"){parsedValue=value==="true"}else if(!isNaN(Number(value))){parsedValue=Number(value)}else if(value?.startsWith("{")||value?.startsWith("[")){try{parsedValue=JSON.parse(value)}catch{}}config[configKey]=parsedValue}_logger.logger.debug("从环境变量加载配置:",config);return config}static async loadFromAllSources(sources=[],defaultConfig={},includeEnv=true,envPrefix="FRAMEWORK_"){const oldConfig={...defaultConfig};let merged={...defaultConfig};const fileConfigs=await this.loadFromMultipleSources(sources.filter(source=>typeof source==="object"&&"path"in source));merged=this.mergeConfig(merged,fileConfigs);if(includeEnv){const envConfig=this.loadFromEnv(envPrefix);merged=this.mergeConfig(merged,envConfig)}const codeConfigs=sources.filter(source=>typeof source==="object"&&!("path"in source));for(const codeConfig of codeConfigs){merged=this.mergeConfig(merged,codeConfig)}configChangeNotifier.notify(merged,oldConfig);return merged}static onConfigChange(listener){return configChangeNotifier.addListener(listener)}static removeConfigChangeListener(listener){configChangeNotifier.removeListener(listener)}};
|
|
@@ -1,133 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
* 使用Zod进行配置验证
|
|
4
|
-
*/ "use strict";
|
|
5
|
-
Object.defineProperty(exports, "__esModule", {
|
|
6
|
-
value: true
|
|
7
|
-
});
|
|
8
|
-
function _export(target, all) {
|
|
9
|
-
for(var name in all)Object.defineProperty(target, name, {
|
|
10
|
-
enumerable: true,
|
|
11
|
-
get: Object.getOwnPropertyDescriptor(all, name).get
|
|
12
|
-
});
|
|
13
|
-
}
|
|
14
|
-
_export(exports, {
|
|
15
|
-
get ConfigValidationError () {
|
|
16
|
-
return ConfigValidationError;
|
|
17
|
-
},
|
|
18
|
-
get ConfigValidator () {
|
|
19
|
-
return ConfigValidator;
|
|
20
|
-
}
|
|
21
|
-
});
|
|
22
|
-
const _zod = require("zod");
|
|
23
|
-
function _define_property(obj, key, value) {
|
|
24
|
-
if (key in obj) {
|
|
25
|
-
Object.defineProperty(obj, key, {
|
|
26
|
-
value: value,
|
|
27
|
-
enumerable: true,
|
|
28
|
-
configurable: true,
|
|
29
|
-
writable: true
|
|
30
|
-
});
|
|
31
|
-
} else {
|
|
32
|
-
obj[key] = value;
|
|
33
|
-
}
|
|
34
|
-
return obj;
|
|
35
|
-
}
|
|
36
|
-
let ConfigValidationError = class ConfigValidationError extends Error {
|
|
37
|
-
constructor(message, errors){
|
|
38
|
-
super(message), _define_property(this, "errors", void 0), this.errors = errors;
|
|
39
|
-
this.name = 'ConfigValidationError';
|
|
40
|
-
}
|
|
41
|
-
};
|
|
42
|
-
let ConfigValidator = class ConfigValidator {
|
|
43
|
-
/**
|
|
44
|
-
* 验证配置
|
|
45
|
-
*
|
|
46
|
-
* @param config - 要验证的配置
|
|
47
|
-
* @param schema - Zod模式
|
|
48
|
-
* @returns 验证后的配置
|
|
49
|
-
* @throws ConfigValidationError 如果配置验证失败
|
|
50
|
-
*/ static validate(config, schema) {
|
|
51
|
-
const result = schema.safeParse(config);
|
|
52
|
-
if (!result.success) {
|
|
53
|
-
throw new ConfigValidationError('配置验证失败', result.error);
|
|
54
|
-
}
|
|
55
|
-
return result.data;
|
|
56
|
-
}
|
|
57
|
-
/**
|
|
58
|
-
* 安全验证配置(不抛出异常)
|
|
59
|
-
*
|
|
60
|
-
* @param config - 要验证的配置
|
|
61
|
-
* @param schema - Zod模式
|
|
62
|
-
* @returns 验证结果
|
|
63
|
-
*/ static safeValidate(config, schema) {
|
|
64
|
-
const result = schema.safeParse(config);
|
|
65
|
-
if (result.success) {
|
|
66
|
-
return {
|
|
67
|
-
success: true,
|
|
68
|
-
data: result.data
|
|
69
|
-
};
|
|
70
|
-
}
|
|
71
|
-
return {
|
|
72
|
-
success: false,
|
|
73
|
-
error: result.error
|
|
74
|
-
};
|
|
75
|
-
}
|
|
76
|
-
/**
|
|
77
|
-
* 创建StartOptions的部分验证模式
|
|
78
|
-
* 注意:这是一个基础模式,可以根据需要扩展
|
|
79
|
-
*/ static createStartOptionsSchema() {
|
|
80
|
-
return _zod.z.object({
|
|
81
|
-
loggerLevel: _zod.z.enum([
|
|
82
|
-
'DEBUG',
|
|
83
|
-
'INFO',
|
|
84
|
-
'WARN',
|
|
85
|
-
'ERROR'
|
|
86
|
-
]).optional(),
|
|
87
|
-
showSplashScreen: _zod.z.enum([
|
|
88
|
-
'auto',
|
|
89
|
-
'always',
|
|
90
|
-
'never',
|
|
91
|
-
'first-time-only'
|
|
92
|
-
]).optional(),
|
|
93
|
-
minSplashScreenTime: _zod.z.number().positive().optional(),
|
|
94
|
-
security: _zod.z.object({
|
|
95
|
-
enableXSSProtection: _zod.z.boolean().optional(),
|
|
96
|
-
validateConfig: _zod.z.boolean().optional(),
|
|
97
|
-
sanitizeUserInput: _zod.z.boolean().optional(),
|
|
98
|
-
csp: _zod.z.object({
|
|
99
|
-
defaultSrc: _zod.z.array(_zod.z.string()).optional(),
|
|
100
|
-
scriptSrc: _zod.z.array(_zod.z.string()).optional(),
|
|
101
|
-
styleSrc: _zod.z.array(_zod.z.string()).optional(),
|
|
102
|
-
imgSrc: _zod.z.array(_zod.z.string()).optional(),
|
|
103
|
-
connectSrc: _zod.z.array(_zod.z.string()).optional(),
|
|
104
|
-
fontSrc: _zod.z.array(_zod.z.string()).optional(),
|
|
105
|
-
frameSrc: _zod.z.array(_zod.z.string()).optional(),
|
|
106
|
-
allowUnsafeInline: _zod.z.boolean().optional(),
|
|
107
|
-
allowUnsafeEval: _zod.z.boolean().optional()
|
|
108
|
-
}).optional()
|
|
109
|
-
}).optional()
|
|
110
|
-
}).passthrough(); // passthrough允许其他字段通过
|
|
111
|
-
}
|
|
112
|
-
/**
|
|
113
|
-
* 验证配置并提供友好的错误信息
|
|
114
|
-
*
|
|
115
|
-
* @param config - 要验证的配置
|
|
116
|
-
* @param schema - Zod模式
|
|
117
|
-
* @returns 验证后的配置
|
|
118
|
-
* @throws ConfigValidationError 如果配置验证失败,包含详细的错误信息
|
|
119
|
-
*/ static validateWithFriendlyErrors(config, schema) {
|
|
120
|
-
const result = schema.safeParse(config);
|
|
121
|
-
if (!result.success) {
|
|
122
|
-
// 构建友好的错误信息
|
|
123
|
-
// 注意:ZodError 使用 issues 属性,不是 errors
|
|
124
|
-
const errorMessages = result.error.issues.map((issue)=>{
|
|
125
|
-
const path = issue.path.length > 0 ? issue.path.join('.') : 'root';
|
|
126
|
-
return `配置项 "${path}": ${issue.message}`;
|
|
127
|
-
});
|
|
128
|
-
const friendlyMessage = `配置验证失败:\n${errorMessages.join('\n')}`;
|
|
129
|
-
throw new ConfigValidationError(friendlyMessage, result.error);
|
|
130
|
-
}
|
|
131
|
-
return result.data;
|
|
132
|
-
}
|
|
133
|
-
};
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:true});function _export(target,all){for(var name in all)Object.defineProperty(target,name,{enumerable:true,get:Object.getOwnPropertyDescriptor(all,name).get})}_export(exports,{get ConfigValidationError(){return ConfigValidationError},get ConfigValidator(){return ConfigValidator}});const _zod=require("zod");function _define_property(obj,key,value){if(key in obj){Object.defineProperty(obj,key,{value:value,enumerable:true,configurable:true,writable:true})}else{obj[key]=value}return obj}let ConfigValidationError=class ConfigValidationError extends Error{constructor(message,errors){super(message),_define_property(this,"errors",void 0),this.errors=errors;this.name="ConfigValidationError"}};let ConfigValidator=class ConfigValidator{static validate(config,schema){const result=schema.safeParse(config);if(!result.success){throw new ConfigValidationError("配置验证失败",result.error)}return result.data}static safeValidate(config,schema){const result=schema.safeParse(config);if(result.success){return{success:true,data:result.data}}return{success:false,error:result.error}}static createStartOptionsSchema(){return _zod.z.object({loggerLevel:_zod.z.enum(["DEBUG","INFO","WARN","ERROR"]).optional(),showSplashScreen:_zod.z.enum(["auto","always","never","first-time-only"]).optional(),minSplashScreenTime:_zod.z.number().positive().optional(),security:_zod.z.object({enableXSSProtection:_zod.z.boolean().optional(),validateConfig:_zod.z.boolean().optional(),sanitizeUserInput:_zod.z.boolean().optional(),csp:_zod.z.object({defaultSrc:_zod.z.array(_zod.z.string()).optional(),scriptSrc:_zod.z.array(_zod.z.string()).optional(),styleSrc:_zod.z.array(_zod.z.string()).optional(),imgSrc:_zod.z.array(_zod.z.string()).optional(),connectSrc:_zod.z.array(_zod.z.string()).optional(),fontSrc:_zod.z.array(_zod.z.string()).optional(),frameSrc:_zod.z.array(_zod.z.string()).optional(),allowUnsafeInline:_zod.z.boolean().optional(),allowUnsafeEval:_zod.z.boolean().optional()}).optional()}).optional()}).passthrough()}static validateWithFriendlyErrors(config,schema){const result=schema.safeParse(config);if(!result.success){const errorMessages=result.error.issues.map(issue=>{const path=issue.path.length>0?issue.path.join("."):"root";return`配置项 "${path}": ${issue.message}`});const friendlyMessage=`配置验证失败:
|
|
2
|
+
${errorMessages.join("\n")}`;throw new ConfigValidationError(friendlyMessage,result.error)}return result.data}};
|
|
@@ -1,28 +1 @@
|
|
|
1
|
-
|
|
2
|
-
* 配置模块统一导出
|
|
3
|
-
*/ "use strict";
|
|
4
|
-
Object.defineProperty(exports, "__esModule", {
|
|
5
|
-
value: true
|
|
6
|
-
});
|
|
7
|
-
Object.defineProperty(exports, "appConfig", {
|
|
8
|
-
enumerable: true,
|
|
9
|
-
get: function() {
|
|
10
|
-
return _AppConfig.appConfig;
|
|
11
|
-
}
|
|
12
|
-
});
|
|
13
|
-
_export_star(require("./ConfigValidator"), exports);
|
|
14
|
-
_export_star(require("./ConfigLoader"), exports);
|
|
15
|
-
const _AppConfig = require("./AppConfig");
|
|
16
|
-
function _export_star(from, to) {
|
|
17
|
-
Object.keys(from).forEach(function(k) {
|
|
18
|
-
if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) {
|
|
19
|
-
Object.defineProperty(to, k, {
|
|
20
|
-
enumerable: true,
|
|
21
|
-
get: function() {
|
|
22
|
-
return from[k];
|
|
23
|
-
}
|
|
24
|
-
});
|
|
25
|
-
}
|
|
26
|
-
});
|
|
27
|
-
return from;
|
|
28
|
-
}
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:true});Object.defineProperty(exports,"appConfig",{enumerable:true,get:function(){return _AppConfig.appConfig}});_export_star(require("./ConfigValidator"),exports);_export_star(require("./ConfigLoader"),exports);const _AppConfig=require("./AppConfig");function _export_star(from,to){Object.keys(from).forEach(function(k){if(k!=="default"&&!Object.prototype.hasOwnProperty.call(to,k)){Object.defineProperty(to,k,{enumerable:true,get:function(){return from[k]}})}});return from}
|