@snail-js/api 0.1.25 → 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
@@ -3467,7 +3467,7 @@ class MemoryCache {
3467
3467
  data: null
3468
3468
  });
3469
3469
  }
3470
- resolve({ error: null, data: data.data });
3470
+ resolve({ error: null, data });
3471
3471
  } catch (error) {
3472
3472
  console.error("[MemoryCache]获取缓存错误:", error);
3473
3473
  reject(error);
@@ -3545,7 +3545,7 @@ class LocalStorageCache {
3545
3545
  data: null
3546
3546
  });
3547
3547
  }
3548
- resolve({ error: null, data: data.data });
3548
+ resolve({ error: null, data });
3549
3549
  } catch (error) {
3550
3550
  reject({ error, data: null });
3551
3551
  }
@@ -3648,7 +3648,7 @@ class IndexDBCache {
3648
3648
  this.delete(key);
3649
3649
  return resolve({ error: new Error("缓存已过期"), data: null });
3650
3650
  }
3651
- resolve({ error: null, data: result.data.data });
3651
+ resolve({ error: null, data: result.data });
3652
3652
  };
3653
3653
  select.onerror = (event) => {
3654
3654
  reject({
@@ -4285,12 +4285,7 @@ class SnailMethod {
4285
4285
  this.enableLog() && console.log("setCacheData:", methodKey);
4286
4286
  const cacheStorage = CacheStorageMap.get(serverName);
4287
4287
  if (!cacheStorage) throw new Error("CacheStorage not created");
4288
- const ttl = CacheTtlMap.get(serverName);
4289
- const cacheData = {
4290
- data: responseData.data,
4291
- exp: Date.now() + ttl * 1e3
4292
- };
4293
- cacheStorage.set(methodKey, cacheData);
4288
+ cacheStorage.set(methodKey, responseData);
4294
4289
  }
4295
4290
  get response() {
4296
4291
  return this.Response;
@@ -4389,7 +4384,6 @@ class SnailMethod {
4389
4384
  }
4390
4385
  }
4391
4386
  const CacheStorageMap = /* @__PURE__ */ new Map();
4392
- const CacheTtlMap = /* @__PURE__ */ new Map();
4393
4387
  const CacheForMap = /* @__PURE__ */ new Map();
4394
4388
  const ExpireSourceMap = /* @__PURE__ */ new Map();
4395
4389
  const AxiosInstanceMap = /* @__PURE__ */ new Map();
@@ -4518,7 +4512,6 @@ class SnailServer {
4518
4512
  if (!cacheStorage && options !== void 0) {
4519
4513
  const storage = createCache(options);
4520
4514
  CacheStorageMap.set(this.Name, storage);
4521
- CacheTtlMap.set(this.Name, options.ttl || 500);
4522
4515
  }
4523
4516
  if (cacheFor) {
4524
4517
  if (Array.isArray(cacheFor)) {
@@ -3471,7 +3471,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
3471
3471
  data: null
3472
3472
  });
3473
3473
  }
3474
- resolve({ error: null, data: data.data });
3474
+ resolve({ error: null, data });
3475
3475
  } catch (error) {
3476
3476
  console.error("[MemoryCache]获取缓存错误:", error);
3477
3477
  reject(error);
@@ -3549,7 +3549,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
3549
3549
  data: null
3550
3550
  });
3551
3551
  }
3552
- resolve({ error: null, data: data.data });
3552
+ resolve({ error: null, data });
3553
3553
  } catch (error) {
3554
3554
  reject({ error, data: null });
3555
3555
  }
@@ -3652,7 +3652,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
3652
3652
  this.delete(key);
3653
3653
  return resolve({ error: new Error("缓存已过期"), data: null });
3654
3654
  }
3655
- resolve({ error: null, data: result.data.data });
3655
+ resolve({ error: null, data: result.data });
3656
3656
  };
3657
3657
  select.onerror = (event) => {
3658
3658
  reject({
@@ -4289,12 +4289,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
4289
4289
  this.enableLog() && console.log("setCacheData:", methodKey);
4290
4290
  const cacheStorage = CacheStorageMap.get(serverName);
4291
4291
  if (!cacheStorage) throw new Error("CacheStorage not created");
4292
- const ttl = CacheTtlMap.get(serverName);
4293
- const cacheData = {
4294
- data: responseData.data,
4295
- exp: Date.now() + ttl * 1e3
4296
- };
4297
- cacheStorage.set(methodKey, cacheData);
4292
+ cacheStorage.set(methodKey, responseData);
4298
4293
  }
4299
4294
  get response() {
4300
4295
  return this.Response;
@@ -4393,7 +4388,6 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
4393
4388
  }
4394
4389
  }
4395
4390
  const CacheStorageMap = /* @__PURE__ */ new Map();
4396
- const CacheTtlMap = /* @__PURE__ */ new Map();
4397
4391
  const CacheForMap = /* @__PURE__ */ new Map();
4398
4392
  const ExpireSourceMap = /* @__PURE__ */ new Map();
4399
4393
  const AxiosInstanceMap = /* @__PURE__ */ new Map();
@@ -4522,7 +4516,6 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
4522
4516
  if (!cacheStorage && options !== void 0) {
4523
4517
  const storage = createCache(options);
4524
4518
  CacheStorageMap.set(this.Name, storage);
4525
- CacheTtlMap.set(this.Name, options.ttl || 500);
4526
4519
  }
4527
4520
  if (cacheFor) {
4528
4521
  if (Array.isArray(cacheFor)) {
@@ -2,9 +2,7 @@ import MemoryCache from "../cache/memoryCache";
2
2
  import LocalStorageCache from "../cache/localstorageCache";
3
3
  import IndexDBCache from "../cache/indexDBCache";
4
4
  export interface CacheSetData<T = any> {
5
- data: {
6
- data: T;
7
- };
5
+ data: T;
8
6
  exp: number;
9
7
  }
10
8
  export type CacheGetData<T = any> = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@snail-js/api",
3
- "version": "0.1.25",
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",