@pisell/core 1.0.28 → 1.0.30

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.
@@ -0,0 +1,91 @@
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;
@@ -0,0 +1,46 @@
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>;
@@ -10,6 +10,7 @@ function _asyncToGenerator(fn) { return function () { var self = this, args = ar
10
10
  //@ts-ignore
11
11
  import md5 from 'js-md5';
12
12
  import { getConfig } from "./config";
13
+ import { RequestModeENUM } from "./type";
13
14
  import { getApp } from "../app";
14
15
  // 缓存池
15
16
  var CACHES = {};
@@ -27,8 +28,9 @@ var MAX_CACHE_TIME = 7 * 60 * 60 * 1000;
27
28
  var createCacheKey = function createCacheKey(url, data, cache) {
28
29
  var _getConfig = getConfig(),
29
30
  storage = _getConfig.storage;
31
+ var _data = (cache === null || cache === void 0 ? void 0 : cache.cacheKeyData) || data;
30
32
  // @ts-ignore
31
- return cache.key ? storage.createKey(cache.key) : md5("".concat(url, "_").concat(JSON.stringify(data)));
33
+ return cache.key ? storage.createKey(cache.key) : md5("".concat(url, "_").concat(JSON.stringify(_data)));
32
34
  };
33
35
 
34
36
  /**
@@ -265,6 +267,39 @@ export var setCacheData = function setCacheData(url, data, res) {
265
267
  var _key = createCacheKey(url, data, cache);
266
268
  setCache(_key, res, cache);
267
269
  };
270
+ var getIsCache = function getIsCache(config) {
271
+ // 没有传递缓存参数, 则不缓存
272
+ if (!(config !== null && config !== void 0 && config.cache) && !(config !== null && config !== void 0 && config.useCache)) {
273
+ return false;
274
+ }
275
+ var cache = (config === null || config === void 0 ? void 0 : config.cache) || {};
276
+
277
+ // 强制本地走缓存
278
+ if (cache.mode === RequestModeENUM.LOCAL) {
279
+ return true;
280
+ }
281
+
282
+ // 强制云端不走缓存
283
+ if (cache.mode === RequestModeENUM.REMOTE) {
284
+ return false;
285
+ }
286
+
287
+ // 优先本地缓存
288
+ if (cache.mode === RequestModeENUM.LOCAL_REMOTE) {
289
+ return true;
290
+ }
291
+
292
+ // 优先使用云端, 没网使用本地
293
+ if (cache.mode === RequestModeENUM.REMOTE_LOCAL) {
294
+ var _getApp;
295
+ // 判断是否有网络, 有网络就使用接口
296
+ if ((_getApp = getApp()) !== null && _getApp !== void 0 && (_getApp = _getApp.getPlugin("network")) !== null && _getApp !== void 0 && _getApp.connected) {
297
+ return false;
298
+ }
299
+ return true;
300
+ }
301
+ return true;
302
+ };
268
303
 
269
304
  /**
270
305
  * @title: 缓存函数包装器
@@ -278,13 +313,14 @@ export var setCacheData = function setCacheData(url, data, res) {
278
313
  */
279
314
  export var cacheFn = /*#__PURE__*/function () {
280
315
  var _ref4 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(props, fn) {
281
- var url, data, config, cache, _data, _config$cache;
316
+ var url, data, config, isCache, cache, _data, _config$cache;
282
317
  return _regeneratorRuntime().wrap(function _callee4$(_context4) {
283
318
  while (1) switch (_context4.prev = _context4.next) {
284
319
  case 0:
285
320
  url = props.url, data = props.data, config = props.config;
286
- if (!(config !== null && config !== void 0 && config.cache || config !== null && config !== void 0 && config.useCache)) {
287
- _context4.next = 10;
321
+ isCache = getIsCache(config);
322
+ if (!isCache) {
323
+ _context4.next = 11;
288
324
  break;
289
325
  }
290
326
  cache = config.cache;
@@ -294,12 +330,12 @@ export var cacheFn = /*#__PURE__*/function () {
294
330
  };
295
331
  }
296
332
  // 获取缓存数据
297
- _context4.next = 6;
333
+ _context4.next = 7;
298
334
  return getCacheData(url, data, cache);
299
- case 6:
335
+ case 7:
300
336
  _data = _context4.sent;
301
337
  if (!_data) {
302
- _context4.next = 10;
338
+ _context4.next = 11;
303
339
  break;
304
340
  }
305
341
  // 如果开启更新缓存执行函数
@@ -313,9 +349,9 @@ export var cacheFn = /*#__PURE__*/function () {
313
349
  }));
314
350
  }
315
351
  return _context4.abrupt("return", _data);
316
- case 10:
317
- return _context4.abrupt("return", fn(props));
318
352
  case 11:
353
+ return _context4.abrupt("return", fn(props));
354
+ case 12:
319
355
  case "end":
320
356
  return _context4.stop();
321
357
  }
@@ -0,0 +1,24 @@
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;
@@ -0,0 +1,52 @@
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 +1,10 @@
1
- export {};
1
+ export var RequestModeENUM = /*#__PURE__*/function (RequestModeENUM) {
2
+ RequestModeENUM["LOCAL"] = "local";
3
+ RequestModeENUM["REMOTE"] = "remote";
4
+ RequestModeENUM["LOCAL_REMOTE"] = "local_remote";
5
+ RequestModeENUM["REMOTE_LOCAL"] = "remote_local";
6
+ RequestModeENUM["OS_SERVER"] = "os_server";
7
+ return RequestModeENUM;
8
+ }({});
9
+
10
+ // 请求模式
@@ -0,0 +1,46 @@
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;
@@ -0,0 +1,128 @@
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: "uncompleted" | "completed";
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
+ }
@@ -0,0 +1,61 @@
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;
@@ -0,0 +1,100 @@
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 {};
@@ -0,0 +1,91 @@
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;
@@ -0,0 +1,46 @@
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>;
@@ -38,12 +38,14 @@ __export(cache_exports, {
38
38
  module.exports = __toCommonJS(cache_exports);
39
39
  var import_js_md5 = __toESM(require("js-md5"));
40
40
  var import_config = require("./config");
41
+ var import_type = require("./type");
41
42
  var import_app = require("../app");
42
43
  var CACHES = {};
43
44
  var MAX_CACHE_TIME = 7 * 60 * 60 * 1e3;
44
45
  var createCacheKey = (url, data, cache) => {
45
46
  const { storage } = (0, import_config.getConfig)();
46
- return cache.key ? storage.createKey(cache.key) : (0, import_js_md5.default)(`${url}_${JSON.stringify(data)}`);
47
+ let _data = (cache == null ? void 0 : cache.cacheKeyData) || data;
48
+ return cache.key ? storage.createKey(cache.key) : (0, import_js_md5.default)(`${url}_${JSON.stringify(_data)}`);
47
49
  };
48
50
  var setCache = async (key, data, cache) => {
49
51
  const { storage } = (0, import_config.getConfig)();
@@ -131,10 +133,34 @@ var setCacheData = (url, data, res, cache = {
131
133
  let _key = createCacheKey(url, data, cache);
132
134
  setCache(_key, res, cache);
133
135
  };
136
+ var getIsCache = (config) => {
137
+ var _a, _b;
138
+ if (!(config == null ? void 0 : config.cache) && !(config == null ? void 0 : config.useCache)) {
139
+ return false;
140
+ }
141
+ const cache = (config == null ? void 0 : config.cache) || {};
142
+ if (cache.mode === import_type.RequestModeENUM.LOCAL) {
143
+ return true;
144
+ }
145
+ if (cache.mode === import_type.RequestModeENUM.REMOTE) {
146
+ return false;
147
+ }
148
+ if (cache.mode === import_type.RequestModeENUM.LOCAL_REMOTE) {
149
+ return true;
150
+ }
151
+ if (cache.mode === import_type.RequestModeENUM.REMOTE_LOCAL) {
152
+ if ((_b = (_a = (0, import_app.getApp)()) == null ? void 0 : _a.getPlugin("network")) == null ? void 0 : _b.connected) {
153
+ return false;
154
+ }
155
+ return true;
156
+ }
157
+ return true;
158
+ };
134
159
  var cacheFn = async (props, fn) => {
135
160
  var _a;
136
161
  const { url, data, config } = props;
137
- if ((config == null ? void 0 : config.cache) || (config == null ? void 0 : config.useCache)) {
162
+ const isCache = getIsCache(config);
163
+ if (isCache) {
138
164
  let cache = config.cache;
139
165
  if (config.useCache) {
140
166
  cache = {
@@ -0,0 +1,24 @@
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;
@@ -0,0 +1,52 @@
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
+ }
@@ -2,6 +2,10 @@ var __defProp = Object.defineProperty;
2
2
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
3
  var __getOwnPropNames = Object.getOwnPropertyNames;
4
4
  var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
5
9
  var __copyProps = (to, from, except, desc) => {
6
10
  if (from && typeof from === "object" || typeof from === "function") {
7
11
  for (let key of __getOwnPropNames(from))
@@ -14,4 +18,19 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
14
18
 
15
19
  // src/request/type.ts
16
20
  var type_exports = {};
21
+ __export(type_exports, {
22
+ RequestModeENUM: () => RequestModeENUM
23
+ });
17
24
  module.exports = __toCommonJS(type_exports);
25
+ var RequestModeENUM = /* @__PURE__ */ ((RequestModeENUM2) => {
26
+ RequestModeENUM2["LOCAL"] = "local";
27
+ RequestModeENUM2["REMOTE"] = "remote";
28
+ RequestModeENUM2["LOCAL_REMOTE"] = "local_remote";
29
+ RequestModeENUM2["REMOTE_LOCAL"] = "remote_local";
30
+ RequestModeENUM2["OS_SERVER"] = "os_server";
31
+ return RequestModeENUM2;
32
+ })(RequestModeENUM || {});
33
+ // Annotate the CommonJS export names for ESM import in node:
34
+ 0 && (module.exports = {
35
+ RequestModeENUM
36
+ });
@@ -0,0 +1,46 @@
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;
@@ -0,0 +1,128 @@
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: "uncompleted" | "completed";
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
+ }
@@ -0,0 +1,61 @@
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;
@@ -0,0 +1,100 @@
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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pisell/core",
3
- "version": "1.0.28",
3
+ "version": "1.0.30",
4
4
  "sideEffects": false,
5
5
  "main": "./lib/index.js",
6
6
  "module": "./es/index.js",