@pisell/core 1.0.26 → 1.0.28
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/request/cache.js +44 -28
- package/es/request/utils.js +1 -1
- package/es/tasks/index.js +444 -101
- package/es/tasks/scheduledTasksExample.js +351 -0
- package/lib/request/cache.js +15 -4
- package/lib/request/utils.js +1 -1
- package/lib/tasks/index.js +326 -77
- package/lib/tasks/scheduledTasksExample.js +267 -0
- package/package.json +1 -1
- package/es/app/app.d.ts +0 -89
- package/es/request/cache.d.ts +0 -46
- package/es/request/index.d.ts +0 -24
- package/es/request/type.d.ts +0 -42
- package/es/request/utils.d.ts +0 -46
- package/es/tasks/index.d.ts +0 -83
- package/es/tasks/type.d.ts +0 -62
- package/lib/app/app.d.ts +0 -89
- package/lib/request/cache.d.ts +0 -46
- package/lib/request/index.d.ts +0 -24
- package/lib/request/type.d.ts +0 -42
- package/lib/request/utils.d.ts +0 -46
- package/lib/tasks/index.d.ts +0 -83
- package/lib/tasks/type.d.ts +0 -62
package/es/request/cache.js
CHANGED
|
@@ -124,20 +124,26 @@ var getCache = /*#__PURE__*/function () {
|
|
|
124
124
|
case 0:
|
|
125
125
|
_getConfig3 = getConfig(), storage = _getConfig3.storage; // 如果 当前时间 - 数据缓存时间 小于 超时时间, 则数据正常.
|
|
126
126
|
if (!(cache.type === 'memory')) {
|
|
127
|
-
_context2.next =
|
|
127
|
+
_context2.next = 8;
|
|
128
128
|
break;
|
|
129
129
|
}
|
|
130
|
-
if (
|
|
130
|
+
if (CACHES[key]) {
|
|
131
131
|
_context2.next = 4;
|
|
132
132
|
break;
|
|
133
133
|
}
|
|
134
|
-
return _context2.abrupt("return",
|
|
134
|
+
return _context2.abrupt("return", null);
|
|
135
135
|
case 4:
|
|
136
|
-
|
|
137
|
-
|
|
136
|
+
if (!getIsEffectiveTime(CACHES[key].time)) {
|
|
137
|
+
_context2.next = 6;
|
|
138
|
+
break;
|
|
139
|
+
}
|
|
140
|
+
return _context2.abrupt("return", CACHES[key].data);
|
|
138
141
|
case 6:
|
|
142
|
+
_context2.next = 23;
|
|
143
|
+
break;
|
|
144
|
+
case 8:
|
|
139
145
|
if (!(cache.type === 'storage')) {
|
|
140
|
-
_context2.next =
|
|
146
|
+
_context2.next = 15;
|
|
141
147
|
break;
|
|
142
148
|
}
|
|
143
149
|
storageDetail = storage.getStorage(key) || "";
|
|
@@ -145,35 +151,35 @@ var getCache = /*#__PURE__*/function () {
|
|
|
145
151
|
storageDetail = JSON.parse(storageDetail);
|
|
146
152
|
}
|
|
147
153
|
if (!getIsEffectiveTime(storageDetail.time)) {
|
|
148
|
-
_context2.next =
|
|
154
|
+
_context2.next = 13;
|
|
149
155
|
break;
|
|
150
156
|
}
|
|
151
157
|
return _context2.abrupt("return", (_storageDetail = storageDetail) === null || _storageDetail === void 0 ? void 0 : _storageDetail.data);
|
|
152
|
-
case 11:
|
|
153
|
-
_context2.next = 21;
|
|
154
|
-
break;
|
|
155
158
|
case 13:
|
|
159
|
+
_context2.next = 23;
|
|
160
|
+
break;
|
|
161
|
+
case 15:
|
|
156
162
|
if (!(cache.type === 'indexDB')) {
|
|
157
|
-
_context2.next =
|
|
163
|
+
_context2.next = 23;
|
|
158
164
|
break;
|
|
159
165
|
}
|
|
160
166
|
app = getApp();
|
|
161
167
|
if (!app.dbManager) {
|
|
162
|
-
_context2.next =
|
|
168
|
+
_context2.next = 23;
|
|
163
169
|
break;
|
|
164
170
|
}
|
|
165
|
-
_context2.next =
|
|
171
|
+
_context2.next = 20;
|
|
166
172
|
return app.dbManager.get('requests', key);
|
|
167
|
-
case
|
|
173
|
+
case 20:
|
|
168
174
|
indexDBDetail = _context2.sent;
|
|
169
175
|
if (!indexDBDetail) {
|
|
170
|
-
_context2.next =
|
|
176
|
+
_context2.next = 23;
|
|
171
177
|
break;
|
|
172
178
|
}
|
|
173
179
|
return _context2.abrupt("return", indexDBDetail === null || indexDBDetail === void 0 ? void 0 : indexDBDetail.data);
|
|
174
|
-
case
|
|
180
|
+
case 23:
|
|
175
181
|
return _context2.abrupt("return", null);
|
|
176
|
-
case
|
|
182
|
+
case 24:
|
|
177
183
|
case "end":
|
|
178
184
|
return _context2.stop();
|
|
179
185
|
}
|
|
@@ -251,7 +257,10 @@ export var getCacheData = /*#__PURE__*/function () {
|
|
|
251
257
|
* @return {*}
|
|
252
258
|
* @Author: zhiwei.Wang
|
|
253
259
|
*/
|
|
254
|
-
export var setCacheData = function setCacheData(url, data, res
|
|
260
|
+
export var setCacheData = function setCacheData(url, data, res) {
|
|
261
|
+
var cache = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {
|
|
262
|
+
type: 'memory'
|
|
263
|
+
};
|
|
255
264
|
// 创建缓存key
|
|
256
265
|
var _key = createCacheKey(url, data, cache);
|
|
257
266
|
setCache(_key, res, cache);
|
|
@@ -269,37 +278,44 @@ export var setCacheData = function setCacheData(url, data, res, cache) {
|
|
|
269
278
|
*/
|
|
270
279
|
export var cacheFn = /*#__PURE__*/function () {
|
|
271
280
|
var _ref4 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(props, fn) {
|
|
272
|
-
var url, data, config, _data, _config$cache;
|
|
281
|
+
var url, data, config, cache, _data, _config$cache;
|
|
273
282
|
return _regeneratorRuntime().wrap(function _callee4$(_context4) {
|
|
274
283
|
while (1) switch (_context4.prev = _context4.next) {
|
|
275
284
|
case 0:
|
|
276
285
|
url = props.url, data = props.data, config = props.config;
|
|
277
|
-
if (!(config !== null && config !== void 0 && config.cache)) {
|
|
278
|
-
_context4.next =
|
|
286
|
+
if (!(config !== null && config !== void 0 && config.cache || config !== null && config !== void 0 && config.useCache)) {
|
|
287
|
+
_context4.next = 10;
|
|
279
288
|
break;
|
|
280
289
|
}
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
290
|
+
cache = config.cache;
|
|
291
|
+
if (config.useCache) {
|
|
292
|
+
cache = {
|
|
293
|
+
type: 'memory'
|
|
294
|
+
};
|
|
295
|
+
}
|
|
296
|
+
// 获取缓存数据
|
|
297
|
+
_context4.next = 6;
|
|
298
|
+
return getCacheData(url, data, cache);
|
|
299
|
+
case 6:
|
|
284
300
|
_data = _context4.sent;
|
|
285
301
|
if (!_data) {
|
|
286
|
-
_context4.next =
|
|
302
|
+
_context4.next = 10;
|
|
287
303
|
break;
|
|
288
304
|
}
|
|
289
305
|
// 如果开启更新缓存执行函数
|
|
290
306
|
if ((_config$cache = config.cache) !== null && _config$cache !== void 0 && _config$cache.updateCache) {
|
|
291
307
|
fn(_objectSpread(_objectSpread({}, props), {}, {
|
|
292
308
|
config: _objectSpread(_objectSpread({}, props.config), {}, {
|
|
293
|
-
cache: _objectSpread(_objectSpread({},
|
|
309
|
+
cache: _objectSpread(_objectSpread({}, cache), {}, {
|
|
294
310
|
updateCache: false
|
|
295
311
|
})
|
|
296
312
|
})
|
|
297
313
|
}));
|
|
298
314
|
}
|
|
299
315
|
return _context4.abrupt("return", _data);
|
|
300
|
-
case
|
|
316
|
+
case 10:
|
|
301
317
|
return _context4.abrupt("return", fn(props));
|
|
302
|
-
case
|
|
318
|
+
case 11:
|
|
303
319
|
case "end":
|
|
304
320
|
return _context4.stop();
|
|
305
321
|
}
|
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.cache) {
|
|
131
|
+
if (config !== null && config !== void 0 && config.useCache || 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);
|