@snail-js/api 0.1.10 → 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.
@@ -1,6 +1,6 @@
1
1
  export default class IndexDBCache {
2
2
  ttl: number;
3
- private db;
3
+ private db?;
4
4
  constructor(ttl: number);
5
5
  init(): Promise<void>;
6
6
  private openDB;
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", null);
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
- return reject({ error: new Error("数据库未初始化"), data: null });
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
- return reject({ error: new Error("数据库未初始化"), data: null });
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
- data: value,
3627
- exp: Math.ceil((/* @__PURE__ */ new Date()).getTime() / 1e3) + this.ttl,
3628
- key
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
- return reject({ error: new Error("数据库未初始化"), data: null });
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 = () => {
@@ -4143,7 +4141,7 @@ class Snail {
4143
4141
  );
4144
4142
  const sseUrl = this.generateSseUrl(baseURL, versionUrl || url);
4145
4143
  enableLog && console.log("sse-url:", sseUrl);
4146
- return this.initSse(sseUrl, sseOption, target);
4144
+ return () => this.initSse(sseUrl, sseOption, target);
4147
4145
  }
4148
4146
  }
4149
4147
  });
@@ -4164,12 +4162,10 @@ class Snail {
4164
4162
  }
4165
4163
  setSse(target) {
4166
4164
  const onOpenFunc = Reflect.getMetadata(EVENT_SOURCE_OPEN_KEY, target);
4167
- console.log("sse-proxy[open]:", onOpenFunc);
4168
4165
  if (typeof onOpenFunc == "function") {
4169
4166
  this.eventSource && (this.eventSource.onopen = onOpenFunc);
4170
4167
  }
4171
4168
  const onErrorFunc = Reflect.getMetadata(EVENT_SOURCE_ERROR_KEY, target);
4172
- console.log("sse-proxy[error]:", onErrorFunc);
4173
4169
  if (typeof onErrorFunc == "function") {
4174
4170
  this.eventSource && (this.eventSource.onerror = onErrorFunc);
4175
4171
  }
@@ -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", null);
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
- return reject({ error: new Error("数据库未初始化"), data: null });
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
- return reject({ error: new Error("数据库未初始化"), data: null });
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
- data: value,
3631
- exp: Math.ceil((/* @__PURE__ */ new Date()).getTime() / 1e3) + this.ttl,
3632
- key
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
- return reject({ error: new Error("数据库未初始化"), data: null });
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 = () => {
@@ -4147,7 +4145,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
4147
4145
  );
4148
4146
  const sseUrl = this.generateSseUrl(baseURL, versionUrl || url);
4149
4147
  enableLog && console.log("sse-url:", sseUrl);
4150
- return this.initSse(sseUrl, sseOption, target);
4148
+ return () => this.initSse(sseUrl, sseOption, target);
4151
4149
  }
4152
4150
  }
4153
4151
  });
@@ -4168,12 +4166,10 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
4168
4166
  }
4169
4167
  setSse(target) {
4170
4168
  const onOpenFunc = Reflect.getMetadata(EVENT_SOURCE_OPEN_KEY, target);
4171
- console.log("sse-proxy[open]:", onOpenFunc);
4172
4169
  if (typeof onOpenFunc == "function") {
4173
4170
  this.eventSource && (this.eventSource.onopen = onOpenFunc);
4174
4171
  }
4175
4172
  const onErrorFunc = Reflect.getMetadata(EVENT_SOURCE_ERROR_KEY, target);
4176
- console.log("sse-proxy[error]:", onErrorFunc);
4177
4173
  if (typeof onErrorFunc == "function") {
4178
4174
  this.eventSource && (this.eventSource.onerror = onErrorFunc);
4179
4175
  }
@@ -4,8 +4,7 @@ export interface PaginationData<T> {
4
4
  size: number;
5
5
  record: T[];
6
6
  }
7
- export interface ResponseData<T = any> {
7
+ export interface ResponseData {
8
8
  code: 0;
9
9
  message: string;
10
- data: T | PaginationData<T>;
11
10
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@snail-js/api",
3
- "version": "0.1.10",
3
+ "version": "0.1.12",
4
4
  "description": "Http Request with Decorators Api, build on axios",
5
5
  "type": "module",
6
6
  "main": "./src/index.ts",