@snail-js/api 0.1.11 → 0.1.12
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/dist/cache/indexDBCache.d.ts +1 -1
- package/dist/snail-api.js +15 -17
- package/dist/snail-api.umd.cjs +15 -17
- package/dist/typings/response.data.d.ts +1 -2
- package/package.json +1 -1
package/dist/snail-api.js
CHANGED
|
@@ -3566,7 +3566,7 @@ const INDEXDB_INDEX_NAME = "SNAIL_CACHE_INDEX";
|
|
|
3566
3566
|
class IndexDBCache {
|
|
3567
3567
|
constructor(ttl) {
|
|
3568
3568
|
__publicField(this, "ttl");
|
|
3569
|
-
__publicField(this, "db"
|
|
3569
|
+
__publicField(this, "db");
|
|
3570
3570
|
this.ttl = ttl;
|
|
3571
3571
|
}
|
|
3572
3572
|
async init() {
|
|
@@ -3595,9 +3595,9 @@ class IndexDBCache {
|
|
|
3595
3595
|
});
|
|
3596
3596
|
}
|
|
3597
3597
|
async get(key) {
|
|
3598
|
-
return new Promise((resolve, reject) => {
|
|
3599
|
-
if (this.db === null) {
|
|
3600
|
-
|
|
3598
|
+
return new Promise(async (resolve, reject) => {
|
|
3599
|
+
if (this.db === null || this.db === void 0) {
|
|
3600
|
+
await this.init();
|
|
3601
3601
|
}
|
|
3602
3602
|
const select = this.db.transaction(INDEXDB_OBJECT_STORE_NAME, "readonly").objectStore(INDEXDB_OBJECT_STORE_NAME).get(key);
|
|
3603
3603
|
select.onsuccess = () => {
|
|
@@ -3617,17 +3617,15 @@ class IndexDBCache {
|
|
|
3617
3617
|
});
|
|
3618
3618
|
}
|
|
3619
3619
|
async set(key, value) {
|
|
3620
|
-
return new Promise((resolve, reject) => {
|
|
3621
|
-
if (this.db === null) {
|
|
3622
|
-
|
|
3620
|
+
return new Promise(async (resolve, reject) => {
|
|
3621
|
+
if (this.db === null || this.db === void 0) {
|
|
3622
|
+
await this.init();
|
|
3623
3623
|
}
|
|
3624
|
-
const select = this.db.transaction(INDEXDB_OBJECT_STORE_NAME, "readwrite").objectStore(INDEXDB_OBJECT_STORE_NAME).put(
|
|
3625
|
-
|
|
3626
|
-
|
|
3627
|
-
|
|
3628
|
-
|
|
3629
|
-
}
|
|
3630
|
-
);
|
|
3624
|
+
const select = this.db.transaction(INDEXDB_OBJECT_STORE_NAME, "readwrite").objectStore(INDEXDB_OBJECT_STORE_NAME).put({
|
|
3625
|
+
data: value,
|
|
3626
|
+
exp: Math.ceil((/* @__PURE__ */ new Date()).getTime() / 1e3) + this.ttl,
|
|
3627
|
+
key
|
|
3628
|
+
});
|
|
3631
3629
|
select.onsuccess = () => {
|
|
3632
3630
|
resolve({ error: null, data: true });
|
|
3633
3631
|
};
|
|
@@ -3640,9 +3638,9 @@ class IndexDBCache {
|
|
|
3640
3638
|
});
|
|
3641
3639
|
}
|
|
3642
3640
|
async delete(key) {
|
|
3643
|
-
return new Promise((resolve, reject) => {
|
|
3644
|
-
if (this.db === null) {
|
|
3645
|
-
|
|
3641
|
+
return new Promise(async (resolve, reject) => {
|
|
3642
|
+
if (this.db === null || this.db === void 0) {
|
|
3643
|
+
await this.init();
|
|
3646
3644
|
}
|
|
3647
3645
|
const select = this.db.transaction(INDEXDB_OBJECT_STORE_NAME, "readwrite").objectStore(INDEXDB_OBJECT_STORE_NAME).delete(key);
|
|
3648
3646
|
select.onsuccess = () => {
|
package/dist/snail-api.umd.cjs
CHANGED
|
@@ -3570,7 +3570,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
3570
3570
|
class IndexDBCache {
|
|
3571
3571
|
constructor(ttl) {
|
|
3572
3572
|
__publicField(this, "ttl");
|
|
3573
|
-
__publicField(this, "db"
|
|
3573
|
+
__publicField(this, "db");
|
|
3574
3574
|
this.ttl = ttl;
|
|
3575
3575
|
}
|
|
3576
3576
|
async init() {
|
|
@@ -3599,9 +3599,9 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
3599
3599
|
});
|
|
3600
3600
|
}
|
|
3601
3601
|
async get(key) {
|
|
3602
|
-
return new Promise((resolve, reject) => {
|
|
3603
|
-
if (this.db === null) {
|
|
3604
|
-
|
|
3602
|
+
return new Promise(async (resolve, reject) => {
|
|
3603
|
+
if (this.db === null || this.db === void 0) {
|
|
3604
|
+
await this.init();
|
|
3605
3605
|
}
|
|
3606
3606
|
const select = this.db.transaction(INDEXDB_OBJECT_STORE_NAME, "readonly").objectStore(INDEXDB_OBJECT_STORE_NAME).get(key);
|
|
3607
3607
|
select.onsuccess = () => {
|
|
@@ -3621,17 +3621,15 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
3621
3621
|
});
|
|
3622
3622
|
}
|
|
3623
3623
|
async set(key, value) {
|
|
3624
|
-
return new Promise((resolve, reject) => {
|
|
3625
|
-
if (this.db === null) {
|
|
3626
|
-
|
|
3624
|
+
return new Promise(async (resolve, reject) => {
|
|
3625
|
+
if (this.db === null || this.db === void 0) {
|
|
3626
|
+
await this.init();
|
|
3627
3627
|
}
|
|
3628
|
-
const select = this.db.transaction(INDEXDB_OBJECT_STORE_NAME, "readwrite").objectStore(INDEXDB_OBJECT_STORE_NAME).put(
|
|
3629
|
-
|
|
3630
|
-
|
|
3631
|
-
|
|
3632
|
-
|
|
3633
|
-
}
|
|
3634
|
-
);
|
|
3628
|
+
const select = this.db.transaction(INDEXDB_OBJECT_STORE_NAME, "readwrite").objectStore(INDEXDB_OBJECT_STORE_NAME).put({
|
|
3629
|
+
data: value,
|
|
3630
|
+
exp: Math.ceil((/* @__PURE__ */ new Date()).getTime() / 1e3) + this.ttl,
|
|
3631
|
+
key
|
|
3632
|
+
});
|
|
3635
3633
|
select.onsuccess = () => {
|
|
3636
3634
|
resolve({ error: null, data: true });
|
|
3637
3635
|
};
|
|
@@ -3644,9 +3642,9 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
3644
3642
|
});
|
|
3645
3643
|
}
|
|
3646
3644
|
async delete(key) {
|
|
3647
|
-
return new Promise((resolve, reject) => {
|
|
3648
|
-
if (this.db === null) {
|
|
3649
|
-
|
|
3645
|
+
return new Promise(async (resolve, reject) => {
|
|
3646
|
+
if (this.db === null || this.db === void 0) {
|
|
3647
|
+
await this.init();
|
|
3650
3648
|
}
|
|
3651
3649
|
const select = this.db.transaction(INDEXDB_OBJECT_STORE_NAME, "readwrite").objectStore(INDEXDB_OBJECT_STORE_NAME).delete(key);
|
|
3652
3650
|
select.onsuccess = () => {
|