@pisell/core 1.0.41 → 1.0.42

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,19 @@
1
+ import APP from '../app';
2
+ import { Application, ApplicationData } from './application';
3
+ export * from "./application";
4
+ export declare class ApplicationManager {
5
+ applicationList: Application[];
6
+ protected app: APP;
7
+ applications: Map<string, Application>;
8
+ constructor(applicationList: Application[], app: APP);
9
+ init(applicationList: Application[] | ApplicationData[]): Promise<unknown>;
10
+ add(application: Application): Promise<void>;
11
+ get(appName: Application['name']): Application | undefined;
12
+ remove(appName: Application['name']): void;
13
+ load(): Promise<void>;
14
+ /**
15
+ * 循环所有的应用, 找出所有的components进行渲染
16
+ * @returns
17
+ */
18
+ getAllComponents(): any[];
19
+ }
@@ -0,0 +1,23 @@
1
+ import { LocationDescriptor } from "history";
2
+ import type { History as HistoryType } from "history";
3
+ import { useHistory, useLocation, useParams } from "react-router-dom";
4
+ import App from "../app";
5
+ export interface HistoryOptions {
6
+ basename?: string;
7
+ interceptor?: (path: LocationDescriptor<unknown>, state: any, next: () => void) => void;
8
+ }
9
+ export declare class History {
10
+ instance: HistoryType<unknown>;
11
+ useHistory: typeof useHistory;
12
+ useLocation: typeof useLocation;
13
+ useParams: typeof useParams;
14
+ app: App;
15
+ interceptor?: (path: LocationDescriptor<unknown>, state: unknown, next: () => void) => void;
16
+ constructor(app: App, options?: HistoryOptions);
17
+ push: HistoryType["push"];
18
+ replace: HistoryType["replace"];
19
+ reload: () => void;
20
+ reloadTo: (path: string) => void;
21
+ externalPage: (path: string) => void;
22
+ goLogin: () => any;
23
+ }
package/lib/index.d.ts ADDED
@@ -0,0 +1,7 @@
1
+ export { default as request } from './request';
2
+ export { default as hooks } from './hooks';
3
+ export { default as models } from './models';
4
+ export { default as pubsub } from './pubsub';
5
+ export { default as socket } from './socket';
6
+ export * from './applicationManager';
7
+ export * from './app';
@@ -52,7 +52,7 @@ var IndexDBManager = class _IndexDBManager {
52
52
  // 内存存储:每个 store 使用一个 Map,key 为主键,value 为数据
53
53
  memoryStorage = /* @__PURE__ */ new Map();
54
54
  // 操作超时时间(毫秒)
55
- timeout = 5e3;
55
+ timeout = 1e4;
56
56
  /**
57
57
  * 创建 IndexDBManager 实例
58
58
  * @param {DBOptions} options - 数据库配置选项
@@ -63,7 +63,7 @@ var IndexDBManager = class _IndexDBManager {
63
63
  this.version = options.version;
64
64
  this.stores = options.stores;
65
65
  this.useIndexDB = _IndexDBManager.isSupported();
66
- this.timeout = options.timeout ?? 5e3;
66
+ this.timeout = options.timeout ?? 1e4;
67
67
  if (!this.useIndexDB) {
68
68
  this.stores.forEach((store) => {
69
69
  this.memoryStorage.set(store.name, /* @__PURE__ */ new Map());
@@ -200,11 +200,6 @@ var IndexDBManager = class _IndexDBManager {
200
200
  }
201
201
  const uuid = `[ IndexDB ] ADD: - ${storeName} - ${(0, import_dayjs.default)().valueOf()}`;
202
202
  if (log) {
203
- this.app.logger.addLog({
204
- type: "info",
205
- title: uuid,
206
- metadata: { msg: "添加数据前", data }
207
- });
208
203
  }
