@pisell/core 1.0.56 → 1.0.58
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/indexDB/index.d.ts +1 -0
- package/es/indexDB/index.js +434 -473
- package/es/request/cache.js +2 -2
- package/lib/indexDB/index.d.ts +1 -0
- package/lib/indexDB/index.js +22 -16
- package/lib/request/cache.js +2 -2
- package/package.json +1 -1
package/es/request/cache.js
CHANGED
|
@@ -90,13 +90,13 @@ export var setCache = /*#__PURE__*/function () {
|
|
|
90
90
|
break;
|
|
91
91
|
}
|
|
92
92
|
_context.next = 19;
|
|
93
|
-
return app.dbManager.
|
|
93
|
+
return app.dbManager.debouncedAdd('requests', cacheData);
|
|
94
94
|
case 19:
|
|
95
95
|
_context.next = 23;
|
|
96
96
|
break;
|
|
97
97
|
case 21:
|
|
98
98
|
_context.next = 23;
|
|
99
|
-
return app.dbManager.
|
|
99
|
+
return app.dbManager.debouncedUpdate('requests', cacheData);
|
|
100
100
|
case 23:
|
|
101
101
|
console.log('设置缓存成功', CACHES);
|
|
102
102
|
case 24:
|
package/lib/indexDB/index.d.ts
CHANGED
package/lib/indexDB/index.js
CHANGED
|
@@ -29,11 +29,19 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
29
29
|
// src/indexDB/index.ts
|
|
30
30
|
var indexDB_exports = {};
|
|
31
31
|
__export(indexDB_exports, {
|
|
32
|
-
default: () => indexDB_default
|
|
32
|
+
default: () => indexDB_default,
|
|
33
|
+
mockPromise: () => mockPromise
|
|
33
34
|
});
|
|
34
35
|
module.exports = __toCommonJS(indexDB_exports);
|
|
35
36
|
var import_dayjs = __toESM(require("dayjs"));
|
|
36
37
|
var import_dexie = __toESM(require("dexie"));
|
|
38
|
+
var mockPromise = (data, timeout = 200) => {
|
|
39
|
+
return new Promise((resolve, reject) => {
|
|
40
|
+
setTimeout(() => {
|
|
41
|
+
resolve(data);
|
|
42
|
+
}, timeout);
|
|
43
|
+
});
|
|
44
|
+
};
|
|
37
45
|
var IndexDBManager = class _IndexDBManager {
|
|
38
46
|
/**
|
|
39
47
|
* 检查环境是否支持 IndexedDB
|
|
@@ -205,13 +213,6 @@ var IndexDBManager = class _IndexDBManager {
|
|
|
205
213
|
* @param data 数据
|
|
206
214
|
*/
|
|
207
215
|
debouncedAdd(storeName, data) {
|
|
208
|
-
if (!this.useIndexDB) {
|
|
209
|
-
const storeConfig = this.stores.find((s) => s.name === storeName);
|
|
210
|
-
const keyPath = (storeConfig == null ? void 0 : storeConfig.keyPath) || "id";
|
|
211
|
-
const key = data[keyPath];
|
|
212
|
-
this.getMemoryStore(storeName).set(key, data);
|
|
213
|
-
return;
|
|
214
|
-
}
|
|
215
216
|
if (!this.db) return;
|
|
216
217
|
if (!this.debouncedBuffers.has(storeName)) {
|
|
217
218
|
this.debouncedBuffers.set(storeName, []);
|
|
@@ -240,11 +241,13 @@ var IndexDBManager = class _IndexDBManager {
|
|
|
240
241
|
try {
|
|
241
242
|
while (buffer.length > 0) {
|
|
242
243
|
const batch = buffer.splice(0, this.debouncedBatchSize);
|
|
243
|
-
|
|
244
|
-
|
|
244
|
+
for (const item of batch) {
|
|
245
|
+
await mockPromise({}, this.debouncedDelay);
|
|
246
|
+
try {
|
|
245
247
|
await this.add(storeName, item);
|
|
248
|
+
} catch (err) {
|
|
246
249
|
}
|
|
247
|
-
}
|
|
250
|
+
}
|
|
248
251
|
}
|
|
249
252
|
} catch (error) {
|
|
250
253
|
this.app.logger.addLog({
|
|
@@ -314,11 +317,10 @@ var IndexDBManager = class _IndexDBManager {
|
|
|
314
317
|
bufferMap.clear();
|
|
315
318
|
for (let i = 0; i < entries.length; i += this.debouncedUpdateBatchSize) {
|
|
316
319
|
const batch = entries.slice(i, i + this.debouncedUpdateBatchSize);
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
});
|
|
320
|
+
for (const item of batch) {
|
|
321
|
+
await mockPromise(item, this.debouncedUpdateDelay);
|
|
322
|
+
await this.update(storeName, item);
|
|
323
|
+
}
|
|
322
324
|
}
|
|
323
325
|
} catch (error) {
|
|
324
326
|
this.app.logger.addLog({
|
|
@@ -756,3 +758,7 @@ var IndexDBManager = class _IndexDBManager {
|
|
|
756
758
|
}
|
|
757
759
|
};
|
|
758
760
|
var indexDB_default = IndexDBManager;
|
|
761
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
762
|
+
0 && (module.exports = {
|
|
763
|
+
mockPromise
|
|
764
|
+
});
|
package/lib/request/cache.js
CHANGED
|
@@ -65,9 +65,9 @@ var setCache = async (key, data, cache) => {
|
|
|
65
65
|
if (app.dbManager) {
|
|
66
66
|
let tasksData = await app.dbManager.get("requests", key);
|
|
67
67
|
if (!tasksData) {
|
|
68
|
-
await app.dbManager.
|
|
68
|
+
await app.dbManager.debouncedAdd("requests", cacheData);
|
|
69
69
|
} else {
|
|
70
|
-
await app.dbManager.
|
|
70
|
+
await app.dbManager.debouncedUpdate("requests", cacheData);
|
|
71
71
|
}
|
|
72
72
|
}
|
|
73
73
|
}
|