@snail-js/api 0.1.24 → 0.1.26

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.
@@ -4,7 +4,6 @@ import { Strategy, ApiInstanceOptions, VersioningOption, CacheStorage, ApiProxy,
4
4
  import { SnailApi } from "./snailApi";
5
5
  import { SnailSse } from "./snailSse";
6
6
  export declare const CacheStorageMap: Map<string, CacheStorage>;
7
- export declare const CacheTtlMap: Map<string, number>;
8
7
  export declare const CacheForMap: Map<string, string[]>;
9
8
  export declare const ExpireSourceMap: Map<string, Set<string>>;
10
9
  export declare const AxiosInstanceMap: Map<string, AxiosInstance>;
package/dist/snail-api.js CHANGED
@@ -3695,7 +3695,10 @@ class IndexDBCache {
3695
3695
  async clear() {
3696
3696
  return new Promise(async (resolve, reject) => {
3697
3697
  if (!this.db) await this.init();
3698
- const transaction = this.db.transaction(INDEXDB_OBJECT_STORE_NAME, "readwrite");
3698
+ const transaction = this.db.transaction(
3699
+ INDEXDB_OBJECT_STORE_NAME,
3700
+ "readwrite"
3701
+ );
3699
3702
  const request = transaction.objectStore(INDEXDB_OBJECT_STORE_NAME).clear();
3700
3703
  request.onsuccess = () => resolve(true);
3701
3704
  request.onerror = (event) => {
@@ -3707,7 +3710,10 @@ class IndexDBCache {
3707
3710
  async keys() {
3708
3711
  return new Promise(async (resolve, reject) => {
3709
3712
  if (!this.db) await this.init();
3710
- const transaction = this.db.transaction(INDEXDB_OBJECT_STORE_NAME, "readonly");
3713
+ const transaction = this.db.transaction(
3714
+ INDEXDB_OBJECT_STORE_NAME,
3715
+ "readonly"
3716
+ );
3711
3717
  const request = transaction.objectStore(INDEXDB_OBJECT_STORE_NAME).getAllKeys();
3712
3718
  request.onsuccess = () => resolve(request.result.map((key) => key.toString()));
3713
3719
  request.onerror = (event) => {
@@ -4279,12 +4285,7 @@ class SnailMethod {
4279
4285
  this.enableLog() && console.log("setCacheData:", methodKey);
4280
4286
  const cacheStorage = CacheStorageMap.get(serverName);
4281
4287
  if (!cacheStorage) throw new Error("CacheStorage not created");
4282
- const ttl = CacheTtlMap.get(serverName);
4283
- const cacheData = {
4284
- data: responseData.data,
4285
- exp: Date.now() + ttl * 1e3
4286
- };
4287
- cacheStorage.set(methodKey, cacheData);
4288
+ cacheStorage.set(methodKey, responseData);
4288
4289
  }
4289
4290
  get response() {
4290
4291
  return this.Response;
@@ -4383,7 +4384,6 @@ class SnailMethod {
4383
4384
  }
4384
4385
  }
4385
4386
  const CacheStorageMap = /* @__PURE__ */ new Map();
4386
- const CacheTtlMap = /* @__PURE__ */ new Map();
4387
4387
  const CacheForMap = /* @__PURE__ */ new Map();
4388
4388
  const ExpireSourceMap = /* @__PURE__ */ new Map();
4389
4389
  const AxiosInstanceMap = /* @__PURE__ */ new Map();
@@ -4512,7 +4512,6 @@ class SnailServer {
4512
4512
  if (!cacheStorage && options !== void 0) {
4513
4513
  const storage = createCache(options);
4514
4514
  CacheStorageMap.set(this.Name, storage);
4515
- CacheTtlMap.set(this.Name, options.ttl || 500);
4516
4515
  }
4517
4516
  if (cacheFor) {
4518
4517
  if (Array.isArray(cacheFor)) {
@@ -3699,7 +3699,10 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
3699
3699
  async clear() {
3700
3700
  return new Promise(async (resolve, reject) => {
3701
3701
  if (!this.db) await this.init();
3702
- const transaction = this.db.transaction(INDEXDB_OBJECT_STORE_NAME, "readwrite");
3702
+ const transaction = this.db.transaction(
3703
+ INDEXDB_OBJECT_STORE_NAME,
3704
+ "readwrite"
3705
+ );
3703
3706
  const request = transaction.objectStore(INDEXDB_OBJECT_STORE_NAME).clear();
3704
3707
  request.onsuccess = () => resolve(true);
3705
3708
  request.onerror = (event) => {
@@ -3711,7 +3714,10 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
3711
3714
  async keys() {
3712
3715
  return new Promise(async (resolve, reject) => {
3713
3716
  if (!this.db) await this.init();
3714
- const transaction = this.db.transaction(INDEXDB_OBJECT_STORE_NAME, "readonly");
3717
+ const transaction = this.db.transaction(
3718
+ INDEXDB_OBJECT_STORE_NAME,
3719
+ "readonly"
3720
+ );
3715
3721
  const request = transaction.objectStore(INDEXDB_OBJECT_STORE_NAME).getAllKeys();
3716
3722
  request.onsuccess = () => resolve(request.result.map((key) => key.toString()));
3717
3723
  request.onerror = (event) => {
@@ -4283,12 +4289,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
4283
4289
  this.enableLog() && console.log("setCacheData:", methodKey);
4284
4290
  const cacheStorage = CacheStorageMap.get(serverName);
4285
4291
  if (!cacheStorage) throw new Error("CacheStorage not created");
4286
- const ttl = CacheTtlMap.get(serverName);
4287
- const cacheData = {
4288
- data: responseData.data,
4289
- exp: Date.now() + ttl * 1e3
4290
- };
4291
- cacheStorage.set(methodKey, cacheData);
4292
+ cacheStorage.set(methodKey, responseData);
4292
4293
  }
4293
4294
  get response() {
4294
4295
  return this.Response;
@@ -4387,7 +4388,6 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
4387
4388
  }
4388
4389
  }
4389
4390
  const CacheStorageMap = /* @__PURE__ */ new Map();
4390
- const CacheTtlMap = /* @__PURE__ */ new Map();
4391
4391
  const CacheForMap = /* @__PURE__ */ new Map();
4392
4392
  const ExpireSourceMap = /* @__PURE__ */ new Map();
4393
4393
  const AxiosInstanceMap = /* @__PURE__ */ new Map();
@@ -4516,7 +4516,6 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
4516
4516
  if (!cacheStorage && options !== void 0) {
4517
4517
  const storage = createCache(options);
4518
4518
  CacheStorageMap.set(this.Name, storage);
4519
- CacheTtlMap.set(this.Name, options.ttl || 500);
4520
4519
  }
4521
4520
  if (cacheFor) {
4522
4521
  if (Array.isArray(cacheFor)) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@snail-js/api",
3
- "version": "0.1.24",
3
+ "version": "0.1.26",
4
4
  "description": "Http Request with Decorators Api, build on axios",
5
5
  "type": "module",
6
6
  "main": "./src/index.ts",