@pisell/core 1.0.30 → 1.1.1
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 +3 -7
- package/es/app/app.js +0 -3
- package/es/indexDB/index.d.ts +6 -3
- package/es/indexDB/index.js +265 -41
- package/es/request/cache.d.ts +1 -1
- package/es/request/cache.js +29 -81
- package/es/request/index.d.ts +3 -3
- package/es/request/index.js +1 -14
- package/es/request/type.d.ts +0 -11
- package/es/request/type.js +1 -10
- package/es/request/utils.js +1 -1
- package/es/tasks/index.d.ts +0 -45
- package/es/tasks/index.js +101 -444
- package/es/tasks/type.d.ts +0 -38
- package/lib/app/app.d.ts +3 -7
- package/lib/app/app.js +0 -3
- package/lib/indexDB/index.d.ts +6 -3
- package/lib/indexDB/index.js +218 -21
- package/lib/request/cache.d.ts +1 -1
- package/lib/request/cache.js +5 -42
- package/lib/request/index.d.ts +3 -3
- package/lib/request/index.js +1 -10
- package/lib/request/type.d.ts +0 -11
- package/lib/request/type.js +0 -19
- package/lib/request/utils.js +1 -1
- package/lib/tasks/index.d.ts +0 -45
- package/lib/tasks/index.js +77 -326
- package/lib/tasks/type.d.ts +0 -38
- package/package.json +1 -1
- package/es/tasks/scheduledTasksExample.d.ts +0 -61
- package/es/tasks/scheduledTasksExample.js +0 -351
- package/lib/tasks/scheduledTasksExample.d.ts +0 -61
- package/lib/tasks/scheduledTasksExample.js +0 -267
package/es/request/cache.js
CHANGED
|
@@ -10,7 +10,6 @@ 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";
|
|
14
13
|
import { getApp } from "../app";
|
|
15
14
|
// 缓存池
|
|
16
15
|
var CACHES = {};
|
|
@@ -28,9 +27,8 @@ var MAX_CACHE_TIME = 7 * 60 * 60 * 1000;
|
|
|
28
27
|
var createCacheKey = function createCacheKey(url, data, cache) {
|
|
29
28
|
var _getConfig = getConfig(),
|
|
30
29
|
storage = _getConfig.storage;
|
|
31
|
-
var _data = (cache === null || cache === void 0 ? void 0 : cache.cacheKeyData) || data;
|
|
32
30
|
// @ts-ignore
|
|
33
|
-
return cache.key ? storage.createKey(cache.key) : md5("".concat(url, "_").concat(JSON.stringify(
|
|
31
|
+
return cache.key ? storage.createKey(cache.key) : md5("".concat(url, "_").concat(JSON.stringify(data)));
|
|
34
32
|
};
|
|
35
33
|
|
|
36
34
|
/**
|
|
@@ -126,26 +124,20 @@ var getCache = /*#__PURE__*/function () {
|
|
|
126
124
|
case 0:
|
|
127
125
|
_getConfig3 = getConfig(), storage = _getConfig3.storage; // 如果 当前时间 - 数据缓存时间 小于 超时时间, 则数据正常.
|
|
128
126
|
if (!(cache.type === 'memory')) {
|
|
129
|
-
_context2.next =
|
|
130
|
-
break;
|
|
131
|
-
}
|
|
132
|
-
if (CACHES[key]) {
|
|
133
|
-
_context2.next = 4;
|
|
127
|
+
_context2.next = 6;
|
|
134
128
|
break;
|
|
135
129
|
}
|
|
136
|
-
return _context2.abrupt("return", null);
|
|
137
|
-
case 4:
|
|
138
130
|
if (!getIsEffectiveTime(CACHES[key].time)) {
|
|
139
|
-
_context2.next =
|
|
131
|
+
_context2.next = 4;
|
|
140
132
|
break;
|
|
141
133
|
}
|
|
142
134
|
return _context2.abrupt("return", CACHES[key].data);
|
|
143
|
-
case
|
|
144
|
-
_context2.next =
|
|
135
|
+
case 4:
|
|
136
|
+
_context2.next = 21;
|
|
145
137
|
break;
|
|
146
|
-
case
|
|
138
|
+
case 6:
|
|
147
139
|
if (!(cache.type === 'storage')) {
|
|
148
|
-
_context2.next =
|
|
140
|
+
_context2.next = 13;
|
|
149
141
|
break;
|
|
150
142
|
}
|
|
151
143
|
storageDetail = storage.getStorage(key) || "";
|
|
@@ -153,35 +145,35 @@ var getCache = /*#__PURE__*/function () {
|
|
|
153
145
|
storageDetail = JSON.parse(storageDetail);
|
|
154
146
|
}
|
|
155
147
|
if (!getIsEffectiveTime(storageDetail.time)) {
|
|
156
|
-
_context2.next =
|
|
148
|
+
_context2.next = 11;
|
|
157
149
|
break;
|
|
158
150
|
}
|
|
159
151
|
return _context2.abrupt("return", (_storageDetail = storageDetail) === null || _storageDetail === void 0 ? void 0 : _storageDetail.data);
|
|
160
|
-
case
|
|
161
|
-
_context2.next =
|
|
152
|
+
case 11:
|
|
153
|
+
_context2.next = 21;
|
|
162
154
|
break;
|
|
163
|
-
case
|
|
155
|
+
case 13:
|
|
164
156
|
if (!(cache.type === 'indexDB')) {
|
|
165
|
-
_context2.next =
|
|
157
|
+
_context2.next = 21;
|
|
166
158
|
break;
|
|
167
159
|
}
|
|
168
160
|
app = getApp();
|
|
169
161
|
if (!app.dbManager) {
|
|
170
|
-
_context2.next =
|
|
162
|
+
_context2.next = 21;
|
|
171
163
|
break;
|
|
172
164
|
}
|
|
173
|
-
_context2.next =
|
|
165
|
+
_context2.next = 18;
|
|
174
166
|
return app.dbManager.get('requests', key);
|
|
175
|
-
case
|
|
167
|
+
case 18:
|
|
176
168
|
indexDBDetail = _context2.sent;
|
|
177
169
|
if (!indexDBDetail) {
|
|
178
|
-
_context2.next =
|
|
170
|
+
_context2.next = 21;
|
|
179
171
|
break;
|
|
180
172
|
}
|
|
181
173
|
return _context2.abrupt("return", indexDBDetail === null || indexDBDetail === void 0 ? void 0 : indexDBDetail.data);
|
|
182
|
-
case
|
|
174
|
+
case 21:
|
|
183
175
|
return _context2.abrupt("return", null);
|
|
184
|
-
case
|
|
176
|
+
case 22:
|
|
185
177
|
case "end":
|
|
186
178
|
return _context2.stop();
|
|
187
179
|
}
|
|
@@ -259,47 +251,11 @@ export var getCacheData = /*#__PURE__*/function () {
|
|
|
259
251
|
* @return {*}
|
|
260
252
|
* @Author: zhiwei.Wang
|
|
261
253
|
*/
|
|
262
|
-
export var setCacheData = function setCacheData(url, data, res) {
|
|
263
|
-
var cache = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {
|
|
264
|
-
type: 'memory'
|
|
265
|
-
};
|
|
254
|
+
export var setCacheData = function setCacheData(url, data, res, cache) {
|
|
266
255
|
// 创建缓存key
|
|
267
256
|
var _key = createCacheKey(url, data, cache);
|
|
268
257
|
setCache(_key, res, cache);
|
|
269
258
|
};
|
|
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
|
-
};
|
|
303
259
|
|
|
304
260
|
/**
|
|
305
261
|
* @title: 缓存函数包装器
|
|
@@ -313,45 +269,37 @@ var getIsCache = function getIsCache(config) {
|
|
|
313
269
|
*/
|
|
314
270
|
export var cacheFn = /*#__PURE__*/function () {
|
|
315
271
|
var _ref4 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(props, fn) {
|
|
316
|
-
var url, data, config,
|
|
272
|
+
var url, data, config, _data, _config$cache;
|
|
317
273
|
return _regeneratorRuntime().wrap(function _callee4$(_context4) {
|
|
318
274
|
while (1) switch (_context4.prev = _context4.next) {
|
|
319
275
|
case 0:
|
|
320
276
|
url = props.url, data = props.data, config = props.config;
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
_context4.next = 11;
|
|
277
|
+
if (!(config !== null && config !== void 0 && config.cache)) {
|
|
278
|
+
_context4.next = 8;
|
|
324
279
|
break;
|
|
325
280
|
}
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
type: 'memory'
|
|
330
|
-
};
|
|
331
|
-
}
|
|
332
|
-
// 获取缓存数据
|
|
333
|
-
_context4.next = 7;
|
|
334
|
-
return getCacheData(url, data, cache);
|
|
335
|
-
case 7:
|
|
281
|
+
_context4.next = 4;
|
|
282
|
+
return getCacheData(url, data, config.cache);
|
|
283
|
+
case 4:
|
|
336
284
|
_data = _context4.sent;
|
|
337
285
|
if (!_data) {
|
|
338
|
-
_context4.next =
|
|
286
|
+
_context4.next = 8;
|
|
339
287
|
break;
|
|
340
288
|
}
|
|
341
289
|
// 如果开启更新缓存执行函数
|
|
342
290
|
if ((_config$cache = config.cache) !== null && _config$cache !== void 0 && _config$cache.updateCache) {
|
|
343
291
|
fn(_objectSpread(_objectSpread({}, props), {}, {
|
|
344
292
|
config: _objectSpread(_objectSpread({}, props.config), {}, {
|
|
345
|
-
cache: _objectSpread(_objectSpread({}, cache), {}, {
|
|
293
|
+
cache: _objectSpread(_objectSpread({}, props.config.cache), {}, {
|
|
346
294
|
updateCache: false
|
|
347
295
|
})
|
|
348
296
|
})
|
|
349
297
|
}));
|
|
350
298
|
}
|
|
351
299
|
return _context4.abrupt("return", _data);
|
|
352
|
-
case
|
|
300
|
+
case 8:
|
|
353
301
|
return _context4.abrupt("return", fn(props));
|
|
354
|
-
case
|
|
302
|
+
case 9:
|
|
355
303
|
case "end":
|
|
356
304
|
return _context4.stop();
|
|
357
305
|
}
|
package/es/request/index.d.ts
CHANGED
|
@@ -5,19 +5,19 @@ export declare const createRequest: (props: RequestWrapperProps) => Promise<unkn
|
|
|
5
5
|
* @param props
|
|
6
6
|
* @returns
|
|
7
7
|
*/
|
|
8
|
-
export declare const request: (props: RequestWrapperProps) => any
|
|
8
|
+
export declare const request: (props: RequestWrapperProps) => Promise<any>;
|
|
9
9
|
export declare const get: (url: RequestWrapperProps["url"], data: RequestWrapperProps["data"], config: RequestWrapperProps["config"]) => Promise<any>;
|
|
10
10
|
export declare const post: (url: RequestWrapperProps["url"], data: RequestWrapperProps["data"], config: RequestWrapperProps["config"]) => Promise<any>;
|
|
11
11
|
export declare const put: (url: RequestWrapperProps["url"], data: RequestWrapperProps["data"], config: RequestWrapperProps["config"]) => Promise<any>;
|
|
12
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
|
|
13
|
+
export declare const custom: (url: RequestWrapperProps["url"], config: RequestWrapperProps["config"]) => Promise<any>;
|
|
14
14
|
export * from "./type";
|
|
15
15
|
declare const _default: {
|
|
16
16
|
get: (url: string, data: any, config: import("./type").RequestSetting | undefined) => Promise<any>;
|
|
17
17
|
post: (url: string, data: any, config: import("./type").RequestSetting | undefined) => Promise<any>;
|
|
18
18
|
put: (url: string, data: any, config: import("./type").RequestSetting | undefined) => Promise<any>;
|
|
19
19
|
remove: (url: string, data: any, config: import("./type").RequestSetting | undefined) => Promise<any>;
|
|
20
|
-
custom: (url: string, config: import("./type").RequestSetting | undefined) => any
|
|
20
|
+
custom: (url: string, config: import("./type").RequestSetting | undefined) => Promise<any>;
|
|
21
21
|
setConfig: (newConfig: Partial<RequestConfig>) => void;
|
|
22
22
|
getConfig: () => RequestConfig;
|
|
23
23
|
};
|
package/es/request/index.js
CHANGED
|
@@ -13,7 +13,6 @@ import { cacheFn } from "./cache";
|
|
|
13
13
|
import { interceptorsRequest, interceptorsResponse, interceptorsRequestError, interceptorsResponseError, requestCallback } from "./utils";
|
|
14
14
|
import axios from "axios";
|
|
15
15
|
import { getConfig, setConfig } from "./config";
|
|
16
|
-
import { getApp } from "../app";
|
|
17
16
|
// 实例
|
|
18
17
|
var axiosInstance = axios.create(axiosConfig);
|
|
19
18
|
|
|
@@ -60,25 +59,13 @@ export var createRequest = function createRequest(props) {
|
|
|
60
59
|
*/
|
|
61
60
|
export var request = function request(props) {
|
|
62
61
|
var config = props.config,
|
|
63
|
-
url = props.url
|
|
64
|
-
method = props.method;
|
|
62
|
+
url = props.url;
|
|
65
63
|
// 请求防抖
|
|
66
64
|
if (config !== null && config !== void 0 && config.abort) {
|
|
67
65
|
var signal = createSignal(config.abort, url);
|
|
68
66
|
config.signal = signal;
|
|
69
67
|
}
|
|
70
68
|
|
|
71
|
-
// 使用os服务层
|
|
72
|
-
if (config !== null && config !== void 0 && config.osServer) {
|
|
73
|
-
var _app$getPisellos, _pisellos$server, _pisellos$server$hasR;
|
|
74
|
-
var app = getApp();
|
|
75
|
-
var pisellos = (_app$getPisellos = app.getPisellos) === null || _app$getPisellos === void 0 ? void 0 : _app$getPisellos.call(app);
|
|
76
|
-
if (pisellos !== null && pisellos !== void 0 && pisellos.server && pisellos !== null && pisellos !== void 0 && (_pisellos$server = pisellos.server) !== null && _pisellos$server !== void 0 && (_pisellos$server$hasR = _pisellos$server.hasRoute) !== null && _pisellos$server$hasR !== void 0 && _pisellos$server$hasR.call(_pisellos$server, method, url)) {
|
|
77
|
-
var _pisellos$server2, _pisellos$server2$han;
|
|
78
|
-
return pisellos === null || pisellos === void 0 || (_pisellos$server2 = pisellos.server) === null || _pisellos$server2 === void 0 || (_pisellos$server2$han = _pisellos$server2.handleRoute) === null || _pisellos$server2$han === void 0 ? void 0 : _pisellos$server2$han.call(_pisellos$server2, method, url, props);
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
|
|
82
69
|
// 缓存函数
|
|
83
70
|
return cacheFn(props, createRequest);
|
|
84
71
|
};
|
package/es/request/type.d.ts
CHANGED
|
@@ -19,21 +19,11 @@ 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;
|
|
30
22
|
export interface CacheProps {
|
|
31
23
|
key?: string;
|
|
32
24
|
type?: CacheType;
|
|
33
25
|
updateCache?: boolean;
|
|
34
26
|
cacheUpdateChange?: (data: any) => void;
|
|
35
|
-
mode?: RequestModeType;
|
|
36
|
-
cacheKeyData?: any;
|
|
37
27
|
}
|
|
38
28
|
export interface RequestSetting {
|
|
39
29
|
abort?: boolean;
|
|
@@ -41,7 +31,6 @@ export interface RequestSetting {
|
|
|
41
31
|
cache?: CacheProps;
|
|
42
32
|
signal?: any;
|
|
43
33
|
token?: string;
|
|
44
|
-
osServer?: boolean;
|
|
45
34
|
[key: string]: any;
|
|
46
35
|
}
|
|
47
36
|
export interface RequestWrapperProps {
|
package/es/request/type.js
CHANGED
|
@@ -1,10 +1 @@
|
|
|
1
|
-
export
|
|
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
|
-
// 请求模式
|
|
1
|
+
export {};
|
package/es/request/utils.js
CHANGED
|
@@ -128,7 +128,7 @@ export var requestCallback = function requestCallback(resData) {
|
|
|
128
128
|
if (codeFn) {
|
|
129
129
|
if ((res === null || res === void 0 ? void 0 : res.code) === 200) {
|
|
130
130
|
// 需要缓存的进行缓存数据
|
|
131
|
-
if (config !== null && config !== void 0 && config.
|
|
131
|
+
if (config !== null && config !== void 0 && config.cache) {
|
|
132
132
|
var _config$cacheUpdateCh;
|
|
133
133
|
setCacheData(props.url, props.data, res, config === null || config === void 0 ? void 0 : config.cache);
|
|
134
134
|
config === null || config === void 0 || (_config$cacheUpdateCh = config.cacheUpdateChange) === null || _config$cacheUpdateCh === void 0 || _config$cacheUpdateCh.call(config, res);
|
package/es/tasks/index.d.ts
CHANGED
|
@@ -37,20 +37,6 @@ 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;
|
|
54
40
|
/**
|
|
55
41
|
* @title: 启动轮询
|
|
56
42
|
* @description: 根据轮询间隔定期执行任务
|
|
@@ -89,40 +75,9 @@ export declare class TasksManager {
|
|
|
89
75
|
addTask(payload: AddTaskParams): void;
|
|
90
76
|
private updateTask;
|
|
91
77
|
private updateQueueStatus;
|
|
92
|
-
/**
|
|
93
|
-
* @title: 更新队列运行状态
|
|
94
|
-
* @description: 标记队列是否正在执行
|
|
95
|
-
*/
|
|
96
|
-
private updateQueueRunningState;
|
|
97
|
-
private setTasksData;
|
|
98
78
|
private setTasks;
|
|
99
79
|
clearAllTaskTimer(tasks: Task[]): void;
|
|
100
80
|
clearTasks(payload: RunTaskParams): void;
|
|
101
81
|
clearAllTasks(): void;
|
|
102
82
|
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
83
|
}
|