@vlian/framework 1.2.59 → 1.2.61

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.
Files changed (154) hide show
  1. package/dist/analytics/index.cjs +1 -22
  2. package/dist/analytics.umd.js +1 -1
  3. package/dist/components/LocaleSwitch.cjs +1 -116
  4. package/dist/components/ThemeSwitch.cjs +1 -115
  5. package/dist/components/index.cjs +1 -20
  6. package/dist/components/persistence.cjs +1 -58
  7. package/dist/core/Test.cjs +1 -64
  8. package/dist/core/app/AppContext.cjs +1 -348
  9. package/dist/core/app/AppContext.types.cjs +1 -4
  10. package/dist/core/app/BasicLayout.cjs +1 -122
  11. package/dist/core/app/DefaultApp.cjs +1 -150
  12. package/dist/core/app/index.cjs +1 -41
  13. package/dist/core/config/AppConfig.cjs +1 -139
  14. package/dist/core/config/ConfigLoader.cjs +1 -323
  15. package/dist/core/config/ConfigValidator.cjs +2 -133
  16. package/dist/core/config/index.cjs +1 -28
  17. package/dist/core/dev/DevTools.cjs +1 -226
  18. package/dist/core/error/ErrorBoundary.cjs +1 -401
  19. package/dist/core/error/ErrorHandler.cjs +1 -275
  20. package/dist/core/error/index.cjs +1 -34
  21. package/dist/core/event/AppEventBus.cjs +1 -444
  22. package/dist/core/event/frameworkEvents.cjs +1 -141
  23. package/dist/core/event/hooks.cjs +1 -69
  24. package/dist/core/event/index.cjs +1 -41
  25. package/dist/core/event/types.cjs +1 -62
  26. package/dist/core/event/useEventBus.cjs +1 -25
  27. package/dist/core/index.cjs +1 -140
  28. package/dist/core/initialization/InitializationErrorThrower.cjs +1 -75
  29. package/dist/core/initialization/index.cjs +1 -26
  30. package/dist/core/initialization/initialization.cjs +1 -64
  31. package/dist/core/initialization/initializationErrorState.cjs +1 -66
  32. package/dist/core/kernel/defaultAdapters.cjs +1 -184
  33. package/dist/core/kernel/errors.cjs +1 -69
  34. package/dist/core/kernel/index.cjs +1 -20
  35. package/dist/core/kernel/startKernel.cjs +1 -200
  36. package/dist/core/kernel/types.cjs +1 -4
  37. package/dist/core/middleware.cjs +1 -73
  38. package/dist/core/plugin/PluginEventBus.cjs +1 -298
  39. package/dist/core/plugin/PluginSandbox.cjs +1 -137
  40. package/dist/core/plugin.cjs +1 -494
  41. package/dist/core/router/RouterManager.cjs +1 -286
  42. package/dist/core/router/adapter/AdapterManager.cjs +1 -235
  43. package/dist/core/router/adapter/index.cjs +1 -22
  44. package/dist/core/router/adapter/react-router/ReactRouterAdapter.cjs +1 -128
  45. package/dist/core/router/adapter/react-router/index.cjs +1 -20
  46. package/dist/core/router/adapter/types.cjs +1 -6
  47. package/dist/core/router/dev/RouterDevTools.cjs +1 -260
  48. package/dist/core/router/dev/index.cjs +1 -20
  49. package/dist/core/router/dynamic/DynamicRouteManager.cjs +1 -193
  50. package/dist/core/router/dynamic/index.cjs +1 -20
  51. package/dist/core/router/errors/RouterError.cjs +1 -61
  52. package/dist/core/router/errors/index.cjs +1 -20
  53. package/dist/core/router/index.cjs +1 -36
  54. package/dist/core/router/lifecycle/RouterLifecycleManager.cjs +1 -144
  55. package/dist/core/router/lifecycle/index.cjs +1 -20
  56. package/dist/core/router/middleware/RouterMiddlewareManager.cjs +1 -193
  57. package/dist/core/router/middleware/auth.cjs +1 -66
  58. package/dist/core/router/middleware/index.cjs +1 -22
  59. package/dist/core/router/middleware/types.cjs +1 -6
  60. package/dist/core/router/monitoring/RouterMonitoring.cjs +1 -227
  61. package/dist/core/router/monitoring/index.cjs +1 -20
  62. package/dist/core/router/navigation/RouterNavigation.cjs +1 -239
  63. package/dist/core/router/navigation/index.cjs +1 -20
  64. package/dist/core/router/performance/RouteCache.cjs +1 -305
  65. package/dist/core/router/performance/RoutePreloader.cjs +1 -292
  66. package/dist/core/router/performance/index.cjs +1 -21
  67. package/dist/core/router/plugin/RouterPluginManager.cjs +1 -262
  68. package/dist/core/router/plugin/index.cjs +1 -21
  69. package/dist/core/router/plugin/types.cjs +1 -39
  70. package/dist/core/router/types.cjs +1 -4
  71. package/dist/core/router/utils/adapters/react-router/RouteErrorBoundary.cjs +1 -129
  72. package/dist/core/router/utils/adapters/react-router/transform.cjs +1 -250
  73. package/dist/core/router/utils/transform.cjs +1 -780
  74. package/dist/core/router/validation/RouterConfigValidator.cjs +2 -83
  75. package/dist/core/router/validation/index.cjs +1 -21
  76. package/dist/core/router/validation/schema.cjs +1 -159
  77. package/dist/core/router/version/RouteVersionManager.cjs +1 -205
  78. package/dist/core/router/version/index.cjs +1 -20
  79. package/dist/core/splash/SplashScreen.cjs +1 -341
  80. package/dist/core/splash/index.cjs +1 -22
  81. package/dist/core/splash/splashScreenUtils.cjs +1 -38
  82. package/dist/core/startup/AppInstance.cjs +1 -239
  83. package/dist/core/startup/environment.cjs +1 -169
  84. package/dist/core/startup/index.cjs +1 -23
  85. package/dist/core/startup/initializeServices.cjs +1 -226
  86. package/dist/core/startup/performanceTracker.cjs +1 -179
  87. package/dist/core/startup/renderApp.cjs +1 -314
  88. package/dist/core/startup/startApp.cjs +1 -317
  89. package/dist/core/types.cjs +1 -4
  90. package/dist/index.cjs +1 -52
  91. package/dist/index.umd.cjs +1 -27
  92. package/dist/index.umd.js +1 -1
  93. package/dist/kernel/constants.cjs +1 -65
  94. package/dist/kernel/index.cjs +1 -38
  95. package/dist/kernel/kernel.cjs +1 -295
  96. package/dist/kernel/manager/cacheManager.cjs +1 -46
  97. package/dist/kernel/manager/i18n/I18nManager.cjs +1 -91
  98. package/dist/kernel/manager/i18n/i18n.persistence.cjs +1 -60
  99. package/dist/kernel/manager/i18n/i18n.schema.cjs +1 -86
  100. package/dist/kernel/manager/i18n/index.cjs +1 -11
  101. package/dist/kernel/manager/i18nManager.cjs +1 -11
  102. package/dist/kernel/manager/index.cjs +1 -28
  103. package/dist/kernel/manager/logger/LoggerManager.cjs +1 -107
  104. package/dist/kernel/manager/logger/index.cjs +1 -11
  105. package/dist/kernel/manager/logger/logger.persistence.cjs +1 -62
  106. package/dist/kernel/manager/logger/logger.schema.cjs +1 -74
  107. package/dist/kernel/manager/loggerManager.cjs +1 -11
  108. package/dist/kernel/manager/theme/ThemeManager.cjs +1 -84
  109. package/dist/kernel/manager/theme/index.cjs +1 -11
  110. package/dist/kernel/manager/theme/theme.dom.cjs +1 -61
  111. package/dist/kernel/manager/theme/theme.persistence.cjs +1 -57
  112. package/dist/kernel/manager/theme/theme.schema.cjs +1 -122
  113. package/dist/kernel/manager/themeManager.cjs +1 -11
  114. package/dist/kernel/types.cjs +1 -4
  115. package/dist/library/index.cjs +1 -19
  116. package/dist/library/locale/index.cjs +1 -39
  117. package/dist/library/locale/langs/en-us/index.cjs +1 -32
  118. package/dist/library/locale/langs/zh-cn/index.cjs +1 -32
  119. package/dist/library/locale/types.cjs +1 -4
  120. package/dist/library/storage/cache.cjs +1 -243
  121. package/dist/library/storage/encryption.cjs +1 -147
  122. package/dist/library/storage/index.cjs +1 -124
  123. package/dist/state/StateManager.cjs +1 -166
  124. package/dist/state/adapters/AdapterFactory.cjs +1 -89
  125. package/dist/state/adapters/DefaultAdapter.cjs +1 -75
  126. package/dist/state/adapters/ReduxAdapter.cjs +1 -443
  127. package/dist/state/adapters/ZustandAdapter.cjs +1 -69
  128. package/dist/state/adapters/index.cjs +1 -44
  129. package/dist/state/adapters/types.cjs +1 -20
  130. package/dist/state/core/DerivedStateInstance.cjs +1 -174
  131. package/dist/state/core/StateInstance.cjs +1 -170
  132. package/dist/state/core/StateRegistry.cjs +1 -110
  133. package/dist/state/core/StateScope.cjs +1 -137
  134. package/dist/state/core/index.cjs +1 -30
  135. package/dist/state/index.cjs +1 -30
  136. package/dist/state/types.cjs +1 -12
  137. package/dist/state.umd.js +1 -1
  138. package/dist/types.cjs +1 -4
  139. package/dist/utils/analytics.cjs +1 -217
  140. package/dist/utils/configSecurity.cjs +3 -182
  141. package/dist/utils/csrf.cjs +1 -18
  142. package/dist/utils/errors/ErrorCodes.cjs +1 -25
  143. package/dist/utils/errors.cjs +1 -111
  144. package/dist/utils/index.cjs +1 -135
  145. package/dist/utils/logger.cjs +1 -25
  146. package/dist/utils/logger.types.cjs +1 -11
  147. package/dist/utils/monitoring.cjs +1 -18
  148. package/dist/utils/performance.cjs +1 -22
  149. package/dist/utils/resourceLoader.cjs +1 -22
  150. package/dist/utils/runtimeSecurity.cjs +1 -11
  151. package/dist/utils/security.cjs +1 -19
  152. package/dist/utils/traceId.cjs +1 -37
  153. package/dist/utils/validation.cjs +1 -19
  154. package/package.json +12 -3
