@pisell/core 1.0.27 → 1.0.29
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/es/app/app.d.ts +4 -2
- package/es/request/cache.js +43 -8
- package/es/request/type.d.ts +9 -0
- package/es/request/type.js +10 -1
- package/es/tasks/index.d.ts +45 -0
- package/es/tasks/index.js +444 -101
- package/es/tasks/scheduledTasksExample.d.ts +61 -0
- package/es/tasks/scheduledTasksExample.js +351 -0
- package/es/tasks/type.d.ts +38 -0
- package/lib/app/app.d.ts +4 -2
- package/lib/request/cache.js +26 -1
- package/lib/request/type.d.ts +9 -0
- package/lib/request/type.js +19 -0
- package/lib/tasks/index.d.ts +45 -0
- package/lib/tasks/index.js +326 -77
- package/lib/tasks/scheduledTasksExample.d.ts +61 -0
- package/lib/tasks/scheduledTasksExample.js +267 -0
- package/lib/tasks/type.d.ts +38 -0
- package/package.json +1 -1
package/es/app/app.d.ts
CHANGED
|
@@ -8,8 +8,8 @@ import { MenuManager } from '../menuManager';
|
|
|
8
8
|
import LoggerManager, { LoggerOptions } from '../logger';
|
|
9
9
|
import { TasksManager } from '../tasks';
|
|
10
10
|
import IndexDBManager, { DBOptions } from '../indexDB';
|
|
11
|
-
import CMD from "../cmd";
|
|
12
|
-
import AWS from "../aws";
|
|
11
|
+
import CMD, { CMDOptions } from "../cmd";
|
|
12
|
+
import AWS, { AWSOptions } from "../aws";
|
|
13
13
|
declare global {
|
|
14
14
|
interface Window {
|
|
15
15
|
app: App;
|
|
@@ -22,6 +22,8 @@ export interface AppOptions {
|
|
|
22
22
|
history?: HistoryOptions;
|
|
23
23
|
storage?: StorageOptions;
|
|
24
24
|
locales?: LocalesOptions;
|
|
25
|
+
cmd?: CMDOptions;
|
|
26
|
+
aws?: AWSOptions;
|
|
25
27
|
getPisellos?: () => any;
|
|
26
28
|
}
|
|
27
29
|
declare class App {
|
package/es/request/cache.js
CHANGED
|
@@ -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 = {};
|
|
@@ -265,6 +266,39 @@ export var setCacheData = function setCacheData(url, data, res) {
|
|
|
265
266
|
var _key = createCacheKey(url, data, cache);
|
|
266
267
|
setCache(_key, res, cache);
|
|
267
268
|
};
|
|
269
|
+
var getIsCache = function getIsCache(config) {
|
|
270
|
+
// 没有传递缓存参数, 则不缓存
|
|
271
|
+
if (!(config !== null && config !== void 0 && config.cache) && !(config !== null && config !== void 0 && config.useCache)) {
|
|
272
|
+
return false;
|
|
273
|
+
}
|
|
274
|
+
var cache = (config === null || config === void 0 ? void 0 : config.cache) || {};
|
|
275
|
+
|
|
276
|
+
// 强制本地走缓存
|
|
277
|
+
if (cache.mode === RequestModeENUM.LOCAL) {
|
|
278
|
+
return true;
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
// 强制云端不走缓存
|
|
282
|
+
if (cache.mode === RequestModeENUM.REMOTE) {
|
|
283
|
+
return false;
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
// 优先本地缓存
|
|
287
|
+
if (cache.mode === RequestModeENUM.LOCAL_REMOTE) {
|
|
288
|
+
return true;
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
// 优先使用云端, 没网使用本地
|
|
292
|
+
if (cache.mode === RequestModeENUM.REMOTE_LOCAL) {
|
|
293
|
+
var _getApp;
|
|
294
|
+
// 判断是否有网络, 有网络就使用接口
|
|
295
|
+
if ((_getApp = getApp()) !== null && _getApp !== void 0 && (_getApp = _getApp.getPlugin("network")) !== null && _getApp !== void 0 && _getApp.connected) {
|
|
296
|
+
return false;
|
|
297
|
+
}
|
|
298
|
+
return true;
|
|
299
|
+
}
|
|
300
|
+
return true;
|
|
301
|
+
};
|
|
268
302
|
|
|
269
303
|
/**
|
|
270
304
|
* @title: 缓存函数包装器
|
|
@@ -278,13 +312,14 @@ export var setCacheData = function setCacheData(url, data, res) {
|
|
|
278
312
|
*/
|
|
279
313
|
export var cacheFn = /*#__PURE__*/function () {
|
|
280
314
|
var _ref4 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(props, fn) {
|
|
281
|
-
var url, data, config, cache, _data, _config$cache;
|
|
315
|
+
var url, data, config, isCache, cache, _data, _config$cache;
|
|
282
316
|
return _regeneratorRuntime().wrap(function _callee4$(_context4) {
|
|
283
317
|
while (1) switch (_context4.prev = _context4.next) {
|
|
284
318
|
case 0:
|
|
285
319
|
url = props.url, data = props.data, config = props.config;
|
|
286
|
-
|
|
287
|
-
|
|
320
|
+
isCache = getIsCache(config);
|
|
321
|
+
if (!isCache) {
|
|
322
|
+
_context4.next = 11;
|
|
288
323
|
break;
|
|
289
324
|
}
|
|
290
325
|
cache = config.cache;
|
|
@@ -294,12 +329,12 @@ export var cacheFn = /*#__PURE__*/function () {
|
|
|
294
329
|
};
|
|
295
330
|
}
|
|
296
331
|
// 获取缓存数据
|
|
297
|
-
_context4.next =
|
|
332
|
+
_context4.next = 7;
|
|
298
333
|
return getCacheData(url, data, cache);
|
|
299
|
-
case
|
|
334
|
+
case 7:
|
|
300
335
|
_data = _context4.sent;
|
|
301
336
|
if (!_data) {
|
|
302
|
-
_context4.next =
|
|
337
|
+
_context4.next = 11;
|
|
303
338
|
break;
|
|
304
339
|
}
|
|
305
340
|
// 如果开启更新缓存执行函数
|
|
@@ -313,9 +348,9 @@ export var cacheFn = /*#__PURE__*/function () {
|
|
|
313
348
|
}));
|
|
314
349
|
}
|
|
315
350
|
return _context4.abrupt("return", _data);
|
|
316
|
-
case 10:
|
|
317
|
-
return _context4.abrupt("return", fn(props));
|
|
318
351
|
case 11:
|
|
352
|
+
return _context4.abrupt("return", fn(props));
|
|
353
|
+
case 12:
|
|
319
354
|
case "end":
|
|
320
355
|
return _context4.stop();
|
|
321
356
|
}
|
package/es/request/type.d.ts
CHANGED
|
@@ -19,11 +19,20 @@ export interface RequestConfig {
|
|
|
19
19
|
[key: string]: any;
|
|
20
20
|
};
|
|
21
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;
|
|
22
30
|
export interface CacheProps {
|
|
23
31
|
key?: string;
|
|
24
32
|
type?: CacheType;
|
|
25
33
|
updateCache?: boolean;
|
|
26
34
|
cacheUpdateChange?: (data: any) => void;
|
|
35
|
+
mode?: RequestModeType;
|
|
27
36
|
}
|
|
28
37
|
export interface RequestSetting {
|
|
29
38
|
abort?: boolean;
|
package/es/request/type.js
CHANGED
|
@@ -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
|
+
// 请求模式
|
package/es/tasks/index.d.ts
CHANGED
|
@@ -37,6 +37,20 @@ export declare class TasksManager {
|
|
|
37
37
|
* @param {NodeJS.Timeout} timerId
|
|
38
38
|
*/
|
|
39
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;
|
|
40
54
|
/**
|
|
41
55
|
* @title: 启动轮询
|
|
42
56
|
* @description: 根据轮询间隔定期执行任务
|
|
@@ -75,9 +89,40 @@ export declare class TasksManager {
|
|
|
75
89
|
addTask(payload: AddTaskParams): void;
|
|
76
90
|
private updateTask;
|
|
77
91
|
private updateQueueStatus;
|
|
92
|
+
/**
|
|
93
|
+
* @title: 更新队列运行状态
|
|
94
|
+
* @description: 标记队列是否正在执行
|
|
95
|
+
*/
|
|
96
|
+
private updateQueueRunningState;
|
|
97
|
+
private setTasksData;
|
|
78
98
|
private setTasks;
|
|
79
99
|
clearAllTaskTimer(tasks: Task[]): void;
|
|
80
100
|
clearTasks(payload: RunTaskParams): void;
|
|
81
101
|
clearAllTasks(): void;
|
|
82
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;
|
|
83
128
|
}
|