@pisell/core 1.0.33 → 1.0.34

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.
@@ -79,8 +79,9 @@ var IndexDBManager = /*#__PURE__*/function () {
79
79
  key: "withTimeout",
80
80
  value: function withTimeout(promise, operation) {
81
81
  var _this2 = this;
82
- return Promise.race([promise, new Promise(function (_, reject) {
83
- setTimeout(function () {
82
+ var timeoutId = null;
83
+ var timeoutPromise = new Promise(function (_, reject) {
84
+ timeoutId = setTimeout(function () {
84
85
  var error = new Error("\u64CD\u4F5C\u8D85\u65F6: ".concat(operation, " \u5728 ").concat(_this2.timeout, "ms \u5185\u672A\u5B8C\u6210"));
85
86
  _this2.app.logger.addLog({
86
87
  type: 'error',
@@ -93,7 +94,16 @@ var IndexDBManager = /*#__PURE__*/function () {
93
94
  });
94
95
  reject(error);
95
96
  }, _this2.timeout);
96
- })]);
97
+ });
98
+ return Promise.race([promise.then(function (result) {
99
+ // Promise 成功完成,清除超时定时器
100
+ if (timeoutId) clearTimeout(timeoutId);
101
+ return result;
102
+ }, function (error) {
103
+ // Promise 失败,清除超时定时器
104
+ if (timeoutId) clearTimeout(timeoutId);
105
+ throw error;
106
+ }), timeoutPromise]);
97
107
  }
98
108
 
99
109
  /**
@@ -77,23 +77,34 @@ var IndexDBManager = class _IndexDBManager {
77
77
  * @private
78
78
  */
79
79
  withTimeout(promise, operation) {
80
+ let timeoutId = null;
81
+ const timeoutPromise = new Promise((_, reject) => {
82
+ timeoutId = setTimeout(() => {
83
+ const error = new Error(`操作超时: ${operation} 在 ${this.timeout}ms 内未完成`);
84
+ this.app.logger.addLog({
85
+ type: "error",
86
+ title: "[ IndexDB ] TIMEOUT",
87
+ metadata: {
88
+ msg: `操作超时: ${operation}`,
89
+ timeout: this.timeout,
90
+ operation
91
+ }
92
+ });
93
+ reject(error);
94
+ }, this.timeout);
95
+ });
80
96
  return Promise.race([
81
- promise,
82
- new Promise((_, reject) => {
83
- setTimeout(() => {
84
- const error = new Error(`操作超时: ${operation} 在 ${this.timeout}ms 内未完成`);
85
- this.app.logger.addLog({
86
- type: "error",
87
- title: "[ IndexDB ] TIMEOUT",
88
- metadata: {
89
- msg: `操作超时: ${operation}`,
90
- timeout: this.timeout,
91
- operation
92
- }
93
- });
94
- reject(error);
95
- }, this.timeout);
96
- })
97
+ promise.then(
98
+ (result) => {
99
+ if (timeoutId) clearTimeout(timeoutId);
100
+ return result;
101
+ },
102
+ (error) => {
103
+ if (timeoutId) clearTimeout(timeoutId);
104
+ throw error;
105
+ }
106
+ ),
107
+ timeoutPromise
97
108
  ]);
98
109
  }
99
110
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pisell/core",
3
- "version": "1.0.33",
3
+ "version": "1.0.34",
4
4
  "sideEffects": false,
5
5
  "main": "./lib/index.js",
6
6
  "module": "./es/index.js",
package/es/app/app.d.ts DELETED
@@ -1,91 +0,0 @@
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, { CMDOptions } from "../cmd";
12
- import AWS, { AWSOptions } 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
- cmd?: CMDOptions;
26
- aws?: AWSOptions;
27
- getPisellos?: () => any;
28
- }
29
- declare class App {
30
- private static instance;
31
- private plugins;
32
- globalData: any;
33
- router: RouterManager;
34
- applicationManager: ApplicationManager;
35
- history: History;
36
- data: Data;
37
- hooks: import("../hooks").HooksExport;
38
- locales: Locales;
39
- models: {
40
- getStore: () => import("../models").Store;
41
- StoreProvider: typeof import("react-redux").Provider;
42
- setConfig: (models: any[]) => void;
43
- };
44
- request: {
45
- get: (url: string, data: any, config: import("../request").RequestSetting | undefined) => Promise<any>;
46
- post: (url: string, data: any, config: import("../request").RequestSetting | undefined) => Promise<any>;
47
- put: (url: string, data: any, config: import("../request").RequestSetting | undefined) => Promise<any>;
48
- remove: (url: string, data: any, config: import("../request").RequestSetting | undefined) => Promise<any>;
49
- custom: (url: string, config: import("../request").RequestSetting | undefined) => any;
50
- setConfig: (newConfig: Partial<import("../request").RequestConfig>) => void;
51
- getConfig: () => import("../request").RequestConfig;
52
- };
53
- storage: Storage;
54
- menuManager: MenuManager;
55
- cookie: {
56
- setCookie: (name: string, value: string, domain?: string | undefined) => void;
57
- getCookie: (name: string) => string | null;
58
- deleteCookie: (name: string, domain?: string | undefined) => void;
59
- checkCookie: (name: string) => boolean;
60
- updateCookie: (name: string, value: string, domain?: string | undefined) => void;
61
- };
62
- website: {
63
- setTitle: (title: string) => void;
64
- setIcon: (paramsIcon: string) => void;
65
- setAppleWebAppTitle: (title: string) => void;
66
- };
67
- logger: LoggerManager;
68
- pubsub: import("../pubsub").PubSub;
69
- cmd: CMD;
70
- aws: AWS;
71
- tasksManager: TasksManager;
72
- getPisellos: any;
73
- dbManager: IndexDBManager | null;
74
- constants: {
75
- channel: string;
76
- [key: string]: string;
77
- };
78
- private constructor();
79
- static getInstance(options?: AppOptions): App;
80
- setGlobalData(globalData: any): void;
81
- usePlugin(name: string, plugin: any): void;
82
- usePlugins(plugins: {
83
- name: string;
84
- plugin: any;
85
- }[]): void;
86
- getPlugin(name: string): any;
87
- getGlobalData(): any;
88
- install(): void;
89
- unInstall(): void;
90
- }
91
- export default App;
@@ -1,46 +0,0 @@
1
- import { CacheProps } from './type';
2
- export declare type CacheType = 'memory' | 'storage' | 'indexDB';
3
- /**
4
- * @title: 设置缓存
5
- * @description:
6
- * @return {*}
7
- * @Author: zhiwei.Wang
8
- */
9
- export declare const setCache: (key: string, data: any, cache: CacheProps) => Promise<void>;
10
- /**
11
- * @title: 删除缓存数据
12
- * @description:
13
- * @return {*}
14
- * @Author: zhiwei.Wang
15
- */
16
- export declare const removeCache: (key: string, cache: CacheProps) => void;
17
- /**
18
- * @title: 获取数据
19
- * @description:
20
- * @param {any} url
21
- * @param {any} data
22
- * @return {*}
23
- * @Author: zhiwei.Wang
24
- */
25
- export declare const getCacheData: (url: string, data: any, cache: CacheProps) => Promise<any>;
26
- /**
27
- * @title: 设置缓存
28
- * @description:
29
- * @param {any} url 路径
30
- * @param {any} data 参数
31
- * @param {any} res 数据
32
- * @return {*}
33
- * @Author: zhiwei.Wang
34
- */
35
- export declare const setCacheData: (url: string, data: any, res: any, cache?: CacheProps) => any | null;
36
- /**
37
- * @title: 缓存函数包装器
38
- * @description:
39
- * @param {any} url
40
- * @param {any} data
41
- * @param {any} config
42
- * @param {any} fn
43
- * @return {*}
44
- * @Author: zhiwei.Wang
45
- */
46
- export declare const cacheFn: (props: any, fn: any) => Promise<any>;
@@ -1,24 +0,0 @@
1
- import { RequestWrapperProps, RequestConfig } from "./type";
2
- export declare const createRequest: (props: RequestWrapperProps) => Promise<unknown>;
3
- /**
4
- * 请求
5
- * @param props
6
- * @returns
7
- */
8
- export declare const request: (props: RequestWrapperProps) => any;
9
- export declare const get: (url: RequestWrapperProps["url"], data: RequestWrapperProps["data"], config: RequestWrapperProps["config"]) => Promise<any>;
10
- export declare const post: (url: RequestWrapperProps["url"], data: RequestWrapperProps["data"], config: RequestWrapperProps["config"]) => Promise<any>;
11
- export declare const put: (url: RequestWrapperProps["url"], data: RequestWrapperProps["data"], config: RequestWrapperProps["config"]) => Promise<any>;
12
- export declare const remove: (url: RequestWrapperProps["url"], data: RequestWrapperProps["data"], config: RequestWrapperProps["config"]) => Promise<any>;
13
- export declare const custom: (url: RequestWrapperProps["url"], config: RequestWrapperProps["config"]) => any;
14
- export * from "./type";
15
- declare const _default: {
16
- get: (url: string, data: any, config: import("./type").RequestSetting | undefined) => Promise<any>;
17
- post: (url: string, data: any, config: import("./type").RequestSetting | undefined) => Promise<any>;
18
- put: (url: string, data: any, config: import("./type").RequestSetting | undefined) => Promise<any>;
19
- remove: (url: string, data: any, config: import("./type").RequestSetting | undefined) => Promise<any>;
20
- custom: (url: string, config: import("./type").RequestSetting | undefined) => any;
21
- setConfig: (newConfig: Partial<RequestConfig>) => void;
22
- getConfig: () => RequestConfig;
23
- };
24
- export default _default;
@@ -1,52 +0,0 @@
1
- import { CreateAxiosDefaults } from "axios";
2
- import { CacheType } from './cache';
3
- export interface RequestConfig {
4
- interceptorsRequest?: ((value: any) => any | Promise<any>) | null;
5
- interceptorsRequestError?: ((error: any) => any) | null;
6
- interceptorsResponse?: any;
7
- interceptorsResponseError?: ((error: any) => any) | null;
8
- axiosConfig?: CreateAxiosDefaults;
9
- storage?: any;
10
- getToken?: () => string | null;
11
- setToken?: (token: string) => void;
12
- getLocale?: () => string | null;
13
- getUrl?: (config: any) => string;
14
- requestCallbacks?: {
15
- 200?: (data: any) => void;
16
- 401?: (data: any) => void;
17
- 403?: (data: any) => void;
18
- other?: (data: any) => void;
19
- [key: string]: any;
20
- };
21
- }
22
- export declare enum RequestModeENUM {
23
- LOCAL = "local",
24
- REMOTE = "remote",
25
- LOCAL_REMOTE = "local_remote",
26
- REMOTE_LOCAL = "remote_local",
27
- OS_SERVER = "os_server"
28
- }
29
- export declare type RequestModeType = RequestModeENUM.LOCAL | RequestModeENUM.REMOTE | RequestModeENUM.LOCAL_REMOTE | RequestModeENUM.REMOTE_LOCAL | RequestModeENUM.OS_SERVER;
30
- export interface CacheProps {
31
- key?: string;
32
- type?: CacheType;
33
- updateCache?: boolean;
34
- cacheUpdateChange?: (data: any) => void;
35
- mode?: RequestModeType;
36
- cacheKeyData?: any;
37
- }
38
- export interface RequestSetting {
39
- abort?: boolean;
40
- headers?: any;
41
- cache?: CacheProps;
42
- signal?: any;
43
- token?: string;
44
- osServer?: boolean;
45
- [key: string]: any;
46
- }
47
- export interface RequestWrapperProps {
48
- url: string;
49
- method: 'get' | 'post' | 'remove' | 'put';
50
- data?: any;
51
- config?: RequestSetting;
52
- }
@@ -1,46 +0,0 @@
1
- import { InternalAxiosRequestConfig } from "axios";
2
- import { RequestSetting, RequestConfig, RequestWrapperProps } from "./type";
3
- export declare const getRequestHeaders: (config: InternalAxiosRequestConfig<RequestSetting> & Record<string, any>) => Record<string, string | null>;
4
- /**
5
- * @title: 请求前拦截
6
- * @description:
7
- * @param {any} config
8
- * @return {*}
9
- * @Author: zhiwei.Wang
10
- * @Date: 2024-07-04 10:51
11
- */
12
- export declare const interceptorsRequest: (config: InternalAxiosRequestConfig<RequestSetting> & Record<string, any>) => Promise<InternalAxiosRequestConfig<RequestSetting> & Record<string, any>>;
13
- /**
14
- * @title: 请求前error
15
- * @description:
16
- * @param {any} err
17
- * @return {*}
18
- * @Author: zhiwei.Wang
19
- * @Date: 2024-07-04 10:51
20
- */
21
- export declare const interceptorsRequestError: (err: RequestConfig["interceptorsRequestError"]) => any;
22
- /**
23
- * @title: 请求后拦截
24
- * @description:
25
- * @param {any} response
26
- * @return {*}
27
- * @Author: zhiwei.Wang
28
- * @Date: 2024-07-04 10:51
29
- */
30
- export declare const interceptorsResponse: (response: RequestConfig["interceptorsResponse"]) => any;
31
- /**
32
- * @title: 请求后错误拦截
33
- * @description:
34
- * @param {any} response
35
- * @return {*}
36
- * @Author: zhiwei.Wang
37
- * @Date: 2024-07-04 10:51
38
- */
39
- export declare const interceptorsResponseError: (response: RequestConfig["interceptorsResponseError"]) => any;
40
- export declare const requestCallback: (resData: {
41
- res?: any;
42
- props: RequestWrapperProps;
43
- resolve: (value: unknown) => void;
44
- reject: () => void;
45
- err?: any;
46
- }) => void;
@@ -1,128 +0,0 @@
1
- import { Task, TasksModule, RunTaskParams, AddTaskParams, DeleteTaskParams } from "./type";
2
- import App from "../app";
3
- export declare class TasksManager {
4
- private static instance;
5
- private taskFunctions;
6
- private tasks;
7
- private app;
8
- private db;
9
- useTasks: () => {
10
- tasks: TasksModule;
11
- };
12
- watchTaskCallback: (taskModule: TasksModule) => void;
13
- private timerIds;
14
- constructor(app: App);
15
- static getInstance(app?: App): TasksManager;
16
- addTaskFunction<T>(name: string, fun: T): void;
17
- addTaskFunctions<T>(tasks: {
18
- name: string;
19
- fun: T;
20
- }[]): void;
21
- getTasks(): TasksModule;
22
- getTaskFunction(name: string): any;
23
- init(): Promise<void>;
24
- private saveTaskQueueToLocal;
25
- private loadTaskQueueFromLocal;
26
- /**
27
- * @title: 执行任务
28
- * @description:
29
- * @param {Task} task
30
- * @return {*}
31
- * @Author: zhiwei.Wang
32
- * @Date: 2024-09-26 13:53
33
- */
34
- private runTask;
35
- /**
36
- * @title: 清除任务定时器
37
- * @param {NodeJS.Timeout} timerId
38
- */
39
- private clearTaskTimer;
40
- /**
41
- * @title: 计算下一次执行时间
42
- * @description: 根据定时任务配置计算下一次执行时间
43
- * @param {Task} task
44
- * @return {string | null} 下一次执行时间
45
- */
46
- private calculateNextExecuteTime;
47
- /**
48
- * @title: 启动定时任务
49
- * @description: 在特定时间点执行任务(仅在 scheduledTasks 模块中生效)
50
- * @param {Task} task
51
- * @return {*}
52
- */
53
- private startScheduledTask;
54
- /**
55
- * @title: 启动轮询
56
- * @description: 根据轮询间隔定期执行任务
57
- * @param {Task} task
58
- * @return {*}
59
- */
60
- private startPolling;
61
- /**
62
- * @title: 创建任务数据
63
- * @description:
64
- * @param {Partial} payload
65
- * @return {*}
66
- * @Author: zhiwei.Wang
67
- * @Date: 2024-09-26 13:54
68
- */
69
- private createTaskData;
70
- private getTaskQueue;
71
- private timeout;
72
- /**
73
- * @title: 执行任务队列
74
- * @description:
75
- * @return {*}
76
- * @Author: zhiwei.Wang
77
- * @Date: 2024-09-26 13:52
78
- */
79
- run(payload: RunTaskParams): Promise<void>;
80
- deleteTask(payload: DeleteTaskParams): void;
81
- /**
82
- * @title: 重试任务
83
- * @description:
84
- * @return {*}
85
- * @Author: zhiwei.Wang
86
- * @Date: 2024-09-26 13:53
87
- */
88
- retryTask(payload: RunTaskParams): void;
89
- addTask(payload: AddTaskParams): void;
90
- private updateTask;
91
- private updateQueueStatus;
92
- /**
93
- * @title: 更新队列运行状态
94
- * @description: 标记队列是否正在执行
95
- */
96
- private updateQueueRunningState;
97
- private setTasksData;
98
- private setTasks;
99
- clearAllTaskTimer(tasks: Task[]): void;
100
- clearTasks(payload: RunTaskParams): void;
101
- clearAllTasks(): void;
102
- watchTask(callback: (taskModule: TasksModule) => void): void;
103
- /**
104
- * @title: 获取队列执行状态
105
- * @description: 获取指定队列的执行状态和进度信息
106
- * @param {string} module - 模块名
107
- * @param {string} queueId - 队列ID
108
- * @return {object} 队列状态信息
109
- */
110
- getQueueStatus(module: string, queueId: string): {
111
- isRunning: boolean;
112
- status: "completed" | "uncompleted";
113
- progress: {
114
- total: number;
115
- completed: number;
116
- failed: number;
117
- inProgress: number;
118
- };
119
- lastRunAt: string | null;
120
- tasksCount: number;
121
- } | null;
122
- /**
123
- * @title: 获取所有队列状态
124
- * @description: 获取所有任务队列的执行状态概览
125
- * @return {object} 所有队列的状态信息
126
- */
127
- getAllQueuesStatus(): any;
128
- }
@@ -1,61 +0,0 @@
1
- /**
2
- * 定时任务示例代码
3
- * 本文件展示了如何使用定时任务功能
4
- *
5
- * 重要提示:
6
- * - 定时任务必须添加到 'scheduledTasks' 模块才能生效
7
- * - 在其他模块中,scheduled 配置会被忽略,任务将作为普通任务立即执行
8
- * - 这是为了性能优化,避免在所有模块中检查定时任务配置
9
- */
10
- import { TasksManager } from './index';
11
- /**
12
- * 示例1:创建一次性定时任务
13
- * 在特定时间点执行一次
14
- *
15
- * 注意:定时任务必须添加到 'scheduledTasks' 模块才能生效
16
- */
17
- export declare function createOnceScheduledTask(tasksManager: TasksManager): void;
18
- /**
19
- * 示例2:创建每日重复的定时任务
20
- * 每天在固定时间执行
21
- */
22
- export declare function createDailyScheduledTask(tasksManager: TasksManager): void;
23
- /**
24
- * 示例3:创建带结束时间的重复任务
25
- * 在特定时间段内重复执行
26
- */
27
- export declare function createLimitedRepeatTask(tasksManager: TasksManager): void;
28
- /**
29
- * 示例4:创建多个时间点的任务
30
- * 在一天中的多个时间点分别执行
31
- */
32
- export declare function createMultiTimeTask(tasksManager: TasksManager): void;
33
- /**
34
- * 示例5:创建每周重复任务
35
- * 每周一早上9点执行周报
36
- */
37
- export declare function createWeeklyTask(tasksManager: TasksManager): void;
38
- /**
39
- * 示例6:创建每月重复任务
40
- * 每月1号生成月报
41
- */
42
- export declare function createMonthlyTask(tasksManager: TasksManager): void;
43
- /**
44
- * 示例7:查询和管理定时任务
45
- */
46
- export declare function manageScheduledTasks(tasksManager: TasksManager): void;
47
- /**
48
- * 完整使用示例
49
- */
50
- export declare function fullExample(app: any): void;
51
- declare const _default: {
52
- createOnceScheduledTask: typeof createOnceScheduledTask;
53
- createDailyScheduledTask: typeof createDailyScheduledTask;
54
- createLimitedRepeatTask: typeof createLimitedRepeatTask;
55
- createMultiTimeTask: typeof createMultiTimeTask;
56
- createWeeklyTask: typeof createWeeklyTask;
57
- createMonthlyTask: typeof createMonthlyTask;
58
- manageScheduledTasks: typeof manageScheduledTasks;
59
- fullExample: typeof fullExample;
60
- };
61
- export default _default;
@@ -1,100 +0,0 @@
1
- export declare type TaskRunStatus = "pending" | "in-progress" | "success" | "failure";
2
- export interface Task {
3
- id?: string;
4
- type?: "local" | "cloud";
5
- retries?: number;
6
- maxRetries?: number;
7
- status?: TaskRunStatus;
8
- action: string;
9
- payload: any;
10
- beforeAction?: string;
11
- beforePayload?: any;
12
- afterAction?: string;
13
- afterPayload?: any;
14
- polling?: {
15
- interval?: number;
16
- };
17
- pollingResult?: {
18
- count: number;
19
- timerId?: any;
20
- };
21
- scheduled?: {
22
- executeAt: string | string[];
23
- repeat?: boolean;
24
- repeatType?: 'daily' | 'weekly' | 'monthly' | 'yearly';
25
- repeatInterval?: number;
26
- endAt?: string;
27
- };
28
- scheduledResult?: {
29
- count: number;
30
- timerId?: any;
31
- nextExecuteTime?: string;
32
- };
33
- manual?: boolean;
34
- destroy?: boolean;
35
- [key: string]: any;
36
- }
37
- export interface TaskConfig {
38
- tasks: Task[];
39
- }
40
- declare type TaskModuleName = string;
41
- declare type TaskQueueName = string;
42
- declare type TaskStatus = "uncompleted" | "completed";
43
- export interface TaskQueue {
44
- status: TaskStatus;
45
- tasks: Task[];
46
- isRunning?: boolean;
47
- progress?: {
48
- total: number;
49
- completed: number;
50
- failed: number;
51
- inProgress: number;
52
- };
53
- lastRunAt?: string;
54
- }
55
- export interface RunTaskParams {
56
- module: TaskModuleName;
57
- queueId: TaskQueueName;
58
- callback?: () => void;
59
- }
60
- export interface DeleteTaskParams {
61
- module: TaskModuleName;
62
- queueId: TaskQueueName;
63
- taskId: string;
64
- }
65
- export interface AddTaskParams {
66
- module: TaskModuleName;
67
- queueId: TaskQueueName;
68
- tasks: Task[];
69
- }
70
- export interface AddTaskDataParams {
71
- module: TaskModuleName;
72
- queueId: TaskQueueName;
73
- [key: string]: any;
74
- }
75
- export interface TaskRunResult {
76
- status: TaskRunStatus;
77
- [key: string]: any;
78
- }
79
- /**
80
- * 任务模块
81
- * 注意:'scheduledTasks' 是保留的模块名,专门用于定时任务
82
- * 在其他模块中,scheduled 配置会被忽略,任务将作为普通任务执行
83
- */
84
- export interface TasksModule {
85
- [key: TaskModuleName]: {
86
- [key: TaskQueueName]: {
87
- status: TaskStatus;
88
- tasks: Task[];
89
- isRunning?: boolean;
90
- progress?: {
91
- total: number;
92
- completed: number;
93
- failed: number;
94
- inProgress: number;
95
- };
96
- lastRunAt?: string;
97
- };
98
- };
99
- }
100
- export {};
package/lib/app/app.d.ts DELETED
@@ -1,91 +0,0 @@
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, { CMDOptions } from "../cmd";
12
- import AWS, { AWSOptions } 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
- cmd?: CMDOptions;
26
- aws?: AWSOptions;
27
- getPisellos?: () => any;
28
- }
29
- declare class App {
30
- private static instance;
31
- private plugins;
32
- globalData: any;
33
- router: RouterManager;
34
- applicationManager: ApplicationManager;
35
- history: History;
36
- data: Data;
37
- hooks: import("../hooks").HooksExport;
38
- locales: Locales;
39
- models: {
40
- getStore: () => import("../models").Store;
41
- StoreProvider: typeof import("react-redux").Provider;
42
- setConfig: (models: any[]) => void;
43
- };
44
- request: {
45
- get: (url: string, data: any, config: import("../request").RequestSetting | undefined) => Promise<any>;
46
- post: (url: string, data: any, config: import("../request").RequestSetting | undefined) => Promise<any>;
47
- put: (url: string, data: any, config: import("../request").RequestSetting | undefined) => Promise<any>;
48
- remove: (url: string, data: any, config: import("../request").RequestSetting | undefined) => Promise<any>;
49
- custom: (url: string, config: import("../request").RequestSetting | undefined) => any;
50
- setConfig: (newConfig: Partial<import("../request").RequestConfig>) => void;
51
- getConfig: () => import("../request").RequestConfig;
52
- };
53
- storage: Storage;
54
- menuManager: MenuManager;
55
- cookie: {
56
- setCookie: (name: string, value: string, domain?: string | undefined) => void;
57
- getCookie: (name: string) => string | null;
58
- deleteCookie: (name: string, domain?: string | undefined) => void;
59
- checkCookie: (name: string) => boolean;
60
- updateCookie: (name: string, value: string, domain?: string | undefined) => void;
61
- };
62
- website: {
63
- setTitle: (title: string) => void;
64
- setIcon: (paramsIcon: string) => void;
65
- setAppleWebAppTitle: (title: string) => void;
66
- };
67
- logger: LoggerManager;
68
- pubsub: import("../pubsub").PubSub;
69
- cmd: CMD;
70
- aws: AWS;
71
- tasksManager: TasksManager;
72
- getPisellos: any;
73
- dbManager: IndexDBManager | null;
74
- constants: {
75
- channel: string;
76
- [key: string]: string;
77
- };
78
- private constructor();
79
- static getInstance(options?: AppOptions): App;
80
- setGlobalData(globalData: any): void;
81
- usePlugin(name: string, plugin: any): void;
82
- usePlugins(plugins: {
83
- name: string;
84
- plugin: any;
85
- }[]): void;
86
- getPlugin(name: string): any;
87
- getGlobalData(): any;
88
- install(): void;
89
- unInstall(): void;
90
- }
91
- export default App;
@@ -1,46 +0,0 @@
1
- import { CacheProps } from './type';
2
- export declare type CacheType = 'memory' | 'storage' | 'indexDB';
3
- /**
4
- * @title: 设置缓存
5
- * @description:
6
- * @return {*}
7
- * @Author: zhiwei.Wang
8
- */
9
- export declare const setCache: (key: string, data: any, cache: CacheProps) => Promise<void>;
10
- /**
11
- * @title: 删除缓存数据
12
- * @description:
13
- * @return {*}
14
- * @Author: zhiwei.Wang
15
- */
16
- export declare const removeCache: (key: string, cache: CacheProps) => void;
17
- /**
18
- * @title: 获取数据
19
- * @description:
20
- * @param {any} url
21
- * @param {any} data
22
- * @return {*}
23
- * @Author: zhiwei.Wang
24
- */
25
- export declare const getCacheData: (url: string, data: any, cache: CacheProps) => Promise<any>;
26
- /**
27
- * @title: 设置缓存
28
- * @description:
29
- * @param {any} url 路径
30
- * @param {any} data 参数
31
- * @param {any} res 数据
32
- * @return {*}
33
- * @Author: zhiwei.Wang
34
- */
35
- export declare const setCacheData: (url: string, data: any, res: any, cache?: CacheProps) => any | null;
36
- /**
37
- * @title: 缓存函数包装器
38
- * @description:
39
- * @param {any} url
40
- * @param {any} data
41
- * @param {any} config
42
- * @param {any} fn
43
- * @return {*}
44
- * @Author: zhiwei.Wang
45
- */
46
- export declare const cacheFn: (props: any, fn: any) => Promise<any>;
@@ -1,24 +0,0 @@
1
- import { RequestWrapperProps, RequestConfig } from "./type";
2
- export declare const createRequest: (props: RequestWrapperProps) => Promise<unknown>;
3
- /**
4
- * 请求
5
- * @param props
6
- * @returns
7
- */
8
- export declare const request: (props: RequestWrapperProps) => any;
9
- export declare const get: (url: RequestWrapperProps["url"], data: RequestWrapperProps["data"], config: RequestWrapperProps["config"]) => Promise<any>;
10
- export declare const post: (url: RequestWrapperProps["url"], data: RequestWrapperProps["data"], config: RequestWrapperProps["config"]) => Promise<any>;
11
- export declare const put: (url: RequestWrapperProps["url"], data: RequestWrapperProps["data"], config: RequestWrapperProps["config"]) => Promise<any>;
12
- export declare const remove: (url: RequestWrapperProps["url"], data: RequestWrapperProps["data"], config: RequestWrapperProps["config"]) => Promise<any>;
13
- export declare const custom: (url: RequestWrapperProps["url"], config: RequestWrapperProps["config"]) => any;
14
- export * from "./type";
15
- declare const _default: {
16
- get: (url: string, data: any, config: import("./type").RequestSetting | undefined) => Promise<any>;
17
- post: (url: string, data: any, config: import("./type").RequestSetting | undefined) => Promise<any>;
18
- put: (url: string, data: any, config: import("./type").RequestSetting | undefined) => Promise<any>;
19
- remove: (url: string, data: any, config: import("./type").RequestSetting | undefined) => Promise<any>;
20
- custom: (url: string, config: import("./type").RequestSetting | undefined) => any;
21
- setConfig: (newConfig: Partial<RequestConfig>) => void;
22
- getConfig: () => RequestConfig;
23
- };
24
- export default _default;
@@ -1,52 +0,0 @@
1
- import { CreateAxiosDefaults } from "axios";
2
- import { CacheType } from './cache';
3
- export interface RequestConfig {
4
- interceptorsRequest?: ((value: any) => any | Promise<any>) | null;
5
- interceptorsRequestError?: ((error: any) => any) | null;
6
- interceptorsResponse?: any;
7
- interceptorsResponseError?: ((error: any) => any) | null;
8
- axiosConfig?: CreateAxiosDefaults;
9
- storage?: any;
10
- getToken?: () => string | null;
11
- setToken?: (token: string) => void;
12
- getLocale?: () => string | null;
13
- getUrl?: (config: any) => string;
14
- requestCallbacks?: {
15
- 200?: (data: any) => void;
16
- 401?: (data: any) => void;
17
- 403?: (data: any) => void;
18
- other?: (data: any) => void;
19
- [key: string]: any;
20
- };
21
- }
22
- export declare enum RequestModeENUM {
23
- LOCAL = "local",
24
- REMOTE = "remote",
25
- LOCAL_REMOTE = "local_remote",
26
- REMOTE_LOCAL = "remote_local",
27
- OS_SERVER = "os_server"
28
- }
29
- export declare type RequestModeType = RequestModeENUM.LOCAL | RequestModeENUM.REMOTE | RequestModeENUM.LOCAL_REMOTE | RequestModeENUM.REMOTE_LOCAL | RequestModeENUM.OS_SERVER;
30
- export interface CacheProps {
31
- key?: string;
32
- type?: CacheType;
33
- updateCache?: boolean;
34
- cacheUpdateChange?: (data: any) => void;
35
- mode?: RequestModeType;
36
- cacheKeyData?: any;
37
- }
38
- export interface RequestSetting {
39
- abort?: boolean;
40
- headers?: any;
41
- cache?: CacheProps;
42
- signal?: any;
43
- token?: string;
44
- osServer?: boolean;
45
- [key: string]: any;
46
- }
47
- export interface RequestWrapperProps {
48
- url: string;
49
- method: 'get' | 'post' | 'remove' | 'put';
50
- data?: any;
51
- config?: RequestSetting;
52
- }
@@ -1,46 +0,0 @@
1
- import { InternalAxiosRequestConfig } from "axios";
2
- import { RequestSetting, RequestConfig, RequestWrapperProps } from "./type";
3
- export declare const getRequestHeaders: (config: InternalAxiosRequestConfig<RequestSetting> & Record<string, any>) => Record<string, string | null>;
4
- /**
5
- * @title: 请求前拦截
6
- * @description:
7
- * @param {any} config
8
- * @return {*}
9
- * @Author: zhiwei.Wang
10
- * @Date: 2024-07-04 10:51
11
- */
12
- export declare const interceptorsRequest: (config: InternalAxiosRequestConfig<RequestSetting> & Record<string, any>) => Promise<InternalAxiosRequestConfig<RequestSetting> & Record<string, any>>;
13
- /**
14
- * @title: 请求前error
15
- * @description:
16
- * @param {any} err
17
- * @return {*}
18
- * @Author: zhiwei.Wang
19
- * @Date: 2024-07-04 10:51
20
- */
21
- export declare const interceptorsRequestError: (err: RequestConfig["interceptorsRequestError"]) => any;
22
- /**
23
- * @title: 请求后拦截
24
- * @description:
25
- * @param {any} response
26
- * @return {*}
27
- * @Author: zhiwei.Wang
28
- * @Date: 2024-07-04 10:51
29
- */
30
- export declare const interceptorsResponse: (response: RequestConfig["interceptorsResponse"]) => any;
31
- /**
32
- * @title: 请求后错误拦截
33
- * @description:
34
- * @param {any} response
35
- * @return {*}
36
- * @Author: zhiwei.Wang
37
- * @Date: 2024-07-04 10:51
38
- */
39
- export declare const interceptorsResponseError: (response: RequestConfig["interceptorsResponseError"]) => any;
40
- export declare const requestCallback: (resData: {
41
- res?: any;
42
- props: RequestWrapperProps;
43
- resolve: (value: unknown) => void;
44
- reject: () => void;
45
- err?: any;
46
- }) => void;
@@ -1,128 +0,0 @@
1
- import { Task, TasksModule, RunTaskParams, AddTaskParams, DeleteTaskParams } from "./type";
2
- import App from "../app";
3
- export declare class TasksManager {
4
- private static instance;
5
- private taskFunctions;
6
- private tasks;
7
- private app;
8
- private db;
9
- useTasks: () => {
10
- tasks: TasksModule;
11
- };
12
- watchTaskCallback: (taskModule: TasksModule) => void;
13
- private timerIds;
14
- constructor(app: App);
15
- static getInstance(app?: App): TasksManager;
16
- addTaskFunction<T>(name: string, fun: T): void;
17
- addTaskFunctions<T>(tasks: {
18
- name: string;
19
- fun: T;
20
- }[]): void;
21
- getTasks(): TasksModule;
22
- getTaskFunction(name: string): any;
23
- init(): Promise<void>;
24
- private saveTaskQueueToLocal;
25
- private loadTaskQueueFromLocal;
26
- /**
27
- * @title: 执行任务
28
- * @description:
29
- * @param {Task} task
30
- * @return {*}
31
- * @Author: zhiwei.Wang
32
- * @Date: 2024-09-26 13:53
33
- */
34
- private runTask;
35
- /**
36
- * @title: 清除任务定时器
37
- * @param {NodeJS.Timeout} timerId
38
- */
39
- private clearTaskTimer;
40
- /**
41
- * @title: 计算下一次执行时间
42
- * @description: 根据定时任务配置计算下一次执行时间
43
- * @param {Task} task
44
- * @return {string | null} 下一次执行时间
45
- */
46
- private calculateNextExecuteTime;
47
- /**
48
- * @title: 启动定时任务
49
- * @description: 在特定时间点执行任务(仅在 scheduledTasks 模块中生效)
50
- * @param {Task} task
51
- * @return {*}
52
- */
53
- private startScheduledTask;
54
- /**
55
- * @title: 启动轮询
56
- * @description: 根据轮询间隔定期执行任务
57
- * @param {Task} task
58
- * @return {*}
59
- */
60
- private startPolling;
61
- /**
62
- * @title: 创建任务数据
63
- * @description:
64
- * @param {Partial} payload
65
- * @return {*}
66
- * @Author: zhiwei.Wang
67
- * @Date: 2024-09-26 13:54
68
- */
69
- private createTaskData;
70
- private getTaskQueue;
71
- private timeout;
72
- /**
73
- * @title: 执行任务队列
74
- * @description:
75
- * @return {*}
76
- * @Author: zhiwei.Wang
77
- * @Date: 2024-09-26 13:52
78
- */
79
- run(payload: RunTaskParams): Promise<void>;
80
- deleteTask(payload: DeleteTaskParams): void;
81
- /**
82
- * @title: 重试任务
83
- * @description:
84
- * @return {*}
85
- * @Author: zhiwei.Wang
86
- * @Date: 2024-09-26 13:53
87
- */
88
- retryTask(payload: RunTaskParams): void;
89
- addTask(payload: AddTaskParams): void;
90
- private updateTask;
91
- private updateQueueStatus;
92
- /**
93
- * @title: 更新队列运行状态
94
- * @description: 标记队列是否正在执行
95
- */
96
- private updateQueueRunningState;
97
- private setTasksData;
98
- private setTasks;
99
- clearAllTaskTimer(tasks: Task[]): void;
100
- clearTasks(payload: RunTaskParams): void;
101
- clearAllTasks(): void;
102
- watchTask(callback: (taskModule: TasksModule) => void): void;
103
- /**
104
- * @title: 获取队列执行状态
105
- * @description: 获取指定队列的执行状态和进度信息
106
- * @param {string} module - 模块名
107
- * @param {string} queueId - 队列ID
108
- * @return {object} 队列状态信息
109
- */
110
- getQueueStatus(module: string, queueId: string): {
111
- isRunning: boolean;
112
- status: "completed" | "uncompleted";
113
- progress: {
114
- total: number;
115
- completed: number;
116
- failed: number;
117
- inProgress: number;
118
- };
119
- lastRunAt: string | null;
120
- tasksCount: number;
121
- } | null;
122
- /**
123
- * @title: 获取所有队列状态
124
- * @description: 获取所有任务队列的执行状态概览
125
- * @return {object} 所有队列的状态信息
126
- */
127
- getAllQueuesStatus(): any;
128
- }
@@ -1,61 +0,0 @@
1
- /**
2
- * 定时任务示例代码
3
- * 本文件展示了如何使用定时任务功能
4
- *
5
- * 重要提示:
6
- * - 定时任务必须添加到 'scheduledTasks' 模块才能生效
7
- * - 在其他模块中,scheduled 配置会被忽略,任务将作为普通任务立即执行
8
- * - 这是为了性能优化,避免在所有模块中检查定时任务配置
9
- */
10
- import { TasksManager } from './index';
11
- /**
12
- * 示例1:创建一次性定时任务
13
- * 在特定时间点执行一次
14
- *
15
- * 注意:定时任务必须添加到 'scheduledTasks' 模块才能生效
16
- */
17
- export declare function createOnceScheduledTask(tasksManager: TasksManager): void;
18
- /**
19
- * 示例2:创建每日重复的定时任务
20
- * 每天在固定时间执行
21
- */
22
- export declare function createDailyScheduledTask(tasksManager: TasksManager): void;
23
- /**
24
- * 示例3:创建带结束时间的重复任务
25
- * 在特定时间段内重复执行
26
- */
27
- export declare function createLimitedRepeatTask(tasksManager: TasksManager): void;
28
- /**
29
- * 示例4:创建多个时间点的任务
30
- * 在一天中的多个时间点分别执行
31
- */
32
- export declare function createMultiTimeTask(tasksManager: TasksManager): void;
33
- /**
34
- * 示例5:创建每周重复任务
35
- * 每周一早上9点执行周报
36
- */
37
- export declare function createWeeklyTask(tasksManager: TasksManager): void;
38
- /**
39
- * 示例6:创建每月重复任务
40
- * 每月1号生成月报
41
- */
42
- export declare function createMonthlyTask(tasksManager: TasksManager): void;
43
- /**
44
- * 示例7:查询和管理定时任务
45
- */
46
- export declare function manageScheduledTasks(tasksManager: TasksManager): void;
47
- /**
48
- * 完整使用示例
49
- */
50
- export declare function fullExample(app: any): void;
51
- declare const _default: {
52
- createOnceScheduledTask: typeof createOnceScheduledTask;
53
- createDailyScheduledTask: typeof createDailyScheduledTask;
54
- createLimitedRepeatTask: typeof createLimitedRepeatTask;
55
- createMultiTimeTask: typeof createMultiTimeTask;
56
- createWeeklyTask: typeof createWeeklyTask;
57
- createMonthlyTask: typeof createMonthlyTask;
58
- manageScheduledTasks: typeof manageScheduledTasks;
59
- fullExample: typeof fullExample;
60
- };
61
- export default _default;
@@ -1,100 +0,0 @@
1
- export declare type TaskRunStatus = "pending" | "in-progress" | "success" | "failure";
2
- export interface Task {
3
- id?: string;
4
- type?: "local" | "cloud";
5
- retries?: number;
6
- maxRetries?: number;
7
- status?: TaskRunStatus;
8
- action: string;
9
- payload: any;
10
- beforeAction?: string;
11
- beforePayload?: any;
12
- afterAction?: string;
13
- afterPayload?: any;
14
- polling?: {
15
- interval?: number;
16
- };
17
- pollingResult?: {
18
- count: number;
19
- timerId?: any;
20
- };
21
- scheduled?: {
22
- executeAt: string | string[];
23
- repeat?: boolean;
24
- repeatType?: 'daily' | 'weekly' | 'monthly' | 'yearly';
25
- repeatInterval?: number;
26
- endAt?: string;
27
- };
28
- scheduledResult?: {
29
- count: number;
30
- timerId?: any;
31
- nextExecuteTime?: string;
32
- };
33
- manual?: boolean;
34
- destroy?: boolean;
35
- [key: string]: any;
36
- }
37
- export interface TaskConfig {
38
- tasks: Task[];
39
- }
40
- declare type TaskModuleName = string;
41
- declare type TaskQueueName = string;
42
- declare type TaskStatus = "uncompleted" | "completed";
43
- export interface TaskQueue {
44
- status: TaskStatus;
45
- tasks: Task[];
46
- isRunning?: boolean;
47
- progress?: {
48
- total: number;
49
- completed: number;
50
- failed: number;
51
- inProgress: number;
52
- };
53
- lastRunAt?: string;
54
- }
55
- export interface RunTaskParams {
56
- module: TaskModuleName;
57
- queueId: TaskQueueName;
58
- callback?: () => void;
59
- }
60
- export interface DeleteTaskParams {
61
- module: TaskModuleName;
62
- queueId: TaskQueueName;
63
- taskId: string;
64
- }
65
- export interface AddTaskParams {
66
- module: TaskModuleName;
67
- queueId: TaskQueueName;
68
- tasks: Task[];
69
- }
70
- export interface AddTaskDataParams {
71
- module: TaskModuleName;
72
- queueId: TaskQueueName;
73
- [key: string]: any;
74
- }
75
- export interface TaskRunResult {
76
- status: TaskRunStatus;
77
- [key: string]: any;
78
- }
79
- /**
80
- * 任务模块
81
- * 注意:'scheduledTasks' 是保留的模块名,专门用于定时任务
82
- * 在其他模块中,scheduled 配置会被忽略,任务将作为普通任务执行
83
- */
84
- export interface TasksModule {
85
- [key: TaskModuleName]: {
86
- [key: TaskQueueName]: {
87
- status: TaskStatus;
88
- tasks: Task[];
89
- isRunning?: boolean;
90
- progress?: {
91
- total: number;
92
- completed: number;
93
- failed: number;
94
- inProgress: number;
95
- };
96
- lastRunAt?: string;
97
- };
98
- };
99
- }
100
- export {};