@@ -1,83 +1,2 @@
1
- /**
2
- * 路由配置验证器
3
- * 使用 Zod 进行配置验证,并提供友好的错误信息
4
- */ "use strict";
5
- Object.defineProperty(exports, "__esModule", {
6
- value: true
7
- });
8
- Object.defineProperty(exports, "RouterConfigValidator", {
9
- enumerable: true,
10
- get: function() {
11
- return RouterConfigValidator;
12
- }
13
- });
14
- const _ConfigValidator = require("../../config/ConfigValidator");
15
- const _logger = require("@vlian/logger");
16
- const _schema = require("./schema");
17
- let RouterConfigValidator = class RouterConfigValidator {
18
- /**
19
- * 验证路由配置
20
- *
21
- * @param config - 要验证的路由配置
22
- * @returns 验证后的路由配置
23
- * @throws ConfigValidationError 如果配置验证失败
24
- */ static validate(config) {
25
- const result = (0, _schema.safeValidateRouterConfig)(config);
26
- if (!result.success) {
27
- // 构建友好的错误信息
28
- const errorMessages = result.error.issues.map((issue)=>{
29
- const path = issue.path.length > 0 ? issue.path.join('.') : 'root';
30
- return `路由配置项 "${path}": ${issue.message}`;
31
- });
32
- const friendlyMessage = `路由配置验证失败:\n${errorMessages.join('\n')}`;
33
- _logger.logger.error('路由配置验证失败', {
34
- errors: result.error.issues,
35
- config
36
- });
37
- throw new _ConfigValidator.ConfigValidationError(friendlyMessage, result.error);
38
- }
39
- return result.data;
40
- }
41
- /**
42
- * 安全验证路由配置(不抛出异常)
43
- *
44
- * @param config - 要验证的路由配置
45
- * @returns 验证结果
46
- */ static safeValidate(config) {
47
- return (0, _schema.safeValidateRouterConfig)(config);
48
- }
49
- /**
50
- * 验证路由配置并提供修复建议
51
- *
52
- * @param config - 要验证的路由配置
53
- * @returns 验证结果和修复建议
54
- */ static validateWithSuggestions(config) {
55
- const result = (0, _schema.safeValidateRouterConfig)(config);
56
- if (!result.success) {
57
- const suggestions = [];
58
- result.error.issues.forEach((issue)=>{
59
- const path = issue.path.join('.');
60
- // 根据错误类型提供修复建议
61
- if (issue.code === 'invalid_type') {
62
- const invalidTypeIssue = issue;
63
- suggestions.push(`配置项 "${path}" 类型错误: 期望 ${invalidTypeIssue.expected},实际 ${invalidTypeIssue.received}`);
64
- } else if (issue.code === 'too_small') {
65
- suggestions.push(`配置项 "${path}" 值太小: ${issue.message}`);
66
- } else if (issue.code === 'too_big') {
67
- suggestions.push(`配置项 "${path}" 值太大: ${issue.message}`);
68
- } else {
69
- suggestions.push(`配置项 "${path}": ${issue.message}`);
70
- }
71
- });
72
- return {
73
- success: false,
74
- errors: result.error.issues,
75
- suggestions
76
- };
77
- }
78
- return {
79
- success: true,
80
- data: result.data
81
- };
82
- }
83
- };
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:true});Object.defineProperty(exports,"RouterConfigValidator",{enumerable:true,get:function(){return RouterConfigValidator}});const _ConfigValidator=require("../../config/ConfigValidator");const _logger=require("@vlian/logger");const _schema=require("./schema");let RouterConfigValidator=class RouterConfigValidator{static validate(config){const result=(0,_schema.safeValidateRouterConfig)(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")}`;_logger.logger.error("路由配置验证失败",{errors:result.error.issues,config});throw new _ConfigValidator.ConfigValidationError(friendlyMessage,result.error)}return result.data}static safeValidate(config){return(0,_schema.safeValidateRouterConfig)(config)}static validateWithSuggestions(config){const result=(0,_schema.safeValidateRouterConfig)(config);if(!result.success){const suggestions=[];result.error.issues.forEach(issue=>{const path=issue.path.join(".");if(issue.code==="invalid_type"){const invalidTypeIssue=issue;suggestions.push(`配置项 "${path}" 类型错误: 期望 ${invalidTypeIssue.expected},实际 ${invalidTypeIssue.received}`)}else if(issue.code==="too_small"){suggestions.push(`配置项 "${path}" 值太小: ${issue.message}`)}else if(issue.code==="too_big"){suggestions.push(`配置项 "${path}" 值太大: ${issue.message}`)}else{suggestions.push(`配置项 "${path}": ${issue.message}`)}});return{success:false,errors:result.error.issues,suggestions}}return{success:true,data:result.data}}};
@@ -1,21 +1 @@
1
- /**
2
- * 路由配置验证模块入口
3
- */ "use strict";
4
- Object.defineProperty(exports, "__esModule", {
5
- value: true
6
- });
7
- _export_star(require("./schema"), exports);
8
- _export_star(require("./RouterConfigValidator"), exports);
9
- function _export_star(from, to) {
10
- Object.keys(from).forEach(function(k) {
11
- if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) {
12
- Object.defineProperty(to, k, {
13
- enumerable: true,
14
- get: function() {
15
- return from[k];
16
- }
17
- });
18
- }
19
- });
20
- return from;
21
- }
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:true});_export_star(require("./schema"),exports);_export_star(require("./RouterConfigValidator"),exports);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}
@@ -1,159 +1 @@
1
- /**
2
- * 路由配置验证 Schema(使用 Zod)
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 componentImportSchema () {
15
- return componentImportSchema;
16
- },
17
- get routeConfigSchema () {
18
- return routeConfigSchema;
19
- },
20
- get routeItemHandleSchema () {
21
- return routeItemHandleSchema;
22
- },
23
- get routerConfigSchema () {
24
- return routerConfigSchema;
25
- },
26
- get safeValidateRouterConfig () {
27
- return safeValidateRouterConfig;
28
- },
29
- get validateRouterConfig () {
30
- return validateRouterConfig;
31
- }
32
- });
33
- const _zod = require("zod");
34
- const routeItemHandleSchema = _zod.z.object({
35
- title: _zod.z.string().min(1, '路由标题不能为空'),
36
- i18nKey: _zod.z.string().optional(),
37
- order: _zod.z.number().int('排序值必须是整数'),
38
- icon: _zod.z.string().optional(),
39
- hideInMenu: _zod.z.boolean().optional(),
40
- hideFooter: _zod.z.boolean().optional(),
41
- keepAlive: _zod.z.boolean().optional(),
42
- needLogin: _zod.z.boolean().optional(),
43
- roles: _zod.z.array(_zod.z.string()).optional(),
44
- name: _zod.z.string().optional()
45
- }).passthrough(); // 允许其他自定义字段
46
- const componentImportSchema = _zod.z.union([
47
- _zod.z.string().min(1, '组件路径不能为空'),
48
- _zod.z.function(),
49
- _zod.z.null()
50
- ]);
51
- const routerOptionsSchema = _zod.z.object({
52
- basename: _zod.z.string().optional(),
53
- future: _zod.z.record(_zod.z.string(), _zod.z.union([
54
- _zod.z.boolean(),
55
- _zod.z.string(),
56
- _zod.z.number()
57
- ])).optional(),
58
- hydrationData: _zod.z.unknown().optional(),
59
- window: _zod.z.unknown().optional(),
60
- initialEntries: _zod.z.array(_zod.z.string()).optional(),
61
- initialIndex: _zod.z.number().int().nonnegative().optional()
62
- }).passthrough();
63
- const transformOptionsSchema = _zod.z.object({
64
- pathValidation: _zod.z.object({
65
- enablePathValidation: _zod.z.boolean().optional(),
66
- allowedPathPrefixes: _zod.z.array(_zod.z.string().min(1)).optional(),
67
- maxPathLength: _zod.z.number().int().positive().optional(),
68
- allowAbsolutePaths: _zod.z.boolean().optional()
69
- }).optional(),
70
- performance: _zod.z.object({
71
- enableCache: _zod.z.boolean().optional(),
72
- cacheTTL: _zod.z.number().int().positive().optional(),
73
- maxCacheSize: _zod.z.number().int().positive().optional(),
74
- maxRecursionDepth: _zod.z.number().int().positive().optional(),
75
- enableParallelProcessing: _zod.z.boolean().optional(),
76
- parallelBatchSize: _zod.z.number().int().positive().optional()
77
- }).optional(),
78
- enableDebugLog: _zod.z.boolean().optional()
79
- }).passthrough();
80
- const routeConfigSchema = _zod.z.lazy(()=>_zod.z.object({
81
- layout: componentImportSchema.optional().nullable(),
82
- page: componentImportSchema.optional().nullable(),
83
- loading: componentImportSchema.optional().nullable(),
84
- error: componentImportSchema.optional().nullable(),
85
- errors: componentImportSchema.optional().nullable(),
86
- name: _zod.z.string().min(1, '路由名称不能为空'),
87
- path: _zod.z.string().optional(),
88
- isGroup: _zod.z.boolean().optional(),
89
- enableRedirection: _zod.z.boolean().optional(),
90
- handle: routeItemHandleSchema,
91
- children: _zod.z.array(routeConfigSchema).optional()
92
- }));
93
- const routerConfigSchema = _zod.z.object({
94
- enabled: _zod.z.union([
95
- _zod.z.boolean(),
96
- _zod.z.literal('disabled')
97
- ]).optional(),
98
- routes: _zod.z.union([
99
- _zod.z.array(routeConfigSchema),
100
- _zod.z.function()
101
- ]).optional(),
102
- mode: _zod.z.enum([
103
- 'browser',
104
- 'hash',
105
- 'memory'
106
- ]).optional(),
107
- options: routerOptionsSchema.optional(),
108
- pathResolve: _zod.z.object({
109
- basePath: _zod.z.string().optional(),
110
- pathAliases: _zod.z.record(_zod.z.string(), _zod.z.string()).optional()
111
- }).optional(),
112
- transformOptions: transformOptionsSchema.optional(),
113
- preload: _zod.z.object({
114
- strategy: _zod.z.enum([
115
- 'none',
116
- 'next-level',
117
- 'all',
118
- 'visible'
119
- ]).optional(),
120
- delay: _zod.z.number().int().positive().optional(),
121
- priorityThreshold: _zod.z.number().int().nonnegative().optional(),
122
- timeout: _zod.z.number().int().positive().optional()
123
- }).optional(),
124
- enableHydrateFallback: _zod.z.boolean().optional()
125
- }).superRefine((config, ctx)=>{
126
- if (!Array.isArray(config.routes)) {
127
- return;
128
- }
129
- const routeNameMap = new Map();
130
- const walk = (routes, parentPath)=>{
131
- routes.forEach((route, index)=>{
132
- const currentPath = `${parentPath}[${index}]`;
133
- const existingPath = routeNameMap.get(route.name);
134
- if (existingPath) {
135
- ctx.addIssue({
136
- code: _zod.z.ZodIssueCode.custom,
137
- path: [
138
- 'routes',
139
- index,
140
- 'name'
141
- ],
142
- message: `路由名称重复: "${route.name}",首次定义位置 ${existingPath}`
143
- });
144
- } else {
145
- routeNameMap.set(route.name, currentPath);
146
- }
147
- if (Array.isArray(route.children) && route.children.length > 0) {
148
- walk(route.children, `${currentPath}.children`);
149
- }
150
- });
151
- };
152
- walk(config.routes, 'routes');
153
- });
154
- function validateRouterConfig(config) {
155
- return routerConfigSchema.parse(config);
156
- }
157
- function safeValidateRouterConfig(config) {
158
- return routerConfigSchema.safeParse(config);
159
- }
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 componentImportSchema(){return componentImportSchema},get routeConfigSchema(){return routeConfigSchema},get routeItemHandleSchema(){return routeItemHandleSchema},get routerConfigSchema(){return routerConfigSchema},get safeValidateRouterConfig(){return safeValidateRouterConfig},get validateRouterConfig(){return validateRouterConfig}});const _zod=require("zod");const routeItemHandleSchema=_zod.z.object({title:_zod.z.string().min(1,"路由标题不能为空"),i18nKey:_zod.z.string().optional(),order:_zod.z.number().int("排序值必须是整数"),icon:_zod.z.string().optional(),hideInMenu:_zod.z.boolean().optional(),hideFooter:_zod.z.boolean().optional(),keepAlive:_zod.z.boolean().optional(),needLogin:_zod.z.boolean().optional(),roles:_zod.z.array(_zod.z.string()).optional(),name:_zod.z.string().optional()}).passthrough();const componentImportSchema=_zod.z.union([_zod.z.string().min(1,"组件路径不能为空"),_zod.z.function(),_zod.z.null()]);const routerOptionsSchema=_zod.z.object({basename:_zod.z.string().optional(),future:_zod.z.record(_zod.z.string(),_zod.z.union([_zod.z.boolean(),_zod.z.string(),_zod.z.number()])).optional(),hydrationData:_zod.z.unknown().optional(),window:_zod.z.unknown().optional(),initialEntries:_zod.z.array(_zod.z.string()).optional(),initialIndex:_zod.z.number().int().nonnegative().optional()}).passthrough();const transformOptionsSchema=_zod.z.object({pathValidation:_zod.z.object({enablePathValidation:_zod.z.boolean().optional(),allowedPathPrefixes:_zod.z.array(_zod.z.string().min(1)).optional(),maxPathLength:_zod.z.number().int().positive().optional(),allowAbsolutePaths:_zod.z.boolean().optional()}).optional(),performance:_zod.z.object({enableCache:_zod.z.boolean().optional(),cacheTTL:_zod.z.number().int().positive().optional(),maxCacheSize:_zod.z.number().int().positive().optional(),maxRecursionDepth:_zod.z.number().int().positive().optional(),enableParallelProcessing:_zod.z.boolean().optional(),parallelBatchSize:_zod.z.number().int().positive().optional()}).optional(),enableDebugLog:_zod.z.boolean().optional()}).passthrough();const routeConfigSchema=_zod.z.lazy(()=>_zod.z.object({layout:componentImportSchema.optional().nullable(),page:componentImportSchema.optional().nullable(),loading:componentImportSchema.optional().nullable(),error:componentImportSchema.optional().nullable(),errors:componentImportSchema.optional().nullable(),name:_zod.z.string().min(1,"路由名称不能为空"),path:_zod.z.string().optional(),isGroup:_zod.z.boolean().optional(),enableRedirection:_zod.z.boolean().optional(),handle:routeItemHandleSchema,children:_zod.z.array(routeConfigSchema).optional()}));const routerConfigSchema=_zod.z.object({enabled:_zod.z.union([_zod.z.boolean(),_zod.z.literal("disabled")]).optional(),routes:_zod.z.union([_zod.z.array(routeConfigSchema),_zod.z.function()]).optional(),mode:_zod.z.enum(["browser","hash","memory"]).optional(),options:routerOptionsSchema.optional(),pathResolve:_zod.z.object({basePath:_zod.z.string().optional(),pathAliases:_zod.z.record(_zod.z.string(),_zod.z.string()).optional()}).optional(),transformOptions:transformOptionsSchema.optional(),preload:_zod.z.object({strategy:_zod.z.enum(["none","next-level","all","visible"]).optional(),delay:_zod.z.number().int().positive().optional(),priorityThreshold:_zod.z.number().int().nonnegative().optional(),timeout:_zod.z.number().int().positive().optional()}).optional(),enableHydrateFallback:_zod.z.boolean().optional()}).superRefine((config,ctx)=>{if(!Array.isArray(config.routes)){return}const routeNameMap=new Map;const walk=(routes,parentPath)=>{routes.forEach((route,index)=>{const currentPath=`${parentPath}[${index}]`;const existingPath=routeNameMap.get(route.name);if(existingPath){ctx.addIssue({code:_zod.z.ZodIssueCode.custom,path:["routes",index,"name"],message:`路由名称重复: "${route.name}",首次定义位置 ${existingPath}`})}else{routeNameMap.set(route.name,currentPath)}if(Array.isArray(route.children)&&route.children.length>0){walk(route.children,`${currentPath}.children`)}})};walk(config.routes,"routes")});function validateRouterConfig(config){return routerConfigSchema.parse(config)}function safeValidateRouterConfig(config){return routerConfigSchema.safeParse(config)}
@@ -1,205 +1 @@
1
- /**
2
- * 路由版本管理器
3
- * 支持路由版本控制和迁移
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 RouteVersionManager () {
16
- return RouteVersionManager;
17
- },
18
- get getRouteVersionManager () {
19
- return getRouteVersionManager;
20
- }
21
- });
22
- const _logger = require("@vlian/logger");
23
- const _errors = require("../errors");
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
- let RouteVersionManager = class RouteVersionManager {
38
- /**
39
- * 注册路由版本
40
- *
41
- * @param version - 版本信息
42
- */ registerVersion(version) {
43
- // 验证版本号格式(简单的语义化版本检查)
44
- if (!/^\d+\.\d+\.\d+/.test(version.version)) {
45
- throw new Error(`无效的版本号格式: ${version.version}`);
46
- }
47
- this.versions.set(version.version, {
48
- ...version,
49
- createdAt: version.createdAt || Date.now()
50
- });
51
- _logger.logger.debug(`路由版本已注册: ${version.version}`);
52
- }
53
- /**
54
- * 注册版本迁移函数
55
- *
56
- * @param fromVersion - 源版本
57
- * @param toVersion - 目标版本
58
- * @param migration - 迁移函数
59
- */ registerMigration(fromVersion, toVersion, migration) {
60
- const key = `${fromVersion}->${toVersion}`;
61
- this.migrations.set(key, migration);
62
- _logger.logger.debug(`路由版本迁移已注册: ${key}`);
63
- }
64
- /**
65
- * 检查版本兼容性
66
- *
67
- * @param version - 要检查的版本
68
- * @returns 是否兼容
69
- */ checkCompatibility(version) {
70
- const versionInfo = this.versions.get(version);
71
- if (!versionInfo) {
72
- return false;
73
- }
74
- // 如果明确标记为不兼容,返回 false
75
- if (versionInfo.compatible === false) {
76
- return false;
77
- }
78
- // 简单的版本兼容性检查(主版本号相同)
79
- const currentMajor = parseInt(this.config.currentVersion.split('.')[0]);
80
- const targetMajor = parseInt(version.split('.')[0]);
81
- return currentMajor === targetMajor;
82
- }
83
- /**
84
- * 迁移路由配置
85
- *
86
- * @param fromVersion - 源版本
87
- * @param toVersion - 目标版本
88
- * @param routes - 路由配置
89
- * @returns 迁移后的路由配置
90
- */ async migrate(fromVersion, toVersion, routes) {
91
- if (fromVersion === toVersion) {
92
- return routes;
93
- }
94
- const migrationKey = `${fromVersion}->${toVersion}`;
95
- const migration = this.migrations.get(migrationKey);
96
- if (!migration) {
97
- // 如果没有直接迁移,尝试逐步迁移
98
- return this.migrateStepwise(fromVersion, toVersion, routes);
99
- }
100
- try {
101
- const migratedRoutes = await migration(fromVersion, toVersion, routes);
102
- _logger.logger.info(`路由版本迁移完成: ${fromVersion} -> ${toVersion}`);
103
- return migratedRoutes;
104
- } catch (error) {
105
- _logger.logger.error(`路由版本迁移失败: ${fromVersion} -> ${toVersion}`, error);
106
- const errorContext = {
107
- fromVersion,
108
- toVersion
109
- };
110
- if (error instanceof Error) {
111
- errorContext.originalError = error;
112
- }
113
- throw new _errors.RouterError(`路由版本迁移失败: ${fromVersion} -> ${toVersion}`, _errors.RouterErrorCode.ROUTE_TRANSFORM_FAILED, undefined, error instanceof Error ? error : undefined, errorContext);
114
- }
115
- }
116
- /**
117
- * 逐步迁移(通过中间版本)
118
- */ async migrateStepwise(fromVersion, toVersion, routes) {
119
- // 获取所有版本并按版本号排序
120
- const allVersions = Array.from(this.versions.keys()).sort((a, b)=>{
121
- const aParts = a.split('.').map(Number);
122
- const bParts = b.split('.').map(Number);
123
- for(let i = 0; i < 3; i++){
124
- if (aParts[i] !== bParts[i]) {
125
- return aParts[i] - bParts[i];
126
- }
127
- }
128
- return 0;
129
- });
130
- // 找到从 fromVersion 到 toVersion 的路径
131
- const fromIndex = allVersions.indexOf(fromVersion);
132
- const toIndex = allVersions.indexOf(toVersion);
133
- if (fromIndex === -1 || toIndex === -1) {
134
- throw new Error(`无法找到版本迁移路径: ${fromVersion} -> ${toVersion}`);
135
- }
136
- let currentRoutes = routes;
137
- const step = fromIndex < toIndex ? 1 : -1;
138
- for(let i = fromIndex; i !== toIndex; i += step){
139
- const currentVersion = allVersions[i];
140
- const nextVersion = allVersions[i + step];
141
- const migrationKey = `${currentVersion}->${nextVersion}`;
142
- const migration = this.migrations.get(migrationKey);
143
- if (migration) {
144
- currentRoutes = await migration(currentVersion, nextVersion, currentRoutes);
145
- } else {
146
- // 如果没有迁移函数,直接使用当前路由(可能不兼容)
147
- _logger.logger.warn(`缺少迁移函数: ${migrationKey},跳过迁移`);
148
- }
149
- }
150
- return currentRoutes;
151
- }
152
- /**
153
- * 获取版本信息
154
- *
155
- * @param version - 版本号
156
- * @returns 版本信息,如果不存在返回 undefined
157
- */ getVersion(version) {
158
- return this.versions.get(version);
159
- }
160
- /**
161
- * 获取所有版本
162
- *
163
- * @returns 版本信息数组
164
- */ getAllVersions() {
165
- return Array.from(this.versions.values());
166
- }
167
- /**
168
- * 获取当前版本
169
- *
170
- * @returns 当前版本信息
171
- */ getCurrentVersion() {
172
- return this.versions.get(this.config.currentVersion);
173
- }
174
- /**
175
- * 回滚到指定版本
176
- *
177
- * @param version - 目标版本
178
- * @param routes - 当前路由配置
179
- * @returns 回滚后的路由配置
180
- */ async rollback(version, routes) {
181
- return this.migrate(this.config.currentVersion, version, routes);
182
- }
183
- constructor(config){
184
- _define_property(this, "versions", new Map());
185
- _define_property(this, "migrations", new Map());
186
- _define_property(this, "config", void 0);
187
- this.config = {
188
- enableVersionCheck: config.enableVersionCheck ?? true,
189
- enableAutoMigration: config.enableAutoMigration ?? false,
190
- currentVersion: config.currentVersion
191
- };
192
- }
193
- };
194
- /**
195
- * 获取路由版本管理器单例
196
- */ let versionManagerInstance = null;
197
- function getRouteVersionManager(config) {
198
- if (!versionManagerInstance && config) {
199
- versionManagerInstance = new RouteVersionManager(config);
200
- }
201
- if (!versionManagerInstance) {
202
- throw new Error('路由版本管理器未初始化,请先提供配置');
203
- }
204
- return versionManagerInstance;
205
- }
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 RouteVersionManager(){return RouteVersionManager},get getRouteVersionManager(){return getRouteVersionManager}});const _logger=require("@vlian/logger");const _errors=require("../errors");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 RouteVersionManager=class RouteVersionManager{registerVersion(version){if(!/^\d+\.\d+\.\d+/.test(version.version)){throw new Error(`无效的版本号格式: ${version.version}`)}this.versions.set(version.version,{...version,createdAt:version.createdAt||Date.now()});_logger.logger.debug(`路由版本已注册: ${version.version}`)}registerMigration(fromVersion,toVersion,migration){const key=`${fromVersion}->${toVersion}`;this.migrations.set(key,migration);_logger.logger.debug(`路由版本迁移已注册: ${key}`)}checkCompatibility(version){const versionInfo=this.versions.get(version);if(!versionInfo){return false}if(versionInfo.compatible===false){return false}const currentMajor=parseInt(this.config.currentVersion.split(".")[0]);const targetMajor=parseInt(version.split(".")[0]);return currentMajor===targetMajor}async migrate(fromVersion,toVersion,routes){if(fromVersion===toVersion){return routes}const migrationKey=`${fromVersion}->${toVersion}`;const migration=this.migrations.get(migrationKey);if(!migration){return this.migrateStepwise(fromVersion,toVersion,routes)}try{const migratedRoutes=await migration(fromVersion,toVersion,routes);_logger.logger.info(`路由版本迁移完成: ${fromVersion} -> ${toVersion}`);return migratedRoutes}catch(error){_logger.logger.error(`路由版本迁移失败: ${fromVersion} -> ${toVersion}`,error);const errorContext={fromVersion,toVersion};if(error instanceof Error){errorContext.originalError=error}throw new _errors.RouterError(`路由版本迁移失败: ${fromVersion} -> ${toVersion}`,_errors.RouterErrorCode.ROUTE_TRANSFORM_FAILED,undefined,error instanceof Error?error:undefined,errorContext)}}async migrateStepwise(fromVersion,toVersion,routes){const allVersions=Array.from(this.versions.keys()).sort((a,b)=>{const aParts=a.split(".").map(Number);const bParts=b.split(".").map(Number);for(let i=0;i<3;i++){if(aParts[i]!==bParts[i]){return aParts[i]-bParts[i]}}return 0});const fromIndex=allVersions.indexOf(fromVersion);const toIndex=allVersions.indexOf(toVersion);if(fromIndex===-1||toIndex===-1){throw new Error(`无法找到版本迁移路径: ${fromVersion} -> ${toVersion}`)}let currentRoutes=routes;const step=fromIndex<toIndex?1:-1;for(let i=fromIndex;i!==toIndex;i+=step){const currentVersion=allVersions[i];const nextVersion=allVersions[i+step];const migrationKey=`${currentVersion}->${nextVersion}`;const migration=this.migrations.get(migrationKey);if(migration){currentRoutes=await migration(currentVersion,nextVersion,currentRoutes)}else{_logger.logger.warn(`缺少迁移函数: ${migrationKey},跳过迁移`)}}return currentRoutes}getVersion(version){return this.versions.get(version)}getAllVersions(){return Array.from(this.versions.values())}getCurrentVersion(){return this.versions.get(this.config.currentVersion)}async rollback(version,routes){return this.migrate(this.config.currentVersion,version,routes)}constructor(config){_define_property(this,"versions",new Map);_define_property(this,"migrations",new Map);_define_property(this,"config",void 0);this.config={enableVersionCheck:config.enableVersionCheck??true,enableAutoMigration:config.enableAutoMigration??false,currentVersion:config.currentVersion}}};let versionManagerInstance=null;function getRouteVersionManager(config){if(!versionManagerInstance&&config){versionManagerInstance=new RouteVersionManager(config)}if(!versionManagerInstance){throw new Error("路由版本管理器未初始化,请先提供配置")}return versionManagerInstance}
@@ -1,20 +1 @@
1
- /**
2
- * 路由版本管理模块入口
3
- */ "use strict";
4
- Object.defineProperty(exports, "__esModule", {
5
- value: true
6
- });
7
- _export_star(require("./RouteVersionManager"), exports);
8
- function _export_star(from, to) {
9
- Object.keys(from).forEach(function(k) {
10
- if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) {
11
- Object.defineProperty(to, k, {
12
- enumerable: true,
13
- get: function() {
14
- return from[k];
15
- }
16
- });
17
- }
18
- });
19
- return from;
20
- }
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:true});_export_star(require("./RouteVersionManager"),exports);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}