@pisell/core 1.0.14 → 1.0.15
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/es/app/app.d.ts +87 -0
- package/es/app/const.d.ts +4 -0
- package/es/app/index.d.ts +14 -0
- package/es/applicationManager/application.d.ts +50 -0
- package/es/applicationManager/index.d.ts +13 -0
- package/es/aws/index.d.ts +16 -0
- package/es/cmd/const.d.ts +11 -0
- package/es/cmd/index.d.ts +13 -0
- package/es/cmd/type.d.ts +5 -0
- package/es/config.d.ts +3 -0
- package/es/cookie/index.d.ts +13 -0
- package/es/data/index.d.ts +8 -0
- package/es/history/config.d.ts +24 -0
- package/es/history/index.d.ts +20 -0
- package/es/history/type.d.ts +2 -0
- package/es/hooks/index.d.ts +12 -0
- package/es/hooks/useDelayedValue/index.d.ts +2 -0
- package/es/hooks/useDispatch/index.d.ts +2 -0
- package/es/hooks/useLowCode/index.d.ts +13 -0
- package/es/hooks/useStore/index.d.ts +6 -0
- package/es/index.d.ts +6 -0
- package/es/indexDB/index.d.ts +248 -0
- package/es/indexDB/index.js +453 -70
- package/es/locales/en.d.ts +3 -0
- package/es/locales/index.d.ts +39 -0
- package/es/locales/original.d.ts +3 -0
- package/es/locales/type.d.ts +19 -0
- package/es/locales/zh-CN.d.ts +3 -0
- package/es/locales/zh-HK.d.ts +3 -0
- package/es/logger/feishu.d.ts +11 -0
- package/es/logger/index.d.ts +134 -0
- package/es/menuManager/hooks.d.ts +17 -0
- package/es/menuManager/index.d.ts +28 -0
- package/es/models/global.d.ts +32 -0
- package/es/models/index.d.ts +45 -0
- package/es/models/type.d.ts +2 -0
- package/es/plugin/index.d.ts +0 -0
- package/es/pubsub/example.d.ts +5 -0
- package/es/pubsub/index.d.ts +63 -0
- package/es/request/cache.d.ts +46 -0
- package/es/request/cancelToken.d.ts +38 -0
- package/es/request/config.d.ts +3 -0
- package/es/request/constants.d.ts +2 -0
- package/es/request/index.d.ts +24 -0
- package/es/request/pisell2Request.d.ts +6 -0
- package/es/request/type.d.ts +41 -0
- package/es/request/utils.d.ts +46 -0
- package/es/routes/config.d.ts +7 -0
- package/es/routes/index.d.ts +28 -0
- package/es/socket/components/SocketMonitorPage.d.ts +6 -0
- package/es/socket/components/index.d.ts +2 -0
- package/es/socket/constants.d.ts +33 -0
- package/es/socket/events.d.ts +31 -0
- package/es/socket/heartbeat.d.ts +66 -0
- package/es/socket/index.d.ts +61 -0
- package/es/socket/monitor.d.ts +169 -0
- package/es/socket/reconnect.d.ts +61 -0
- package/es/socket/socket.d.ts +130 -0
- package/es/socket/types.d.ts +84 -0
- package/es/storage/index.d.ts +17 -0
- package/es/tasks/index.d.ts +83 -0
- package/es/tasks/type.d.ts +62 -0
- package/es/tasks/useTasks.d.ts +5 -0
- package/es/type.d.ts +2 -0
- package/es/variables/VariablesProvider.d.ts +7 -0
- package/es/variables/config.d.ts +3 -0
- package/es/variables/index.d.ts +6 -0
- package/es/variables/type.d.ts +2 -0
- package/es/website/index.d.ts +6 -0
- package/lib/app/app.d.ts +87 -0
- package/lib/app/const.d.ts +4 -0
- package/lib/app/index.d.ts +14 -0
- package/lib/applicationManager/application.d.ts +50 -0
- package/lib/applicationManager/index.d.ts +13 -0
- package/lib/aws/index.d.ts +16 -0
- package/lib/cmd/const.d.ts +11 -0
- package/lib/cmd/index.d.ts +13 -0
- package/lib/cmd/type.d.ts +5 -0
- package/lib/config.d.ts +3 -0
- package/lib/cookie/index.d.ts +13 -0
- package/lib/data/index.d.ts +8 -0
- package/lib/history/config.d.ts +24 -0
- package/lib/history/index.d.ts +20 -0
- package/lib/history/type.d.ts +2 -0
- package/lib/hooks/index.d.ts +12 -0
- package/lib/hooks/useDelayedValue/index.d.ts +2 -0
- package/lib/hooks/useDispatch/index.d.ts +2 -0
- package/lib/hooks/useLowCode/index.d.ts +13 -0
- package/lib/hooks/useStore/index.d.ts +6 -0
- package/lib/index.d.ts +6 -0
- package/lib/indexDB/index.d.ts +248 -0
- package/lib/indexDB/index.js +159 -0
- package/lib/locales/en.d.ts +3 -0
- package/lib/locales/index.d.ts +39 -0
- package/lib/locales/original.d.ts +3 -0
- package/lib/locales/type.d.ts +19 -0
- package/lib/locales/zh-CN.d.ts +3 -0
- package/lib/locales/zh-HK.d.ts +3 -0
- package/lib/logger/feishu.d.ts +11 -0
- package/lib/logger/index.d.ts +134 -0
- package/lib/menuManager/hooks.d.ts +17 -0
- package/lib/menuManager/index.d.ts +28 -0
- package/lib/models/global.d.ts +32 -0
- package/lib/models/index.d.ts +45 -0
- package/lib/models/type.d.ts +2 -0
- package/lib/plugin/index.d.ts +0 -0
- package/lib/pubsub/example.d.ts +5 -0
- package/lib/pubsub/index.d.ts +63 -0
- package/lib/request/cache.d.ts +46 -0
- package/lib/request/cancelToken.d.ts +38 -0
- package/lib/request/config.d.ts +3 -0
- package/lib/request/constants.d.ts +2 -0
- package/lib/request/index.d.ts +24 -0
- package/lib/request/pisell2Request.d.ts +6 -0
- package/lib/request/type.d.ts +41 -0
- package/lib/request/utils.d.ts +46 -0
- package/lib/routes/config.d.ts +7 -0
- package/lib/routes/index.d.ts +28 -0
- package/lib/socket/components/SocketMonitorPage.d.ts +6 -0
- package/lib/socket/components/index.d.ts +2 -0
- package/lib/socket/constants.d.ts +33 -0
- package/lib/socket/events.d.ts +31 -0
- package/lib/socket/heartbeat.d.ts +66 -0
- package/lib/socket/index.d.ts +61 -0
- package/lib/socket/monitor.d.ts +169 -0
- package/lib/socket/reconnect.d.ts +61 -0
- package/lib/socket/socket.d.ts +130 -0
- package/lib/socket/types.d.ts +84 -0
- package/lib/storage/index.d.ts +17 -0
- package/lib/tasks/index.d.ts +83 -0
- package/lib/tasks/type.d.ts +62 -0
- package/lib/tasks/useTasks.d.ts +5 -0
- package/lib/type.d.ts +2 -0
- package/lib/variables/VariablesProvider.d.ts +7 -0
- package/lib/variables/config.d.ts +3 -0
- package/lib/variables/index.d.ts +6 -0
- package/lib/variables/type.d.ts +2 -0
- package/lib/website/index.d.ts +6 -0
- package/package.json +7 -7
package/es/app/app.d.ts
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { RouterManager } from '../routes';
|
|
2
|
+
import { ApplicationManager } from '../applicationManager';
|
|
3
|
+
import { History, HistoryOptions } from '../history';
|
|
4
|
+
import { Data } from '../data';
|
|
5
|
+
import { Locales, LocalesOptions } from '../locales';
|
|
6
|
+
import { Storage, StorageOptions } from '../storage';
|
|
7
|
+
import { MenuManager } from '../menuManager';
|
|
8
|
+
import LoggerManager, { LoggerOptions } from '../logger';
|
|
9
|
+
import { TasksManager } from '../tasks';
|
|
10
|
+
import IndexDBManager, { DBOptions } from '../indexDB';
|
|
11
|
+
import CMD from "../cmd";
|
|
12
|
+
import AWS from "../aws";
|
|
13
|
+
declare global {
|
|
14
|
+
interface Window {
|
|
15
|
+
app: App;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
export interface AppOptions {
|
|
19
|
+
logger?: LoggerOptions;
|
|
20
|
+
db?: DBOptions;
|
|
21
|
+
constants?: any;
|
|
22
|
+
history?: HistoryOptions;
|
|
23
|
+
storage?: StorageOptions;
|
|
24
|
+
locales?: LocalesOptions;
|
|
25
|
+
}
|
|
26
|
+
declare class App {
|
|
27
|
+
private static instance;
|
|
28
|
+
private plugins;
|
|
29
|
+
globalData: any;
|
|
30
|
+
router: RouterManager;
|
|
31
|
+
applicationManager: ApplicationManager;
|
|
32
|
+
history: History;
|
|
33
|
+
data: Data;
|
|
34
|
+
hooks: import("../hooks").HooksExport;
|
|
35
|
+
locales: Locales;
|
|
36
|
+
models: {
|
|
37
|
+
getStore: () => import("../models").Store;
|
|
38
|
+
StoreProvider: typeof import("react-redux").Provider;
|
|
39
|
+
setConfig: (models: any[]) => void;
|
|
40
|
+
};
|
|
41
|
+
request: {
|
|
42
|
+
get: (url: string, data: any, config: import("../request").RequestSetting | undefined) => Promise<any>;
|
|
43
|
+
post: (url: string, data: any, config: import("../request").RequestSetting | undefined) => Promise<any>;
|
|
44
|
+
put: (url: string, data: any, config: import("../request").RequestSetting | undefined) => Promise<any>;
|
|
45
|
+
remove: (url: string, data: any, config: import("../request").RequestSetting | undefined) => Promise<any>;
|
|
46
|
+
custom: (url: string, config: import("../request").RequestSetting | undefined) => Promise<any>;
|
|
47
|
+
setConfig: (newConfig: Partial<import("../request").RequestConfig>) => void;
|
|
48
|
+
getConfig: () => import("../request").RequestConfig;
|
|
49
|
+
};
|
|
50
|
+
storage: Storage;
|
|
51
|
+
menuManager: MenuManager;
|
|
52
|
+
cookie: {
|
|
53
|
+
setCookie: (name: string, value: string, domain?: string | undefined) => void;
|
|
54
|
+
getCookie: (name: string) => string | null;
|
|
55
|
+
deleteCookie: (name: string, domain?: string | undefined) => void;
|
|
56
|
+
checkCookie: (name: string) => boolean;
|
|
57
|
+
updateCookie: (name: string, value: string, domain?: string | undefined) => void;
|
|
58
|
+
};
|
|
59
|
+
website: {
|
|
60
|
+
setTitle: (title: string) => void;
|
|
61
|
+
setIcon: (paramsIcon: string) => void;
|
|
62
|
+
setAppleWebAppTitle: (title: string) => void;
|
|
63
|
+
};
|
|
64
|
+
logger: LoggerManager;
|
|
65
|
+
pubsub: import("../pubsub").PubSub;
|
|
66
|
+
cmd: CMD;
|
|
67
|
+
aws: AWS;
|
|
68
|
+
tasksManager: TasksManager;
|
|
69
|
+
dbManager: IndexDBManager | null;
|
|
70
|
+
constants: {
|
|
71
|
+
channel: string;
|
|
72
|
+
[key: string]: string;
|
|
73
|
+
};
|
|
74
|
+
private constructor();
|
|
75
|
+
static getInstance(options?: AppOptions): App;
|
|
76
|
+
setGlobalData(globalData: any): void;
|
|
77
|
+
usePlugin(name: string, plugin: any): void;
|
|
78
|
+
usePlugins(plugins: {
|
|
79
|
+
name: string;
|
|
80
|
+
plugin: any;
|
|
81
|
+
}[]): void;
|
|
82
|
+
getPlugin(name: string): any;
|
|
83
|
+
getGlobalData(): any;
|
|
84
|
+
install(): void;
|
|
85
|
+
unInstall(): void;
|
|
86
|
+
}
|
|
87
|
+
export default App;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import App, { AppOptions } from "./app";
|
|
3
|
+
declare type AppContextType = {
|
|
4
|
+
globalData: any;
|
|
5
|
+
setGlobalData: React.Dispatch<React.SetStateAction<any>>;
|
|
6
|
+
app: App;
|
|
7
|
+
};
|
|
8
|
+
export declare const AppProvider: React.FC<{
|
|
9
|
+
children: React.ReactNode;
|
|
10
|
+
options: AppOptions;
|
|
11
|
+
}>;
|
|
12
|
+
export declare const useApp: () => AppContextType;
|
|
13
|
+
export declare const getApp: typeof App.getInstance;
|
|
14
|
+
export default App;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import App from "../app";
|
|
2
|
+
import { LoadLibraryByUrlParams } from "../locales/type";
|
|
3
|
+
import { MenuItem } from "../menuManager/index";
|
|
4
|
+
export declare type ApplicationInterface = {
|
|
5
|
+
page_type: "low_code" | "code";
|
|
6
|
+
page_id: number | string;
|
|
7
|
+
page_code: string;
|
|
8
|
+
page_version?: string;
|
|
9
|
+
page_name: string;
|
|
10
|
+
router: string;
|
|
11
|
+
category: "page" | "component" | "function";
|
|
12
|
+
Component?: any;
|
|
13
|
+
children?: any;
|
|
14
|
+
layout?: string;
|
|
15
|
+
originalUrl?: string;
|
|
16
|
+
};
|
|
17
|
+
export declare type ApplicationData = {
|
|
18
|
+
app_id: number;
|
|
19
|
+
app_name: string;
|
|
20
|
+
app_type: "system" | "custom";
|
|
21
|
+
interfaces: ApplicationInterface[];
|
|
22
|
+
functions?: any[];
|
|
23
|
+
menu?: {
|
|
24
|
+
[key: string]: MenuItem[];
|
|
25
|
+
};
|
|
26
|
+
locales?: LoadLibraryByUrlParams;
|
|
27
|
+
[key: string]: any;
|
|
28
|
+
};
|
|
29
|
+
export declare class Application {
|
|
30
|
+
options: ApplicationData;
|
|
31
|
+
name: ApplicationData["app_name"];
|
|
32
|
+
interfaces: Map<ApplicationInterface["page_name"], ApplicationInterface>;
|
|
33
|
+
components: Map<string, any>;
|
|
34
|
+
functions: Map<string, any>;
|
|
35
|
+
app: App;
|
|
36
|
+
constructor(options: ApplicationData, app: App);
|
|
37
|
+
afterAdd(application: Application): Promise<void>;
|
|
38
|
+
beforeLoad(): Promise<void>;
|
|
39
|
+
load(): Promise<void>;
|
|
40
|
+
initInterfaces(interfaces: ApplicationData["interfaces"]): void;
|
|
41
|
+
initFunctions(functions: ApplicationData["functions"]): void;
|
|
42
|
+
loadInterface(interfaceItem: ApplicationInterface): Promise<ApplicationInterface>;
|
|
43
|
+
setInterface(code: string, interfaceItem: ApplicationInterface): void;
|
|
44
|
+
setComponent(code: string, component: ApplicationInterface): void;
|
|
45
|
+
setFunction(code: string, functionItem: ApplicationInterface): void;
|
|
46
|
+
getInterface(code: string): ApplicationInterface | undefined;
|
|
47
|
+
getComponent(code: string): any;
|
|
48
|
+
getFunction(code: string): any;
|
|
49
|
+
runFunction(code: string, params?: any, ...args: any): any;
|
|
50
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import APP from "../app";
|
|
2
|
+
import { Application, ApplicationData } from "./application";
|
|
3
|
+
export declare class ApplicationManager {
|
|
4
|
+
applicationList: Application[];
|
|
5
|
+
protected app: APP;
|
|
6
|
+
applications: Map<string, Application>;
|
|
7
|
+
constructor(applicationList: Application[], app: APP);
|
|
8
|
+
init(applicationList: Application[] | ApplicationData[]): Promise<unknown>;
|
|
9
|
+
add(application: Application): Promise<void>;
|
|
10
|
+
get(appName: Application["name"]): Application | undefined;
|
|
11
|
+
remove(appName: Application["name"]): void;
|
|
12
|
+
load(): Promise<void>;
|
|
13
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { S3ClientConfig, PutObjectCommandInput } from '@aws-sdk/client-s3';
|
|
2
|
+
import App from '../app';
|
|
3
|
+
export interface AWSOptions extends S3ClientConfig {
|
|
4
|
+
s3Config: S3ClientConfig;
|
|
5
|
+
bucketName?: string;
|
|
6
|
+
}
|
|
7
|
+
export interface UploadParams extends PutObjectCommandInput {
|
|
8
|
+
}
|
|
9
|
+
declare class AWS {
|
|
10
|
+
private s3Client?;
|
|
11
|
+
private app;
|
|
12
|
+
private config?;
|
|
13
|
+
constructor(app: App, options?: AWSOptions);
|
|
14
|
+
upload(params: UploadParams): Promise<import("@aws-sdk/client-s3").PutObjectCommandOutput | undefined>;
|
|
15
|
+
}
|
|
16
|
+
export default AWS;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import App from "../app";
|
|
2
|
+
import { CMDCoreEnum } from "./const";
|
|
3
|
+
export interface CMDOptions {
|
|
4
|
+
socketUrl?: string;
|
|
5
|
+
}
|
|
6
|
+
declare class CMD {
|
|
7
|
+
private app;
|
|
8
|
+
private options?;
|
|
9
|
+
constructor(app: App, options?: CMDOptions);
|
|
10
|
+
init(): void;
|
|
11
|
+
}
|
|
12
|
+
export { CMDCoreEnum };
|
|
13
|
+
export default CMD;
|
package/es/cmd/type.d.ts
ADDED
package/es/config.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
declare function setCookie(name: string, value: string, domain?: string): void;
|
|
2
|
+
declare function getCookie(name: string): string | null;
|
|
3
|
+
declare function deleteCookie(name: string, domain?: string): void;
|
|
4
|
+
declare function checkCookie(name: string): boolean;
|
|
5
|
+
declare function updateCookie(name: string, value: string, domain?: string): void;
|
|
6
|
+
declare const _default: {
|
|
7
|
+
setCookie: typeof setCookie;
|
|
8
|
+
getCookie: typeof getCookie;
|
|
9
|
+
deleteCookie: typeof deleteCookie;
|
|
10
|
+
checkCookie: typeof checkCookie;
|
|
11
|
+
updateCookie: typeof updateCookie;
|
|
12
|
+
};
|
|
13
|
+
export default _default;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { HistoryConfig } from './type';
|
|
2
|
+
/**
|
|
3
|
+
* @title: 默认配置
|
|
4
|
+
* @description:
|
|
5
|
+
* @return {*}
|
|
6
|
+
* @Author: zhiwei.Wang
|
|
7
|
+
*/
|
|
8
|
+
export declare const defaultConfig: HistoryConfig;
|
|
9
|
+
/**
|
|
10
|
+
* @title: 设置配置
|
|
11
|
+
* @description:
|
|
12
|
+
* @param {Partial} newConfig
|
|
13
|
+
* @return {*}
|
|
14
|
+
* @Author: zhiwei.Wang
|
|
15
|
+
*/
|
|
16
|
+
export declare const setConfig: (newConfig: Partial<HistoryConfig>) => HistoryConfig;
|
|
17
|
+
/**
|
|
18
|
+
* @title: 获取配置
|
|
19
|
+
* @description:
|
|
20
|
+
* @param {*} HistoryConfig
|
|
21
|
+
* @return {*}
|
|
22
|
+
* @Author: zhiwei.Wang
|
|
23
|
+
*/
|
|
24
|
+
export declare const getConfig: () => HistoryConfig;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { History as HistoryType } from "history";
|
|
2
|
+
import { useHistory, useLocation, useParams } from "react-router-dom";
|
|
3
|
+
import App from "../app";
|
|
4
|
+
export interface HistoryOptions {
|
|
5
|
+
basename?: string;
|
|
6
|
+
}
|
|
7
|
+
export declare class History {
|
|
8
|
+
instance: HistoryType<unknown>;
|
|
9
|
+
useHistory: typeof useHistory;
|
|
10
|
+
useLocation: typeof useLocation;
|
|
11
|
+
useParams: typeof useParams;
|
|
12
|
+
app: App;
|
|
13
|
+
constructor(app: App, options?: HistoryOptions);
|
|
14
|
+
push: HistoryType["push"];
|
|
15
|
+
replace: HistoryType["replace"];
|
|
16
|
+
reload: () => void;
|
|
17
|
+
reloadTo: (path: string) => void;
|
|
18
|
+
externalPage: (path: string) => void;
|
|
19
|
+
goLogin: () => any;
|
|
20
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import useLowCode from './useLowCode';
|
|
2
|
+
import useDelayedValue from './useDelayedValue';
|
|
3
|
+
import useStore from './useStore';
|
|
4
|
+
import useDispatch from './useDispatch';
|
|
5
|
+
export interface HooksExport {
|
|
6
|
+
useLowCode: typeof useLowCode;
|
|
7
|
+
useDelayedValue: typeof useDelayedValue;
|
|
8
|
+
useStore: typeof useStore;
|
|
9
|
+
useDispatch: typeof useDispatch;
|
|
10
|
+
}
|
|
11
|
+
declare const _default: HooksExport;
|
|
12
|
+
export default _default;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export interface useLowCodeProps {
|
|
2
|
+
onChange: (e: any) => void;
|
|
3
|
+
onReady: (e: any) => void;
|
|
4
|
+
}
|
|
5
|
+
export interface useLowCodeResult {
|
|
6
|
+
lowcodeRef: {
|
|
7
|
+
onReady: (e: any) => void;
|
|
8
|
+
onChange: (e: any) => void;
|
|
9
|
+
};
|
|
10
|
+
setState: (values: any, callback?: any) => any;
|
|
11
|
+
}
|
|
12
|
+
declare const useLowCode: (props: Partial<useLowCodeProps>) => useLowCodeResult;
|
|
13
|
+
export default useLowCode;
|
package/es/index.d.ts
ADDED
|
@@ -0,0 +1,248 @@
|
|
|
1
|
+
import App from "../app";
|
|
2
|
+
/**
|
|
3
|
+
* IndexDB 管理器模块
|
|
4
|
+
*
|
|
5
|
+
* 这个模块提供了对浏览器 IndexedDB 的简单封装,并在不支持 IndexedDB 的环境中
|
|
6
|
+
* 自动降级使用 localStorage 作为备选存储方案。
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* 数据库配置选项接口
|
|
10
|
+
* @interface DBOptions
|
|
11
|
+
* @property {string} dbName - 数据库名称
|
|
12
|
+
* @property {number} version - 数据库版本号
|
|
13
|
+
* @property {Array} stores - 存储对象配置数组
|
|
14
|
+
* @property {string} stores[].name - 存储对象名称
|
|
15
|
+
* @property {string} stores[].keyPath - 主键路径
|
|
16
|
+
* @property {Array} [stores[].indexes] - 索引配置数组(可选)
|
|
17
|
+
* @property {string} stores[].indexes[].name - 索引名称
|
|
18
|
+
* @property {string} stores[].indexes[].keyPath - 索引键路径
|
|
19
|
+
* @property {IDBIndexParameters} [stores[].indexes[].options] - 索引选项(可选)
|
|
20
|
+
*/
|
|
21
|
+
export interface DBOptions {
|
|
22
|
+
dbName: string;
|
|
23
|
+
version: number;
|
|
24
|
+
stores: {
|
|
25
|
+
name: string;
|
|
26
|
+
keyPath: string;
|
|
27
|
+
indexes?: {
|
|
28
|
+
name: string;
|
|
29
|
+
keyPath: string;
|
|
30
|
+
options?: IDBIndexParameters;
|
|
31
|
+
}[];
|
|
32
|
+
}[];
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* IndexDB 管理器类
|
|
36
|
+
* 提供对 IndexedDB 的简单封装,支持自动降级到 localStorage
|
|
37
|
+
* @class IndexDBManager
|
|
38
|
+
*/
|
|
39
|
+
declare class IndexDBManager {
|
|
40
|
+
/**
|
|
41
|
+
* 检查环境是否支持 IndexedDB
|
|
42
|
+
* @returns {boolean} 是否支持 IndexedDB
|
|
43
|
+
* @private
|
|
44
|
+
*/
|
|
45
|
+
private static isSupported;
|
|
46
|
+
private db;
|
|
47
|
+
private dbName;
|
|
48
|
+
private version;
|
|
49
|
+
private stores;
|
|
50
|
+
private useIndexDB;
|
|
51
|
+
private app;
|
|
52
|
+
/**
|
|
53
|
+
* 创建 IndexDBManager 实例
|
|
54
|
+
* @param {DBOptions} options - 数据库配置选项
|
|
55
|
+
*/
|
|
56
|
+
constructor(app: App, options: DBOptions);
|
|
57
|
+
/**
|
|
58
|
+
* 初始化数据库连接
|
|
59
|
+
* 如果环境不支持 IndexedDB,将自动使用 localStorage
|
|
60
|
+
* @returns {Promise<boolean>} 连接是否成功
|
|
61
|
+
*/
|
|
62
|
+
connect(): Promise<boolean>;
|
|
63
|
+
/**
|
|
64
|
+
* 生成用于 localStorage 的存储键
|
|
65
|
+
* @param {string} storeName - 存储对象名称
|
|
66
|
+
* @param {string|number} [key] - 可选的键值
|
|
67
|
+
* @returns {string} 格式化的存储键
|
|
68
|
+
* @private
|
|
69
|
+
*/
|
|
70
|
+
private getStorageKey;
|
|
71
|
+
/**
|
|
72
|
+
* 添加数据到指定的存储对象
|
|
73
|
+
* @param {string} storeName - 存储对象名称
|
|
74
|
+
* @param {T} data - 要添加的数据
|
|
75
|
+
* @returns {Promise<T>} 添加的数据
|
|
76
|
+
* @template T
|
|
77
|
+
*/
|
|
78
|
+
add<T>(storeName: string, data: T): Promise<T>;
|
|
79
|
+
/**
|
|
80
|
+
* 快速检查指定存储对象中的数据是否存在
|
|
81
|
+
* @param {string} storeName - 存储对象名称
|
|
82
|
+
* @param {string|number} key - 数据主键
|
|
83
|
+
* @returns {Promise<boolean>} 数据是否存在
|
|
84
|
+
*/
|
|
85
|
+
exists(storeName: string, key: string | number): Promise<boolean>;
|
|
86
|
+
/**
|
|
87
|
+
* 获取指定存储对象中的数据
|
|
88
|
+
* @param {string} storeName - 存储对象名称
|
|
89
|
+
* @param {string|number} key - 数据主键
|
|
90
|
+
* @returns {Promise<T|null>} 获取的数据,不存在则返回 null
|
|
91
|
+
* @template T
|
|
92
|
+
*/
|
|
93
|
+
get<T>(storeName: string, key: string | number): Promise<T | null>;
|
|
94
|
+
/**
|
|
95
|
+
* 更新指定存储对象中的数据
|
|
96
|
+
* @param {string} storeName - 存储对象名称
|
|
97
|
+
* @param {T} data - 要更新的数据
|
|
98
|
+
* @returns {Promise<T>} 更新后的数据
|
|
99
|
+
* @template T
|
|
100
|
+
*/
|
|
101
|
+
update<T>(storeName: string, data: T): Promise<T>;
|
|
102
|
+
/**
|
|
103
|
+
* 删除指定存储对象中的数据
|
|
104
|
+
* @param {string} storeName - 存储对象名称
|
|
105
|
+
* @param {string|number} key - 数据主键
|
|
106
|
+
* @returns {Promise<boolean>} 删除是否成功
|
|
107
|
+
*/
|
|
108
|
+
delete(storeName: string, key: string | number): Promise<boolean>;
|
|
109
|
+
/**
|
|
110
|
+
* 通过索引获取数据
|
|
111
|
+
* @param {string} storeName - 存储对象名称
|
|
112
|
+
* @param {string} indexName - 索引名称
|
|
113
|
+
* @param {string|number} indexValue - 索引值
|
|
114
|
+
* @returns {Promise<T|null>} 获取的数据,不存在则返回 null
|
|
115
|
+
* @template T
|
|
116
|
+
*/
|
|
117
|
+
getByIndex<T>(storeName: string, indexName: string, indexValue: string | number): Promise<T | null>;
|
|
118
|
+
/**
|
|
119
|
+
* 通过索引检查数据是否存在
|
|
120
|
+
* @param {string} storeName - 存储对象名称
|
|
121
|
+
* @param {string} indexName - 索引名称
|
|
122
|
+
* @param {string|number} indexValue - 索引值
|
|
123
|
+
* @returns {Promise<boolean>} 数据是否存在
|
|
124
|
+
*/
|
|
125
|
+
existsByIndex(storeName: string, indexName: string, indexValue: string | number): Promise<boolean>;
|
|
126
|
+
/**
|
|
127
|
+
* 通过索引获取多条数据
|
|
128
|
+
* @param {string} storeName - 存储对象名称
|
|
129
|
+
* @param {string} indexName - 索引名称
|
|
130
|
+
* @param {string|number} indexValue - 索引值
|
|
131
|
+
* @returns {Promise<T[]>} 数据数组
|
|
132
|
+
* @template T
|
|
133
|
+
*/
|
|
134
|
+
getAllByIndex<T>(storeName: string, indexName: string, indexValue: string | number): Promise<T[]>;
|
|
135
|
+
/**
|
|
136
|
+
* 统计指定存储对象中的数据数量
|
|
137
|
+
* @param {string} storeName - 存储对象名称
|
|
138
|
+
* @returns {Promise<number>} 数据数量
|
|
139
|
+
*/
|
|
140
|
+
count(storeName: string): Promise<number>;
|
|
141
|
+
/**
|
|
142
|
+
* 通过索引统计数据数量
|
|
143
|
+
* @param {string} storeName - 存储对象名称
|
|
144
|
+
* @param {string} indexName - 索引名称
|
|
145
|
+
* @param {string|number} indexValue - 索引值
|
|
146
|
+
* @returns {Promise<number>} 数据数量
|
|
147
|
+
*/
|
|
148
|
+
countByIndex(storeName: string, indexName: string, indexValue: string | number): Promise<number>;
|
|
149
|
+
/**
|
|
150
|
+
* 获取指定存储对象中的所有数据
|
|
151
|
+
* @param {string} storeName - 存储对象名称
|
|
152
|
+
* @returns {Promise<T[]>} 数据数组
|
|
153
|
+
* @template T
|
|
154
|
+
*/
|
|
155
|
+
getAll<T>(storeName: string): Promise<T[]>;
|
|
156
|
+
/**
|
|
157
|
+
* 清空指定存储对象中的所有数据
|
|
158
|
+
* @param {string} storeName - 存储对象名称
|
|
159
|
+
* @returns {Promise<boolean>} 清空是否成功
|
|
160
|
+
*/
|
|
161
|
+
clear(storeName: string): Promise<boolean>;
|
|
162
|
+
/**
|
|
163
|
+
* 关闭数据库连接
|
|
164
|
+
* 在不再需要使用数据库时调用,释放资源
|
|
165
|
+
*/
|
|
166
|
+
close(): void;
|
|
167
|
+
/**
|
|
168
|
+
* 获取当前使用的存储方式
|
|
169
|
+
* @returns {'indexDB'|'localStorage'} 当前使用的存储方式
|
|
170
|
+
*/
|
|
171
|
+
getCurrentStorage(): 'indexDB' | 'localStorage';
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* 使用示例:
|
|
175
|
+
*
|
|
176
|
+
* // 1. 创建数据库配置
|
|
177
|
+
* const dbOptions: DBOptions = {
|
|
178
|
+
* dbName: 'myApp',
|
|
179
|
+
* version: 1,
|
|
180
|
+
* stores: [
|
|
181
|
+
* {
|
|
182
|
+
* name: 'users',
|
|
183
|
+
* keyPath: 'id',
|
|
184
|
+
* indexes: [
|
|
185
|
+
* { name: 'email', keyPath: 'email', options: { unique: true } },
|
|
186
|
+
* { name: 'department', keyPath: 'department', options: { unique: false } }
|
|
187
|
+
* ]
|
|
188
|
+
* },
|
|
189
|
+
* {
|
|
190
|
+
* name: 'products',
|
|
191
|
+
* keyPath: 'id'
|
|
192
|
+
* }
|
|
193
|
+
* ]
|
|
194
|
+
* };
|
|
195
|
+
*
|
|
196
|
+
* // 2. 创建并连接数据库
|
|
197
|
+
* const db = new IndexDBManager(app, dbOptions);
|
|
198
|
+
* await db.connect();
|
|
199
|
+
*
|
|
200
|
+
* // 3. 添加数据
|
|
201
|
+
* const user = { id: '1', name: '张三', email: 'zhangsan@example.com', department: 'IT' };
|
|
202
|
+
* await db.add('users', user);
|
|
203
|
+
*
|
|
204
|
+
* // 4. 获取数据
|
|
205
|
+
* const retrievedUser = await db.get('users', '1');
|
|
206
|
+
*
|
|
207
|
+
* // 5. 快速检查数据是否存在(推荐用法)
|
|
208
|
+
* const userExists = await db.exists('users', '1'); // 返回 true/false,比 get 更高效
|
|
209
|
+
*
|
|
210
|
+
* // 6. 通过索引获取数据
|
|
211
|
+
* const userByEmail = await db.getByIndex('users', 'email', 'zhangsan@example.com');
|
|
212
|
+
*
|
|
213
|
+
* // 7. 通过索引检查数据是否存在
|
|
214
|
+
* const emailExists = await db.existsByIndex('users', 'email', 'zhangsan@example.com');
|
|
215
|
+
*
|
|
216
|
+
* // 8. 通过索引获取多条数据
|
|
217
|
+
* const itUsers = await db.getAllByIndex('users', 'department', 'IT');
|
|
218
|
+
*
|
|
219
|
+
* // 9. 统计数据数量
|
|
220
|
+
* const totalUsers = await db.count('users');
|
|
221
|
+
* const itUserCount = await db.countByIndex('users', 'department', 'IT');
|
|
222
|
+
*
|
|
223
|
+
* // 10. 更新数据
|
|
224
|
+
* user.name = '张三 (已更新)';
|
|
225
|
+
* await db.update('users', user);
|
|
226
|
+
*
|
|
227
|
+
* // 11. 获取所有数据
|
|
228
|
+
* const allUsers = await db.getAll('users');
|
|
229
|
+
*
|
|
230
|
+
* // 12. 删除数据
|
|
231
|
+
* await db.delete('users', '1');
|
|
232
|
+
*
|
|
233
|
+
* // 13. 清空存储对象
|
|
234
|
+
* await db.clear('users');
|
|
235
|
+
*
|
|
236
|
+
* // 14. 关闭数据库连接
|
|
237
|
+
* db.close();
|
|
238
|
+
*
|
|
239
|
+
* // 15. 检查当前使用的存储方式
|
|
240
|
+
* const storageType = db.getCurrentStorage(); // 'indexDB' 或 'localStorage'
|
|
241
|
+
*
|
|
242
|
+
* // 性能优化建议:
|
|
243
|
+
* // - 使用 exists() 而不是 get() 来检查数据是否存在
|
|
244
|
+
* // - 为常用查询字段创建索引
|
|
245
|
+
* // - 使用索引查询方法来提高查询效率
|
|
246
|
+
* // - 批量操作时使用事务(可以考虑后续扩展)
|
|
247
|
+
*/
|
|
248
|
+
export default IndexDBManager;
|