@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/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
|
|
12
|
-
import AWS
|
|
11
|
+
import CMD from "../cmd";
|
|
12
|
+
import AWS from "../aws";
|
|
13
13
|
declare global {
|
|
14
14
|
interface Window {
|
|
15
15
|
app: App;
|
|
@@ -22,9 +22,6 @@ export interface AppOptions {
|
|
|
22
22
|
history?: HistoryOptions;
|
|
23
23
|
storage?: StorageOptions;
|
|
24
24
|
locales?: LocalesOptions;
|
|
25
|
-
cmd?: CMDOptions;
|
|
26
|
-
aws?: AWSOptions;
|
|
27
|
-
getPisellos?: () => any;
|
|
28
25
|
}
|
|
29
26
|
declare class App {
|
|
30
27
|
private static instance;
|
|
@@ -46,7 +43,7 @@ declare class App {
|
|
|
46
43
|
post: (url: string, data: any, config: import("../request").RequestSetting | undefined) => Promise<any>;
|
|
47
44
|
put: (url: string, data: any, config: import("../request").RequestSetting | undefined) => Promise<any>;
|
|
48
45
|
remove: (url: string, data: any, config: import("../request").RequestSetting | undefined) => Promise<any>;
|
|
49
|
-
custom: (url: string, config: import("../request").RequestSetting | undefined) => any
|
|
46
|
+
custom: (url: string, config: import("../request").RequestSetting | undefined) => Promise<any>;
|
|
50
47
|
setConfig: (newConfig: Partial<import("../request").RequestConfig>) => void;
|
|
51
48
|
getConfig: () => import("../request").RequestConfig;
|
|
52
49
|
};
|
|
@@ -69,7 +66,6 @@ declare class App {
|
|
|
69
66
|
cmd: CMD;
|
|
70
67
|
aws: AWS;
|
|
71
68
|
tasksManager: TasksManager;
|
|
72
|
-
getPisellos: any;
|
|
73
69
|
dbManager: IndexDBManager | null;
|
|
74
70
|
constants: {
|
|
75
71
|
channel: string;
|
package/es/app/app.js
CHANGED
|
@@ -67,8 +67,6 @@ var App = /*#__PURE__*/function () {
|
|
|
67
67
|
_defineProperty(this, "aws", void 0);
|
|
68
68
|
// 任务管理
|
|
69
69
|
_defineProperty(this, "tasksManager", void 0);
|
|
70
|
-
// getPisellos
|
|
71
|
-
_defineProperty(this, "getPisellos", void 0);
|
|
72
70
|
_defineProperty(this, "dbManager", null);
|
|
73
71
|
_defineProperty(this, "constants", {
|
|
74
72
|
channel: ""
|
|
@@ -89,7 +87,6 @@ var App = /*#__PURE__*/function () {
|
|
|
89
87
|
this.tasksManager = new TasksManager(this);
|
|
90
88
|
this.cmd = new CMD(this, options === null || options === void 0 ? void 0 : options.cmd);
|
|
91
89
|
this.aws = new AWS(this, options === null || options === void 0 ? void 0 : options.aws);
|
|
92
|
-
this.getPisellos = options === null || options === void 0 ? void 0 : options.getPisellos;
|
|
93
90
|
if (options !== null && options !== void 0 && options.constants) {
|
|
94
91
|
this.constants = options.constants || {};
|
|
95
92
|
}
|
package/es/indexDB/index.d.ts
CHANGED
|
@@ -72,10 +72,11 @@ declare class IndexDBManager {
|
|
|
72
72
|
* 添加数据到指定的存储对象
|
|
73
73
|
* @param {string} storeName - 存储对象名称
|
|
74
74
|
* @param {T} data - 要添加的数据
|
|
75
|
+
* * @param {boolean} [log=true] - 是否记录日志
|
|
75
76
|
* @returns {Promise<T>} 添加的数据
|
|
76
77
|
* @template T
|
|
77
78
|
*/
|
|
78
|
-
add<T>(storeName: string, data: T): Promise<T>;
|
|
79
|
+
add<T>(storeName: string, data: T, log?: boolean): Promise<T>;
|
|
79
80
|
/**
|
|
80
81
|
* 快速检查指定存储对象中的数据是否存在
|
|
81
82
|
* @param {string} storeName - 存储对象名称
|
|
@@ -87,18 +88,20 @@ declare class IndexDBManager {
|
|
|
87
88
|
* 获取指定存储对象中的数据
|
|
88
89
|
* @param {string} storeName - 存储对象名称
|
|
89
90
|
* @param {string|number} key - 数据主键
|
|
91
|
+
* * @param {boolean} [log=true] - 是否记录日志
|
|
90
92
|
* @returns {Promise<T|null>} 获取的数据,不存在则返回 null
|
|
91
93
|
* @template T
|
|
92
94
|
*/
|
|
93
|
-
get<T>(storeName: string, key: string | number): Promise<T | null>;
|
|
95
|
+
get<T>(storeName: string, key: string | number, log?: boolean): Promise<T | null>;
|
|
94
96
|
/**
|
|
95
97
|
* 更新指定存储对象中的数据
|
|
96
98
|
* @param {string} storeName - 存储对象名称
|
|
97
99
|
* @param {T} data - 要更新的数据
|
|
100
|
+
* * @param {boolean} [log=true] - 是否记录日志
|
|
98
101
|
* @returns {Promise<T>} 更新后的数据
|
|
99
102
|
* @template T
|
|
100
103
|
*/
|
|
101
|
-
update<T>(storeName: string, data: T): Promise<T>;
|
|
104
|
+
update<T>(storeName: string, data: T, log?: boolean): Promise<T>;
|
|
102
105
|
/**
|
|
103
106
|
* 删除指定存储对象中的数据
|
|
104
107
|
* @param {string} storeName - 存储对象名称
|
package/es/indexDB/index.js
CHANGED
|
@@ -8,12 +8,14 @@ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _d
|
|
|
8
8
|
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
9
9
|
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
10
10
|
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
11
|
+
import dayjs from 'dayjs';
|
|
11
12
|
/**
|
|
12
13
|
* IndexDB 管理器模块
|
|
13
14
|
*
|
|
14
15
|
* 这个模块提供了对浏览器 IndexedDB 的简单封装,并在不支持 IndexedDB 的环境中
|
|
15
16
|
* 自动降级使用 localStorage 作为备选存储方案。
|
|
16
17
|
*/
|
|
18
|
+
|
|
17
19
|
/**
|
|
18
20
|
* 数据库配置选项接口
|
|
19
21
|
* @interface DBOptions
|
|
@@ -125,15 +127,16 @@ var IndexDBManager = /*#__PURE__*/function () {
|
|
|
125
127
|
* 添加数据到指定的存储对象
|
|
126
128
|
* @param {string} storeName - 存储对象名称
|
|
127
129
|
* @param {T} data - 要添加的数据
|
|
130
|
+
* * @param {boolean} [log=true] - 是否记录日志
|
|
128
131
|
* @returns {Promise<T>} 添加的数据
|
|
129
132
|
* @template T
|
|
130
133
|
*/
|
|
131
134
|
}, {
|
|
132
135
|
key: "add",
|
|
133
136
|
value: (function () {
|
|
134
|
-
var _add = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(storeName, data) {
|
|
137
|
+
var _add = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(storeName, data, log) {
|
|
135
138
|
var _this2 = this;
|
|
136
|
-
var _this$stores$find, key;
|
|
139
|
+
var _this$stores$find, key, uuid;
|
|
137
140
|
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
138
141
|
while (1) switch (_context2.prev = _context2.next) {
|
|
139
142
|
case 0:
|
|
@@ -147,8 +150,19 @@ var IndexDBManager = /*#__PURE__*/function () {
|
|
|
147
150
|
this.app.storage.setStorage(key, JSON.stringify(data));
|
|
148
151
|
return _context2.abrupt("return", data);
|
|
149
152
|
case 4:
|
|
153
|
+
uuid = "[ IndexDB ] ADD: - ".concat(storeName, " - ").concat(dayjs().valueOf());
|
|
150
154
|
return _context2.abrupt("return", new Promise(function (resolve, reject) {
|
|
151
155
|
if (!_this2.db) {
|
|
156
|
+
if (log) {
|
|
157
|
+
_this2.app.logger.addLog({
|
|
158
|
+
type: 'info',
|
|
159
|
+
title: uuid,
|
|
160
|
+
metadata: {
|
|
161
|
+
msg: '添加数据前',
|
|
162
|
+
data: data
|
|
163
|
+
}
|
|
164
|
+
});
|
|
165
|
+
}
|
|
152
166
|
reject(new Error('数据库未连接'));
|
|
153
167
|
return;
|
|
154
168
|
}
|
|
@@ -156,19 +170,75 @@ var IndexDBManager = /*#__PURE__*/function () {
|
|
|
156
170
|
var store = transaction.objectStore(storeName);
|
|
157
171
|
var request = store.add(data);
|
|
158
172
|
request.onsuccess = function () {
|
|
173
|
+
if (log) {
|
|
174
|
+
_this2.app.logger.addLog({
|
|
175
|
+
type: 'info',
|
|
176
|
+
title: uuid,
|
|
177
|
+
metadata: {
|
|
178
|
+
msg: '添加数据成功'
|
|
179
|
+
}
|
|
180
|
+
});
|
|
181
|
+
}
|
|
159
182
|
return resolve(data);
|
|
160
183
|
};
|
|
161
184
|
request.onerror = function () {
|
|
185
|
+
if (log) {
|
|
186
|
+
_this2.app.logger.addLog({
|
|
187
|
+
type: 'info',
|
|
188
|
+
title: uuid,
|
|
189
|
+
metadata: {
|
|
190
|
+
msg: '添加数据失败'
|
|
191
|
+
}
|
|
192
|
+
});
|
|
193
|
+
}
|
|
162
194
|
return reject(new Error('添加数据失败'));
|
|
163
195
|
};
|
|
196
|
+
transaction.oncomplete = function () {
|
|
197
|
+
console.log('✅ 添加事务完成');
|
|
198
|
+
if (log) {
|
|
199
|
+
_this2.app.logger.addLog({
|
|
200
|
+
type: 'info',
|
|
201
|
+
title: uuid,
|
|
202
|
+
metadata: {
|
|
203
|
+
msg: '事务完成'
|
|
204
|
+
}
|
|
205
|
+
});
|
|
206
|
+
}
|
|
207
|
+
return;
|
|
208
|
+
};
|
|
209
|
+
transaction.onerror = function (e) {
|
|
210
|
+
var _transaction$error;
|
|
211
|
+
if (log) {
|
|
212
|
+
_this2.app.logger.addLog({
|
|
213
|
+
type: 'info',
|
|
214
|
+
title: uuid,
|
|
215
|
+
metadata: {
|
|
216
|
+
msg: '事务错误'
|
|
217
|
+
}
|
|
218
|
+
});
|
|
219
|
+
}
|
|
220
|
+
return reject((_transaction$error = transaction.error) !== null && _transaction$error !== void 0 ? _transaction$error : new Error('事务错误'));
|
|
221
|
+
};
|
|
222
|
+
transaction.onabort = function (e) {
|
|
223
|
+
if (log) {
|
|
224
|
+
_this2.app.logger.addLog({
|
|
225
|
+
type: 'info',
|
|
226
|
+
title: uuid,
|
|
227
|
+
metadata: {
|
|
228
|
+
msg: '事务被中止'
|
|
229
|
+
}
|
|
230
|
+
});
|
|
231
|
+
}
|
|
232
|
+
return reject(new Error('事务被中止'));
|
|
233
|
+
};
|
|
164
234
|
}));
|
|
165
|
-
case
|
|
235
|
+
case 6:
|
|
166
236
|
case "end":
|
|
167
237
|
return _context2.stop();
|
|
168
238
|
}
|
|
169
239
|
}, _callee2, this);
|
|
170
240
|
}));
|
|
171
|
-
function add(_x, _x2) {
|
|
241
|
+
function add(_x, _x2, _x3) {
|
|
172
242
|
return _add.apply(this, arguments);
|
|
173
243
|
}
|
|
174
244
|
return add;
|
|
@@ -217,7 +287,7 @@ var IndexDBManager = /*#__PURE__*/function () {
|
|
|
217
287
|
}
|
|
218
288
|
}, _callee3, this);
|
|
219
289
|
}));
|
|
220
|
-
function exists(
|
|
290
|
+
function exists(_x4, _x5) {
|
|
221
291
|
return _exists.apply(this, arguments);
|
|
222
292
|
}
|
|
223
293
|
return exists;
|
|
@@ -226,6 +296,7 @@ var IndexDBManager = /*#__PURE__*/function () {
|
|
|
226
296
|
* 获取指定存储对象中的数据
|
|
227
297
|
* @param {string} storeName - 存储对象名称
|
|
228
298
|
* @param {string|number} key - 数据主键
|
|
299
|
+
* * @param {boolean} [log=true] - 是否记录日志
|
|
229
300
|
* @returns {Promise<T|null>} 获取的数据,不存在则返回 null
|
|
230
301
|
* @template T
|
|
231
302
|
*/
|
|
@@ -233,14 +304,24 @@ var IndexDBManager = /*#__PURE__*/function () {
|
|
|
233
304
|
}, {
|
|
234
305
|
key: "get",
|
|
235
306
|
value: (function () {
|
|
236
|
-
var _get = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(storeName, key) {
|
|
307
|
+
var _get = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(storeName, key, log) {
|
|
237
308
|
var _this4 = this;
|
|
238
|
-
var storageKey, data;
|
|
309
|
+
var uuid, storageKey, data;
|
|
239
310
|
return _regeneratorRuntime().wrap(function _callee4$(_context4) {
|
|
240
311
|
while (1) switch (_context4.prev = _context4.next) {
|
|
241
312
|
case 0:
|
|
313
|
+
uuid = "[ IndexDB ] GET: - ".concat(storeName, " - ").concat(key, " - ").concat(dayjs().valueOf());
|
|
314
|
+
if (log) {
|
|
315
|
+
this.app.logger.addLog({
|
|
316
|
+
type: 'info',
|
|
317
|
+
title: uuid,
|
|
318
|
+
metadata: {
|
|
319
|
+
msg: '获取数据前'
|
|
320
|
+
}
|
|
321
|
+
});
|
|
322
|
+
}
|
|
242
323
|
if (this.useIndexDB) {
|
|
243
|
-
_context4.next =
|
|
324
|
+
_context4.next = 7;
|
|
244
325
|
break;
|
|
245
326
|
}
|
|
246
327
|
storageKey = this.getStorageKey(storeName, key);
|
|
@@ -249,29 +330,101 @@ var IndexDBManager = /*#__PURE__*/function () {
|
|
|
249
330
|
data = JSON.parse(data);
|
|
250
331
|
}
|
|
251
332
|
return _context4.abrupt("return", data);
|
|
252
|
-
case
|
|
333
|
+
case 7:
|
|
253
334
|
return _context4.abrupt("return", new Promise(function (resolve, reject) {
|
|
254
335
|
if (!_this4.db) {
|
|
336
|
+
if (log) {
|
|
337
|
+
_this4.app.logger.addLog({
|
|
338
|
+
type: 'info',
|
|
339
|
+
title: uuid,
|
|
340
|
+
metadata: {
|
|
341
|
+
msg: '数据库未连接'
|
|
342
|
+
}
|
|
343
|
+
});
|
|
344
|
+
}
|
|
255
345
|
reject(new Error('数据库未连接'));
|
|
256
346
|
return;
|
|
257
347
|
}
|
|
258
|
-
var
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
348
|
+
var resolved = false;
|
|
349
|
+
try {
|
|
350
|
+
var transaction = _this4.db.transaction(storeName, 'readonly');
|
|
351
|
+
var store = transaction.objectStore(storeName);
|
|
352
|
+
var request = store.get(key);
|
|
353
|
+
request.onsuccess = function () {
|
|
354
|
+
var _request$result;
|
|
355
|
+
resolved = true;
|
|
356
|
+
if (log) {
|
|
357
|
+
_this4.app.logger.addLog({
|
|
358
|
+
type: 'info',
|
|
359
|
+
title: uuid,
|
|
360
|
+
metadata: {
|
|
361
|
+
msg: '获取成功'
|
|
362
|
+
}
|
|
363
|
+
});
|
|
364
|
+
}
|
|
365
|
+
resolve((_request$result = request.result) !== null && _request$result !== void 0 ? _request$result : null);
|
|
366
|
+
};
|
|
367
|
+
request.onerror = function () {
|
|
368
|
+
var _request$error;
|
|
369
|
+
resolved = true;
|
|
370
|
+
if (log) {
|
|
371
|
+
_this4.app.logger.addLog({
|
|
372
|
+
type: 'info',
|
|
373
|
+
title: uuid,
|
|
374
|
+
metadata: {
|
|
375
|
+
msg: '获取失败'
|
|
376
|
+
}
|
|
377
|
+
});
|
|
378
|
+
}
|
|
379
|
+
reject((_request$error = request.error) !== null && _request$error !== void 0 ? _request$error : new Error('获取数据失败'));
|
|
380
|
+
};
|
|
381
|
+
transaction.onabort = function () {
|
|
382
|
+
if (log) {
|
|
383
|
+
_this4.app.logger.addLog({
|
|
384
|
+
type: 'info',
|
|
385
|
+
title: uuid,
|
|
386
|
+
metadata: {
|
|
387
|
+
msg: '事务被中止'
|
|
388
|
+
}
|
|
389
|
+
});
|
|
390
|
+
}
|
|
391
|
+
if (!resolved) reject(new Error('事务被中止'));
|
|
392
|
+
};
|
|
393
|
+
transaction.onerror = function (event) {
|
|
394
|
+
if (log) {
|
|
395
|
+
_this4.app.logger.addLog({
|
|
396
|
+
type: 'info',
|
|
397
|
+
title: uuid,
|
|
398
|
+
metadata: {
|
|
399
|
+
msg: "\u4E8B\u52A1\u9519\u8BEF: ".concat(event.target.error)
|
|
400
|
+
}
|
|
401
|
+
});
|
|
402
|
+
}
|
|
403
|
+
if (!resolved) reject(new Error("\u4E8B\u52A1\u9519\u8BEF: ".concat(event.target.error)));
|
|
404
|
+
};
|
|
405
|
+
transaction.oncomplete = function () {
|
|
406
|
+
if (log) {
|
|
407
|
+
_this4.app.logger.addLog({
|
|
408
|
+
type: 'info',
|
|
409
|
+
title: uuid,
|
|
410
|
+
metadata: {
|
|
411
|
+
msg: '事务完成'
|
|
412
|
+
}
|
|
413
|
+
});
|
|
414
|
+
}
|
|
415
|
+
// ✅ 事务顺利结束
|
|
416
|
+
};
|
|
417
|
+
} catch (e) {
|
|
418
|
+
reject(e);
|
|
419
|
+
}
|
|
267
420
|
}));
|
|
268
|
-
case
|
|
421
|
+
case 8:
|
|
269
422
|
case "end":
|
|
270
423
|
return _context4.stop();
|
|
271
424
|
}
|
|
272
425
|
}, _callee4, this);
|
|
273
426
|
}));
|
|
274
|
-
function get(
|
|
427
|
+
function get(_x6, _x7, _x8) {
|
|
275
428
|
return _get.apply(this, arguments);
|
|
276
429
|
}
|
|
277
430
|
return get;
|
|
@@ -280,6 +433,7 @@ var IndexDBManager = /*#__PURE__*/function () {
|
|
|
280
433
|
* 更新指定存储对象中的数据
|
|
281
434
|
* @param {string} storeName - 存储对象名称
|
|
282
435
|
* @param {T} data - 要更新的数据
|
|
436
|
+
* * @param {boolean} [log=true] - 是否记录日志
|
|
283
437
|
* @returns {Promise<T>} 更新后的数据
|
|
284
438
|
* @template T
|
|
285
439
|
*/
|
|
@@ -287,9 +441,9 @@ var IndexDBManager = /*#__PURE__*/function () {
|
|
|
287
441
|
}, {
|
|
288
442
|
key: "update",
|
|
289
443
|
value: (function () {
|
|
290
|
-
var _update = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(storeName, data) {
|
|
444
|
+
var _update = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(storeName, data, log) {
|
|
291
445
|
var _this5 = this;
|
|
292
|
-
var _this$stores$find2, key;
|
|
446
|
+
var _this$stores$find2, key, uuid;
|
|
293
447
|
return _regeneratorRuntime().wrap(function _callee5$(_context5) {
|
|
294
448
|
while (1) switch (_context5.prev = _context5.next) {
|
|
295
449
|
case 0:
|
|
@@ -303,28 +457,98 @@ var IndexDBManager = /*#__PURE__*/function () {
|
|
|
303
457
|
this.app.storage.setStorage(key, JSON.stringify(data));
|
|
304
458
|
return _context5.abrupt("return", data);
|
|
305
459
|
case 4:
|
|
460
|
+
uuid = "[ IndexDB ] UPDATE: - ".concat(storeName, " - ").concat(dayjs().valueOf());
|
|
461
|
+
if (log) {
|
|
462
|
+
this.app.logger.addLog({
|
|
463
|
+
type: 'info',
|
|
464
|
+
title: uuid,
|
|
465
|
+
metadata: {
|
|
466
|
+
msg: '更新数据前',
|
|
467
|
+
data: data
|
|
468
|
+
}
|
|
469
|
+
});
|
|
470
|
+
}
|
|
306
471
|
return _context5.abrupt("return", new Promise(function (resolve, reject) {
|
|
307
472
|
if (!_this5.db) {
|
|
473
|
+
if (log) {
|
|
474
|
+
_this5.app.logger.addLog({
|
|
475
|
+
type: 'info',
|
|
476
|
+
title: uuid,
|
|
477
|
+
metadata: {
|
|
478
|
+
msg: '数据库未连接'
|
|
479
|
+
}
|
|
480
|
+
});
|
|
481
|
+
}
|
|
308
482
|
reject(new Error('数据库未连接'));
|
|
309
483
|
return;
|
|
310
484
|
}
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
485
|
+
try {
|
|
486
|
+
var transaction = _this5.db.transaction(storeName, 'readwrite');
|
|
487
|
+
var store = transaction.objectStore(storeName);
|
|
488
|
+
var request = store.put(data);
|
|
489
|
+
request.onsuccess = function () {
|
|
490
|
+
_this5.app.logger.addLog({
|
|
491
|
+
type: 'info',
|
|
492
|
+
title: uuid,
|
|
493
|
+
metadata: {
|
|
494
|
+
msg: '数据更新完成'
|
|
495
|
+
}
|
|
496
|
+
});
|
|
497
|
+
return resolve(data);
|
|
498
|
+
};
|
|
499
|
+
request.onerror = function () {
|
|
500
|
+
var _request$error2;
|
|
501
|
+
_this5.app.logger.addLog({
|
|
502
|
+
type: 'info',
|
|
503
|
+
title: uuid,
|
|
504
|
+
metadata: {
|
|
505
|
+
msg: '数据更新失败'
|
|
506
|
+
}
|
|
507
|
+
});
|
|
508
|
+
return reject((_request$error2 = request.error) !== null && _request$error2 !== void 0 ? _request$error2 : new Error('更新数据失败'));
|
|
509
|
+
};
|
|
510
|
+
transaction.oncomplete = function () {
|
|
511
|
+
_this5.app.logger.addLog({
|
|
512
|
+
type: 'info',
|
|
513
|
+
title: uuid,
|
|
514
|
+
metadata: {
|
|
515
|
+
msg: '事务完成'
|
|
516
|
+
}
|
|
517
|
+
});
|
|
518
|
+
return console.log('✅ 事务完成');
|
|
519
|
+
};
|
|
520
|
+
transaction.onabort = function (e) {
|
|
521
|
+
_this5.app.logger.addLog({
|
|
522
|
+
type: 'info',
|
|
523
|
+
title: uuid,
|
|
524
|
+
metadata: {
|
|
525
|
+
msg: '事务被中止'
|
|
526
|
+
}
|
|
527
|
+
});
|
|
528
|
+
return reject(new Error('事务被中止'));
|
|
529
|
+
};
|
|
530
|
+
transaction.onerror = function (e) {
|
|
531
|
+
var _transaction$error2;
|
|
532
|
+
_this5.app.logger.addLog({
|
|
533
|
+
type: 'info',
|
|
534
|
+
title: uuid,
|
|
535
|
+
metadata: {
|
|
536
|
+
msg: '事务错误'
|
|
537
|
+
}
|
|
538
|
+
});
|
|
539
|
+
return reject((_transaction$error2 = transaction.error) !== null && _transaction$error2 !== void 0 ? _transaction$error2 : new Error('事务错误'));
|
|
540
|
+
};
|
|
541
|
+
} catch (e) {
|
|
542
|
+
reject(e);
|
|
543
|
+
}
|
|
320
544
|
}));
|
|
321
|
-
case
|
|
545
|
+
case 7:
|
|
322
546
|
case "end":
|
|
323
547
|
return _context5.stop();
|
|
324
548
|
}
|
|
325
549
|
}, _callee5, this);
|
|
326
550
|
}));
|
|
327
|
-
function update(
|
|
551
|
+
function update(_x9, _x10, _x11) {
|
|
328
552
|
return _update.apply(this, arguments);
|
|
329
553
|
}
|
|
330
554
|
return update;
|
|
@@ -374,7 +598,7 @@ var IndexDBManager = /*#__PURE__*/function () {
|
|
|
374
598
|
}
|
|
375
599
|
}, _callee6, this);
|
|
376
600
|
}));
|
|
377
|
-
function _delete(
|
|
601
|
+
function _delete(_x12, _x13) {
|
|
378
602
|
return _delete2.apply(this, arguments);
|
|
379
603
|
}
|
|
380
604
|
return _delete;
|
|
@@ -443,7 +667,7 @@ var IndexDBManager = /*#__PURE__*/function () {
|
|
|
443
667
|
}
|
|
444
668
|
}, _callee7, this);
|
|
445
669
|
}));
|
|
446
|
-
function getByIndex(
|
|
670
|
+
function getByIndex(_x14, _x15, _x16) {
|
|
447
671
|
return _getByIndex.apply(this, arguments);
|
|
448
672
|
}
|
|
449
673
|
return getByIndex;
|
|
@@ -511,7 +735,7 @@ var IndexDBManager = /*#__PURE__*/function () {
|
|
|
511
735
|
}
|
|
512
736
|
}, _callee8, this);
|
|
513
737
|
}));
|
|
514
|
-
function existsByIndex(
|
|
738
|
+
function existsByIndex(_x17, _x18, _x19) {
|
|
515
739
|
return _existsByIndex.apply(this, arguments);
|
|
516
740
|
}
|
|
517
741
|
return existsByIndex;
|
|
@@ -580,7 +804,7 @@ var IndexDBManager = /*#__PURE__*/function () {
|
|
|
580
804
|
}
|
|
581
805
|
}, _callee9, this);
|
|
582
806
|
}));
|
|
583
|
-
function getAllByIndex(
|
|
807
|
+
function getAllByIndex(_x20, _x21, _x22) {
|
|
584
808
|
return _getAllByIndex.apply(this, arguments);
|
|
585
809
|
}
|
|
586
810
|
return getAllByIndex;
|
|
@@ -631,7 +855,7 @@ var IndexDBManager = /*#__PURE__*/function () {
|
|
|
631
855
|
}
|
|
632
856
|
}, _callee10, this);
|
|
633
857
|
}));
|
|
634
|
-
function count(
|
|
858
|
+
function count(_x23) {
|
|
635
859
|
return _count.apply(this, arguments);
|
|
636
860
|
}
|
|
637
861
|
return count;
|
|
@@ -685,7 +909,7 @@ var IndexDBManager = /*#__PURE__*/function () {
|
|
|
685
909
|
}
|
|
686
910
|
}, _callee11, this);
|
|
687
911
|
}));
|
|
688
|
-
function countByIndex(
|
|
912
|
+
function countByIndex(_x24, _x25, _x26) {
|
|
689
913
|
return _countByIndex.apply(this, arguments);
|
|
690
914
|
}
|
|
691
915
|
return countByIndex;
|
|
@@ -747,7 +971,7 @@ var IndexDBManager = /*#__PURE__*/function () {
|
|
|
747
971
|
}
|
|
748
972
|
}, _callee12, this);
|
|
749
973
|
}));
|
|
750
|
-
function getAll(
|
|
974
|
+
function getAll(_x27) {
|
|
751
975
|
return _getAll.apply(this, arguments);
|
|
752
976
|
}
|
|
753
977
|
return getAll;
|
|
@@ -805,7 +1029,7 @@ var IndexDBManager = /*#__PURE__*/function () {
|
|
|
805
1029
|
}
|
|
806
1030
|
}, _callee13, this);
|
|
807
1031
|
}));
|
|
808
|
-
function clear(
|
|
1032
|
+
function clear(_x28) {
|
|
809
1033
|
return _clear.apply(this, arguments);
|
|
810
1034
|
}
|
|
811
1035
|
return clear;
|
package/es/request/cache.d.ts
CHANGED
|
@@ -32,7 +32,7 @@ export declare const getCacheData: (url: string, data: any, cache: CacheProps) =
|
|
|
32
32
|
* @return {*}
|
|
33
33
|
* @Author: zhiwei.Wang
|
|
34
34
|
*/
|
|
35
|
-
export declare const setCacheData: (url: string, data: any, res: any, cache
|
|
35
|
+
export declare const setCacheData: (url: string, data: any, res: any, cache: CacheProps) => any | null;
|
|
36
36
|
/**
|
|
37
37
|
* @title: 缓存函数包装器
|
|
38
38
|
* @description:
|