@pisell/core 1.0.33 → 1.0.35
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 +7 -7
- package/es/app/index.d.ts +1 -1
- package/es/applicationManager/application.d.ts +2 -2
- package/es/cmd/const.d.ts +5 -5
- package/es/hooks/useStore/index.d.ts +1 -1
- package/es/indexDB/index.d.ts +2 -2
- package/es/indexDB/index.js +633 -572
- package/es/locales/type.d.ts +3 -3
- package/es/logger/index.d.ts +1 -1
- package/es/models/index.d.ts +4 -4
- package/es/pubsub/index.d.ts +1 -1
- package/es/request/cache.d.ts +1 -1
- package/es/request/pisell2Request.d.ts +1 -1
- package/es/request/type.d.ts +1 -1
- package/es/routes/index.d.ts +2 -2
- package/es/socket/monitor.js +2 -0
- package/es/socket/types.d.ts +4 -3
- package/es/tasks/index.d.ts +0 -1
- package/es/tasks/index.js +0 -1
- package/es/tasks/type.d.ts +4 -4
- package/es/variables/index.d.ts +3 -3
- package/lib/app/app.d.ts +7 -7
- package/lib/app/app.js +21 -51
- package/lib/app/index.d.ts +1 -1
- package/lib/applicationManager/application.d.ts +2 -2
- package/lib/applicationManager/application.js +6 -12
- package/lib/applicationManager/index.js +4 -2
- package/lib/aws/index.js +0 -3
- package/lib/cmd/const.d.ts +5 -5
- package/lib/cmd/const.js +5 -5
- package/lib/cmd/index.js +0 -2
- package/lib/cookie/index.js +4 -2
- package/lib/data/index.js +0 -3
- package/lib/history/index.js +22 -24
- package/lib/hooks/useStore/index.d.ts +1 -1
- package/lib/indexDB/index.d.ts +2 -2
- package/lib/indexDB/index.js +233 -327
- package/lib/locales/index.js +94 -95
- package/lib/locales/type.d.ts +3 -3
- package/lib/logger/index.d.ts +1 -1
- package/lib/logger/index.js +8 -18
- package/lib/menuManager/index.js +12 -9
- package/lib/models/index.d.ts +4 -4
- package/lib/pubsub/index.d.ts +1 -1
- package/lib/pubsub/index.js +3 -1
- package/lib/request/cache.d.ts +1 -1
- package/lib/request/pisell2Request.d.ts +1 -1
- package/lib/request/type.d.ts +1 -1
- package/lib/routes/index.d.ts +2 -2
- package/lib/routes/index.js +1 -3
- package/lib/socket/components/SocketMonitorPage.js +12 -6
- package/lib/socket/heartbeat.js +5 -10
- package/lib/socket/index.js +3 -1
- package/lib/socket/monitor.js +26 -26
- package/lib/socket/reconnect.js +3 -10
- package/lib/socket/socket.js +10 -12
- package/lib/socket/types.d.ts +4 -3
- package/lib/storage/index.js +24 -25
- package/lib/tasks/index.d.ts +0 -1
- package/lib/tasks/index.js +329 -334
- package/lib/tasks/type.d.ts +4 -4
- package/lib/variables/index.d.ts +3 -3
- package/package.json +3 -2
package/lib/indexDB/index.js
CHANGED
|
@@ -33,35 +33,23 @@ __export(indexDB_exports, {
|
|
|
33
33
|
});
|
|
34
34
|
module.exports = __toCommonJS(indexDB_exports);
|
|
35
35
|
var import_dayjs = __toESM(require("dayjs"));
|
|
36
|
-
var
|
|
37
|
-
|
|
38
|
-
* 检查环境是否支持 IndexedDB
|
|
39
|
-
* @returns {boolean} 是否支持 IndexedDB
|
|
40
|
-
* @private
|
|
41
|
-
*/
|
|
42
|
-
static isSupported() {
|
|
43
|
-
return window && "indexedDB" in window;
|
|
44
|
-
}
|
|
45
|
-
db = null;
|
|
46
|
-
dbName;
|
|
47
|
-
version;
|
|
48
|
-
stores;
|
|
49
|
-
useIndexDB;
|
|
50
|
-
app;
|
|
51
|
-
// 内存存储:每个 store 使用一个 Map,key 为主键,value 为数据
|
|
52
|
-
memoryStorage = /* @__PURE__ */ new Map();
|
|
53
|
-
// 操作超时时间(毫秒)
|
|
54
|
-
timeout = 5e3;
|
|
36
|
+
var import_dexie = __toESM(require("dexie"));
|
|
37
|
+
var IndexDBManager = class {
|
|
55
38
|
/**
|
|
56
39
|
* 创建 IndexDBManager 实例
|
|
57
40
|
* @param {DBOptions} options - 数据库配置选项
|
|
58
41
|
*/
|
|
59
42
|
constructor(app, options) {
|
|
43
|
+
this.db = null;
|
|
44
|
+
// 内存存储:每个 store 使用一个 Map,key 为主键,value 为数据
|
|
45
|
+
this.memoryStorage = /* @__PURE__ */ new Map();
|
|
46
|
+
// 操作超时时间(毫秒)
|
|
47
|
+
this.timeout = 5e3;
|
|
60
48
|
this.app = app;
|
|
61
49
|
this.dbName = options.dbName;
|
|
62
50
|
this.version = options.version;
|
|
63
51
|
this.stores = options.stores;
|
|
64
|
-
this.useIndexDB =
|
|
52
|
+
this.useIndexDB = IndexDBManager.isSupported();
|
|
65
53
|
this.timeout = options.timeout ?? 5e3;
|
|
66
54
|
if (!this.useIndexDB) {
|
|
67
55
|
this.stores.forEach((store) => {
|
|
@@ -69,6 +57,14 @@ var IndexDBManager = class _IndexDBManager {
|
|
|
69
57
|
});
|
|
70
58
|
}
|
|
71
59
|
}
|
|
60
|
+
/**
|
|
61
|
+
* 检查环境是否支持 IndexedDB
|
|
62
|
+
* @returns {boolean} 是否支持 IndexedDB
|
|
63
|
+
* @private
|
|
64
|
+
*/
|
|
65
|
+
static isSupported() {
|
|
66
|
+
return typeof window !== "undefined" && "indexedDB" in window;
|
|
67
|
+
}
|
|
72
68
|
/**
|
|
73
69
|
* 超时包装器 - 为 Promise 添加超时控制
|
|
74
70
|
* @param {Promise<T>} promise - 需要包装的 Promise
|
|
@@ -77,23 +73,36 @@ var IndexDBManager = class _IndexDBManager {
|
|
|
77
73
|
* @private
|
|
78
74
|
*/
|
|
79
75
|
withTimeout(promise, operation) {
|
|
76
|
+
let timeoutId = null;
|
|
77
|
+
const timeoutPromise = new Promise((_, reject) => {
|
|
78
|
+
timeoutId = setTimeout(() => {
|
|
79
|
+
const error = new Error(`操作超时: ${operation} 在 ${this.timeout}ms 内未完成`);
|
|
80
|
+
this.app.logger.addLog({
|
|
81
|
+
type: "error",
|
|
82
|
+
title: "[ IndexDB ] TIMEOUT",
|
|
83
|
+
metadata: {
|
|
84
|
+
msg: `操作超时: ${operation}`,
|
|
85
|
+
timeout: this.timeout,
|
|
86
|
+
operation
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
reject(error);
|
|
90
|
+
}, this.timeout);
|
|
91
|
+
});
|
|
80
92
|
return Promise.race([
|
|
81
|
-
promise
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
reject(error);
|
|
95
|
-
}, this.timeout);
|
|
96
|
-
})
|
|
93
|
+
promise.then(
|
|
94
|
+
(result) => {
|
|
95
|
+
if (timeoutId)
|
|
96
|
+
clearTimeout(timeoutId);
|
|
97
|
+
return result;
|
|
98
|
+
},
|
|
99
|
+
(error) => {
|
|
100
|
+
if (timeoutId)
|
|
101
|
+
clearTimeout(timeoutId);
|
|
102
|
+
throw error;
|
|
103
|
+
}
|
|
104
|
+
),
|
|
105
|
+
timeoutPromise
|
|
97
106
|
]);
|
|
98
107
|
}
|
|
99
108
|
/**
|
|
@@ -106,58 +115,52 @@ var IndexDBManager = class _IndexDBManager {
|
|
|
106
115
|
return true;
|
|
107
116
|
}
|
|
108
117
|
return this.withTimeout(
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
this.
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
118
|
+
(async () => {
|
|
119
|
+
try {
|
|
120
|
+
this.db = new import_dexie.default(this.dbName);
|
|
121
|
+
const schema = {};
|
|
122
|
+
this.stores.forEach((store) => {
|
|
123
|
+
var _a;
|
|
124
|
+
const indexes = ((_a = store.indexes) == null ? void 0 : _a.map((index) => {
|
|
125
|
+
var _a2, _b;
|
|
126
|
+
let indexStr = index.name;
|
|
127
|
+
if ((_a2 = index.options) == null ? void 0 : _a2.unique) {
|
|
128
|
+
indexStr = `&${indexStr}`;
|
|
129
|
+
}
|
|
130
|
+
if ((_b = index.options) == null ? void 0 : _b.multiEntry) {
|
|
131
|
+
indexStr = `*${indexStr}`;
|
|
132
|
+
}
|
|
133
|
+
return indexStr;
|
|
134
|
+
})) || [];
|
|
135
|
+
const primaryKey = store.keyPath;
|
|
136
|
+
schema[store.name] = [primaryKey, ...indexes].join(",");
|
|
128
137
|
});
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
request.onupgradeneeded = (event) => {
|
|
133
|
-
const db = event.target.result;
|
|
134
|
-
db.onerror = (event2) => {
|
|
135
|
-
var _a, _b;
|
|
138
|
+
this.db.version(this.version).stores(schema);
|
|
139
|
+
await this.db.open();
|
|
140
|
+
this.db.on("blocked", () => {
|
|
136
141
|
this.app.logger.addLog({
|
|
137
142
|
type: "error",
|
|
138
|
-
title: "[ IndexDB ]
|
|
139
|
-
metadata: { msg: "DB
|
|
143
|
+
title: "[ IndexDB ] blocked",
|
|
144
|
+
metadata: { msg: "DB blocked" }
|
|
140
145
|
});
|
|
141
|
-
};
|
|
142
|
-
db.
|
|
143
|
-
var _a, _b;
|
|
146
|
+
});
|
|
147
|
+
this.db.on("close", () => {
|
|
144
148
|
this.app.logger.addLog({
|
|
145
149
|
type: "error",
|
|
146
150
|
title: "[ IndexDB ] CLOSE",
|
|
147
|
-
metadata: { msg: "DB close"
|
|
151
|
+
metadata: { msg: "DB close" }
|
|
148
152
|
});
|
|
149
|
-
};
|
|
150
|
-
this.stores.forEach((store) => {
|
|
151
|
-
var _a;
|
|
152
|
-
if (!db.objectStoreNames.contains(store.name)) {
|
|
153
|
-
const objectStore = db.createObjectStore(store.name, { keyPath: store.keyPath });
|
|
154
|
-
(_a = store.indexes) == null ? void 0 : _a.forEach((index) => {
|
|
155
|
-
objectStore.createIndex(index.name, index.keyPath, index.options);
|
|
156
|
-
});
|
|
157
|
-
}
|
|
158
153
|
});
|
|
159
|
-
|
|
160
|
-
|
|
154
|
+
return true;
|
|
155
|
+
} catch (error) {
|
|
156
|
+
this.app.logger.addLog({
|
|
157
|
+
type: "error",
|
|
158
|
+
title: "[ IndexDB ] ERROR",
|
|
159
|
+
metadata: { msg: "DB request error", message: error.message }
|
|
160
|
+
});
|
|
161
|
+
throw error;
|
|
162
|
+
}
|
|
163
|
+
})(),
|
|
161
164
|
"connect"
|
|
162
165
|
);
|
|
163
166
|
}
|
|
@@ -201,7 +204,7 @@ var IndexDBManager = class _IndexDBManager {
|
|
|
201
204
|
});
|
|
202
205
|
}
|
|
203
206
|
return this.withTimeout(
|
|
204
|
-
|
|
207
|
+
(async () => {
|
|
205
208
|
if (!this.db) {
|
|
206
209
|
if (log) {
|
|
207
210
|
this.app.logger.addLog({
|
|
@@ -210,64 +213,35 @@ var IndexDBManager = class _IndexDBManager {
|
|
|
210
213
|
metadata: { msg: "添加数据前 数据库未连接", data }
|
|
211
214
|
});
|
|
212
215
|
}
|
|
213
|
-
|
|
214
|
-
return;
|
|
216
|
+
throw new Error("数据库未连接");
|
|
215
217
|
}
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
const request = store.add(data);
|
|
219
|
-
request.onsuccess = () => {
|
|
218
|
+
try {
|
|
219
|
+
await this.db.table(storeName).add(data);
|
|
220
220
|
if (log) {
|
|
221
221
|
this.app.logger.addLog({
|
|
222
222
|
type: "info",
|
|
223
223
|
title: uuid,
|
|
224
224
|
metadata: { msg: "添加数据成功" }
|
|
225
225
|
});
|
|
226
|
-
|
|
227
|
-
return resolve(data);
|
|
228
|
-
};
|
|
229
|
-
request.onerror = () => {
|
|
230
|
-
if (log) {
|
|
231
|
-
this.app.logger.addLog({
|
|
232
|
-
type: "error",
|
|
233
|
-
title: uuid,
|
|
234
|
-
metadata: { msg: "添加数据失败" }
|
|
235
|
-
});
|
|
236
|
-
}
|
|
237
|
-
return reject(new Error("添加数据失败"));
|
|
238
|
-
};
|
|
239
|
-
transaction.oncomplete = () => {
|
|
240
|
-
console.log("✅ 添加事务完成");
|
|
241
|
-
if (log) {
|
|
226
|
+
console.log("✅ 添加事务完成");
|
|
242
227
|
this.app.logger.addLog({
|
|
243
228
|
type: "info",
|
|
244
229
|
title: uuid,
|
|
245
230
|
metadata: { msg: "事务完成" }
|
|
246
231
|
});
|
|
247
232
|
}
|
|
248
|
-
return;
|
|
249
|
-
}
|
|
250
|
-
transaction.onerror = (e) => {
|
|
233
|
+
return data;
|
|
234
|
+
} catch (error) {
|
|
251
235
|
if (log) {
|
|
252
236
|
this.app.logger.addLog({
|
|
253
237
|
type: "error",
|
|
254
238
|
title: uuid,
|
|
255
|
-
metadata: { msg: "
|
|
239
|
+
metadata: { msg: "添加数据失败", error: error.message }
|
|
256
240
|
});
|
|
257
241
|
}
|
|
258
|
-
|
|
259
|
-
}
|
|
260
|
-
|
|
261
|
-
if (log) {
|
|
262
|
-
this.app.logger.addLog({
|
|
263
|
-
type: "error",
|
|
264
|
-
title: uuid,
|
|
265
|
-
metadata: { msg: "事务被中止" }
|
|
266
|
-
});
|
|
267
|
-
}
|
|
268
|
-
return reject(new Error("事务被中止"));
|
|
269
|
-
};
|
|
270
|
-
}),
|
|
242
|
+
throw new Error("添加数据失败");
|
|
243
|
+
}
|
|
244
|
+
})(),
|
|
271
245
|
`add(${storeName})`
|
|
272
246
|
);
|
|
273
247
|
}
|
|
@@ -283,17 +257,17 @@ var IndexDBManager = class _IndexDBManager {
|
|
|
283
257
|
return memStore.has(key);
|
|
284
258
|
}
|
|
285
259
|
return this.withTimeout(
|
|
286
|
-
|
|
260
|
+
(async () => {
|
|
287
261
|
if (!this.db) {
|
|
288
|
-
|
|
289
|
-
return;
|
|
262
|
+
throw new Error("数据库未连接");
|
|
290
263
|
}
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
264
|
+
try {
|
|
265
|
+
const result = await this.db.table(storeName).get(key);
|
|
266
|
+
return result !== void 0;
|
|
267
|
+
} catch (error) {
|
|
268
|
+
throw new Error("检查数据存在性失败");
|
|
269
|
+
}
|
|
270
|
+
})(),
|
|
297
271
|
`exists(${storeName})`
|
|
298
272
|
);
|
|
299
273
|
}
|
|
@@ -319,7 +293,7 @@ var IndexDBManager = class _IndexDBManager {
|
|
|
319
293
|
return memStore.get(key) ?? null;
|
|
320
294
|
}
|
|
321
295
|
return this.withTimeout(
|
|
322
|
-
|
|
296
|
+
(async () => {
|
|
323
297
|
if (!this.db) {
|
|
324
298
|
if (log) {
|
|
325
299
|
this.app.logger.addLog({
|
|
@@ -328,69 +302,34 @@ var IndexDBManager = class _IndexDBManager {
|
|
|
328
302
|
metadata: { msg: "数据库未连接" }
|
|
329
303
|
});
|
|
330
304
|
}
|
|
331
|
-
|
|
332
|
-
return;
|
|
305
|
+
throw new Error("数据库未连接");
|
|
333
306
|
}
|
|
334
|
-
let resolved = false;
|
|
335
307
|
try {
|
|
336
|
-
const
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
}
|
|
347
|
-
}
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
reject(request.error ?? new Error("获取数据失败"));
|
|
360
|
-
};
|
|
361
|
-
transaction.onabort = () => {
|
|
362
|
-
if (log) {
|
|
363
|
-
this.app.logger.addLog({
|
|
364
|
-
type: "info",
|
|
365
|
-
title: uuid,
|
|
366
|
-
metadata: { msg: "事务被中止" }
|
|
367
|
-
});
|
|
368
|
-
}
|
|
369
|
-
if (!resolved) reject(new Error("事务被中止"));
|
|
370
|
-
};
|
|
371
|
-
transaction.onerror = (event) => {
|
|
372
|
-
if (log) {
|
|
373
|
-
this.app.logger.addLog({
|
|
374
|
-
type: "error",
|
|
375
|
-
title: uuid,
|
|
376
|
-
metadata: { msg: `事务错误: ${event.target.error}` }
|
|
377
|
-
});
|
|
378
|
-
}
|
|
379
|
-
if (!resolved) reject(new Error(`事务错误: ${event.target.error}`));
|
|
380
|
-
};
|
|
381
|
-
transaction.oncomplete = () => {
|
|
382
|
-
if (log) {
|
|
383
|
-
this.app.logger.addLog({
|
|
384
|
-
type: "info",
|
|
385
|
-
title: uuid,
|
|
386
|
-
metadata: { msg: "事务完成" }
|
|
387
|
-
});
|
|
388
|
-
}
|
|
389
|
-
};
|
|
390
|
-
} catch (e) {
|
|
391
|
-
reject(e);
|
|
308
|
+
const result = await this.db.table(storeName).get(key);
|
|
309
|
+
if (log) {
|
|
310
|
+
this.app.logger.addLog({
|
|
311
|
+
type: "info",
|
|
312
|
+
title: uuid,
|
|
313
|
+
metadata: { msg: "获取成功" }
|
|
314
|
+
});
|
|
315
|
+
this.app.logger.addLog({
|
|
316
|
+
type: "info",
|
|
317
|
+
title: uuid,
|
|
318
|
+
metadata: { msg: "事务完成" }
|
|
319
|
+
});
|
|
320
|
+
}
|
|
321
|
+
return result ?? null;
|
|
322
|
+
} catch (error) {
|
|
323
|
+
if (log) {
|
|
324
|
+
this.app.logger.addLog({
|
|
325
|
+
type: "error",
|
|
326
|
+
title: uuid,
|
|
327
|
+
metadata: { msg: "获取失败", error: error.message }
|
|
328
|
+
});
|
|
329
|
+
}
|
|
330
|
+
throw new Error("获取数据失败");
|
|
392
331
|
}
|
|
393
|
-
}),
|
|
332
|
+
})(),
|
|
394
333
|
`get(${storeName})`
|
|
395
334
|
);
|
|
396
335
|
}
|
|
@@ -420,7 +359,7 @@ var IndexDBManager = class _IndexDBManager {
|
|
|
420
359
|
});
|
|
421
360
|
}
|
|
422
361
|
return this.withTimeout(
|
|
423
|
-
|
|
362
|
+
(async () => {
|
|
424
363
|
if (!this.db) {
|
|
425
364
|
if (log) {
|
|
426
365
|
this.app.logger.addLog({
|
|
@@ -429,67 +368,35 @@ var IndexDBManager = class _IndexDBManager {
|
|
|
429
368
|
metadata: { msg: "数据库未连接" }
|
|
430
369
|
});
|
|
431
370
|
}
|
|
432
|
-
|
|
433
|
-
return;
|
|
371
|
+
throw new Error("数据库未连接");
|
|
434
372
|
}
|
|
435
373
|
try {
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
}
|
|
459
|
-
|
|
460
|
-
if (log) {
|
|
461
|
-
this.app.logger.addLog({
|
|
462
|
-
type: "info",
|
|
463
|
-
title: uuid,
|
|
464
|
-
metadata: { msg: "事务完成" }
|
|
465
|
-
});
|
|
466
|
-
}
|
|
467
|
-
return console.log("✅ 事务完成");
|
|
468
|
-
};
|
|
469
|
-
transaction.onabort = (e) => {
|
|
470
|
-
if (log) {
|
|
471
|
-
this.app.logger.addLog({
|
|
472
|
-
type: "error",
|
|
473
|
-
title: uuid,
|
|
474
|
-
metadata: { msg: "事务被中止" }
|
|
475
|
-
});
|
|
476
|
-
}
|
|
477
|
-
return reject(new Error("事务被中止"));
|
|
478
|
-
};
|
|
479
|
-
transaction.onerror = (e) => {
|
|
480
|
-
if (log) {
|
|
481
|
-
this.app.logger.addLog({
|
|
482
|
-
type: "error",
|
|
483
|
-
title: uuid,
|
|
484
|
-
metadata: { msg: "事务错误" }
|
|
485
|
-
});
|
|
486
|
-
}
|
|
487
|
-
return reject(transaction.error ?? new Error("事务错误"));
|
|
488
|
-
};
|
|
489
|
-
} catch (e) {
|
|
490
|
-
reject(e);
|
|
374
|
+
await this.db.table(storeName).put(data);
|
|
375
|
+
if (log) {
|
|
376
|
+
this.app.logger.addLog({
|
|
377
|
+
type: "info",
|
|
378
|
+
title: uuid,
|
|
379
|
+
metadata: { msg: "数据更新完成" }
|
|
380
|
+
});
|
|
381
|
+
console.log("✅ 事务完成");
|
|
382
|
+
this.app.logger.addLog({
|
|
383
|
+
type: "info",
|
|
384
|
+
title: uuid,
|
|
385
|
+
metadata: { msg: "事务完成" }
|
|
386
|
+
});
|
|
387
|
+
}
|
|
388
|
+
return data;
|
|
389
|
+
} catch (error) {
|
|
390
|
+
if (log) {
|
|
391
|
+
this.app.logger.addLog({
|
|
392
|
+
type: "error",
|
|
393
|
+
title: uuid,
|
|
394
|
+
metadata: { msg: "数据更新失败", error: error.message }
|
|
395
|
+
});
|
|
396
|
+
}
|
|
397
|
+
throw new Error("更新数据失败");
|
|
491
398
|
}
|
|
492
|
-
}),
|
|
399
|
+
})(),
|
|
493
400
|
`update(${storeName})`
|
|
494
401
|
);
|
|
495
402
|
}
|
|
@@ -505,17 +412,17 @@ var IndexDBManager = class _IndexDBManager {
|
|
|
505
412
|
return memStore.delete(key);
|
|
506
413
|
}
|
|
507
414
|
return this.withTimeout(
|
|
508
|
-
|
|
415
|
+
(async () => {
|
|
509
416
|
if (!this.db) {
|
|
510
|
-
|
|
511
|
-
return;
|
|
417
|
+
throw new Error("数据库未连接");
|
|
512
418
|
}
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
419
|
+
try {
|
|
420
|
+
await this.db.table(storeName).delete(key);
|
|
421
|
+
return true;
|
|
422
|
+
} catch (error) {
|
|
423
|
+
throw new Error("删除数据失败");
|
|
424
|
+
}
|
|
425
|
+
})(),
|
|
519
426
|
`delete(${storeName})`
|
|
520
427
|
);
|
|
521
428
|
}
|
|
@@ -533,22 +440,22 @@ var IndexDBManager = class _IndexDBManager {
|
|
|
533
440
|
const allData = await this.getAll(storeName);
|
|
534
441
|
const storeConfig = this.stores.find((s) => s.name === storeName);
|
|
535
442
|
const index = (_a = storeConfig == null ? void 0 : storeConfig.indexes) == null ? void 0 : _a.find((i) => i.name === indexName);
|
|
536
|
-
if (!index)
|
|
443
|
+
if (!index)
|
|
444
|
+
return null;
|
|
537
445
|
return allData.find((item) => item[index.keyPath] === indexValue) || null;
|
|
538
446
|
}
|
|
539
447
|
return this.withTimeout(
|
|
540
|
-
|
|
448
|
+
(async () => {
|
|
541
449
|
if (!this.db) {
|
|
542
|
-
|
|
543
|
-
|
|
450
|
+
throw new Error("数据库未连接");
|
|
451
|
+
}
|
|
452
|
+
try {
|
|
453
|
+
const result = await this.db.table(storeName).where(indexName).equals(indexValue).first();
|
|
454
|
+
return result || null;
|
|
455
|
+
} catch (error) {
|
|
456
|
+
throw new Error("通过索引获取数据失败");
|
|
544
457
|
}
|
|
545
|
-
|
|
546
|
-
const store = transaction.objectStore(storeName);
|
|
547
|
-
const index = store.index(indexName);
|
|
548
|
-
const request = index.get(indexValue);
|
|
549
|
-
request.onsuccess = () => resolve(request.result || null);
|
|
550
|
-
request.onerror = () => reject(new Error("通过索引获取数据失败"));
|
|
551
|
-
}),
|
|
458
|
+
})(),
|
|
552
459
|
`getByIndex(${storeName}, ${indexName})`
|
|
553
460
|
);
|
|
554
461
|
}
|
|
@@ -565,22 +472,22 @@ var IndexDBManager = class _IndexDBManager {
|
|
|
565
472
|
const allData = await this.getAll(storeName);
|
|
566
473
|
const storeConfig = this.stores.find((s) => s.name === storeName);
|
|
567
474
|
const index = (_a = storeConfig == null ? void 0 : storeConfig.indexes) == null ? void 0 : _a.find((i) => i.name === indexName);
|
|
568
|
-
if (!index)
|
|
475
|
+
if (!index)
|
|
476
|
+
return false;
|
|
569
477
|
return allData.some((item) => item[index.keyPath] === indexValue);
|
|
570
478
|
}
|
|
571
479
|
return this.withTimeout(
|
|
572
|
-
|
|
480
|
+
(async () => {
|
|
573
481
|
if (!this.db) {
|
|
574
|
-
|
|
575
|
-
|
|
482
|
+
throw new Error("数据库未连接");
|
|
483
|
+
}
|
|
484
|
+
try {
|
|
485
|
+
const count = await this.db.table(storeName).where(indexName).equals(indexValue).count();
|
|
486
|
+
return count > 0;
|
|
487
|
+
} catch (error) {
|
|
488
|
+
throw new Error("通过索引检查数据存在性失败");
|
|
576
489
|
}
|
|
577
|
-
|
|
578
|
-
const store = transaction.objectStore(storeName);
|
|
579
|
-
const index = store.index(indexName);
|
|
580
|
-
const request = index.count(indexValue);
|
|
581
|
-
request.onsuccess = () => resolve(request.result > 0);
|
|
582
|
-
request.onerror = () => reject(new Error("通过索引检查数据存在性失败"));
|
|
583
|
-
}),
|
|
490
|
+
})(),
|
|
584
491
|
`existsByIndex(${storeName}, ${indexName})`
|
|
585
492
|
);
|
|
586
493
|
}
|
|
@@ -598,22 +505,22 @@ var IndexDBManager = class _IndexDBManager {
|
|
|
598
505
|
const allData = await this.getAll(storeName);
|
|
599
506
|
const storeConfig = this.stores.find((s) => s.name === storeName);
|
|
600
507
|
const index = (_a = storeConfig == null ? void 0 : storeConfig.indexes) == null ? void 0 : _a.find((i) => i.name === indexName);
|
|
601
|
-
if (!index)
|
|
508
|
+
if (!index)
|
|
509
|
+
return [];
|
|
602
510
|
return allData.filter((item) => item[index.keyPath] === indexValue);
|
|
603
511
|
}
|
|
604
512
|
return this.withTimeout(
|
|
605
|
-
|
|
513
|
+
(async () => {
|
|
606
514
|
if (!this.db) {
|
|
607
|
-
|
|
608
|
-
return;
|
|
515
|
+
throw new Error("数据库未连接");
|
|
609
516
|
}
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
}),
|
|
517
|
+
try {
|
|
518
|
+
const results = await this.db.table(storeName).where(indexName).equals(indexValue).toArray();
|
|
519
|
+
return results;
|
|
520
|
+
} catch (error) {
|
|
521
|
+
throw new Error("通过索引获取多条数据失败");
|
|
522
|
+
}
|
|
523
|
+
})(),
|
|
617
524
|
`getAllByIndex(${storeName}, ${indexName})`
|
|
618
525
|
);
|
|
619
526
|
}
|
|
@@ -628,17 +535,17 @@ var IndexDBManager = class _IndexDBManager {
|
|
|
628
535
|
return allData.length;
|
|
629
536
|
}
|
|
630
537
|
return this.withTimeout(
|
|
631
|
-
|
|
538
|
+
(async () => {
|
|
632
539
|
if (!this.db) {
|
|
633
|
-
|
|
634
|
-
|
|
540
|
+
throw new Error("数据库未连接");
|
|
541
|
+
}
|
|
542
|
+
try {
|
|
543
|
+
const count = await this.db.table(storeName).count();
|
|
544
|
+
return count;
|
|
545
|
+
} catch (error) {
|
|
546
|
+
throw new Error("统计数据数量失败");
|
|
635
547
|
}
|
|
636
|
-
|
|
637
|
-
const store = transaction.objectStore(storeName);
|
|
638
|
-
const request = store.count();
|
|
639
|
-
request.onsuccess = () => resolve(request.result);
|
|
640
|
-
request.onerror = () => reject(new Error("统计数据数量失败"));
|
|
641
|
-
}),
|
|
548
|
+
})(),
|
|
642
549
|
`count(${storeName})`
|
|
643
550
|
);
|
|
644
551
|
}
|
|
@@ -655,18 +562,17 @@ var IndexDBManager = class _IndexDBManager {
|
|
|
655
562
|
return matchingData.length;
|
|
656
563
|
}
|
|
657
564
|
return this.withTimeout(
|
|
658
|
-
|
|
565
|
+
(async () => {
|
|
659
566
|
if (!this.db) {
|
|
660
|
-
|
|
661
|
-
return;
|
|
567
|
+
throw new Error("数据库未连接");
|
|
662
568
|
}
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
}),
|
|
569
|
+
try {
|
|
570
|
+
const count = await this.db.table(storeName).where(indexName).equals(indexValue).count();
|
|
571
|
+
return count;
|
|
572
|
+
} catch (error) {
|
|
573
|
+
throw new Error("通过索引统计数据数量失败");
|
|
574
|
+
}
|
|
575
|
+
})(),
|
|
670
576
|
`countByIndex(${storeName}, ${indexName})`
|
|
671
577
|
);
|
|
672
578
|
}
|
|
@@ -682,17 +588,17 @@ var IndexDBManager = class _IndexDBManager {
|
|
|
682
588
|
return Array.from(memStore.values());
|
|
683
589
|
}
|
|
684
590
|
return this.withTimeout(
|
|
685
|
-
|
|
591
|
+
(async () => {
|
|
686
592
|
if (!this.db) {
|
|
687
|
-
|
|
688
|
-
|
|
593
|
+
throw new Error("数据库未连接");
|
|
594
|
+
}
|
|
595
|
+
try {
|
|
596
|
+
const results = await this.db.table(storeName).toArray();
|
|
597
|
+
return results;
|
|
598
|
+
} catch (error) {
|
|
599
|
+
throw new Error("获取所有数据失败");
|
|
689
600
|
}
|
|
690
|
-
|
|
691
|
-
const store = transaction.objectStore(storeName);
|
|
692
|
-
const request = store.getAll();
|
|
693
|
-
request.onsuccess = () => resolve(request.result);
|
|
694
|
-
request.onerror = () => reject(new Error("获取所有数据失败"));
|
|
695
|
-
}),
|
|
601
|
+
})(),
|
|
696
602
|
`getAll(${storeName})`
|
|
697
603
|
);
|
|
698
604
|
}
|
|
@@ -708,17 +614,17 @@ var IndexDBManager = class _IndexDBManager {
|
|
|
708
614
|
return true;
|
|
709
615
|
}
|
|
710
616
|
return this.withTimeout(
|
|
711
|
-
|
|
617
|
+
(async () => {
|
|
712
618
|
if (!this.db) {
|
|
713
|
-
|
|
714
|
-
|
|
619
|
+
throw new Error("数据库未连接");
|
|
620
|
+
}
|
|
621
|
+
try {
|
|
622
|
+
await this.db.table(storeName).clear();
|
|
623
|
+
return true;
|
|
624
|
+
} catch (error) {
|
|
625
|
+
throw new Error("清空数据失败");
|
|
715
626
|
}
|
|
716
|
-
|
|
717
|
-
const store = transaction.objectStore(storeName);
|
|
718
|
-
const request = store.clear();
|
|
719
|
-
request.onsuccess = () => resolve(true);
|
|
720
|
-
request.onerror = () => reject(new Error("清空数据失败"));
|
|
721
|
-
}),
|
|
627
|
+
})(),
|
|
722
628
|
`clear(${storeName})`
|
|
723
629
|
);
|
|
724
630
|
}
|