209
204
  return this.withTimeout(
210
205
  (async () => {
@@ -221,17 +216,7 @@ var IndexDBManager = class _IndexDBManager {
221
216
  try {
222
217
  await this.db.table(storeName).add(data);
223
218
  if (log) {
224
- this.app.logger.addLog({
225
- type: "info",
226
- title: uuid,
227
- metadata: { msg: "添加数据成功" }
228
- });
229
219
  console.log("✅ 添加事务完成");
230
- this.app.logger.addLog({
231
- type: "info",
232
- title: uuid,
233
- metadata: { msg: "事务完成" }
234
- });
235
220
  }
236
221
  return data;
237
222
  } catch (error) {
@@ -285,11 +270,6 @@ var IndexDBManager = class _IndexDBManager {
285
270
  async get(storeName, key, log = false) {
286
271
  const uuid = `[ IndexDB ] GET: - ${storeName} - ${key} - ${(0, import_dayjs.default)().valueOf()}`;
287
272
  if (log) {
288
- this.app.logger.addLog({
289
- type: "info",
290
- title: uuid,
291
- metadata: { msg: "获取数据前" }
292
- });
293
273
  }
294
274
  if (!this.useIndexDB) {
295
275
  const memStore = this.getMemoryStore(storeName);
@@ -310,16 +290,6 @@ var IndexDBManager = class _IndexDBManager {
310
290
  try {
311
291
  const result = await this.db.table(storeName).get(key);
312
292
  if (log) {
313
- this.app.logger.addLog({
314
- type: "info",
315
- title: uuid,
316
- metadata: { msg: "获取成功" }
317
- });
318
- this.app.logger.addLog({
319
- type: "info",
320
- title: uuid,
321
- metadata: { msg: "事务完成" }
322
- });
323
293
  }
324
294
  return result ?? null;
325
295
  } catch (error) {
@@ -355,11 +325,6 @@ var IndexDBManager = class _IndexDBManager {
355
325
  }
356
326
  const uuid = `[ IndexDB ] UPDATE: - ${storeName} - ${(0, import_dayjs.default)().valueOf()}`;
357
327
  if (log) {
358
- this.app.logger.addLog({
359
- type: "info",
360
- title: uuid,
361
- metadata: { msg: "更新数据前", data }
362
- });
363
328
  }
364
329
  return this.withTimeout(
365
330
  (async () => {
@@ -376,17 +341,6 @@ var IndexDBManager = class _IndexDBManager {
376
341
  try {
377
342
  await this.db.table(storeName).put(data);
378
343
  if (log) {
379
- this.app.logger.addLog({
380
- type: "info",
381
- title: uuid,
382
- metadata: { msg: "数据更新完成" }
383
- });
384
- console.log("✅ 事务完成");
385
- this.app.logger.addLog({
386
- type: "info",
387
- title: uuid,
388
- metadata: { msg: "事务完成" }
389
- });
390
344
  }
391
345
  return data;
392
346
  } catch (error) {
@@ -236,8 +236,16 @@ var LoggerManager = class {
236
236
  type: "error",
237
237
  title: "存储日志到AWS失败",
238
238
  metadata: {
239
- error: JSON.stringify(error),
240
- indexDBError: JSON.stringify(indexDBError)
239
+ error: {
240
+ name: error == null ? void 0 : error.name,
241
+ message: error == null ? void 0 : error.message,
242
+ stack: error == null ? void 0 : error.stack
243
+ },
244
+ indexDBError: {
245
+ name: indexDBError == null ? void 0 : indexDBError.name,
246
+ message: indexDBError == null ? void 0 : indexDBError.message,
247
+ stack: indexDBError == null ? void 0 : indexDBError.stack
248
+ }
241
249
  }
242
250
  });
243
251
  console.error("存储日志到IndexDB也失败:", indexDBError);
@@ -266,7 +274,11 @@ var LoggerManager = class {
266
274
  type: "error",
267
275
  title: "存储IndexDB日志到AWS失败",
268
276
  metadata: {
269
- error: JSON.stringify(error)
277
+ error: {
278
+ name: error == null ? void 0 : error.name,
279
+ message: error == null ? void 0 : error.message,
280
+ stack: error == null ? void 0 : error.stack
281
+ }
270
282
  }
271
283
  });
272
284
  throw error;
@@ -0,0 +1,28 @@
1
+ import React from 'react';
2
+ import App from '../app';
3
+ export interface MenuItem {
4
+ key: string;
5
+ label: string;
6
+ path: string;
7
+ children?: MenuItem[];
8
+ icon?: string | React.ReactNode;
9
+ hide?: boolean;
10
+ }
11
+ export declare class MenuManager {
12
+ private menuItems;
13
+ private menuMaps;
14
+ private app;
15
+ useMenu: () => import("./hooks").MenuContextType;
16
+ MenuProvider: React.FC<{
17
+ children: React.ReactNode;
18
+ menus: MenuItem[];
19
+ }>;
20
+ constructor(items: MenuItem[], app: App);
21
+ set(items: MenuItem[]): void;
22
+ getMenus(): MenuItem[];
23
+ getMenuMaps(): void;
24
+ findMenuItemByPath(items: MenuItem[], path: string): MenuItem | null;
25
+ findParent(items: MenuItem[], key: string, parent?: MenuItem | null): MenuItem | null;
26
+ getShowChildren(items: MenuItem[]): MenuItem[];
27
+ findMenuItemByKey(items: MenuItem[], key: string): MenuItem | null;
28
+ }
@@ -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>;
@@ -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
+ }
@@ -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;
@@ -20,7 +20,7 @@ export declare class RouterManager {
20
20
  get(name: string): RouteType;
21
21
  has(name: string): boolean;
22
22
  remove(name: string): void;
23
- renderComponent(item: RouteType, children?: React.ReactNode): string | number | boolean | React.ReactFragment | JSX.Element | null | undefined;
23
+ renderComponent(item: RouteType, children?: React.ReactNode): string | number | boolean | JSX.Element | React.ReactFragment | null | undefined;
24
24
  getPageByRoute(route: string): ApplicationInterface | undefined;
25
25
  getRouterComponent({ fallback }: {
26
26
  fallback?: React.ReactNode;
@@ -0,0 +1,127 @@
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
+ */
38
+ private clearTaskTimer;
39
+ /**
40
+ * @title: 计算下一次执行时间
41
+ * @description: 根据定时任务配置计算下一次执行时间
42
+ * @param {Task} task
43
+ * @return {string | null} 下一次执行时间
44
+ */
45
+ private calculateNextExecuteTime;
46
+ /**
47
+ * @title: 启动定时任务
48
+ * @description: 在特定时间点执行任务(仅在 scheduledTasks 模块中生效)
49
+ * @param {Task} task
50
+ * @return {*}
51
+ */
52
+ private startScheduledTask;
53
+ /**
54
+ * @title: 启动轮询
55
+ * @description: 根据轮询间隔定期执行任务
56
+ * @param {Task} task
57
+ * @return {*}
58
+ */
59
+ private startPolling;
60
+ /**
61
+ * @title: 创建任务数据
62
+ * @description:
63
+ * @param {Partial} payload
64
+ * @return {*}
65
+ * @Author: zhiwei.Wang
66
+ * @Date: 2024-09-26 13:54
67
+ */
68
+ private createTaskData;
69
+ private getTaskQueue;
70
+ private timeout;
71
+ /**
72
+ * @title: 执行任务队列
73
+ * @description:
74
+ * @return {*}
75
+ * @Author: zhiwei.Wang
76
+ * @Date: 2024-09-26 13:52
77
+ */
78
+ run(payload: RunTaskParams): Promise<void>;
79
+ deleteTask(payload: DeleteTaskParams): void;
80
+ /**
81
+ * @title: 重试任务
82
+ * @description:
83
+ * @return {*}
84
+ * @Author: zhiwei.Wang
85
+ * @Date: 2024-09-26 13:53
86
+ */
87
+ retryTask(payload: RunTaskParams): void;
88
+ addTask(payload: AddTaskParams): void;
89
+ private updateTask;
90
+ private updateQueueStatus;
91
+ /**
92
+ * @title: 更新队列运行状态
93
+ * @description: 标记队列是否正在执行
94
+ */
95
+ private updateQueueRunningState;
96
+ private setTasksData;
97
+ private setTasks;
98
+ clearAllTaskTimer(tasks: Task[]): void;
99
+ clearTasks(payload: RunTaskParams): void;
100
+ clearAllTasks(): void;
101
+ watchTask(callback: (taskModule: TasksModule) => void): void;
102
+ /**
103
+ * @title: 获取队列执行状态
104
+ * @description: 获取指定队列的执行状态和进度信息
105
+ * @param {string} module - 模块名
106
+ * @param {string} queueId - 队列ID
107
+ * @return {object} 队列状态信息
108
+ */
109
+ getQueueStatus(module: string, queueId: string): {
110
+ isRunning: boolean;
111
+ status: "completed" | "uncompleted";
112
+ progress: {
113
+ total: number;
114
+ completed: number;
115
+ failed: number;
116
+ inProgress: number;
117
+ };
118
+ lastRunAt: string | null;
119
+ tasksCount: number;
120
+ } | null;
121
+ /**
122
+ * @title: 获取所有队列状态
123
+ * @description: 获取所有任务队列的执行状态概览
124
+ * @return {object} 所有队列的状态信息
125
+ */
126
+ getAllQueuesStatus(): any;
127
+ }
@@ -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 {};