@vlian/framework 1.2.57 → 1.2.59
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/README.md +15 -3
- package/dist/analytics/index.cjs +0 -2
- package/dist/analytics/index.js +1 -3
- package/dist/analytics.umd.js +8 -208
- package/dist/components/LocaleSwitch.cjs +0 -2
- package/dist/components/LocaleSwitch.js +1 -103
- package/dist/components/ThemeSwitch.cjs +0 -2
- package/dist/components/ThemeSwitch.js +1 -102
- package/dist/components/index.cjs +0 -2
- package/dist/components/index.js +1 -4
- package/dist/components/persistence.cjs +0 -2
- package/dist/components/persistence.js +1 -39
- package/dist/core/Test.cjs +0 -2
- package/dist/core/Test.js +1 -15
- package/dist/core/app/AppContext.cjs +0 -2
- package/dist/core/app/AppContext.js +1 -339
- package/dist/core/app/AppContext.types.cjs +0 -2
- package/dist/core/app/AppContext.types.js +1 -5
- package/dist/core/app/BasicLayout.cjs +0 -2
- package/dist/core/app/BasicLayout.js +1 -74
- package/dist/core/app/DefaultApp.cjs +0 -2
- package/dist/core/app/DefaultApp.js +1 -143
- package/dist/core/app/index.cjs +0 -2
- package/dist/core/app/index.js +1 -7
- package/dist/core/config/AppConfig.cjs +0 -2
- package/dist/core/config/AppConfig.js +1 -133
- package/dist/core/config/ConfigLoader.cjs +0 -2
- package/dist/core/config/ConfigLoader.js +1 -311
- package/dist/core/config/ConfigValidator.cjs +0 -2
- package/dist/core/config/ConfigValidator.js +2 -121
- package/dist/core/config/index.cjs +0 -2
- package/dist/core/config/index.js +1 -7
- package/dist/core/dev/DevTools.cjs +0 -2
- package/dist/core/dev/DevTools.js +1 -210
- package/dist/core/error/ErrorBoundary.cjs +0 -2
- package/dist/core/error/ErrorBoundary.js +1 -399
- package/dist/core/error/ErrorHandler.cjs +0 -2
- package/dist/core/error/ErrorHandler.js +1 -261
- package/dist/core/error/index.cjs +0 -2
- package/dist/core/error/index.js +1 -6
- package/dist/core/event/AppEventBus.cjs +0 -2
- package/dist/core/event/AppEventBus.js +1 -438
- package/dist/core/event/frameworkEvents.cjs +0 -2
- package/dist/core/event/frameworkEvents.js +1 -135
- package/dist/core/event/hooks.cjs +0 -2
- package/dist/core/event/hooks.js +1 -95
- package/dist/core/event/index.cjs +0 -2
- package/dist/core/event/index.js +1 -10
- package/dist/core/event/types.cjs +0 -2
- package/dist/core/event/types.js +1 -56
- package/dist/core/event/useEventBus.cjs +0 -2
- package/dist/core/event/useEventBus.js +1 -39
- package/dist/core/index.cjs +0 -2
- package/dist/core/index.js +1 -69
- package/dist/core/initialization/InitializationErrorThrower.cjs +0 -2
- package/dist/core/initialization/InitializationErrorThrower.js +1 -30
- package/dist/core/initialization/index.cjs +0 -2
- package/dist/core/initialization/index.js +1 -7
- package/dist/core/initialization/initialization.cjs +0 -2
- package/dist/core/initialization/initialization.js +1 -78
- package/dist/core/initialization/initializationErrorState.cjs +0 -2
- package/dist/core/initialization/initializationErrorState.js +1 -60
- package/dist/core/kernel/defaultAdapters.cjs +0 -2
- package/dist/core/kernel/defaultAdapters.js +1 -176
- package/dist/core/kernel/errors.cjs +0 -2
- package/dist/core/kernel/errors.js +1 -53
- package/dist/core/kernel/index.cjs +0 -2
- package/dist/core/kernel/index.js +1 -4
- package/dist/core/kernel/startKernel.cjs +0 -2
- package/dist/core/kernel/startKernel.js +1 -192
- package/dist/core/kernel/types.cjs +0 -2
- package/dist/core/kernel/types.js +1 -3
- package/dist/core/middleware.cjs +0 -2
- package/dist/core/middleware.js +1 -61
- package/dist/core/plugin/PluginEventBus.cjs +0 -2
- package/dist/core/plugin/PluginEventBus.js +1 -286
- package/dist/core/plugin/PluginSandbox.cjs +0 -2
- package/dist/core/plugin/PluginSandbox.js +1 -125
- package/dist/core/plugin.cjs +0 -2
- package/dist/core/plugin.js +1 -438
- package/dist/core/router/RouterManager.cjs +0 -2
- package/dist/core/router/RouterManager.js +1 -272
- package/dist/core/router/adapter/AdapterManager.cjs +0 -2
- package/dist/core/router/adapter/AdapterManager.js +1 -221
- package/dist/core/router/adapter/index.cjs +0 -2
- package/dist/core/router/adapter/index.js +1 -7
- package/dist/core/router/adapter/react-router/ReactRouterAdapter.cjs +0 -2
- package/dist/core/router/adapter/react-router/ReactRouterAdapter.js +1 -116
- package/dist/core/router/adapter/react-router/index.cjs +0 -2
- package/dist/core/router/adapter/react-router/index.js +1 -5
- package/dist/core/router/adapter/types.cjs +0 -2
- package/dist/core/router/adapter/types.js +1 -7
- package/dist/core/router/dev/RouterDevTools.cjs +0 -2
- package/dist/core/router/dev/RouterDevTools.js +1 -211
- package/dist/core/router/dev/index.cjs +0 -2
- package/dist/core/router/dev/index.js +1 -5
- package/dist/core/router/dynamic/DynamicRouteManager.cjs +0 -2
- package/dist/core/router/dynamic/DynamicRouteManager.js +1 -179
- package/dist/core/router/dynamic/index.cjs +0 -2
- package/dist/core/router/dynamic/index.js +1 -5
- package/dist/core/router/errors/RouterError.cjs +0 -2
- package/dist/core/router/errors/RouterError.js +1 -48
- package/dist/core/router/errors/index.cjs +0 -2
- package/dist/core/router/errors/index.js +1 -5
- package/dist/core/router/index.cjs +0 -2
- package/dist/core/router/index.js +1 -32
- package/dist/core/router/lifecycle/RouterLifecycleManager.cjs +0 -2
- package/dist/core/router/lifecycle/RouterLifecycleManager.js +1 -130
- package/dist/core/router/lifecycle/index.cjs +0 -2
- package/dist/core/router/lifecycle/index.js +1 -5
- package/dist/core/router/middleware/RouterMiddlewareManager.cjs +0 -2
- package/dist/core/router/middleware/RouterMiddlewareManager.js +1 -179
- package/dist/core/router/middleware/auth.cjs +0 -2
- package/dist/core/router/middleware/auth.js +1 -63
- package/dist/core/router/middleware/index.cjs +0 -2
- package/dist/core/router/middleware/index.js +1 -7
- package/dist/core/router/middleware/types.cjs +0 -2
- package/dist/core/router/middleware/types.js +1 -7
- package/dist/core/router/monitoring/RouterMonitoring.cjs +0 -2
- package/dist/core/router/monitoring/RouterMonitoring.js +1 -213
- package/dist/core/router/monitoring/index.cjs +0 -2
- package/dist/core/router/monitoring/index.js +1 -5
- package/dist/core/router/navigation/RouterNavigation.cjs +0 -2
- package/dist/core/router/navigation/RouterNavigation.js +1 -192
- package/dist/core/router/navigation/index.cjs +0 -2
- package/dist/core/router/navigation/index.js +1 -5
- package/dist/core/router/performance/RouteCache.cjs +0 -2
- package/dist/core/router/performance/RouteCache.js +1 -291
- package/dist/core/router/performance/RoutePreloader.cjs +0 -2
- package/dist/core/router/performance/RoutePreloader.js +1 -277
- package/dist/core/router/performance/index.cjs +0 -2
- package/dist/core/router/performance/index.js +1 -6
- package/dist/core/router/plugin/RouterPluginManager.cjs +0 -2
- package/dist/core/router/plugin/RouterPluginManager.js +1 -248
- package/dist/core/router/plugin/index.cjs +0 -2
- package/dist/core/router/plugin/index.js +1 -6
- package/dist/core/router/plugin/types.cjs +0 -2
- package/dist/core/router/plugin/types.js +1 -33
- package/dist/core/router/types.cjs +0 -2
- package/dist/core/router/types.js +1 -5
- package/dist/core/router/utils/adapters/react-router/RouteErrorBoundary.cjs +0 -2
- package/dist/core/router/utils/adapters/react-router/RouteErrorBoundary.js +1 -121
- package/dist/core/router/utils/adapters/react-router/transform.cjs +0 -2
- package/dist/core/router/utils/adapters/react-router/transform.js +1 -242
- package/dist/core/router/utils/transform.cjs +0 -2
- package/dist/core/router/utils/transform.js +1 -791
- package/dist/core/router/validation/RouterConfigValidator.cjs +0 -2
- package/dist/core/router/validation/RouterConfigValidator.js +2 -77
- package/dist/core/router/validation/index.cjs +0 -2
- package/dist/core/router/validation/index.js +1 -6
- package/dist/core/router/validation/schema.cjs +0 -2
- package/dist/core/router/validation/schema.js +1 -151
- package/dist/core/router/version/RouteVersionManager.cjs +0 -2
- package/dist/core/router/version/RouteVersionManager.js +1 -191
- package/dist/core/router/version/index.cjs +0 -2
- package/dist/core/router/version/index.js +1 -5
- package/dist/core/splash/SplashScreen.cjs +0 -2
- package/dist/core/splash/SplashScreen.js +1 -293
- package/dist/core/splash/index.cjs +0 -2
- package/dist/core/splash/index.js +1 -6
- package/dist/core/splash/splashScreenUtils.cjs +0 -2
- package/dist/core/splash/splashScreenUtils.js +1 -30
- package/dist/core/startup/AppInstance.cjs +0 -2
- package/dist/core/startup/AppInstance.js +1 -226
- package/dist/core/startup/environment.cjs +0 -2
- package/dist/core/startup/environment.js +1 -154
- package/dist/core/startup/index.cjs +0 -2
- package/dist/core/startup/index.js +1 -8
- package/dist/core/startup/initializeServices.cjs +0 -2
- package/dist/core/startup/initializeServices.js +1 -188
- package/dist/core/startup/performanceTracker.cjs +0 -2
- package/dist/core/startup/performanceTracker.js +1 -167
- package/dist/core/startup/renderApp.cjs +0 -2
- package/dist/core/startup/renderApp.js +1 -267
- package/dist/core/startup/startApp.cjs +0 -2
- package/dist/core/startup/startApp.js +1 -315
- package/dist/core/types.cjs +0 -2
- package/dist/core/types.js +1 -5
- package/dist/index.cjs +0 -2
- package/dist/index.js +1 -11
- package/dist/index.umd.cjs +0 -2
- package/dist/index.umd.js +362 -13233
- package/dist/kernel/constants.cjs +0 -2
- package/dist/kernel/constants.js +1 -43
- package/dist/kernel/index.cjs +0 -2
- package/dist/kernel/index.js +1 -4
- package/dist/kernel/kernel.cjs +0 -2
- package/dist/kernel/kernel.js +1 -273
- package/dist/kernel/manager/cacheManager.cjs +0 -2
- package/dist/kernel/manager/cacheManager.js +1 -38
- package/dist/kernel/manager/i18n/I18nManager.cjs +0 -2
- package/dist/kernel/manager/i18n/I18nManager.js +1 -83
- package/dist/kernel/manager/i18n/i18n.persistence.cjs +0 -2
- package/dist/kernel/manager/i18n/i18n.persistence.js +1 -41
- package/dist/kernel/manager/i18n/i18n.schema.cjs +0 -2
- package/dist/kernel/manager/i18n/i18n.schema.js +1 -64
- package/dist/kernel/manager/i18n/index.cjs +0 -2
- package/dist/kernel/manager/i18n/index.js +1 -3
- package/dist/kernel/manager/i18nManager.cjs +0 -2
- package/dist/kernel/manager/i18nManager.js +1 -3
- package/dist/kernel/manager/index.cjs +0 -2
- package/dist/kernel/manager/index.js +1 -6
- package/dist/kernel/manager/logger/LoggerManager.cjs +0 -2
- package/dist/kernel/manager/logger/LoggerManager.js +1 -99
- package/dist/kernel/manager/logger/index.cjs +0 -2
- package/dist/kernel/manager/logger/index.js +1 -3
- package/dist/kernel/manager/logger/logger.persistence.cjs +0 -2
- package/dist/kernel/manager/logger/logger.persistence.js +1 -43
- package/dist/kernel/manager/logger/logger.schema.cjs +0 -2
- package/dist/kernel/manager/logger/logger.schema.js +1 -55
- package/dist/kernel/manager/loggerManager.cjs +0 -2
- package/dist/kernel/manager/loggerManager.js +1 -3
- package/dist/kernel/manager/theme/ThemeManager.cjs +0 -2
- package/dist/kernel/manager/theme/ThemeManager.js +1 -76
- package/dist/kernel/manager/theme/index.cjs +0 -2
- package/dist/kernel/manager/theme/index.js +1 -3
- package/dist/kernel/manager/theme/theme.dom.cjs +0 -2
- package/dist/kernel/manager/theme/theme.dom.js +1 -45
- package/dist/kernel/manager/theme/theme.persistence.cjs +0 -2
- package/dist/kernel/manager/theme/theme.persistence.js +1 -38
- package/dist/kernel/manager/theme/theme.schema.cjs +0 -2
- package/dist/kernel/manager/theme/theme.schema.js +1 -97
- package/dist/kernel/manager/themeManager.cjs +0 -2
- package/dist/kernel/manager/themeManager.js +1 -3
- package/dist/kernel/types.cjs +0 -2
- package/dist/kernel/types.js +1 -3
- package/dist/library/index.cjs +0 -2
- package/dist/library/index.js +1 -4
- package/dist/library/locale/index.cjs +0 -2
- package/dist/library/locale/index.js +1 -12
- package/dist/library/locale/langs/en-us/index.cjs +0 -2
- package/dist/library/locale/langs/en-us/index.js +1 -24
- package/dist/library/locale/langs/zh-cn/index.cjs +0 -2
- package/dist/library/locale/langs/zh-cn/index.js +1 -24
- package/dist/library/locale/types.cjs +0 -2
- package/dist/library/locale/types.js +1 -3
- package/dist/library/storage/cache.cjs +0 -2
- package/dist/library/storage/cache.js +1 -237
- package/dist/library/storage/encryption.cjs +0 -2
- package/dist/library/storage/encryption.js +1 -141
- package/dist/library/storage/index.cjs +0 -2
- package/dist/library/storage/index.js +1 -106
- package/dist/state/StateManager.cjs +0 -2
- package/dist/state/StateManager.js +1 -160
- package/dist/state/adapters/AdapterFactory.cjs +0 -2
- package/dist/state/adapters/AdapterFactory.js +1 -85
- package/dist/state/adapters/DefaultAdapter.cjs +0 -2
- package/dist/state/adapters/DefaultAdapter.js +1 -71
- package/dist/state/adapters/ReduxAdapter.cjs +0 -2
- package/dist/state/adapters/ReduxAdapter.js +1 -439
- package/dist/state/adapters/ZustandAdapter.cjs +0 -2
- package/dist/state/adapters/ZustandAdapter.js +1 -70
- package/dist/state/adapters/index.cjs +0 -2
- package/dist/state/adapters/index.js +1 -9
- package/dist/state/adapters/types.cjs +0 -2
- package/dist/state/adapters/types.js +1 -5
- package/dist/state/core/DerivedStateInstance.cjs +0 -2
- package/dist/state/core/DerivedStateInstance.js +1 -173
- package/dist/state/core/StateInstance.cjs +0 -2
- package/dist/state/core/StateInstance.js +1 -168
- package/dist/state/core/StateRegistry.cjs +0 -2
- package/dist/state/core/StateRegistry.js +1 -106
- package/dist/state/core/StateScope.cjs +0 -2
- package/dist/state/core/StateScope.js +1 -133
- package/dist/state/core/index.cjs +0 -2
- package/dist/state/core/index.js +1 -8
- package/dist/state/index.cjs +0 -2
- package/dist/state/index.js +1 -12
- package/dist/state/types.cjs +0 -2
- package/dist/state/types.js +1 -13
- package/dist/state.umd.js +22 -1395
- package/dist/types.cjs +0 -2
- package/dist/types.js +1 -3
- package/dist/utils/analytics.cjs +0 -2
- package/dist/utils/analytics.js +1 -204
- package/dist/utils/configSecurity.cjs +0 -2
- package/dist/utils/configSecurity.js +3 -176
- package/dist/utils/csrf.cjs +0 -2
- package/dist/utils/csrf.js +1 -3
- package/dist/utils/errors/ErrorCodes.cjs +0 -2
- package/dist/utils/errors/ErrorCodes.js +1 -3
- package/dist/utils/errors.cjs +0 -2
- package/dist/utils/errors.js +1 -18
- package/dist/utils/index.cjs +0 -2
- package/dist/utils/index.js +1 -48
- package/dist/utils/logger.cjs +0 -2
- package/dist/utils/logger.js +1 -3
- package/dist/utils/logger.types.cjs +0 -2
- package/dist/utils/logger.types.js +1 -3
- package/dist/utils/monitoring.cjs +0 -2
- package/dist/utils/monitoring.js +1 -3
- package/dist/utils/performance.cjs +0 -2
- package/dist/utils/performance.js +1 -3
- package/dist/utils/resourceLoader.cjs +0 -2
- package/dist/utils/resourceLoader.js +1 -3
- package/dist/utils/runtimeSecurity.cjs +0 -2
- package/dist/utils/runtimeSecurity.js +1 -3
- package/dist/utils/security.cjs +0 -2
- package/dist/utils/security.js +1 -3
- package/dist/utils/traceId.cjs +0 -2
- package/dist/utils/traceId.js +1 -3
- package/dist/utils/validation.cjs +0 -2
- package/dist/utils/validation.js +1 -3
- package/package.json +3 -4
- package/dist/analytics/index.cjs.map +0 -1
- package/dist/analytics/index.js.map +0 -1
- package/dist/analytics.umd.js.map +0 -1
- package/dist/components/LocaleSwitch.cjs.map +0 -1
- package/dist/components/LocaleSwitch.js.map +0 -1
- package/dist/components/ThemeSwitch.cjs.map +0 -1
- package/dist/components/ThemeSwitch.js.map +0 -1
- package/dist/components/index.cjs.map +0 -1
- package/dist/components/index.js.map +0 -1
- package/dist/components/persistence.cjs.map +0 -1
- package/dist/components/persistence.js.map +0 -1
- package/dist/core/Test.cjs.map +0 -1
- package/dist/core/Test.js.map +0 -1
- package/dist/core/app/AppContext.cjs.map +0 -1
- package/dist/core/app/AppContext.js.map +0 -1
- package/dist/core/app/AppContext.types.cjs.map +0 -1
- package/dist/core/app/AppContext.types.js.map +0 -1
- package/dist/core/app/BasicLayout.cjs.map +0 -1
- package/dist/core/app/BasicLayout.js.map +0 -1
- package/dist/core/app/DefaultApp.cjs.map +0 -1
- package/dist/core/app/DefaultApp.js.map +0 -1
- package/dist/core/app/index.cjs.map +0 -1
- package/dist/core/app/index.js.map +0 -1
- package/dist/core/config/AppConfig.cjs.map +0 -1
- package/dist/core/config/AppConfig.js.map +0 -1
- package/dist/core/config/ConfigLoader.cjs.map +0 -1
- package/dist/core/config/ConfigLoader.js.map +0 -1
- package/dist/core/config/ConfigValidator.cjs.map +0 -1
- package/dist/core/config/ConfigValidator.js.map +0 -1
- package/dist/core/config/index.cjs.map +0 -1
- package/dist/core/config/index.js.map +0 -1
- package/dist/core/dev/DevTools.cjs.map +0 -1
- package/dist/core/dev/DevTools.js.map +0 -1
- package/dist/core/error/ErrorBoundary.cjs.map +0 -1
- package/dist/core/error/ErrorBoundary.js.map +0 -1
- package/dist/core/error/ErrorHandler.cjs.map +0 -1
- package/dist/core/error/ErrorHandler.js.map +0 -1
- package/dist/core/error/index.cjs.map +0 -1
- package/dist/core/error/index.js.map +0 -1
- package/dist/core/event/AppEventBus.cjs.map +0 -1
- package/dist/core/event/AppEventBus.js.map +0 -1
- package/dist/core/event/frameworkEvents.cjs.map +0 -1
- package/dist/core/event/frameworkEvents.js.map +0 -1
- package/dist/core/event/hooks.cjs.map +0 -1
- package/dist/core/event/hooks.js.map +0 -1
- package/dist/core/event/index.cjs.map +0 -1
- package/dist/core/event/index.js.map +0 -1
- package/dist/core/event/types.cjs.map +0 -1
- package/dist/core/event/types.js.map +0 -1
- package/dist/core/event/useEventBus.cjs.map +0 -1
- package/dist/core/event/useEventBus.js.map +0 -1
- package/dist/core/index.cjs.map +0 -1
- package/dist/core/index.js.map +0 -1
- package/dist/core/initialization/InitializationErrorThrower.cjs.map +0 -1
- package/dist/core/initialization/InitializationErrorThrower.js.map +0 -1
- package/dist/core/initialization/index.cjs.map +0 -1
- package/dist/core/initialization/index.js.map +0 -1
- package/dist/core/initialization/initialization.cjs.map +0 -1
- package/dist/core/initialization/initialization.js.map +0 -1
- package/dist/core/initialization/initializationErrorState.cjs.map +0 -1
- package/dist/core/initialization/initializationErrorState.js.map +0 -1
- package/dist/core/kernel/defaultAdapters.cjs.map +0 -1
- package/dist/core/kernel/defaultAdapters.js.map +0 -1
- package/dist/core/kernel/errors.cjs.map +0 -1
- package/dist/core/kernel/errors.js.map +0 -1
- package/dist/core/kernel/index.cjs.map +0 -1
- package/dist/core/kernel/index.js.map +0 -1
- package/dist/core/kernel/startKernel.cjs.map +0 -1
- package/dist/core/kernel/startKernel.js.map +0 -1
- package/dist/core/kernel/types.cjs.map +0 -1
- package/dist/core/kernel/types.js.map +0 -1
- package/dist/core/middleware.cjs.map +0 -1
- package/dist/core/middleware.js.map +0 -1
- package/dist/core/plugin/PluginEventBus.cjs.map +0 -1
- package/dist/core/plugin/PluginEventBus.js.map +0 -1
- package/dist/core/plugin/PluginSandbox.cjs.map +0 -1
- package/dist/core/plugin/PluginSandbox.js.map +0 -1
- package/dist/core/plugin.cjs.map +0 -1
- package/dist/core/plugin.js.map +0 -1
- package/dist/core/router/RouterManager.cjs.map +0 -1
- package/dist/core/router/RouterManager.js.map +0 -1
- package/dist/core/router/adapter/AdapterManager.cjs.map +0 -1
- package/dist/core/router/adapter/AdapterManager.js.map +0 -1
- package/dist/core/router/adapter/index.cjs.map +0 -1
- package/dist/core/router/adapter/index.js.map +0 -1
- package/dist/core/router/adapter/react-router/ReactRouterAdapter.cjs.map +0 -1
- package/dist/core/router/adapter/react-router/ReactRouterAdapter.js.map +0 -1
- package/dist/core/router/adapter/react-router/index.cjs.map +0 -1
- package/dist/core/router/adapter/react-router/index.js.map +0 -1
- package/dist/core/router/adapter/types.cjs.map +0 -1
- package/dist/core/router/adapter/types.js.map +0 -1
- package/dist/core/router/dev/RouterDevTools.cjs.map +0 -1
- package/dist/core/router/dev/RouterDevTools.js.map +0 -1
- package/dist/core/router/dev/index.cjs.map +0 -1
- package/dist/core/router/dev/index.js.map +0 -1
- package/dist/core/router/dynamic/DynamicRouteManager.cjs.map +0 -1
- package/dist/core/router/dynamic/DynamicRouteManager.js.map +0 -1
- package/dist/core/router/dynamic/index.cjs.map +0 -1
- package/dist/core/router/dynamic/index.js.map +0 -1
- package/dist/core/router/errors/RouterError.cjs.map +0 -1
- package/dist/core/router/errors/RouterError.js.map +0 -1
- package/dist/core/router/errors/index.cjs.map +0 -1
- package/dist/core/router/errors/index.js.map +0 -1
- package/dist/core/router/index.cjs.map +0 -1
- package/dist/core/router/index.js.map +0 -1
- package/dist/core/router/lifecycle/RouterLifecycleManager.cjs.map +0 -1
- package/dist/core/router/lifecycle/RouterLifecycleManager.js.map +0 -1
- package/dist/core/router/lifecycle/index.cjs.map +0 -1
- package/dist/core/router/lifecycle/index.js.map +0 -1
- package/dist/core/router/middleware/RouterMiddlewareManager.cjs.map +0 -1
- package/dist/core/router/middleware/RouterMiddlewareManager.js.map +0 -1
- package/dist/core/router/middleware/auth.cjs.map +0 -1
- package/dist/core/router/middleware/auth.js.map +0 -1
- package/dist/core/router/middleware/index.cjs.map +0 -1
- package/dist/core/router/middleware/index.js.map +0 -1
- package/dist/core/router/middleware/types.cjs.map +0 -1
- package/dist/core/router/middleware/types.js.map +0 -1
- package/dist/core/router/monitoring/RouterMonitoring.cjs.map +0 -1
- package/dist/core/router/monitoring/RouterMonitoring.js.map +0 -1
- package/dist/core/router/monitoring/index.cjs.map +0 -1
- package/dist/core/router/monitoring/index.js.map +0 -1
- package/dist/core/router/navigation/RouterNavigation.cjs.map +0 -1
- package/dist/core/router/navigation/RouterNavigation.js.map +0 -1
- package/dist/core/router/navigation/index.cjs.map +0 -1
- package/dist/core/router/navigation/index.js.map +0 -1
- package/dist/core/router/performance/RouteCache.cjs.map +0 -1
- package/dist/core/router/performance/RouteCache.js.map +0 -1
- package/dist/core/router/performance/RoutePreloader.cjs.map +0 -1
- package/dist/core/router/performance/RoutePreloader.js.map +0 -1
- package/dist/core/router/performance/index.cjs.map +0 -1
- package/dist/core/router/performance/index.js.map +0 -1
- package/dist/core/router/plugin/RouterPluginManager.cjs.map +0 -1
- package/dist/core/router/plugin/RouterPluginManager.js.map +0 -1
- package/dist/core/router/plugin/index.cjs.map +0 -1
- package/dist/core/router/plugin/index.js.map +0 -1
- package/dist/core/router/plugin/types.cjs.map +0 -1
- package/dist/core/router/plugin/types.js.map +0 -1
- package/dist/core/router/types.cjs.map +0 -1
- package/dist/core/router/types.js.map +0 -1
- package/dist/core/router/utils/adapters/react-router/RouteErrorBoundary.cjs.map +0 -1
- package/dist/core/router/utils/adapters/react-router/RouteErrorBoundary.js.map +0 -1
- package/dist/core/router/utils/adapters/react-router/transform.cjs.map +0 -1
- package/dist/core/router/utils/adapters/react-router/transform.js.map +0 -1
- package/dist/core/router/utils/transform.cjs.map +0 -1
- package/dist/core/router/utils/transform.js.map +0 -1
- package/dist/core/router/validation/RouterConfigValidator.cjs.map +0 -1
- package/dist/core/router/validation/RouterConfigValidator.js.map +0 -1
- package/dist/core/router/validation/index.cjs.map +0 -1
- package/dist/core/router/validation/index.js.map +0 -1
- package/dist/core/router/validation/schema.cjs.map +0 -1
- package/dist/core/router/validation/schema.js.map +0 -1
- package/dist/core/router/version/RouteVersionManager.cjs.map +0 -1
- package/dist/core/router/version/RouteVersionManager.js.map +0 -1
- package/dist/core/router/version/index.cjs.map +0 -1
- package/dist/core/router/version/index.js.map +0 -1
- package/dist/core/splash/SplashScreen.cjs.map +0 -1
- package/dist/core/splash/SplashScreen.js.map +0 -1
- package/dist/core/splash/index.cjs.map +0 -1
- package/dist/core/splash/index.js.map +0 -1
- package/dist/core/splash/splashScreenUtils.cjs.map +0 -1
- package/dist/core/splash/splashScreenUtils.js.map +0 -1
- package/dist/core/startup/AppInstance.cjs.map +0 -1
- package/dist/core/startup/AppInstance.js.map +0 -1
- package/dist/core/startup/environment.cjs.map +0 -1
- package/dist/core/startup/environment.js.map +0 -1
- package/dist/core/startup/index.cjs.map +0 -1
- package/dist/core/startup/index.js.map +0 -1
- package/dist/core/startup/initializeServices.cjs.map +0 -1
- package/dist/core/startup/initializeServices.js.map +0 -1
- package/dist/core/startup/performanceTracker.cjs.map +0 -1
- package/dist/core/startup/performanceTracker.js.map +0 -1
- package/dist/core/startup/renderApp.cjs.map +0 -1
- package/dist/core/startup/renderApp.js.map +0 -1
- package/dist/core/startup/startApp.cjs.map +0 -1
- package/dist/core/startup/startApp.js.map +0 -1
- package/dist/core/types.cjs.map +0 -1
- package/dist/core/types.js.map +0 -1
- package/dist/index.cjs.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/index.umd.cjs.map +0 -1
- package/dist/index.umd.js.map +0 -1
- package/dist/kernel/constants.cjs.map +0 -1
- package/dist/kernel/constants.js.map +0 -1
- package/dist/kernel/index.cjs.map +0 -1
- package/dist/kernel/index.js.map +0 -1
- package/dist/kernel/kernel.cjs.map +0 -1
- package/dist/kernel/kernel.js.map +0 -1
- package/dist/kernel/manager/cacheManager.cjs.map +0 -1
- package/dist/kernel/manager/cacheManager.js.map +0 -1
- package/dist/kernel/manager/i18n/I18nManager.cjs.map +0 -1
- package/dist/kernel/manager/i18n/I18nManager.js.map +0 -1
- package/dist/kernel/manager/i18n/i18n.persistence.cjs.map +0 -1
- package/dist/kernel/manager/i18n/i18n.persistence.js.map +0 -1
- package/dist/kernel/manager/i18n/i18n.schema.cjs.map +0 -1
- package/dist/kernel/manager/i18n/i18n.schema.js.map +0 -1
- package/dist/kernel/manager/i18n/index.cjs.map +0 -1
- package/dist/kernel/manager/i18n/index.js.map +0 -1
- package/dist/kernel/manager/i18nManager.cjs.map +0 -1
- package/dist/kernel/manager/i18nManager.js.map +0 -1
- package/dist/kernel/manager/index.cjs.map +0 -1
- package/dist/kernel/manager/index.js.map +0 -1
- package/dist/kernel/manager/logger/LoggerManager.cjs.map +0 -1
- package/dist/kernel/manager/logger/LoggerManager.js.map +0 -1
- package/dist/kernel/manager/logger/index.cjs.map +0 -1
- package/dist/kernel/manager/logger/index.js.map +0 -1
- package/dist/kernel/manager/logger/logger.persistence.cjs.map +0 -1
- package/dist/kernel/manager/logger/logger.persistence.js.map +0 -1
- package/dist/kernel/manager/logger/logger.schema.cjs.map +0 -1
- package/dist/kernel/manager/logger/logger.schema.js.map +0 -1
- package/dist/kernel/manager/loggerManager.cjs.map +0 -1
- package/dist/kernel/manager/loggerManager.js.map +0 -1
- package/dist/kernel/manager/persistence.cjs +0 -78
- package/dist/kernel/manager/persistence.cjs.map +0 -1
- package/dist/kernel/manager/persistence.d.ts +0 -3
- package/dist/kernel/manager/persistence.js +0 -60
- package/dist/kernel/manager/persistence.js.map +0 -1
- package/dist/kernel/manager/theme/ThemeManager.cjs.map +0 -1
- package/dist/kernel/manager/theme/ThemeManager.js.map +0 -1
- package/dist/kernel/manager/theme/index.cjs.map +0 -1
- package/dist/kernel/manager/theme/index.js.map +0 -1
- package/dist/kernel/manager/theme/theme.dom.cjs.map +0 -1
- package/dist/kernel/manager/theme/theme.dom.js.map +0 -1
- package/dist/kernel/manager/theme/theme.persistence.cjs.map +0 -1
- package/dist/kernel/manager/theme/theme.persistence.js.map +0 -1
- package/dist/kernel/manager/theme/theme.schema.cjs.map +0 -1
- package/dist/kernel/manager/theme/theme.schema.js.map +0 -1
- package/dist/kernel/manager/themeManager.cjs.map +0 -1
- package/dist/kernel/manager/themeManager.js.map +0 -1
- package/dist/kernel/types.cjs.map +0 -1
- package/dist/kernel/types.js.map +0 -1
- package/dist/library/index.cjs.map +0 -1
- package/dist/library/index.js.map +0 -1
- package/dist/library/locale/index.cjs.map +0 -1
- package/dist/library/locale/index.js.map +0 -1
- package/dist/library/locale/langs/en-us/index.cjs.map +0 -1
- package/dist/library/locale/langs/en-us/index.js.map +0 -1
- package/dist/library/locale/langs/zh-cn/index.cjs.map +0 -1
- package/dist/library/locale/langs/zh-cn/index.js.map +0 -1
- package/dist/library/locale/types.cjs.map +0 -1
- package/dist/library/locale/types.js.map +0 -1
- package/dist/library/storage/cache.cjs.map +0 -1
- package/dist/library/storage/cache.js.map +0 -1
- package/dist/library/storage/encryption.cjs.map +0 -1
- package/dist/library/storage/encryption.js.map +0 -1
- package/dist/library/storage/index.cjs.map +0 -1
- package/dist/library/storage/index.js.map +0 -1
- package/dist/request/adapter/RequestAdapter.d.ts +0 -85
- package/dist/request/adapter/RequestAdapter.js +0 -70
- package/dist/request/adapter/RequestAdapter.js.map +0 -1
- package/dist/request/adapter/axiosAdapter.d.ts +0 -10
- package/dist/request/adapter/axiosAdapter.js +0 -115
- package/dist/request/adapter/axiosAdapter.js.map +0 -1
- package/dist/request/adapter/fetchAdapter.d.ts +0 -10
- package/dist/request/adapter/fetchAdapter.js +0 -126
- package/dist/request/adapter/fetchAdapter.js.map +0 -1
- package/dist/request/adapter/index.d.ts +0 -9
- package/dist/request/adapter/index.js +0 -14
- package/dist/request/adapter/index.js.map +0 -1
- package/dist/request/adapter/kyAdapter.d.ts +0 -10
- package/dist/request/adapter/kyAdapter.js +0 -142
- package/dist/request/adapter/kyAdapter.js.map +0 -1
- package/dist/request/adapter/undiciAdapter.d.ts +0 -10
- package/dist/request/adapter/undiciAdapter.js +0 -164
- package/dist/request/adapter/undiciAdapter.js.map +0 -1
- package/dist/request/adapter.d.ts +0 -1
- package/dist/request/core/RequestClient.d.ts +0 -134
- package/dist/request/core/RequestClient.js +0 -509
- package/dist/request/core/RequestClient.js.map +0 -1
- package/dist/request/core/index.d.ts +0 -5
- package/dist/request/core/index.js +0 -5
- package/dist/request/core/index.js.map +0 -1
- package/dist/request/core.d.ts +0 -1
- package/dist/request/index.d.ts +0 -1
- package/dist/request/index.js +0 -50
- package/dist/request/index.js.map +0 -1
- package/dist/request/plugin/RequestPlugin.d.ts +0 -170
- package/dist/request/plugin/RequestPlugin.js +0 -203
- package/dist/request/plugin/RequestPlugin.js.map +0 -1
- package/dist/request/plugin/cache.d.ts +0 -33
- package/dist/request/plugin/cache.js +0 -264
- package/dist/request/plugin/cache.js.map +0 -1
- package/dist/request/plugin/csrfPlugin.d.ts +0 -21
- package/dist/request/plugin/csrfPlugin.js +0 -44
- package/dist/request/plugin/csrfPlugin.js.map +0 -1
- package/dist/request/plugin/index.d.ts +0 -11
- package/dist/request/plugin/index.js +0 -12
- package/dist/request/plugin/index.js.map +0 -1
- package/dist/request/plugin/monitoring.d.ts +0 -112
- package/dist/request/plugin/monitoring.js +0 -205
- package/dist/request/plugin/monitoring.js.map +0 -1
- package/dist/request/plugin/queue.d.ts +0 -91
- package/dist/request/plugin/queue.js +0 -156
- package/dist/request/plugin/queue.js.map +0 -1
- package/dist/request/plugin/retry.d.ts +0 -34
- package/dist/request/plugin/retry.js +0 -93
- package/dist/request/plugin/retry.js.map +0 -1
- package/dist/request/plugin/validation.d.ts +0 -26
- package/dist/request/plugin/validation.js +0 -116
- package/dist/request/plugin/validation.js.map +0 -1
- package/dist/request/plugin.d.ts +0 -1
- package/dist/request/runtime/RequestContext.d.ts +0 -50
- package/dist/request/runtime/RequestContext.js +0 -86
- package/dist/request/runtime/RequestContext.js.map +0 -1
- package/dist/request/runtime/index.d.ts +0 -4
- package/dist/request/runtime/index.js +0 -5
- package/dist/request/runtime/index.js.map +0 -1
- package/dist/request/runtime.d.ts +0 -1
- package/dist/request/types.d.ts +0 -1
- package/dist/request/types.js +0 -97
- package/dist/request/types.js.map +0 -1
- package/dist/request/utils/RequestQueueManager.d.ts +0 -74
- package/dist/request/utils/RequestQueueManager.js +0 -160
- package/dist/request/utils/RequestQueueManager.js.map +0 -1
- package/dist/request/utils/dependencyCheck.d.ts +0 -63
- package/dist/request/utils/dependencyCheck.js +0 -192
- package/dist/request/utils/dependencyCheck.js.map +0 -1
- package/dist/request/utils/index.d.ts +0 -5
- package/dist/request/utils/index.js +0 -6
- package/dist/request/utils/index.js.map +0 -1
- package/dist/request/utils.d.ts +0 -1
- package/dist/state/StateManager.cjs.map +0 -1
- package/dist/state/StateManager.js.map +0 -1
- package/dist/state/adapters/AdapterFactory.cjs.map +0 -1
- package/dist/state/adapters/AdapterFactory.js.map +0 -1
- package/dist/state/adapters/DefaultAdapter.cjs.map +0 -1
- package/dist/state/adapters/DefaultAdapter.js.map +0 -1
- package/dist/state/adapters/ReduxAdapter.cjs.map +0 -1
- package/dist/state/adapters/ReduxAdapter.js.map +0 -1
- package/dist/state/adapters/ZustandAdapter.cjs.map +0 -1
- package/dist/state/adapters/ZustandAdapter.js.map +0 -1
- package/dist/state/adapters/index.cjs.map +0 -1
- package/dist/state/adapters/index.js.map +0 -1
- package/dist/state/adapters/types.cjs.map +0 -1
- package/dist/state/adapters/types.js.map +0 -1
- package/dist/state/core/DerivedStateInstance.cjs.map +0 -1
- package/dist/state/core/DerivedStateInstance.js.map +0 -1
- package/dist/state/core/StateInstance.cjs.map +0 -1
- package/dist/state/core/StateInstance.js.map +0 -1
- package/dist/state/core/StateRegistry.cjs.map +0 -1
- package/dist/state/core/StateRegistry.js.map +0 -1
- package/dist/state/core/StateScope.cjs.map +0 -1
- package/dist/state/core/StateScope.js.map +0 -1
- package/dist/state/core/index.cjs.map +0 -1
- package/dist/state/core/index.js.map +0 -1
- package/dist/state/index.cjs.map +0 -1
- package/dist/state/index.js.map +0 -1
- package/dist/state/types.cjs.map +0 -1
- package/dist/state/types.js.map +0 -1
- package/dist/state.umd.js.map +0 -1
- package/dist/types.cjs.map +0 -1
- package/dist/types.js.map +0 -1
- package/dist/utils/analytics.cjs.map +0 -1
- package/dist/utils/analytics.js.map +0 -1
- package/dist/utils/configSecurity.cjs.map +0 -1
- package/dist/utils/configSecurity.js.map +0 -1
- package/dist/utils/csrf.cjs.map +0 -1
- package/dist/utils/csrf.js.map +0 -1
- package/dist/utils/errors/ErrorCodes.cjs.map +0 -1
- package/dist/utils/errors/ErrorCodes.js.map +0 -1
- package/dist/utils/errors.cjs.map +0 -1
- package/dist/utils/errors.js.map +0 -1
- package/dist/utils/index.cjs.map +0 -1
- package/dist/utils/index.js.map +0 -1
- package/dist/utils/logger.cjs.map +0 -1
- package/dist/utils/logger.js.map +0 -1
- package/dist/utils/logger.types.cjs.map +0 -1
- package/dist/utils/logger.types.js.map +0 -1
- package/dist/utils/monitoring.cjs.map +0 -1
- package/dist/utils/monitoring.js.map +0 -1
- package/dist/utils/performance.cjs.map +0 -1
- package/dist/utils/performance.js.map +0 -1
- package/dist/utils/resourceLoader.cjs.map +0 -1
- package/dist/utils/resourceLoader.js.map +0 -1
- package/dist/utils/runtimeSecurity.cjs.map +0 -1
- package/dist/utils/runtimeSecurity.js.map +0 -1
- package/dist/utils/security.cjs.map +0 -1
- package/dist/utils/security.js.map +0 -1
- package/dist/utils/traceId.cjs.map +0 -1
- package/dist/utils/traceId.js.map +0 -1
- package/dist/utils/validation.cjs.map +0 -1
- package/dist/utils/validation.js.map +0 -1
|
@@ -1,791 +1 @@
|
|
|
1
|
-
function _define_property(obj, key, value) {
|
|
2
|
-
if (key in obj) {
|
|
3
|
-
Object.defineProperty(obj, key, {
|
|
4
|
-
value: value,
|
|
5
|
-
enumerable: true,
|
|
6
|
-
configurable: true,
|
|
7
|
-
writable: true
|
|
8
|
-
});
|
|
9
|
-
} else {
|
|
10
|
-
obj[key] = value;
|
|
11
|
-
}
|
|
12
|
-
return obj;
|
|
13
|
-
}
|
|
14
|
-
import { logger } from "@vlian/logger";
|
|
15
|
-
import { SecurityUtils, SecurityError, ValidationError } from "@vlian/utils";
|
|
16
|
-
/**
|
|
17
|
-
* LRU 缓存实现
|
|
18
|
-
*/ let LRUCache = class LRUCache {
|
|
19
|
-
get(key) {
|
|
20
|
-
const item = this.cache.get(key);
|
|
21
|
-
if (item) {
|
|
22
|
-
// 更新访问时间
|
|
23
|
-
item.accessTime = Date.now();
|
|
24
|
-
// 移动到末尾(最近使用)
|
|
25
|
-
this.cache.delete(key);
|
|
26
|
-
this.cache.set(key, item);
|
|
27
|
-
}
|
|
28
|
-
return item;
|
|
29
|
-
}
|
|
30
|
-
set(key, value) {
|
|
31
|
-
// 如果已存在,先删除
|
|
32
|
-
if (this.cache.has(key)) {
|
|
33
|
-
this.cache.delete(key);
|
|
34
|
-
} else if (this.cache.size >= this.maxSize) {
|
|
35
|
-
// 如果达到最大大小,删除最久未使用的项(第一个)
|
|
36
|
-
const firstKey = this.cache.keys().next().value;
|
|
37
|
-
if (firstKey) {
|
|
38
|
-
this.cache.delete(firstKey);
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
value.accessTime = Date.now();
|
|
42
|
-
this.cache.set(key, value);
|
|
43
|
-
}
|
|
44
|
-
delete(key) {
|
|
45
|
-
return this.cache.delete(key);
|
|
46
|
-
}
|
|
47
|
-
clear() {
|
|
48
|
-
this.cache.clear();
|
|
49
|
-
}
|
|
50
|
-
size() {
|
|
51
|
-
return this.cache.size;
|
|
52
|
-
}
|
|
53
|
-
cleanupExpired(cacheTTL) {
|
|
54
|
-
const now = Date.now();
|
|
55
|
-
for (const [key, item] of this.cache.entries()){
|
|
56
|
-
if (now - item.timestamp > cacheTTL) {
|
|
57
|
-
this.cache.delete(key);
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
constructor(maxSize = 50){
|
|
62
|
-
_define_property(this, "cache", new Map());
|
|
63
|
-
_define_property(this, "maxSize", void 0);
|
|
64
|
-
this.maxSize = maxSize;
|
|
65
|
-
}
|
|
66
|
-
};
|
|
67
|
-
/**
|
|
68
|
-
* 转换缓存(使用 LRU 缓存)
|
|
69
|
-
*/ let transformCache = null;
|
|
70
|
-
/**
|
|
71
|
-
* 默认配置
|
|
72
|
-
*/ const DEFAULT_OPTIONS = {
|
|
73
|
-
pathValidation: {
|
|
74
|
-
enablePathValidation: true,
|
|
75
|
-
// 默认仅允许常见本地模块路径,生产环境建议进一步收紧。
|
|
76
|
-
allowedPathPrefixes: [
|
|
77
|
-
'@/',
|
|
78
|
-
'./',
|
|
79
|
-
'../'
|
|
80
|
-
],
|
|
81
|
-
maxPathLength: 500,
|
|
82
|
-
allowAbsolutePaths: false
|
|
83
|
-
},
|
|
84
|
-
performance: {
|
|
85
|
-
enableCache: true,
|
|
86
|
-
cacheTTL: 5 * 60 * 1000,
|
|
87
|
-
maxCacheSize: 50,
|
|
88
|
-
maxRecursionDepth: 100,
|
|
89
|
-
enableParallelProcessing: true,
|
|
90
|
-
parallelBatchSize: 10
|
|
91
|
-
},
|
|
92
|
-
enableDebugLog: false
|
|
93
|
-
};
|
|
94
|
-
/**
|
|
95
|
-
* 优化的字符串哈希函数(用于缓存键)
|
|
96
|
-
* 使用更高效的哈希算法,支持大字符串
|
|
97
|
-
*/ function optimizedHash(str) {
|
|
98
|
-
// 对于小字符串,使用快速哈希
|
|
99
|
-
if (str.length < 100) {
|
|
100
|
-
let hash = 0;
|
|
101
|
-
for(let i = 0; i < str.length; i++){
|
|
102
|
-
const char = str.charCodeAt(i);
|
|
103
|
-
hash = (hash << 5) - hash + char;
|
|
104
|
-
hash = hash & hash; // 转换为 32 位整数
|
|
105
|
-
}
|
|
106
|
-
return Math.abs(hash).toString(36);
|
|
107
|
-
}
|
|
108
|
-
// 对于大字符串,使用分段哈希
|
|
109
|
-
let hash = 0;
|
|
110
|
-
const step = Math.max(1, Math.floor(str.length / 100));
|
|
111
|
-
for(let i = 0; i < str.length; i += step){
|
|
112
|
-
const char = str.charCodeAt(i);
|
|
113
|
-
hash = (hash << 5) - hash + char;
|
|
114
|
-
hash = hash & hash;
|
|
115
|
-
}
|
|
116
|
-
return Math.abs(hash).toString(36);
|
|
117
|
-
}
|
|
118
|
-
/**
|
|
119
|
-
* 使用 crypto API 的哈希函数(如果可用)
|
|
120
|
-
* 保留此函数供未来使用(异步哈希场景)
|
|
121
|
-
*/ // async function cryptoHash(str: string): Promise<string> {
|
|
122
|
-
// // 检查是否支持 crypto API
|
|
123
|
-
// if (typeof crypto !== 'undefined' && crypto.subtle && crypto.subtle.digest) {
|
|
124
|
-
// try {
|
|
125
|
-
// const encoder = new TextEncoder();
|
|
126
|
-
// const data = encoder.encode(str);
|
|
127
|
-
// const hashBuffer = await crypto.subtle.digest('SHA-256', data);
|
|
128
|
-
// const hashArray = Array.from(new Uint8Array(hashBuffer));
|
|
129
|
-
// return hashArray.map(b => b.toString(16).padStart(2, '0')).join('').substring(0, 16);
|
|
130
|
-
// } catch {
|
|
131
|
-
// // 如果 crypto API 失败,回退到优化哈希
|
|
132
|
-
// return optimizedHash(str);
|
|
133
|
-
// }
|
|
134
|
-
// }
|
|
135
|
-
// return optimizedHash(str);
|
|
136
|
-
// }
|
|
137
|
-
/**
|
|
138
|
-
* 同步哈希函数(用于同步场景)
|
|
139
|
-
*/ function simpleHash(str) {
|
|
140
|
-
return optimizedHash(str);
|
|
141
|
-
}
|
|
142
|
-
function serializeComponentRef(value) {
|
|
143
|
-
if (typeof value === 'string') {
|
|
144
|
-
return {
|
|
145
|
-
str: value
|
|
146
|
-
};
|
|
147
|
-
}
|
|
148
|
-
if (typeof value === 'function') {
|
|
149
|
-
// 函数引用无法稳定序列化源码,使用名称和长度参与哈希,避免同名不同体完全碰撞。
|
|
150
|
-
const fnText = String(value);
|
|
151
|
-
return {
|
|
152
|
-
fn: `${value.name || 'anonymous'}:${fnText.length}`
|
|
153
|
-
};
|
|
154
|
-
}
|
|
155
|
-
return {};
|
|
156
|
-
}
|
|
157
|
-
function serializeRouteConfig(route) {
|
|
158
|
-
const page = serializeComponentRef(route.page);
|
|
159
|
-
const layout = serializeComponentRef(route.layout);
|
|
160
|
-
const routeError = serializeComponentRef(route.error ?? route.errors);
|
|
161
|
-
const loading = serializeComponentRef(route.loading);
|
|
162
|
-
return {
|
|
163
|
-
name: route.name,
|
|
164
|
-
path: route.path,
|
|
165
|
-
page: page.str,
|
|
166
|
-
pageFn: page.fn,
|
|
167
|
-
layout: layout.str,
|
|
168
|
-
layoutFn: layout.fn,
|
|
169
|
-
error: routeError.str,
|
|
170
|
-
errorFn: routeError.fn,
|
|
171
|
-
loading: loading.str,
|
|
172
|
-
loadingFn: loading.fn,
|
|
173
|
-
isGroup: route.isGroup,
|
|
174
|
-
enableRedirection: route.enableRedirection,
|
|
175
|
-
handle: route.handle ? {
|
|
176
|
-
title: route.handle.title,
|
|
177
|
-
order: route.handle.order,
|
|
178
|
-
needLogin: route.handle.needLogin,
|
|
179
|
-
roles: Array.isArray(route.handle.roles) ? [
|
|
180
|
-
...route.handle.roles
|
|
181
|
-
] : undefined
|
|
182
|
-
} : undefined,
|
|
183
|
-
children: route.children?.map((child)=>serializeRouteConfig(child))
|
|
184
|
-
};
|
|
185
|
-
}
|
|
186
|
-
/**
|
|
187
|
-
* 生成配置哈希(用于缓存键)
|
|
188
|
-
* 优化:缓存序列化结果,避免重复序列化
|
|
189
|
-
*/ function generateConfigHash(routes) {
|
|
190
|
-
try {
|
|
191
|
-
if (routes.length === 0) {
|
|
192
|
-
return 'empty';
|
|
193
|
-
}
|
|
194
|
-
const serializedRoutes = routes.map((route)=>serializeRouteConfig(route));
|
|
195
|
-
const configStr = JSON.stringify(serializedRoutes);
|
|
196
|
-
return simpleHash(configStr);
|
|
197
|
-
} catch {
|
|
198
|
-
return '';
|
|
199
|
-
}
|
|
200
|
-
}
|
|
201
|
-
/**
|
|
202
|
-
* 路径验证缓存(已验证的路径)
|
|
203
|
-
*/ const validatedPathCache = new Set();
|
|
204
|
-
/**
|
|
205
|
-
* 预编译的正则表达式(用于路径验证)
|
|
206
|
-
*/ const PATH_TRAVERSAL_REGEX = /\.\.(\/|\\)|\.\.%2[Ff]|\.\.%5[Cc]|%2[Ee]%2[Ee]%2[Ff]|%2[Ee]%2[Ee]%5[Cc]/i;
|
|
207
|
-
const ABSOLUTE_PATH_REGEX = /^\/|^[A-Za-z]:\\/;
|
|
208
|
-
const CONTROL_CHAR_REGEX = /[\x00-\x1f\x7f]/;
|
|
209
|
-
const NULL_BYTE_REGEX = /%00|\\0|\x00/;
|
|
210
|
-
const URL_SCHEME_REGEX = /^[A-Za-z][A-Za-z0-9+.-]*:/;
|
|
211
|
-
// 保留供未来使用(命令注入检测)
|
|
212
|
-
// const COMMAND_INJECTION_REGEX = /[;|&$`]/;
|
|
213
|
-
// const ALLOWED_CHARS_REGEX = /^[a-zA-Z0-9\/\-_.@]+$/;
|
|
214
|
-
/**
|
|
215
|
-
* 验证路径是否安全
|
|
216
|
-
* 优化:添加验证缓存、预编译正则、早期返回
|
|
217
|
-
*/ function validatePath(path, config) {
|
|
218
|
-
// 早期返回:检查缓存
|
|
219
|
-
if (validatedPathCache.has(path)) {
|
|
220
|
-
return {
|
|
221
|
-
valid: true
|
|
222
|
-
};
|
|
223
|
-
}
|
|
224
|
-
// 早期返回:检查路径长度(最快检查)
|
|
225
|
-
if (path.length > config.maxPathLength) {
|
|
226
|
-
return {
|
|
227
|
-
valid: false,
|
|
228
|
-
error: process.env.NODE_ENV === 'development' ? `路径长度超过最大限制 ${config.maxPathLength} 字符` : '路径验证失败'
|
|
229
|
-
};
|
|
230
|
-
}
|
|
231
|
-
// 早期返回:检查空字符串
|
|
232
|
-
if (path.length === 0) {
|
|
233
|
-
return {
|
|
234
|
-
valid: false,
|
|
235
|
-
error: '路径不能为空'
|
|
236
|
-
};
|
|
237
|
-
}
|
|
238
|
-
// 检查路径遍历攻击(使用预编译正则)
|
|
239
|
-
if (PATH_TRAVERSAL_REGEX.test(path)) {
|
|
240
|
-
return {
|
|
241
|
-
valid: false,
|
|
242
|
-
error: process.env.NODE_ENV === 'development' ? '路径包含路径遍历字符(../),可能存在安全风险' : '路径验证失败'
|
|
243
|
-
};
|
|
244
|
-
}
|
|
245
|
-
// 检查空字节注入
|
|
246
|
-
if (NULL_BYTE_REGEX.test(path)) {
|
|
247
|
-
return {
|
|
248
|
-
valid: false,
|
|
249
|
-
error: process.env.NODE_ENV === 'development' ? '路径包含空字节,可能存在安全风险' : '路径验证失败'
|
|
250
|
-
};
|
|
251
|
-
}
|
|
252
|
-
// 检查控制字符
|
|
253
|
-
if (CONTROL_CHAR_REGEX.test(path)) {
|
|
254
|
-
return {
|
|
255
|
-
valid: false,
|
|
256
|
-
error: process.env.NODE_ENV === 'development' ? '路径包含控制字符,可能存在安全风险' : '路径验证失败'
|
|
257
|
-
};
|
|
258
|
-
}
|
|
259
|
-
// 检查命令注入字符(可选,根据需求决定是否启用)
|
|
260
|
-
// if (COMMAND_INJECTION_REGEX.test(path)) {
|
|
261
|
-
// return {
|
|
262
|
-
// valid: false,
|
|
263
|
-
// error: process.env.NODE_ENV === 'development'
|
|
264
|
-
// ? '路径包含潜在的命令注入字符'
|
|
265
|
-
// : '路径验证失败',
|
|
266
|
-
// };
|
|
267
|
-
// }
|
|
268
|
-
// 禁止 URL scheme 导入(如 http:, https:, data:, javascript:)
|
|
269
|
-
if (URL_SCHEME_REGEX.test(path)) {
|
|
270
|
-
return {
|
|
271
|
-
valid: false,
|
|
272
|
-
error: process.env.NODE_ENV === 'development' ? '不允许使用带协议的路径' : '路径验证失败'
|
|
273
|
-
};
|
|
274
|
-
}
|
|
275
|
-
// 检查绝对路径(使用预编译正则)
|
|
276
|
-
if (!config.allowAbsolutePaths && ABSOLUTE_PATH_REGEX.test(path)) {
|
|
277
|
-
return {
|
|
278
|
-
valid: false,
|
|
279
|
-
error: process.env.NODE_ENV === 'development' ? '不允许使用绝对路径' : '路径验证失败'
|
|
280
|
-
};
|
|
281
|
-
}
|
|
282
|
-
// 默认仅允许相对路径和别名路径,避免把第三方包名作为动态入口。
|
|
283
|
-
if (!path.startsWith('@/') && !path.startsWith('./') && !path.startsWith('../')) {
|
|
284
|
-
return {
|
|
285
|
-
valid: false,
|
|
286
|
-
error: process.env.NODE_ENV === 'development' ? '仅允许使用 @/、./、../ 开头的模块路径' : '路径验证失败'
|
|
287
|
-
};
|
|
288
|
-
}
|
|
289
|
-
// 检查路径前缀白名单(优化:使用 Set 提高查找速度)
|
|
290
|
-
if (config.allowedPathPrefixes.length > 0) {
|
|
291
|
-
const prefixSet = new Set(config.allowedPathPrefixes);
|
|
292
|
-
const isAllowed = Array.from(prefixSet).some((prefix)=>path.startsWith(prefix));
|
|
293
|
-
if (!isAllowed) {
|
|
294
|
-
return {
|
|
295
|
-
valid: false,
|
|
296
|
-
error: process.env.NODE_ENV === 'development' ? `路径不在允许的前缀列表中: ${config.allowedPathPrefixes.join(', ')}` : '路径验证失败'
|
|
297
|
-
};
|
|
298
|
-
}
|
|
299
|
-
}
|
|
300
|
-
// 使用 SecurityUtils 验证输入(最后检查,因为可能较慢)
|
|
301
|
-
const validation = SecurityUtils.validateInput(path);
|
|
302
|
-
if (!validation.safe) {
|
|
303
|
-
return {
|
|
304
|
-
valid: false,
|
|
305
|
-
error: process.env.NODE_ENV === 'development' ? validation.reason || '路径包含潜在的危险内容' : '路径验证失败'
|
|
306
|
-
};
|
|
307
|
-
}
|
|
308
|
-
// 验证通过,添加到缓存(限制缓存大小)
|
|
309
|
-
if (validatedPathCache.size < 1000) {
|
|
310
|
-
validatedPathCache.add(path);
|
|
311
|
-
}
|
|
312
|
-
return {
|
|
313
|
-
valid: true
|
|
314
|
-
};
|
|
315
|
-
}
|
|
316
|
-
/**
|
|
317
|
-
* 预编译的正则表达式(用于路径规范化)
|
|
318
|
-
*/ const NORMALIZE_REGEX = {
|
|
319
|
-
multipleSlashes: /\/+/g,
|
|
320
|
-
dotSlash: /\/\.\//g,
|
|
321
|
-
trailingDot: /\/\.$/
|
|
322
|
-
};
|
|
323
|
-
/**
|
|
324
|
-
* 规范化路径
|
|
325
|
-
* 优化:合并正则表达式,减少替换次数
|
|
326
|
-
*/ function normalizePath(path) {
|
|
327
|
-
// 合并多个替换操作,减少字符串遍历次数
|
|
328
|
-
return path.replace(NORMALIZE_REGEX.multipleSlashes, '/').replace(NORMALIZE_REGEX.dotSlash, '/').replace(NORMALIZE_REGEX.trailingDot, '').trim();
|
|
329
|
-
}
|
|
330
|
-
/**
|
|
331
|
-
* 类型守卫:检查是否为有效路径字符串
|
|
332
|
-
*/ function isValidPathString(path) {
|
|
333
|
-
return typeof path === 'string' && path.length > 0;
|
|
334
|
-
}
|
|
335
|
-
/**
|
|
336
|
-
* 类型守卫:检查是否为动态导入函数
|
|
337
|
-
*/ function isComponentImport(path) {
|
|
338
|
-
return typeof path === 'function';
|
|
339
|
-
}
|
|
340
|
-
/**
|
|
341
|
-
* 创建动态导入函数
|
|
342
|
-
*
|
|
343
|
-
* 将组件路径字符串转换为动态导入函数,用于代码分割和懒加载
|
|
344
|
-
*
|
|
345
|
-
* @param path - 组件路径字符串,支持相对路径和别名路径(如 '@/pages/home.tsx')
|
|
346
|
-
* @returns 返回动态导入函数,调用后会返回 Promise,resolve 后的值为组件模块对象
|
|
347
|
-
*
|
|
348
|
-
* @remarks
|
|
349
|
-
* - 使用 `@vite-ignore` 注释告诉 Vite 忽略此动态导入的静态分析
|
|
350
|
-
* - 使用类型断言 `as any` 是因为 TypeScript 的 `import()` 需要静态字符串字面量
|
|
351
|
-
* - 在运行时,我们可以使用动态路径进行导入
|
|
352
|
-
* - 组件必须使用默认导出(export default)
|
|
353
|
-
*
|
|
354
|
-
* @example
|
|
355
|
-
* ```typescript
|
|
356
|
-
* const importFn = createDynamicImport('@/pages/home.tsx');
|
|
357
|
-
* const module = await importFn();
|
|
358
|
-
* const HomePage = module.default;
|
|
359
|
-
* ```
|
|
360
|
-
*/ function createDynamicImport(path) {
|
|
361
|
-
// 使用类型断言,因为 TypeScript 的 import() 需要静态字符串
|
|
362
|
-
// 但在运行时,我们可以使用动态路径
|
|
363
|
-
return ()=>import(/* @vite-ignore */ path);
|
|
364
|
-
}
|
|
365
|
-
/**
|
|
366
|
-
* 提取并验证组件路径到 Map 中
|
|
367
|
-
*
|
|
368
|
-
* 如果路径有效且 Map 中不存在,则创建动态导入函数并存储到 Map 中
|
|
369
|
-
* 这样可以避免重复创建相同路径的动态导入函数,提高性能
|
|
370
|
-
*
|
|
371
|
-
* @param path - 组件路径,可能是字符串、动态导入函数、null 或 undefined
|
|
372
|
-
* @param map - 目标 Map,用于存储路径到动态导入函数的映射
|
|
373
|
-
* @param config - 路径验证配置
|
|
374
|
-
* @param options - 转换选项
|
|
375
|
-
* @returns 如果成功提取,返回动态导入函数;否则返回 null
|
|
376
|
-
*
|
|
377
|
-
* @remarks
|
|
378
|
-
* - 如果 path 是函数,直接返回,不添加到 Map(函数本身就可以直接使用)
|
|
379
|
-
* - 只有当路径是有效的非空字符串时才会处理并添加到 Map
|
|
380
|
-
* - 如果 Map 中已存在该路径,则直接返回已有的导入函数
|
|
381
|
-
* - 优化:使用 `get()` 一次获取,判断是否为 undefined,减少函数调用
|
|
382
|
-
* - 会进行路径验证和清理
|
|
383
|
-
*
|
|
384
|
-
* @example
|
|
385
|
-
* ```typescript
|
|
386
|
-
* const pages = new Map<string, () => Promise<any>>();
|
|
387
|
-
* const importFn1 = extractAndValidatePath('@/pages/home.tsx', pages, config, options);
|
|
388
|
-
* const importFn2 = extractAndValidatePath(() => import('@/pages/home.tsx'), pages, config, options);
|
|
389
|
-
* ```
|
|
390
|
-
*/ function extractAndValidatePath(path, map, config, options) {
|
|
391
|
-
// 早期返回:如果是函数,直接返回,不添加到 Map
|
|
392
|
-
if (isComponentImport(path)) {
|
|
393
|
-
return path;
|
|
394
|
-
}
|
|
395
|
-
// 早期返回:检查是否为有效路径字符串
|
|
396
|
-
if (!isValidPathString(path)) {
|
|
397
|
-
return null;
|
|
398
|
-
}
|
|
399
|
-
// 规范化路径
|
|
400
|
-
const normalizedPath = normalizePath(path);
|
|
401
|
-
// 优化:先检查 Map 中是否已存在(避免不必要的验证)
|
|
402
|
-
const existingImport = map.get(normalizedPath);
|
|
403
|
-
if (existingImport !== undefined) {
|
|
404
|
-
return existingImport;
|
|
405
|
-
}
|
|
406
|
-
// 路径验证(仅在 Map 中不存在时进行)
|
|
407
|
-
if (config.enablePathValidation) {
|
|
408
|
-
const validation = validatePath(normalizedPath, config);
|
|
409
|
-
if (!validation.valid) {
|
|
410
|
-
// 生产环境错误信息脱敏
|
|
411
|
-
const errorMessage = process.env.NODE_ENV === 'development' ? `路径验证失败: ${validation.error}` : '路径验证失败';
|
|
412
|
-
const error = new SecurityError(errorMessage, undefined, process.env.NODE_ENV === 'development' ? {
|
|
413
|
-
path: normalizedPath
|
|
414
|
-
} : {});
|
|
415
|
-
if (options.enableDebugLog) {
|
|
416
|
-
logger.error('路径验证失败:', error);
|
|
417
|
-
}
|
|
418
|
-
// 开发环境抛出错误,生产环境记录警告并跳过
|
|
419
|
-
if (process.env.NODE_ENV === 'development') {
|
|
420
|
-
throw error;
|
|
421
|
-
} else {
|
|
422
|
-
// 生产环境日志脱敏
|
|
423
|
-
logger.warn('路径验证失败,已跳过');
|
|
424
|
-
return null;
|
|
425
|
-
}
|
|
426
|
-
}
|
|
427
|
-
}
|
|
428
|
-
// 创建动态导入函数并存储
|
|
429
|
-
const importFn = createDynamicImport(normalizedPath);
|
|
430
|
-
map.set(normalizedPath, importFn);
|
|
431
|
-
if (options.enableDebugLog) {
|
|
432
|
-
logger.debug('提取路径:', normalizedPath);
|
|
433
|
-
}
|
|
434
|
-
return importFn;
|
|
435
|
-
}
|
|
436
|
-
/**
|
|
437
|
-
* 对象池:复用栈节点对象,减少 GC 压力
|
|
438
|
-
*/ let StackNodePool = class StackNodePool {
|
|
439
|
-
acquire(route, depth) {
|
|
440
|
-
if (this.pool.length > 0) {
|
|
441
|
-
const node = this.pool.pop();
|
|
442
|
-
node.route = route;
|
|
443
|
-
node.depth = depth;
|
|
444
|
-
return node;
|
|
445
|
-
}
|
|
446
|
-
return {
|
|
447
|
-
route,
|
|
448
|
-
depth
|
|
449
|
-
};
|
|
450
|
-
}
|
|
451
|
-
release(node) {
|
|
452
|
-
if (this.pool.length < this.maxPoolSize) {
|
|
453
|
-
this.pool.push(node);
|
|
454
|
-
}
|
|
455
|
-
}
|
|
456
|
-
constructor(){
|
|
457
|
-
_define_property(this, "pool", []);
|
|
458
|
-
_define_property(this, "maxPoolSize", 100);
|
|
459
|
-
}
|
|
460
|
-
};
|
|
461
|
-
const stackNodePool = new StackNodePool();
|
|
462
|
-
/**
|
|
463
|
-
* 只提取组件路径到 Map 中,不转换路由配置
|
|
464
|
-
*
|
|
465
|
-
* 使用迭代方式遍历所有路由(包括子路由),提取组件路径到对应的 Map 中
|
|
466
|
-
* 这种设计可以确保:
|
|
467
|
-
* - 相同的组件路径只会创建一个动态导入函数
|
|
468
|
-
* - 使用迭代而非递归,避免栈溢出
|
|
469
|
-
* - 优化:支持并行处理、使用对象池、预分配数组
|
|
470
|
-
*
|
|
471
|
-
* @param routes - 原始路由配置列表
|
|
472
|
-
* @param result - 结果对象,用于累积收集的组件路径
|
|
473
|
-
* @param config - 路径验证配置
|
|
474
|
-
* @param options - 转换选项
|
|
475
|
-
* @param maxDepth - 最大递归深度
|
|
476
|
-
*/ async function extractPathsOnly(routes, result, config, options, maxDepth) {
|
|
477
|
-
const enableParallel = options.performance?.enableParallelProcessing ?? true;
|
|
478
|
-
const batchSize = options.performance?.parallelBatchSize ?? 10;
|
|
479
|
-
// 如果启用并行处理且路由数量较多,使用并行处理
|
|
480
|
-
if (enableParallel && routes.length > batchSize) {
|
|
481
|
-
// 收集所有需要处理的路径(只收集字符串类型,函数类型不需要处理)
|
|
482
|
-
const pathsToProcess = [];
|
|
483
|
-
// 遍历所有路由,收集路径
|
|
484
|
-
const stack = [];
|
|
485
|
-
for(let i = routes.length - 1; i >= 0; i--){
|
|
486
|
-
stack.push({
|
|
487
|
-
route: routes[i],
|
|
488
|
-
depth: 0
|
|
489
|
-
});
|
|
490
|
-
}
|
|
491
|
-
while(stack.length > 0){
|
|
492
|
-
const { route, depth } = stack.pop();
|
|
493
|
-
if (depth > maxDepth) {
|
|
494
|
-
logger.warn(`路径提取达到最大深度 ${maxDepth},跳过路由:`, route.name);
|
|
495
|
-
continue;
|
|
496
|
-
}
|
|
497
|
-
// 收集路径(只收集字符串类型,函数类型不需要处理,会直接使用)
|
|
498
|
-
if (route.page && typeof route.page === 'string') {
|
|
499
|
-
pathsToProcess.push({
|
|
500
|
-
path: route.page,
|
|
501
|
-
map: result.pages
|
|
502
|
-
});
|
|
503
|
-
}
|
|
504
|
-
if (route.layout && typeof route.layout === 'string') {
|
|
505
|
-
pathsToProcess.push({
|
|
506
|
-
path: route.layout,
|
|
507
|
-
map: result.layouts
|
|
508
|
-
});
|
|
509
|
-
}
|
|
510
|
-
const routeError = route.error ?? route.errors;
|
|
511
|
-
if (routeError && typeof routeError === 'string') {
|
|
512
|
-
pathsToProcess.push({
|
|
513
|
-
path: routeError,
|
|
514
|
-
map: result.errors
|
|
515
|
-
});
|
|
516
|
-
}
|
|
517
|
-
if (route.loading && typeof route.loading === 'string') {
|
|
518
|
-
pathsToProcess.push({
|
|
519
|
-
path: route.loading,
|
|
520
|
-
map: result.loadings
|
|
521
|
-
});
|
|
522
|
-
}
|
|
523
|
-
// 处理子路由
|
|
524
|
-
if (route.children && Array.isArray(route.children) && route.children.length > 0) {
|
|
525
|
-
for(let i = route.children.length - 1; i >= 0; i--){
|
|
526
|
-
stack.push({
|
|
527
|
-
route: route.children[i],
|
|
528
|
-
depth: depth + 1
|
|
529
|
-
});
|
|
530
|
-
}
|
|
531
|
-
}
|
|
532
|
-
}
|
|
533
|
-
// 并行处理路径(分批处理)
|
|
534
|
-
for(let i = 0; i < pathsToProcess.length; i += batchSize){
|
|
535
|
-
const batch = pathsToProcess.slice(i, i + batchSize);
|
|
536
|
-
await Promise.all(batch.map(({ path, map })=>Promise.resolve(extractAndValidatePath(path, map, config, options))));
|
|
537
|
-
}
|
|
538
|
-
} else {
|
|
539
|
-
// 串行处理(原有逻辑,优化:使用对象池)
|
|
540
|
-
const stack = [];
|
|
541
|
-
// 初始化栈:将所有路由推入栈中
|
|
542
|
-
for(let i = routes.length - 1; i >= 0; i--){
|
|
543
|
-
stack.push(stackNodePool.acquire(routes[i], 0));
|
|
544
|
-
}
|
|
545
|
-
// 迭代处理栈中的路由
|
|
546
|
-
while(stack.length > 0){
|
|
547
|
-
const node = stack.pop();
|
|
548
|
-
const { route, depth } = node;
|
|
549
|
-
// 检查递归深度
|
|
550
|
-
if (depth > maxDepth) {
|
|
551
|
-
logger.warn(`路径提取达到最大深度 ${maxDepth},跳过路由:`, route.name);
|
|
552
|
-
stackNodePool.release(node);
|
|
553
|
-
continue;
|
|
554
|
-
}
|
|
555
|
-
// 提取组件路径到 Map 中(同时进行验证)
|
|
556
|
-
extractAndValidatePath(route.page, result.pages, config, options);
|
|
557
|
-
extractAndValidatePath(route.layout, result.layouts, config, options);
|
|
558
|
-
extractAndValidatePath(route.error ?? route.errors, result.errors, config, options);
|
|
559
|
-
extractAndValidatePath(route.loading, result.loadings, config, options);
|
|
560
|
-
// 处理子路由
|
|
561
|
-
if (route.children && Array.isArray(route.children) && route.children.length > 0) {
|
|
562
|
-
// 将子路由推入栈中(逆序推入,保证处理顺序正确)
|
|
563
|
-
for(let i = route.children.length - 1; i >= 0; i--){
|
|
564
|
-
stack.push(stackNodePool.acquire(route.children[i], depth + 1));
|
|
565
|
-
}
|
|
566
|
-
}
|
|
567
|
-
// 释放节点到对象池
|
|
568
|
-
stackNodePool.release(node);
|
|
569
|
-
}
|
|
570
|
-
}
|
|
571
|
-
}
|
|
572
|
-
/**
|
|
573
|
-
* 清理过期缓存
|
|
574
|
-
* 优化:使用 LRU 缓存的清理方法
|
|
575
|
-
*/ function cleanupExpiredCache(cacheTTL) {
|
|
576
|
-
if (transformCache) {
|
|
577
|
-
transformCache.cleanupExpired(cacheTTL);
|
|
578
|
-
}
|
|
579
|
-
}
|
|
580
|
-
/**
|
|
581
|
-
* 转换路由配置:提取组件路径到 Map 中,返回原始路由配置
|
|
582
|
-
*
|
|
583
|
-
* 此函数是路由转换的核心函数,主要完成以下任务:
|
|
584
|
-
* 1. 递归提取路由配置中的所有组件路径(page、layout、errors、loading)
|
|
585
|
-
* 2. 将组件路径字符串转换为动态导入函数
|
|
586
|
-
* 3. 将动态导入函数存储在对应的 Map 中,key 为路径字符串,确保不重复
|
|
587
|
-
* 4. 返回原始路由配置列表,不进行转换
|
|
588
|
-
*
|
|
589
|
-
* @param routes - 路由配置列表,可以是:
|
|
590
|
-
* - 路由配置数组(RouteConfig[])
|
|
591
|
-
* - 返回路由配置数组的函数(支持同步或异步:() => RouteConfig[] | Promise<RouteConfig[]>)
|
|
592
|
-
* 支持异步函数是为了支持动态加载路由配置(如从服务器获取)
|
|
593
|
-
* @param options - 转换配置选项
|
|
594
|
-
* @returns 包含以下内容的结果对象:
|
|
595
|
-
* - `pages`: 页面组件路径到动态导入函数的 Map
|
|
596
|
-
* - `layouts`: 布局组件路径到动态导入函数的 Map
|
|
597
|
-
* - `errors`: 错误组件路径到动态导入函数的 Map
|
|
598
|
-
* - `loadings`: 加载组件路径到动态导入函数的 Map
|
|
599
|
-
* - `routes`: 原始路由配置列表,不进行转换
|
|
600
|
-
*
|
|
601
|
-
* @remarks
|
|
602
|
-
* - 如果 `routes` 为 null、undefined 或空数组,返回空结果对象
|
|
603
|
-
* - 如果 `routes` 是函数但返回的不是数组,返回空结果对象
|
|
604
|
-
* - 相同的组件路径只会创建一个动态导入函数,存储在 Map 中复用
|
|
605
|
-
* - 路由配置保持原始格式,组件路径仍为字符串
|
|
606
|
-
* - 支持嵌套路由,会递归处理所有层级的子路由
|
|
607
|
-
* - 支持缓存,相同配置会直接返回缓存结果
|
|
608
|
-
*
|
|
609
|
-
* @example
|
|
610
|
-
* ```typescript
|
|
611
|
-
* // 示例 1: 使用数组配置
|
|
612
|
-
* const result = await transformRoutes([
|
|
613
|
-
* {
|
|
614
|
-
* name: 'home',
|
|
615
|
-
* path: '/',
|
|
616
|
-
* page: '@/pages/home.tsx',
|
|
617
|
-
* errors: '@/pages/error.tsx',
|
|
618
|
-
* handle: { title: '首页', order: 1 },
|
|
619
|
-
* },
|
|
620
|
-
* ]);
|
|
621
|
-
*
|
|
622
|
-
* // 示例 2: 使用异步函数配置
|
|
623
|
-
* const result = await transformRoutes(async () => {
|
|
624
|
-
* const response = await fetch('/api/routes');
|
|
625
|
-
* return response.json();
|
|
626
|
-
* });
|
|
627
|
-
*
|
|
628
|
-
* // 示例 3: 使用配置选项
|
|
629
|
-
* const result = await transformRoutes(routes, {
|
|
630
|
-
* pathValidation: {
|
|
631
|
-
* enablePathValidation: true,
|
|
632
|
-
* allowedPathPrefixes: ['@/pages', '@/components'],
|
|
633
|
-
* },
|
|
634
|
-
* performance: {
|
|
635
|
-
* enableCache: true,
|
|
636
|
-
* cacheTTL: 10 * 60 * 1000, // 10 分钟
|
|
637
|
-
* },
|
|
638
|
-
* });
|
|
639
|
-
* ```
|
|
640
|
-
*/ export async function transformRoutes(routes, options = {}) {
|
|
641
|
-
const startTime = performance.now();
|
|
642
|
-
const mergedOptions = {
|
|
643
|
-
pathValidation: {
|
|
644
|
-
...DEFAULT_OPTIONS.pathValidation,
|
|
645
|
-
...options.pathValidation
|
|
646
|
-
},
|
|
647
|
-
performance: {
|
|
648
|
-
...DEFAULT_OPTIONS.performance,
|
|
649
|
-
...options.performance
|
|
650
|
-
},
|
|
651
|
-
enableDebugLog: options.enableDebugLog ?? DEFAULT_OPTIONS.enableDebugLog
|
|
652
|
-
};
|
|
653
|
-
// 早期返回:如果 routes 为空或未定义,直接返回空结果
|
|
654
|
-
if (!routes) {
|
|
655
|
-
if (mergedOptions.enableDebugLog) {
|
|
656
|
-
logger.debug('路由配置为空,返回空结果');
|
|
657
|
-
}
|
|
658
|
-
return {
|
|
659
|
-
pages: new Map(),
|
|
660
|
-
layouts: new Map(),
|
|
661
|
-
errors: new Map(),
|
|
662
|
-
loadings: new Map(),
|
|
663
|
-
routes: []
|
|
664
|
-
};
|
|
665
|
-
}
|
|
666
|
-
// 处理 routes 可能是函数的情况
|
|
667
|
-
let routesArray;
|
|
668
|
-
try {
|
|
669
|
-
routesArray = typeof routes === 'function' ? await routes() : routes;
|
|
670
|
-
} catch (error) {
|
|
671
|
-
const err = error instanceof Error ? error : new Error('路由配置加载失败');
|
|
672
|
-
logger.error('路由配置加载失败:', err);
|
|
673
|
-
throw new ValidationError('路由配置加载失败', {
|
|
674
|
-
originalError: err
|
|
675
|
-
});
|
|
676
|
-
}
|
|
677
|
-
// 早期返回:如果 routesArray 不是数组,直接返回空结果
|
|
678
|
-
if (!Array.isArray(routesArray) || routesArray.length === 0) {
|
|
679
|
-
if (mergedOptions.enableDebugLog) {
|
|
680
|
-
logger.debug('路由配置不是数组或为空,返回空结果');
|
|
681
|
-
}
|
|
682
|
-
return {
|
|
683
|
-
pages: new Map(),
|
|
684
|
-
layouts: new Map(),
|
|
685
|
-
errors: new Map(),
|
|
686
|
-
loadings: new Map(),
|
|
687
|
-
routes: []
|
|
688
|
-
};
|
|
689
|
-
}
|
|
690
|
-
// 检查缓存
|
|
691
|
-
const cacheTTL = mergedOptions.performance.cacheTTL ?? DEFAULT_OPTIONS.performance.cacheTTL;
|
|
692
|
-
const maxCacheSize = mergedOptions.performance.maxCacheSize ?? DEFAULT_OPTIONS.performance.maxCacheSize;
|
|
693
|
-
if (mergedOptions.performance.enableCache) {
|
|
694
|
-
// 初始化 LRU 缓存(如果尚未初始化或大小发生变化)
|
|
695
|
-
if (!transformCache || transformCache.size() !== maxCacheSize) {
|
|
696
|
-
transformCache = new LRUCache(maxCacheSize);
|
|
697
|
-
}
|
|
698
|
-
const configHash = generateConfigHash(routesArray);
|
|
699
|
-
if (configHash) {
|
|
700
|
-
const cached = transformCache.get(configHash);
|
|
701
|
-
if (cached && Date.now() - cached.timestamp < cacheTTL) {
|
|
702
|
-
if (mergedOptions.enableDebugLog) {
|
|
703
|
-
logger.debug('使用缓存结果');
|
|
704
|
-
}
|
|
705
|
-
// 直接返回缓存结果(LRU 缓存已处理访问时间更新)
|
|
706
|
-
return cached.result;
|
|
707
|
-
}
|
|
708
|
-
}
|
|
709
|
-
// 清理过期缓存
|
|
710
|
-
cleanupExpiredCache(cacheTTL);
|
|
711
|
-
}
|
|
712
|
-
// 初始化结果对象
|
|
713
|
-
const result = {
|
|
714
|
-
pages: new Map(),
|
|
715
|
-
layouts: new Map(),
|
|
716
|
-
errors: new Map(),
|
|
717
|
-
loadings: new Map(),
|
|
718
|
-
routes: []
|
|
719
|
-
};
|
|
720
|
-
try {
|
|
721
|
-
// 性能监控:记录各阶段耗时
|
|
722
|
-
const extractStartTime = performance.now();
|
|
723
|
-
// 提取组件路径到 Map 中(不转换路由配置)
|
|
724
|
-
const pathValidation = {
|
|
725
|
-
enablePathValidation: mergedOptions.pathValidation.enablePathValidation ?? DEFAULT_OPTIONS.pathValidation.enablePathValidation,
|
|
726
|
-
allowedPathPrefixes: mergedOptions.pathValidation.allowedPathPrefixes ?? DEFAULT_OPTIONS.pathValidation.allowedPathPrefixes,
|
|
727
|
-
maxPathLength: mergedOptions.pathValidation.maxPathLength ?? DEFAULT_OPTIONS.pathValidation.maxPathLength,
|
|
728
|
-
allowAbsolutePaths: mergedOptions.pathValidation.allowAbsolutePaths ?? DEFAULT_OPTIONS.pathValidation.allowAbsolutePaths
|
|
729
|
-
};
|
|
730
|
-
const maxRecursionDepth = mergedOptions.performance.maxRecursionDepth ?? DEFAULT_OPTIONS.performance.maxRecursionDepth;
|
|
731
|
-
// 异步提取路径(支持并行处理)
|
|
732
|
-
await extractPathsOnly(routesArray, result, pathValidation, mergedOptions, maxRecursionDepth);
|
|
733
|
-
const extractEndTime = performance.now();
|
|
734
|
-
const extractDuration = extractEndTime - extractStartTime;
|
|
735
|
-
// 直接使用原始路由配置,不进行转换
|
|
736
|
-
result.routes = routesArray;
|
|
737
|
-
// 缓存结果
|
|
738
|
-
const cacheStartTime = performance.now();
|
|
739
|
-
if (mergedOptions.performance.enableCache && transformCache) {
|
|
740
|
-
const configHash = generateConfigHash(routesArray);
|
|
741
|
-
if (configHash) {
|
|
742
|
-
// 注意:Map 中包含函数值,structuredClone 会失败;统一使用手动克隆。
|
|
743
|
-
const cachedResult = {
|
|
744
|
-
pages: new Map(result.pages),
|
|
745
|
-
layouts: new Map(result.layouts),
|
|
746
|
-
errors: new Map(result.errors),
|
|
747
|
-
loadings: new Map(result.loadings),
|
|
748
|
-
routes: JSON.parse(JSON.stringify(result.routes))
|
|
749
|
-
};
|
|
750
|
-
transformCache.set(configHash, {
|
|
751
|
-
result: cachedResult,
|
|
752
|
-
timestamp: Date.now(),
|
|
753
|
-
hash: configHash,
|
|
754
|
-
accessTime: Date.now()
|
|
755
|
-
});
|
|
756
|
-
}
|
|
757
|
-
}
|
|
758
|
-
const cacheEndTime = performance.now();
|
|
759
|
-
const cacheDuration = cacheEndTime - cacheStartTime;
|
|
760
|
-
const endTime = performance.now();
|
|
761
|
-
const totalDuration = endTime - startTime;
|
|
762
|
-
if (mergedOptions.enableDebugLog) {
|
|
763
|
-
// 详细的性能报告
|
|
764
|
-
logger.debug(`路由转换完成,总耗时: ${totalDuration.toFixed(2)}ms`, {
|
|
765
|
-
routeCount: result.routes.length,
|
|
766
|
-
pageCount: result.pages.size,
|
|
767
|
-
layoutCount: result.layouts.size,
|
|
768
|
-
errorCount: result.errors.size,
|
|
769
|
-
loadingCount: result.loadings.size,
|
|
770
|
-
performance: {
|
|
771
|
-
extractDuration: `${extractDuration.toFixed(2)}ms`,
|
|
772
|
-
cacheDuration: `${cacheDuration.toFixed(2)}ms`,
|
|
773
|
-
totalDuration: `${totalDuration.toFixed(2)}ms`
|
|
774
|
-
},
|
|
775
|
-
cache: {
|
|
776
|
-
hit: transformCache ? 'miss' : 'disabled',
|
|
777
|
-
size: transformCache?.size() ?? 0
|
|
778
|
-
}
|
|
779
|
-
});
|
|
780
|
-
}
|
|
781
|
-
return result;
|
|
782
|
-
} catch (error) {
|
|
783
|
-
const err = error instanceof Error ? error : new Error('路由转换失败');
|
|
784
|
-
logger.error('路由转换失败:', err);
|
|
785
|
-
throw new ValidationError('路由转换失败', {
|
|
786
|
-
originalError: err
|
|
787
|
-
});
|
|
788
|
-
}
|
|
789
|
-
}
|
|
790
|
-
|
|
791
|
-
//# sourceMappingURL=transform.js.map
|
|
1
|
+
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}import{logger}from"@vlian/logger";import{SecurityUtils,SecurityError,ValidationError}from"@vlian/utils";let LRUCache=class LRUCache{get(key){const item=this.cache.get(key);if(item){item.accessTime=Date.now();this.cache.delete(key);this.cache.set(key,item)}return item}set(key,value){if(this.cache.has(key)){this.cache.delete(key)}else if(this.cache.size>=this.maxSize){const firstKey=this.cache.keys().next().value;if(firstKey){this.cache.delete(firstKey)}}value.accessTime=Date.now();this.cache.set(key,value)}delete(key){return this.cache.delete(key)}clear(){this.cache.clear()}size(){return this.cache.size}cleanupExpired(cacheTTL){const now=Date.now();for(const[key,item]of this.cache.entries()){if(now-item.timestamp>cacheTTL){this.cache.delete(key)}}}constructor(maxSize=50){_define_property(this,"cache",new Map);_define_property(this,"maxSize",void 0);this.maxSize=maxSize}};let transformCache=null;const DEFAULT_OPTIONS={pathValidation:{enablePathValidation:true,allowedPathPrefixes:["@/","./","../"],maxPathLength:500,allowAbsolutePaths:false},performance:{enableCache:true,cacheTTL:5*60*1e3,maxCacheSize:50,maxRecursionDepth:100,enableParallelProcessing:true,parallelBatchSize:10},enableDebugLog:false};function optimizedHash(str){if(str.length<100){let hash=0;for(let i=0;i<str.length;i++){const char=str.charCodeAt(i);hash=(hash<<5)-hash+char;hash=hash&hash}return Math.abs(hash).toString(36)}let hash=0;const step=Math.max(1,Math.floor(str.length/100));for(let i=0;i<str.length;i+=step){const char=str.charCodeAt(i);hash=(hash<<5)-hash+char;hash=hash&hash}return Math.abs(hash).toString(36)}function simpleHash(str){return optimizedHash(str)}function serializeComponentRef(value){if(typeof value==="string"){return{str:value}}if(typeof value==="function"){const fnText=String(value);return{fn:`${value.name||"anonymous"}:${fnText.length}`}}return{}}function serializeRouteConfig(route){const page=serializeComponentRef(route.page);const layout=serializeComponentRef(route.layout);const routeError=serializeComponentRef(route.error??route.errors);const loading=serializeComponentRef(route.loading);return{name:route.name,path:route.path,page:page.str,pageFn:page.fn,layout:layout.str,layoutFn:layout.fn,error:routeError.str,errorFn:routeError.fn,loading:loading.str,loadingFn:loading.fn,isGroup:route.isGroup,enableRedirection:route.enableRedirection,handle:route.handle?{title:route.handle.title,order:route.handle.order,needLogin:route.handle.needLogin,roles:Array.isArray(route.handle.roles)?[...route.handle.roles]:undefined}:undefined,children:route.children?.map(child=>serializeRouteConfig(child))}}function generateConfigHash(routes){try{if(routes.length===0){return"empty"}const serializedRoutes=routes.map(route=>serializeRouteConfig(route));const configStr=JSON.stringify(serializedRoutes);return simpleHash(configStr)}catch{return""}}const validatedPathCache=new Set;const PATH_TRAVERSAL_REGEX=/\.\.(\/|\\)|\.\.%2[Ff]|\.\.%5[Cc]|%2[Ee]%2[Ee]%2[Ff]|%2[Ee]%2[Ee]%5[Cc]/i;const ABSOLUTE_PATH_REGEX=/^\/|^[A-Za-z]:\\/;const CONTROL_CHAR_REGEX=/[\x00-\x1f\x7f]/;const NULL_BYTE_REGEX=/%00|\\0|\x00/;const URL_SCHEME_REGEX=/^[A-Za-z][A-Za-z0-9+.-]*:/;function validatePath(path,config){if(validatedPathCache.has(path)){return{valid:true}}if(path.length>config.maxPathLength){return{valid:false,error:process.env.NODE_ENV==="development"?`路径长度超过最大限制 ${config.maxPathLength} 字符`:"路径验证失败"}}if(path.length===0){return{valid:false,error:"路径不能为空"}}if(PATH_TRAVERSAL_REGEX.test(path)){return{valid:false,error:process.env.NODE_ENV==="development"?"路径包含路径遍历字符(../),可能存在安全风险":"路径验证失败"}}if(NULL_BYTE_REGEX.test(path)){return{valid:false,error:process.env.NODE_ENV==="development"?"路径包含空字节,可能存在安全风险":"路径验证失败"}}if(CONTROL_CHAR_REGEX.test(path)){return{valid:false,error:process.env.NODE_ENV==="development"?"路径包含控制字符,可能存在安全风险":"路径验证失败"}}if(URL_SCHEME_REGEX.test(path)){return{valid:false,error:process.env.NODE_ENV==="development"?"不允许使用带协议的路径":"路径验证失败"}}if(!config.allowAbsolutePaths&&ABSOLUTE_PATH_REGEX.test(path)){return{valid:false,error:process.env.NODE_ENV==="development"?"不允许使用绝对路径":"路径验证失败"}}if(!path.startsWith("@/")&&!path.startsWith("./")&&!path.startsWith("../")){return{valid:false,error:process.env.NODE_ENV==="development"?"仅允许使用 @/、./、../ 开头的模块路径":"路径验证失败"}}if(config.allowedPathPrefixes.length>0){const prefixSet=new Set(config.allowedPathPrefixes);const isAllowed=Array.from(prefixSet).some(prefix=>path.startsWith(prefix));if(!isAllowed){return{valid:false,error:process.env.NODE_ENV==="development"?`路径不在允许的前缀列表中: ${config.allowedPathPrefixes.join(", ")}`:"路径验证失败"}}}const validation=SecurityUtils.validateInput(path);if(!validation.safe){return{valid:false,error:process.env.NODE_ENV==="development"?validation.reason||"路径包含潜在的危险内容":"路径验证失败"}}if(validatedPathCache.size<1e3){validatedPathCache.add(path)}return{valid:true}}const NORMALIZE_REGEX={multipleSlashes:/\/+/g,dotSlash:/\/\.\//g,trailingDot:/\/\.$/};function normalizePath(path){return path.replace(NORMALIZE_REGEX.multipleSlashes,"/").replace(NORMALIZE_REGEX.dotSlash,"/").replace(NORMALIZE_REGEX.trailingDot,"").trim()}function isValidPathString(path){return typeof path==="string"&&path.length>0}function isComponentImport(path){return typeof path==="function"}function createDynamicImport(path){return()=>import(path)}function extractAndValidatePath(path,map,config,options){if(isComponentImport(path)){return path}if(!isValidPathString(path)){return null}const normalizedPath=normalizePath(path);const existingImport=map.get(normalizedPath);if(existingImport!==undefined){return existingImport}if(config.enablePathValidation){const validation=validatePath(normalizedPath,config);if(!validation.valid){const errorMessage=process.env.NODE_ENV==="development"?`路径验证失败: ${validation.error}`:"路径验证失败";const error=new SecurityError(errorMessage,undefined,process.env.NODE_ENV==="development"?{path:normalizedPath}:{});if(options.enableDebugLog){logger.error("路径验证失败:",error)}if(process.env.NODE_ENV==="development"){throw error}else{logger.warn("路径验证失败,已跳过");return null}}}const importFn=createDynamicImport(normalizedPath);map.set(normalizedPath,importFn);if(options.enableDebugLog){logger.debug("提取路径:",normalizedPath)}return importFn}let StackNodePool=class StackNodePool{acquire(route,depth){if(this.pool.length>0){const node=this.pool.pop();node.route=route;node.depth=depth;return node}return{route,depth}}release(node){if(this.pool.length<this.maxPoolSize){this.pool.push(node)}}constructor(){_define_property(this,"pool",[]);_define_property(this,"maxPoolSize",100)}};const stackNodePool=new StackNodePool;async function extractPathsOnly(routes,result,config,options,maxDepth){const enableParallel=options.performance?.enableParallelProcessing??true;const batchSize=options.performance?.parallelBatchSize??10;if(enableParallel&&routes.length>batchSize){const pathsToProcess=[];const stack=[];for(let i=routes.length-1;i>=0;i--){stack.push({route:routes[i],depth:0})}while(stack.length>0){const{route,depth}=stack.pop();if(depth>maxDepth){logger.warn(`路径提取达到最大深度 ${maxDepth},跳过路由:`,route.name);continue}if(route.page&&typeof route.page==="string"){pathsToProcess.push({path:route.page,map:result.pages})}if(route.layout&&typeof route.layout==="string"){pathsToProcess.push({path:route.layout,map:result.layouts})}const routeError=route.error??route.errors;if(routeError&&typeof routeError==="string"){pathsToProcess.push({path:routeError,map:result.errors})}if(route.loading&&typeof route.loading==="string"){pathsToProcess.push({path:route.loading,map:result.loadings})}if(route.children&&Array.isArray(route.children)&&route.children.length>0){for(let i=route.children.length-1;i>=0;i--){stack.push({route:route.children[i],depth:depth+1})}}}for(let i=0;i<pathsToProcess.length;i+=batchSize){const batch=pathsToProcess.slice(i,i+batchSize);await Promise.all(batch.map(({path,map})=>Promise.resolve(extractAndValidatePath(path,map,config,options))))}}else{const stack=[];for(let i=routes.length-1;i>=0;i--){stack.push(stackNodePool.acquire(routes[i],0))}while(stack.length>0){const node=stack.pop();const{route,depth}=node;if(depth>maxDepth){logger.warn(`路径提取达到最大深度 ${maxDepth},跳过路由:`,route.name);stackNodePool.release(node);continue}extractAndValidatePath(route.page,result.pages,config,options);extractAndValidatePath(route.layout,result.layouts,config,options);extractAndValidatePath(route.error??route.errors,result.errors,config,options);extractAndValidatePath(route.loading,result.loadings,config,options);if(route.children&&Array.isArray(route.children)&&route.children.length>0){for(let i=route.children.length-1;i>=0;i--){stack.push(stackNodePool.acquire(route.children[i],depth+1))}}stackNodePool.release(node)}}}function cleanupExpiredCache(cacheTTL){if(transformCache){transformCache.cleanupExpired(cacheTTL)}}export async function transformRoutes(routes,options={}){const startTime=performance.now();const mergedOptions={pathValidation:{...DEFAULT_OPTIONS.pathValidation,...options.pathValidation},performance:{...DEFAULT_OPTIONS.performance,...options.performance},enableDebugLog:options.enableDebugLog??DEFAULT_OPTIONS.enableDebugLog};if(!routes){if(mergedOptions.enableDebugLog){logger.debug("路由配置为空,返回空结果")}return{pages:new Map,layouts:new Map,errors:new Map,loadings:new Map,routes:[]}}let routesArray;try{routesArray=typeof routes==="function"?await routes():routes}catch(error){const err=error instanceof Error?error:new Error("路由配置加载失败");logger.error("路由配置加载失败:",err);throw new ValidationError("路由配置加载失败",{originalError:err})}if(!Array.isArray(routesArray)||routesArray.length===0){if(mergedOptions.enableDebugLog){logger.debug("路由配置不是数组或为空,返回空结果")}return{pages:new Map,layouts:new Map,errors:new Map,loadings:new Map,routes:[]}}const cacheTTL=mergedOptions.performance.cacheTTL??DEFAULT_OPTIONS.performance.cacheTTL;const maxCacheSize=mergedOptions.performance.maxCacheSize??DEFAULT_OPTIONS.performance.maxCacheSize;if(mergedOptions.performance.enableCache){if(!transformCache||transformCache.size()!==maxCacheSize){transformCache=new LRUCache(maxCacheSize)}const configHash=generateConfigHash(routesArray);if(configHash){const cached=transformCache.get(configHash);if(cached&&Date.now()-cached.timestamp<cacheTTL){if(mergedOptions.enableDebugLog){logger.debug("使用缓存结果")}return cached.result}}cleanupExpiredCache(cacheTTL)}const result={pages:new Map,layouts:new Map,errors:new Map,loadings:new Map,routes:[]};try{const extractStartTime=performance.now();const pathValidation={enablePathValidation:mergedOptions.pathValidation.enablePathValidation??DEFAULT_OPTIONS.pathValidation.enablePathValidation,allowedPathPrefixes:mergedOptions.pathValidation.allowedPathPrefixes??DEFAULT_OPTIONS.pathValidation.allowedPathPrefixes,maxPathLength:mergedOptions.pathValidation.maxPathLength??DEFAULT_OPTIONS.pathValidation.maxPathLength,allowAbsolutePaths:mergedOptions.pathValidation.allowAbsolutePaths??DEFAULT_OPTIONS.pathValidation.allowAbsolutePaths};const maxRecursionDepth=mergedOptions.performance.maxRecursionDepth??DEFAULT_OPTIONS.performance.maxRecursionDepth;await extractPathsOnly(routesArray,result,pathValidation,mergedOptions,maxRecursionDepth);const extractEndTime=performance.now();const extractDuration=extractEndTime-extractStartTime;result.routes=routesArray;const cacheStartTime=performance.now();if(mergedOptions.performance.enableCache&&transformCache){const configHash=generateConfigHash(routesArray);if(configHash){const cachedResult={pages:new Map(result.pages),layouts:new Map(result.layouts),errors:new Map(result.errors),loadings:new Map(result.loadings),routes:JSON.parse(JSON.stringify(result.routes))};transformCache.set(configHash,{result:cachedResult,timestamp:Date.now(),hash:configHash,accessTime:Date.now()})}}const cacheEndTime=performance.now();const cacheDuration=cacheEndTime-cacheStartTime;const endTime=performance.now();const totalDuration=endTime-startTime;if(mergedOptions.enableDebugLog){logger.debug(`路由转换完成,总耗时: ${totalDuration.toFixed(2)}ms`,{routeCount:result.routes.length,pageCount:result.pages.size,layoutCount:result.layouts.size,errorCount:result.errors.size,loadingCount:result.loadings.size,performance:{extractDuration:`${extractDuration.toFixed(2)}ms`,cacheDuration:`${cacheDuration.toFixed(2)}ms`,totalDuration:`${totalDuration.toFixed(2)}ms`},cache:{hit:transformCache?"miss":"disabled",size:transformCache?.size()??0}})}return result}catch(error){const err=error instanceof Error?error:new Error("路由转换失败");logger.error("路由转换失败:",err);throw new ValidationError("路由转换失败",{originalError:err})}}
|