@go-wind/admin-react 0.0.0-stage → 0.2.0

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 (120) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +74 -2
  3. package/dist/access/access-control.d.ts +39 -0
  4. package/dist/access/field-permission.d.ts +11 -0
  5. package/dist/access/index.d.ts +4 -0
  6. package/dist/access/use-access.d.ts +50 -0
  7. package/dist/admin-react.css +2 -0
  8. package/dist/admin-react.js +36561 -0
  9. package/dist/admin-react.js.map +1 -0
  10. package/dist/auth-gateway.d.ts +54 -0
  11. package/dist/components/ListTable/ResizableHeaderCell.d.ts +31 -0
  12. package/dist/components/ListTable/TableSkeleton.d.ts +25 -0
  13. package/dist/components/ListTable/index.d.ts +20 -0
  14. package/dist/components/Loading/index.d.ts +22 -0
  15. package/dist/constants.d.ts +30 -0
  16. package/dist/env.d.ts +5 -0
  17. package/dist/hooks/useClipboard.d.ts +3 -0
  18. package/dist/hooks/useEcharts.d.ts +10 -0
  19. package/dist/hooks/useKeyStroke.d.ts +13 -0
  20. package/dist/hooks/usePageFullscreen.d.ts +9 -0
  21. package/dist/hooks/useProTableScrollY.d.ts +22 -0
  22. package/dist/hooks/useTime.d.ts +6 -0
  23. package/dist/hooks/useTitle.d.ts +1 -0
  24. package/dist/hooks/useTokenRefresh.d.ts +26 -0
  25. package/dist/hooks/useWatermark.d.ts +20 -0
  26. package/dist/i18n/components/LocaleSwitcher/index.d.ts +1 -0
  27. package/dist/i18n/components/index.d.ts +1 -0
  28. package/dist/i18n/config/i18n.d.ts +18 -0
  29. package/dist/i18n/hooks/index.d.ts +2 -0
  30. package/dist/i18n/hooks/useI18n.d.ts +96 -0
  31. package/dist/i18n/hooks/useLocaleSync.d.ts +4 -0
  32. package/dist/i18n/index.d.ts +3 -0
  33. package/dist/i18n/utils/detector.d.ts +26 -0
  34. package/dist/i18n/utils/formatter.d.ts +38 -0
  35. package/dist/i18n/utils/index.d.ts +3 -0
  36. package/dist/i18n/utils/sync.d.ts +27 -0
  37. package/dist/index.d.ts +41 -0
  38. package/dist/locales/en-US/index.d.ts +2 -0
  39. package/dist/locales/index.d.ts +10 -0
  40. package/dist/locales/zh-CN/index.d.ts +2 -0
  41. package/dist/nprogress-CwfUlis6.js +159 -0
  42. package/dist/nprogress-CwfUlis6.js.map +1 -0
  43. package/dist/preferences/components/PreferencesPanel/AppearancePanel.d.ts +3 -0
  44. package/dist/preferences/components/PreferencesPanel/GeneralPanel.d.ts +3 -0
  45. package/dist/preferences/components/PreferencesPanel/LayoutPanel.d.ts +3 -0
  46. package/dist/preferences/components/PreferencesPanel/ShortcutKeyPanel.d.ts +3 -0
  47. package/dist/preferences/components/PreferencesPanel/index.d.ts +8 -0
  48. package/dist/preferences/components/ThemeProvider/index.d.ts +9 -0
  49. package/dist/preferences/components/index.d.ts +2 -0
  50. package/dist/preferences/config/constants.d.ts +24 -0
  51. package/dist/preferences/config/darkTheme.d.ts +32 -0
  52. package/dist/preferences/config/default.d.ts +3 -0
  53. package/dist/preferences/config/index.d.ts +4 -0
  54. package/dist/preferences/config/lightTheme.d.ts +33 -0
  55. package/dist/preferences/hooks/index.d.ts +3 -0
  56. package/dist/preferences/hooks/useLocale.d.ts +23 -0
  57. package/dist/preferences/hooks/usePreferences.d.ts +31 -0
  58. package/dist/preferences/hooks/useThemeConfig.d.ts +2 -0
  59. package/dist/preferences/index.d.ts +5 -0
  60. package/dist/preferences/store/index.d.ts +24 -0
  61. package/dist/preferences/theme-transition.d.ts +17 -0
  62. package/dist/preferences/types/app.d.ts +238 -0
  63. package/dist/preferences/types/index.d.ts +4 -0
  64. package/dist/preferences/types/layout.d.ts +78 -0
  65. package/dist/preferences/types/preferences-root.d.ts +48 -0
  66. package/dist/preferences/types/theme.d.ts +29 -0
  67. package/dist/preferences/utils/diff.d.ts +7 -0
  68. package/dist/preferences/utils/merge.d.ts +9 -0
  69. package/dist/query-client.d.ts +9 -0
  70. package/dist/rolldown-runtime-BbCBk-LD.js +19 -0
  71. package/dist/router/factory.d.ts +7 -0
  72. package/dist/router/generators/generate-menus.d.ts +13 -0
  73. package/dist/router/generators/generate-routes-backend.d.ts +12 -0
  74. package/dist/router/generators/generate-routes-frontend.d.ts +17 -0
  75. package/dist/router/generators/index.d.ts +3 -0
  76. package/dist/router/index.d.ts +5 -0
  77. package/dist/router/routes-context.d.ts +8 -0
  78. package/dist/router/types/index.d.ts +207 -0
  79. package/dist/router/utils/index.d.ts +8 -0
  80. package/dist/router/utils/inject-redirect.d.ts +6 -0
  81. package/dist/router/utils/lazy.d.ts +11 -0
  82. package/dist/router/utils/loader.d.ts +14 -0
  83. package/dist/router/utils/menu.d.ts +5 -0
  84. package/dist/router/utils/merge-route-modules.d.ts +23 -0
  85. package/dist/router/utils/reset-routes.d.ts +18 -0
  86. package/dist/router/utils/sort-routes.d.ts +5 -0
  87. package/dist/router/utils/transform-meta-to-handle.d.ts +11 -0
  88. package/dist/storage/index.d.ts +2 -0
  89. package/dist/storage/storage.class.d.ts +125 -0
  90. package/dist/storage/storage.types.d.ts +199 -0
  91. package/dist/stores/auth.d.ts +56 -0
  92. package/dist/stores/index.d.ts +2 -0
  93. package/dist/stores/user.d.ts +32 -0
  94. package/dist/transport/rest/captcha-headers.d.ts +2 -0
  95. package/dist/transport/rest/index.d.ts +8 -0
  96. package/dist/transport/rest/modules/downloader.d.ts +9 -0
  97. package/dist/transport/rest/modules/interceptor.d.ts +9 -0
  98. package/dist/transport/rest/modules/uploader.d.ts +10 -0
  99. package/dist/transport/rest/pagination.d.ts +73 -0
  100. package/dist/transport/rest/preset-interceptors.d.ts +25 -0
  101. package/dist/transport/rest/request-api.d.ts +6 -0
  102. package/dist/transport/rest/request-client.d.ts +87 -0
  103. package/dist/transport/rest/types.d.ts +38 -0
  104. package/dist/transport/rest/utils.d.ts +16 -0
  105. package/dist/transport/sse/event.d.ts +44 -0
  106. package/dist/transport/sse/index.d.ts +5 -0
  107. package/dist/transport/sse/sse_client.d.ts +76 -0
  108. package/dist/transport/sse/types.d.ts +27 -0
  109. package/dist/types.d.ts +44 -0
  110. package/dist/utils/color.d.ts +27 -0
  111. package/dist/utils/date.d.ts +5 -0
  112. package/dist/utils/diff.d.ts +6 -0
  113. package/dist/utils/index.d.ts +9 -0
  114. package/dist/utils/inference.d.ts +111 -0
  115. package/dist/utils/merge.d.ts +17 -0
  116. package/dist/utils/nprogress.d.ts +11 -0
  117. package/dist/utils/tree.d.ts +27 -0
  118. package/dist/utils/url.d.ts +11 -0
  119. package/dist/utils/utils.d.ts +37 -0
  120. package/package.json +77 -3
@@ -0,0 +1,207 @@
1
+ import type { RouteObject } from "react-router-dom";
2
+ import React, { type ComponentType } from "react";
3
+ import type { ReactNode } from "react";
4
+ export type IconName = string;
5
+ export type IconType = IconName | ComponentType<{
6
+ className?: string;
7
+ style?: React.CSSProperties;
8
+ }>;
9
+ export type BadgeVariant = 'default' | 'primary' | 'success' | 'warning' | 'destructive' | string;
10
+ export type BadgeType = 'dot' | 'normal';
11
+ export type { AccessModeType } from '../../preferences/types/layout';
12
+ /**
13
+ * 后端返回的路由对象(组件路径为字符串)
14
+ */
15
+ export interface BackendRoute extends Omit<AppRouteObject, 'element' | 'children'> {
16
+ component?: string;
17
+ children?: BackendRoute[];
18
+ }
19
+ /**
20
+ * generateRoutesByBackend 的选项。只声明后端生成器实际消费的字段——
21
+ * 此前这里的 staticRoutes/mode 等字段从未被消费,形成"传了也没用"的误导性签名。
22
+ */
23
+ export interface GenerateRoutesOptions {
24
+ /** 从后端拉取菜单路由树(component 为字符串路径) */
25
+ fetchMenuListAsync?: () => Promise<BackendRoute[]>;
26
+ /** 布局组件映射(component 字符串 → React 组件) */
27
+ layoutMap?: ComponentRecord;
28
+ /** 页面组件映射(view 路径 → React 组件) */
29
+ pageMap?: ComponentRecord;
30
+ }
31
+ export interface GenerateRoutesResult {
32
+ routes: AppRouteObject[];
33
+ menus: AppMenu[];
34
+ }
35
+ export interface RouteMeta {
36
+ title?: string;
37
+ icon?: IconType;
38
+ activeIcon?: IconType;
39
+ authority?: string[];
40
+ ignoreAccess?: boolean;
41
+ hideInMenu?: boolean;
42
+ hideInTab?: boolean;
43
+ hideInBreadcrumb?: boolean;
44
+ hideChildrenInMenu?: boolean;
45
+ menuVisibleWithForbidden?: boolean;
46
+ activePath?: string;
47
+ affixTab?: boolean;
48
+ affixTabOrder?: number;
49
+ keepAlive?: boolean;
50
+ loaded?: boolean;
51
+ link?: string;
52
+ iframeSrc?: string;
53
+ openInNewWindow?: boolean;
54
+ order?: number;
55
+ query?: Record<string, any>;
56
+ maxNumOfOpenTab?: number;
57
+ badge?: string;
58
+ badgeType?: 'dot' | 'normal';
59
+ badgeVariants?: BadgeVariant;
60
+ [key: string]: any;
61
+ }
62
+ export interface AppRoute extends Omit<RouteObject, 'meta' | 'children' | 'element'> {
63
+ name: string;
64
+ path: string;
65
+ redirect?: string;
66
+ index?: boolean;
67
+ meta?: RouteMeta;
68
+ children?: AppRoute[];
69
+ element?: ReactNode;
70
+ componentPath?: string;
71
+ parent?: string;
72
+ parents?: string[];
73
+ }
74
+ /**
75
+ * AppRouteObject = RouteObject + meta + 业务字段
76
+ * 用于替代原生的 RouteObject,携带业务元数据
77
+ */
78
+ export interface AppRouteObject extends Omit<RouteObject, 'children'> {
79
+ name?: string;
80
+ path?: string;
81
+ meta?: RouteMeta;
82
+ redirect?: string;
83
+ icon?: IconType;
84
+ activeIcon?: IconType;
85
+ disabled?: boolean;
86
+ show?: boolean;
87
+ order?: number;
88
+ children?: AppRouteObject[];
89
+ parent?: string;
90
+ parents?: string[];
91
+ componentPath?: string;
92
+ element?: ReactNode;
93
+ }
94
+ export interface AppMenuBadge {
95
+ badge?: string;
96
+ badgeType?: BadgeType;
97
+ badgeVariants?: BadgeVariant;
98
+ }
99
+ export interface AppMenu extends AppMenuBadge {
100
+ name: string;
101
+ path: string;
102
+ label: string;
103
+ icon?: IconType;
104
+ activeIcon?: IconType;
105
+ order?: number;
106
+ badge?: string;
107
+ badgeType?: 'dot' | 'normal';
108
+ badgeVariants?: BadgeVariant;
109
+ disabled?: boolean;
110
+ show?: boolean;
111
+ parent?: string;
112
+ parents?: string[];
113
+ children?: AppMenu[];
114
+ authority?: string[];
115
+ menuVisibleWithForbidden?: boolean;
116
+ meta?: RouteMeta;
117
+ [key: string]: any;
118
+ }
119
+ export type ComponentRecordType = Record<string, ComponentType<any>>;
120
+ export type ComponentRecord = Record<string, ComponentType<any>>;
121
+ export interface GenerateMenuAndRoutesOptions {
122
+ fetchMenuListAsync?: () => Promise<BackendRoute[]>;
123
+ forbiddenElement?: React.ReactNode;
124
+ layoutMap?: ComponentRecordType;
125
+ pageMap?: ComponentRecordType;
126
+ permissions?: string[];
127
+ roles?: string[];
128
+ routes: AppRouteObject[];
129
+ autoInjectRedirect?: boolean;
130
+ autoSort?: boolean;
131
+ /** 登录落地兜底路径(宿主注入,如 ROUTES.DEFAULT_HOME);后端模式下无可见菜单时使用 */
132
+ defaultHomePath?: string;
133
+ }
134
+ /**
135
+ * 路由模块的默认导出类型
136
+ * 每个动态导入的路由文件应默认导出 AppRouteObject[]
137
+ */
138
+ export interface RouteModuleType {
139
+ default: AppRouteObject[];
140
+ }
141
+ /**
142
+ * Vite glob 导入的动态模块类型
143
+ * 兼容 .tsx/.ts 文件 + 默认导出
144
+ */
145
+ export type RouteModuleRecord = Record<string, RouteModuleType | AppRouteObject[] | (() => Promise<RouteModuleType>)>;
146
+ export declare const isAppRoute: (route: any) => route is AppRouteObject;
147
+ export interface MenuRecordBadgeRaw {
148
+ /**
149
+ * 徽标
150
+ */
151
+ badge?: string;
152
+ /**
153
+ * 徽标类型
154
+ */
155
+ badgeType?: "dot" | "normal";
156
+ /**
157
+ * 徽标颜色
158
+ */
159
+ badgeVariants?: "destructive" | "primary" | string;
160
+ }
161
+ /**
162
+ * 菜单原始对象
163
+ */
164
+ export interface MenuRecordRaw extends MenuRecordBadgeRaw {
165
+ /**
166
+ * 激活时的图标名
167
+ */
168
+ activeIcon?: string;
169
+ /**
170
+ * 子菜单
171
+ */
172
+ children?: MenuRecordRaw[];
173
+ /**
174
+ * 是否禁用菜单
175
+ * @default false
176
+ */
177
+ disabled?: boolean;
178
+ /**
179
+ * 图标名
180
+ */
181
+ icon?: IconType;
182
+ /**
183
+ * 菜单名
184
+ */
185
+ name: string;
186
+ /**
187
+ * 排序号
188
+ */
189
+ order?: number;
190
+ /**
191
+ * 父级路径
192
+ */
193
+ parent?: string;
194
+ /**
195
+ * 所有父级路径
196
+ */
197
+ parents?: string[];
198
+ /**
199
+ * 菜单路径,唯一,可当作key
200
+ */
201
+ path: string;
202
+ /**
203
+ * 是否显示菜单
204
+ * @default true
205
+ */
206
+ show?: boolean;
207
+ }
@@ -0,0 +1,8 @@
1
+ export * from './inject-redirect';
2
+ export * from './lazy';
3
+ export * from './loader';
4
+ export * from './menu';
5
+ export * from './merge-route-modules';
6
+ export * from './reset-routes';
7
+ export * from './sort-routes';
8
+ export * from './transform-meta-to-handle';
@@ -0,0 +1,6 @@
1
+ import type { AppRoute } from "../../router/types";
2
+ /**
3
+ * 自动注入重定向
4
+ * 规则:父路由有子路由且未配置 redirect 时,指向第一个子路由
5
+ */
6
+ export declare const injectRedirects: (routes: AppRoute[]) => AppRoute[];
@@ -0,0 +1,11 @@
1
+ import { type ComponentType } from 'react';
2
+ /**
3
+ * 创建懒加载路由元素
4
+ * 自动包裹 Suspense + Spin fallback
5
+ *
6
+ * @param loader Vite 动态导入函数,如 () => import('@/pages/dashboard')
7
+ * @returns 可直接赋值给 route.element 的 ReactNode
8
+ */
9
+ export declare const createLazyRoute: (loader: () => Promise<{
10
+ default: ComponentType<any>;
11
+ }>) => import("react").JSX.Element;
@@ -0,0 +1,14 @@
1
+ import type { AppRouteObject } from '../types';
2
+ /**
3
+ * 展平模块导出(兼容 default / 具名导出)
4
+ * 纯函数,无副作用,可单元测试
5
+ */
6
+ export declare const extractRoutes: (module: any) => AppRouteObject[];
7
+ /**
8
+ * 过滤无效路由(开发环境调试用)
9
+ */
10
+ export declare const filterValidRoutes: (routes: AppRouteObject[]) => AppRouteObject[];
11
+ /**
12
+ * 根据权限过滤路由树
13
+ */
14
+ export declare const filterRoutesByPermission: (routes: AppRouteObject[], permissions: string[]) => AppRouteObject[];
@@ -0,0 +1,5 @@
1
+ import type { ProLayoutProps } from '@ant-design/pro-components';
2
+ import type { AppRouteObject } from '../../router/types';
3
+ type MenuRoute = AppRouteObject;
4
+ export declare const transformRoutesToMenu: (routes: MenuRoute[], permissions: string[], parentPath?: string) => NonNullable<ProLayoutProps["route"]>["routes"];
5
+ export {};
@@ -0,0 +1,23 @@
1
+ import type { AppRouteObject, RouteModuleRecord, RouteModuleType } from "../../router";
2
+ /**
3
+ * 合并动态路由模块的默认导出
4
+ *
5
+ * @param routeModules - Vite import.meta.glob 返回的模块对象
6
+ * @param options - 可选配置
7
+ * @returns 合并后的路由配置数组(AppRouteObject[])
8
+ *
9
+ * @example
10
+ *
11
+ */
12
+ export declare function mergeRouteModules(routeModules: RouteModuleRecord, options?: {
13
+ /** 是否过滤空模块 */
14
+ filterEmpty?: boolean;
15
+ /** 是否按路径排序 */
16
+ sortByPath?: boolean;
17
+ }): AppRouteObject[];
18
+ /**
19
+ * 异步合并动态路由模块(用于 lazy 加载)
20
+ * @param routeModules - Vite import.meta.glob 返回的异步模块对象
21
+ * @returns Promise<AppRouteObject[]>
22
+ */
23
+ export declare function mergeRouteModulesAsync(routeModules: Record<string, () => Promise<RouteModuleType | AppRouteObject[]>>): Promise<AppRouteObject[]>;
@@ -0,0 +1,18 @@
1
+ import type { AppRouteObject } from "../../router/types";
2
+ /**
3
+ * 重置可访问路由(保留白名单)
4
+ *
5
+ * ⚠️ React Router v6+ 不支持运行时修改路由,
6
+ * 此函数返回过滤后的路由树,需配合 createBrowserRouter 重新创建 router
7
+ *
8
+ * @param allRoutes - 当前完整路由树(含动态路由)
9
+ * @param staticRouteNames - 静态路由白名单(保留这些路由)
10
+ * @returns 过滤后的路由树(仅含白名单路由)
11
+ */
12
+ export declare function resetAccessibleRoutes(allRoutes: AppRouteObject[], staticRouteNames: string[]): AppRouteObject[];
13
+ /**
14
+ * 提取路由树中所有有效的 name(用于生成白名单)
15
+ * @param routes - 路由树
16
+ * @returns 有效的路由 name 数组
17
+ */
18
+ export declare function extractRouteNames(routes: AppRouteObject[]): string[];
@@ -0,0 +1,5 @@
1
+ import type { AppRoute } from "../../router/types";
2
+ /**
3
+ * 递归排序路由树(按 meta.order 升序)
4
+ */
5
+ export declare const sortRoutes: (routes: AppRoute[]) => AppRoute[];
@@ -0,0 +1,11 @@
1
+ import type { AppRouteObject, RouteMeta } from '../types';
2
+ import type { RouteHandle } from '../../types';
3
+ /**
4
+ * 将 meta 转换为 React Router 的 handle
5
+ * 这样 useMatches() 就能获取到路由元数据
6
+ */
7
+ export declare function transformMetaToHandle(meta?: RouteMeta): RouteHandle | undefined;
8
+ /**
9
+ * 递归转换路由配置,将 meta 映射到 handle
10
+ */
11
+ export declare function transformRoutesWithHandle(routes: AppRouteObject[]): AppRouteObject[];
@@ -0,0 +1,2 @@
1
+ export { StorageManager } from "./storage.class";
2
+ export * from "./storage.types";
@@ -0,0 +1,125 @@
1
+ import type { BatchGetOptions, BatchProgressCallback, BatchResult, BatchSetItem, IStorageCache, StorageManagerOptions, StorageMetrics, SyncMessage } from "./storage.types";
2
+ declare class StorageManager implements IStorageCache {
3
+ private readonly prefix;
4
+ private readonly storage;
5
+ private readonly options;
6
+ private readonly defaultTTL?;
7
+ private readonly tabId;
8
+ private channel;
9
+ private metrics;
10
+ private metricsDebounceTimer;
11
+ private readonly onMetricsCallback?;
12
+ private onSyncCallback?;
13
+ constructor(options?: StorageManagerOptions);
14
+ /**
15
+ * 获取完整存储键(安全添加前缀)
16
+ */
17
+ private getFullKey;
18
+ private getMetaKey;
19
+ private readMeta;
20
+ private writeMeta;
21
+ /**
22
+ * 访问时更新元数据(访问次数和最后访问时间)
23
+ */
24
+ private updateMetaOnAccess;
25
+ /**
26
+ * 设置时更新元数据
27
+ */
28
+ private updateMetaOnSet;
29
+ /**
30
+ * 移除元数据
31
+ */
32
+ private removeMeta;
33
+ private getAllMeta;
34
+ /**
35
+ * 安全解析存储值
36
+ */
37
+ private parseValue;
38
+ /**
39
+ * 序列化存储值
40
+ */
41
+ private serializeValue;
42
+ /**
43
+ * 获取存储项
44
+ */
45
+ getItem<T>(key: string, defaultValue?: T | null): T | null;
46
+ /**
47
+ * 设置存储项
48
+ */
49
+ setItem<T>(key: string, value: T, ttl?: number | null): void;
50
+ /**
51
+ * 移除存储项
52
+ */
53
+ removeItem(key: string): void;
54
+ /**
55
+ * 检查键是否存在且未过期
56
+ */
57
+ hasItem(key: string): boolean;
58
+ /**
59
+ * 清除所有带前缀的项(使用倒序遍历避免索引错位)
60
+ */
61
+ clear(): void;
62
+ /**
63
+ * 清除所有过期项
64
+ */
65
+ clearExpiredItems(): void;
66
+ /**
67
+ * 获取存储键(带前缀过滤)
68
+ */
69
+ key(index: number): string | null;
70
+ /**
71
+ * 获取有效存储项数量(带前缀过滤)
72
+ */
73
+ length(): number;
74
+ /**
75
+ * 获取底层 Storage 实例(用于高级操作)
76
+ */
77
+ getRawStorage(): Storage | null;
78
+ /**
79
+ * 批量获取存储项
80
+ * @param keys 要获取的键数组
81
+ * @param options 获取选项
82
+ * @param onProgress 进度回调(每处理完一个项触发)
83
+ * @returns Promise<Record<string, T | null>> 键值映射
84
+ */
85
+ getItems<T>(keys: string[], options?: BatchGetOptions, onProgress?: BatchProgressCallback): Promise<Record<string, T | null>>;
86
+ /**
87
+ * 批量设置存储项
88
+ * @param items 键值对映射,值可以是普通值或 BatchSetItem 配置
89
+ * @param onProgress 进度回调
90
+ * @returns Promise<BatchResult<T>> 操作结果统计
91
+ */
92
+ setItems<T>(items: Record<string, T | BatchSetItem<T>>, onProgress?: BatchProgressCallback): Promise<BatchResult<T>>;
93
+ /**
94
+ * 批量移除存储项
95
+ * @param keys 要移除的键数组
96
+ * @returns Promise<{ removed: string[]; failed: Record<string, Error> }>
97
+ */
98
+ removeItems(keys: string[]): Promise<{
99
+ removed: string[];
100
+ failed: Record<string, Error>;
101
+ }>;
102
+ /**
103
+ * 批量检查键是否存在(且未过期)
104
+ * @param keys 要检查的键数组
105
+ * @returns Promise<Record<string, boolean>>
106
+ */
107
+ hasItems(keys: string[]): Promise<Record<string, boolean>>;
108
+ /**
109
+ * 内部方法:标准化批量设置的值配置
110
+ */
111
+ private _normalizeBatchValue;
112
+ private checkAndEvict;
113
+ private sortByEvictionPriority;
114
+ private initSync;
115
+ private handleSyncMessage;
116
+ private broadcast;
117
+ onSync(callback: (event: SyncMessage) => void): () => void;
118
+ private trackMetric;
119
+ private updateHitRate;
120
+ private debounceReportMetrics;
121
+ private updateQuotaUsage;
122
+ getMetrics(): StorageMetrics;
123
+ resetMetrics(): void;
124
+ }
125
+ export { StorageManager };
@@ -0,0 +1,199 @@
1
+ /**
2
+ * 存储类型
3
+ */
4
+ export type StorageType = "localStorage" | "sessionStorage";
5
+ /**
6
+ * 缓存驱逐策略
7
+ * - lru: 最近最少使用 (Least Recently Used)
8
+ * - lfu: 最不经常使用 (Least Frequently Used)
9
+ * - hybrid: 混合策略(结合 LRU 和 LFU)
10
+ */
11
+ export type EvictionStrategy = "lru" | "lfu" | "hybrid";
12
+ /**
13
+ * 存储元数据
14
+ * @description 用于跟踪每个存储项的状态信息,支持智能缓存管理
15
+ */
16
+ export interface StorageMeta {
17
+ /** 过期时间戳 (null=永久有效) */
18
+ e: number | null;
19
+ /** 原始数据大小 (bytes) */
20
+ s: number;
21
+ /** 访问次数 (用于 LFU 策略) */
22
+ a: number;
23
+ /** 最后访问时间戳 (用于 LRU 策略) */
24
+ t: number;
25
+ /** 是否已压缩 */
26
+ c: boolean;
27
+ }
28
+ /**
29
+ * 存储性能指标
30
+ * @description 用于监控存储使用情况和分析性能瓶颈
31
+ */
32
+ export interface StorageMetrics {
33
+ /** 命中次数 */
34
+ hits: number;
35
+ /** 未命中次数 */
36
+ misses: number;
37
+ /** 过期清理次数 */
38
+ expirations: number;
39
+ /** 设置操作次数 */
40
+ sets: number;
41
+ /** 错误次数 */
42
+ errors: number;
43
+ /** 配额使用量 (bytes) */
44
+ quotaUsageBytes: number;
45
+ /** 命中率 (0-1) */
46
+ hitRate: number;
47
+ }
48
+ /**
49
+ * 多标签页同步消息
50
+ * @description 用于在不同标签页之间同步存储状态
51
+ */
52
+ export interface SyncMessage {
53
+ /** 操作类型 */
54
+ type: "set" | "remove" | "clear";
55
+ /** 存储键名 */
56
+ key: string;
57
+ /** 标签页 ID */
58
+ tabId: string;
59
+ /** 时间戳 */
60
+ ts: number;
61
+ }
62
+ /**
63
+ * 存储管理器配置选项
64
+ * @description 用于初始化 StorageManager 实例时的配置参数
65
+ */
66
+ export interface StorageManagerOptions {
67
+ /** 存储键名前缀,用于隔离不同模块的数据 */
68
+ prefix?: string;
69
+ /** 存储类型:localStorage 或 sessionStorage */
70
+ storageType?: StorageType;
71
+ /** 触发压缩的阈值 (bytes),默认 1024 */
72
+ compressionThreshold?: number;
73
+ /** 缓存驱逐策略,默认 "hybrid" */
74
+ evictionStrategy?: EvictionStrategy;
75
+ /** 最大存储项数 (0=不限),默认 0 */
76
+ maxItems?: number;
77
+ /** 最大使用量 (MB),默认 10 */
78
+ maxUsageMB?: number;
79
+ /** 默认过期时间 (ms),null 表示永不过期 */
80
+ defaultTTL?: number | null;
81
+ /** 是否开启多标签页同步,默认 true */
82
+ enableSync?: boolean;
83
+ /** 指标变化回调函数 */
84
+ onMetrics?: (metrics: StorageMetrics) => void;
85
+ /** 同步事件回调函数 */
86
+ onSync?: (event: SyncMessage) => void;
87
+ }
88
+ /**
89
+ * 存储项结构(旧版,保留用于兼容)
90
+ * @deprecated 请使用 StorageValue 替代
91
+ */
92
+ export interface StorageItem<T> {
93
+ /** 过期时间戳 */
94
+ expiry?: number;
95
+ /** 存储的值 */
96
+ value: T;
97
+ }
98
+ /**
99
+ * 存储值结构
100
+ * @description 封装数据和过期信息的标准格式
101
+ */
102
+ export interface StorageValue<T> {
103
+ /** 存储的实际数据 */
104
+ data: T;
105
+ /** 过期时间戳 (null=永不过期) */
106
+ expiry: number | null;
107
+ }
108
+ /**
109
+ * 批量设置项的配置
110
+ * @description 用于在批量设置时为每个项指定独立的 TTL
111
+ */
112
+ export interface BatchSetItem<T> {
113
+ /** 要存储的值 */
114
+ value: T;
115
+ /** 过期时间 (ms),覆盖默认 TTL */
116
+ ttl?: number | null;
117
+ }
118
+ /**
119
+ * 批量获取的选项
120
+ * @description 控制批量获取操作的行为
121
+ */
122
+ export interface BatchGetOptions {
123
+ /** 是否跳过过期项(默认 true,自动清理过期数据) */
124
+ skipExpired?: boolean;
125
+ /** 是否返回原始解析结果(用于调试,默认 false) */
126
+ includeRaw?: boolean;
127
+ }
128
+ /**
129
+ * 批量操作结果
130
+ * @description 包含批量操作的执行结果统计
131
+ */
132
+ export interface BatchResult<T> {
133
+ /** 成功设置的项 */
134
+ success: Record<string, T>;
135
+ /** 失败的项及对应的错误信息 */
136
+ failed: Record<string, Error>;
137
+ /** 因过期被清理的键列表 */
138
+ expired: string[];
139
+ }
140
+ /**
141
+ * 批量操作进度回调
142
+ * @description 用于实时监控批量操作的执行进度
143
+ */
144
+ export type BatchProgressCallback = (progress: {
145
+ /** 当前已处理的项目数 */
146
+ current: number;
147
+ /** 总项目数 */
148
+ total: number;
149
+ /** 当前处理的键名 */
150
+ key: string;
151
+ /** 处理状态 */
152
+ status: "success" | "failed" | "expired";
153
+ }) => void;
154
+ /**
155
+ * 存储缓存接口
156
+ * @description 定义存储管理器的基本操作契约
157
+ */
158
+ export interface IStorageCache {
159
+ /** 清除所有存储项 */
160
+ clear(): void;
161
+ /** 清除所有过期项 */
162
+ clearExpiredItems(): void;
163
+ /**
164
+ * 获取指定索引的键名
165
+ * @param index - 索引位置
166
+ * @returns 键名或 null
167
+ */
168
+ key(index: number): string | null;
169
+ /**
170
+ * 获取存储项数量
171
+ * @returns 存储项总数
172
+ */
173
+ length(): number;
174
+ /**
175
+ * 移除指定键的存储项
176
+ * @param key - 存储键名
177
+ */
178
+ removeItem(key: string): void;
179
+ /**
180
+ * 设置存储项
181
+ * @param key - 存储键名
182
+ * @param value - 要存储的值
183
+ * @param ttl - 过期时间 (ms),可选
184
+ */
185
+ setItem<T>(key: string, value: T, ttl?: number | null): void;
186
+ /**
187
+ * 获取存储项
188
+ * @param key - 存储键名
189
+ * @param defaultValue - 默认值,当键不存在时返回
190
+ * @returns 存储的值或默认值
191
+ */
192
+ getItem<T>(key: string, defaultValue?: T | null): T | null;
193
+ /**
194
+ * 检查键是否存在且未过期
195
+ * @param key - 存储键名
196
+ * @returns 是否存在
197
+ */
198
+ hasItem(key: string): boolean;
199
+ }