@agconnect/storage
Advanced tools
Comparing version 1.2.1 to 1.3.0-beta
@@ -1,1 +0,1 @@ | ||
import e from"@agconnect/api";import{Logger as r}from"@agconnect/log";var t=function(){function e(){this.storage={}}return e.getNewInstance=function(r){return new e},e.prototype.get=function(e){return Promise.resolve(this.storage[e])},e.prototype.remove=function(e){return delete this.storage[e],Promise.resolve()},e.prototype.set=function(e,r){return this.storage[e]=r,Promise.resolve()},e}(),n=function(){function e(){this.encryptImpl=void 0}return e.prototype.setEncryptImp=function(e){this.encryptImpl=e},e.prototype.decrypt=function(e){return null!=this.encryptImpl&&null!=this.encryptImpl&&null!=e&&null!=e?this.encryptImpl.decrypt(e):e},e.prototype.encrypt=function(e){return null!=this.encryptImpl&&null!=this.encryptImpl&&null!=e&&null!=e?this.encryptImpl.encrypt(e):e},e}(),o=function(){function e(){this.DB_NAME="agcLocalStorageDb",this.OBJECT_STORE_NAME="agc",this.KEY_PATH="agcStorage",this.VERSION=1,this.agcCryptImpl=new n,this.logger=r.createLogger("AGCStorageService")}return e.getNewInstance=function(r){var t=new e;return t.agcCryptImpl.setEncryptImp(r),t},e.prototype.initIndexedDb=function(e){var r=this;return window.indexedDB?new Promise((function(t,n){var o=window.indexedDB.open(r.DB_NAME,r.VERSION),c=r;o.onupgradeneeded=function(e){var r=e.target.result;try{r.objectStoreNames.contains(c.OBJECT_STORE_NAME)||r.createObjectStore(c.OBJECT_STORE_NAME,{keyPath:c.KEY_PATH})}catch(e){n(e)}},o.onsuccess=function(r){try{t(r.target.result.transaction([c.OBJECT_STORE_NAME],e).objectStore(c.OBJECT_STORE_NAME))}catch(e){n(e)}},o.onerror=function(e){n(new Error(e.target.error))}})):Promise.reject("Your browser doesn't support a stable version of IndexedDB.")},e.prototype.get=function(e){if(!e)return Promise.reject(new Error("key is null"));var r=this;return this.initIndexedDb("readonly").then((function(t){return new Promise((function(n,o){try{var c=t.get(e);c.onsuccess=function(){var e=c.result;n(null!=e&&"value"in e?r.agcCryptImpl.decrypt(e.value):e)},c.onerror=function(e){o(e.target.error)}}catch(e){o(e)}}))})).catch((function(e){return Promise.reject(e)}))},e.prototype.set=function(e,r){if(!e||!r)return Promise.reject(new Error("key or value is null"));var t=this,n={},o={};n[t.KEY_PATH]=e,o.value=t.agcCryptImpl.encrypt(r);var c=Object.assign(o,n);return this.initIndexedDb("readwrite").then((function(r){try{var n=r.get(e);return n.onsuccess=function(){var e=n.result,t=null!=e&&"value"in e?r.put(c):r.add(c);t.onsuccess=function(){return Promise.resolve()},t.onerror=function(e){return Promise.reject(e.target.error)}},n.onerror=function(e){return t.logger.error("---get value from db error."),Promise.reject("get value from db error.")},Promise.resolve()}catch(e){return t.logger.error("---set value to db error."+e),Promise.reject("set value to db error."+e)}})).catch((function(e){return Promise.reject("init db error."+e)}))},e.prototype.remove=function(e){return e?this.initIndexedDb("readwrite").then((function(r){try{var t=r.delete(e);return t.onsuccess=function(){return Promise.resolve()},t.onerror=function(e){return Promise.reject(e.target.error)},Promise.resolve()}catch(e){return Promise.reject(e)}})).catch((function(e){return Promise.reject(e)})):Promise.reject(new Error("key is null"))},e}(),c=function(){function e(){this.agcCryptImpl=new n}return e.getNewInstance=function(r){var t=new e;return t.agcCryptImpl.setEncryptImp(r),t},e.prototype.get=function(e){if(!e)return Promise.reject(new Error("key is null"));try{var r=sessionStorage.getItem(e);return Promise.resolve(""===r?null:this.agcCryptImpl.decrypt(r))}catch(e){return Promise.reject(e)}},e.prototype.set=function(e,r){if(!e||!r)return Promise.reject(new Error("key or value is null"));try{return sessionStorage.setItem(e,this.agcCryptImpl.encrypt(r)),Promise.resolve()}catch(e){return Promise.reject(e)}},e.prototype.remove=function(e){if(!e)return Promise.reject(new Error("key is null"));try{return sessionStorage.removeItem(e),Promise.resolve()}catch(e){return Promise.reject(e)}},e}(),i=function(){function e(){}return e.prototype.getStorageNewInstance=function(e,r){switch(e){case 2:return t.getNewInstance(r);case 0:return o.getNewInstance(r);case 1:default:return c.getNewInstance(r)}},e.prototype.createPersistentStorage=function(){return o.getNewInstance()},e.prototype.createTemporaryStorage=function(){return c.getNewInstance()},e.prototype.createMemoryStorage=function(){return t.getNewInstance()},e}();e.registerInternalService({name:"AGCStorageService",serviceFactory:function(e){return new i}}); | ||
import e from"@agconnect/api";import{Logger as r}from"@agconnect/log";import{DEFAULT_CATEGORY as t}from"@agconnect/core";var n=function(){function e(){this.storage={}}return e.getInstance=function(r,t){return e.memoryInsMap.has(r)&&e.memoryInsMap.get(r)||e.memoryInsMap.set(r,new e),e.memoryInsMap.get(r)},e.prototype.get=function(e){return Promise.resolve(this.storage[e])},e.prototype.remove=function(e){return delete this.storage[e],Promise.resolve()},e.prototype.set=function(e,r){return this.storage[e]=r,Promise.resolve()},e.memoryInsMap=new Map,e}(),o=function(){function e(){this.encryptImpl=void 0}return e.prototype.setEncryptImp=function(e){this.encryptImpl=e},e.prototype.decrypt=function(e){return null!=this.encryptImpl&&null!=this.encryptImpl&&null!=e&&null!=e?this.encryptImpl.decrypt(e):e},e.prototype.encrypt=function(e){return null!=this.encryptImpl&&null!=this.encryptImpl&&null!=e&&null!=e?this.encryptImpl.encrypt(e):e},e}(),s=function(){function e(){this.DB_NAME="agcLocalStorageDb",this.OBJECT_STORE_NAME="agc",this.KEY_PATH="agcStorage",this.VERSION=1,this.agcCryptImpl=new o,this.logger=r.createLogger("AGCStorageService")}return e.getInstance=function(t,n){if(!window.indexedDB)throw r.createLogger("AGCStorageService").error("Your environment doesn't support a stable version of IndexedDB."),new Error("Your environment doesn't support a stable version of IndexedDB.");e.indexedDBInsMap.has(t)&&e.indexedDBInsMap.get(t)||e.indexedDBInsMap.set(t,new e);var o=e.indexedDBInsMap.get(t);return o.agcCryptImpl.setEncryptImp(n),o},e.prototype.initIndexedDb=function(e){var r=this;return window.indexedDB?new Promise((function(t,n){var o=window.indexedDB.open(r.DB_NAME,r.VERSION),s=r;o.onupgradeneeded=function(e){var r=e.target.result;try{r.objectStoreNames.contains(s.OBJECT_STORE_NAME)||r.createObjectStore(s.OBJECT_STORE_NAME,{keyPath:s.KEY_PATH})}catch(e){n(e)}},o.onsuccess=function(r){try{t(r.target.result.transaction([s.OBJECT_STORE_NAME],e).objectStore(s.OBJECT_STORE_NAME))}catch(e){n(e)}},o.onerror=function(e){n(new Error(e.target.error))}})):Promise.reject("Your environment doesn't support a stable version of IndexedDB.")},e.prototype.get=function(e){if(!e)return Promise.reject(new Error("key is null"));var r=this;return this.initIndexedDb("readonly").then((function(t){return new Promise((function(n,o){try{var s=t.get(e);s.onsuccess=function(){var e=s.result;n(null!=e&&"value"in e?r.agcCryptImpl.decrypt(e.value):e)},s.onerror=function(e){o(e.target.error)}}catch(e){o(e)}}))})).catch((function(e){return Promise.reject(e)}))},e.prototype.set=function(e,r){if(!e||!r)return Promise.reject(new Error("key or value is null"));var t=this,n={},o={};n[t.KEY_PATH]=e,o.value=t.agcCryptImpl.encrypt(r);var s=Object.assign(o,n);return this.initIndexedDb("readwrite").then((function(r){try{var n=r.get(e);return n.onsuccess=function(){var e=n.result,t=null!=e&&"value"in e?r.put(s):r.add(s);t.onsuccess=function(){return Promise.resolve()},t.onerror=function(e){return Promise.reject(e.target.error)}},n.onerror=function(e){return t.logger.error("---get value from db error."),Promise.reject("get value from db error.")},Promise.resolve()}catch(e){return t.logger.error("---set value to db error."+e),Promise.reject("set value to db error."+e)}})).catch((function(e){return Promise.reject("init db error."+e)}))},e.prototype.remove=function(e){return e?this.initIndexedDb("readwrite").then((function(r){try{var t=r.delete(e);return t.onsuccess=function(){return Promise.resolve()},t.onerror=function(e){return Promise.reject(e.target.error)},Promise.resolve()}catch(e){return Promise.reject(e)}})).catch((function(e){return Promise.reject(e)})):Promise.reject(new Error("key is null"))},e.indexedDBInsMap=new Map,e}(),i=function(){function e(){this.agcCryptImpl=new o}return e.getInstance=function(t,n){if(!e.isSessionStorageAvailable())throw r.createLogger("AGCStorageService").error("Your environment doesn't support a stable version of sessionStorage."),new Error("Your environment doesn't support a stable version of sessionStorage.");!e.sessionMap.has(t)&&e.sessionMap.get(t)||e.sessionMap.set(t,new e);var o=e.sessionMap.get(t);return o.agcCryptImpl.setEncryptImp(n),o},e.isSessionStorageAvailable=function(){try{return sessionStorage.setItem("agctestKey","testValue"),sessionStorage.removeItem("agctestKey"),!0}catch(e){return!1}},e.prototype.get=function(e){if(!e)return Promise.reject(new Error("key is null"));try{var r=sessionStorage.getItem(e);return Promise.resolve(""===r?null:this.agcCryptImpl.decrypt(r))}catch(e){return Promise.reject(e)}},e.prototype.set=function(e,r){if(!e||!r)return Promise.reject(new Error("key or value is null"));try{return sessionStorage.setItem(e,this.agcCryptImpl.encrypt(r)),Promise.resolve()}catch(e){return Promise.reject(e)}},e.prototype.remove=function(e){if(!e)return Promise.reject(new Error("key is null"));try{return sessionStorage.removeItem(e),Promise.resolve()}catch(e){return Promise.reject(e)}},e.sessionMap=new Map,e}(),a=function(){function e(){this.agcCryptImpl=new o,this.logger=r.createLogger("AGCStorageService")}return e.getInstance=function(r,t){e.MiniProgramStorageMap.has(r)&&e.MiniProgramStorageMap.get(r)||e.MiniProgramStorageMap.set(r,new e);var n=e.MiniProgramStorageMap.get(r);return n.agcCryptImpl.setEncryptImp(t),n},e.prototype.get=function(e){var r=this;return new Promise((function(t,n){try{wx.getStorage({key:e,success:function(e){e?t(r.agcCryptImpl.decrypt(e.data)):(r.logger.log("get storage resp undefined"),t(void 0))},fail:function(e){r.logger.log("get storage failed,",e),t(void 0)}})}catch(e){r.logger.error("catch error in get:",e),n(e)}}))},e.prototype.set=function(e,r){var t=this;return new Promise((function(n,o){try{wx.setStorage({key:e,data:t.agcCryptImpl.encrypt(r),success:function(){t.logger.log("set storage success, key: ",e),n()},fail:function(e){t.logger.log("set storage failed. ",e),o(e)}})}catch(e){t.logger.error("catch error in set:",e),o(e)}}))},e.prototype.remove=function(e){var r=this;return new Promise((function(t,n){try{wx.removeStorage({key:e,success:function(){r.logger.log("remove storage success. "),t()},fail:function(e){r.logger.log("remove storage failed. ",e),n(e)}})}catch(e){r.logger.error("catch error in remove:",e),n(e)}}))},e.MiniProgramStorageMap=new Map,e}(),c="undefined"==typeof window&&"object"==typeof wx,u=function(){function e(e){this.name=t,e&&(this.name=e)}return e.prototype.getStorageInstance=function(e,r){var t;if(!c){switch(e){case 2:t=n.getInstance(this.name,r);break;case 0:t=s.getInstance(this.name,r);break;case 1:t=i.getInstance(this.name,r);break;default:t=n.getInstance(this.name,r)}return t}switch(e){case 2:return n.getInstance(this.name,r);default:return a.getInstance(this.name,r)}},e.prototype.createPersistentStorage=function(){return c?a.getInstance(this.name):s.getInstance(this.name)},e.prototype.createTemporaryStorage=function(){return c?a.getInstance(this.name):i.getInstance(this.name)},e.prototype.createMemoryStorage=function(){return n.getInstance(this.name)},e}();e.registerInternalService({name:"AGCStorageService",serviceFactory:function(e){return new u(e.name())}}); |
@@ -1,1 +0,1 @@ | ||
"use strict";var e=require("@agconnect/api"),r=require("@agconnect/log");function t(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var n=t(e),o=function(){function e(){this.storage={}}return e.getNewInstance=function(r){return new e},e.prototype.get=function(e){return Promise.resolve(this.storage[e])},e.prototype.remove=function(e){return delete this.storage[e],Promise.resolve()},e.prototype.set=function(e,r){return this.storage[e]=r,Promise.resolve()},e}(),c=function(){function e(){this.encryptImpl=void 0}return e.prototype.setEncryptImp=function(e){this.encryptImpl=e},e.prototype.decrypt=function(e){return null!=this.encryptImpl&&null!=this.encryptImpl&&null!=e&&null!=e?this.encryptImpl.decrypt(e):e},e.prototype.encrypt=function(e){return null!=this.encryptImpl&&null!=this.encryptImpl&&null!=e&&null!=e?this.encryptImpl.encrypt(e):e},e}(),i=function(){function e(){this.DB_NAME="agcLocalStorageDb",this.OBJECT_STORE_NAME="agc",this.KEY_PATH="agcStorage",this.VERSION=1,this.agcCryptImpl=new c,this.logger=r.Logger.createLogger("AGCStorageService")}return e.getNewInstance=function(r){var t=new e;return t.agcCryptImpl.setEncryptImp(r),t},e.prototype.initIndexedDb=function(e){var r=this;return window.indexedDB?new Promise((function(t,n){var o=window.indexedDB.open(r.DB_NAME,r.VERSION),c=r;o.onupgradeneeded=function(e){var r=e.target.result;try{r.objectStoreNames.contains(c.OBJECT_STORE_NAME)||r.createObjectStore(c.OBJECT_STORE_NAME,{keyPath:c.KEY_PATH})}catch(e){n(e)}},o.onsuccess=function(r){try{t(r.target.result.transaction([c.OBJECT_STORE_NAME],e).objectStore(c.OBJECT_STORE_NAME))}catch(e){n(e)}},o.onerror=function(e){n(new Error(e.target.error))}})):Promise.reject("Your browser doesn't support a stable version of IndexedDB.")},e.prototype.get=function(e){if(!e)return Promise.reject(new Error("key is null"));var r=this;return this.initIndexedDb("readonly").then((function(t){return new Promise((function(n,o){try{var c=t.get(e);c.onsuccess=function(){var e=c.result;n(null!=e&&"value"in e?r.agcCryptImpl.decrypt(e.value):e)},c.onerror=function(e){o(e.target.error)}}catch(e){o(e)}}))})).catch((function(e){return Promise.reject(e)}))},e.prototype.set=function(e,r){if(!e||!r)return Promise.reject(new Error("key or value is null"));var t=this,n={},o={};n[t.KEY_PATH]=e,o.value=t.agcCryptImpl.encrypt(r);var c=Object.assign(o,n);return this.initIndexedDb("readwrite").then((function(r){try{var n=r.get(e);return n.onsuccess=function(){var e=n.result,t=null!=e&&"value"in e?r.put(c):r.add(c);t.onsuccess=function(){return Promise.resolve()},t.onerror=function(e){return Promise.reject(e.target.error)}},n.onerror=function(e){return t.logger.error("---get value from db error."),Promise.reject("get value from db error.")},Promise.resolve()}catch(e){return t.logger.error("---set value to db error."+e),Promise.reject("set value to db error."+e)}})).catch((function(e){return Promise.reject("init db error."+e)}))},e.prototype.remove=function(e){return e?this.initIndexedDb("readwrite").then((function(r){try{var t=r.delete(e);return t.onsuccess=function(){return Promise.resolve()},t.onerror=function(e){return Promise.reject(e.target.error)},Promise.resolve()}catch(e){return Promise.reject(e)}})).catch((function(e){return Promise.reject(e)})):Promise.reject(new Error("key is null"))},e}(),u=function(){function e(){this.agcCryptImpl=new c}return e.getNewInstance=function(r){var t=new e;return t.agcCryptImpl.setEncryptImp(r),t},e.prototype.get=function(e){if(!e)return Promise.reject(new Error("key is null"));try{var r=sessionStorage.getItem(e);return Promise.resolve(""===r?null:this.agcCryptImpl.decrypt(r))}catch(e){return Promise.reject(e)}},e.prototype.set=function(e,r){if(!e||!r)return Promise.reject(new Error("key or value is null"));try{return sessionStorage.setItem(e,this.agcCryptImpl.encrypt(r)),Promise.resolve()}catch(e){return Promise.reject(e)}},e.prototype.remove=function(e){if(!e)return Promise.reject(new Error("key is null"));try{return sessionStorage.removeItem(e),Promise.resolve()}catch(e){return Promise.reject(e)}},e}(),s=function(){function e(){}return e.prototype.getStorageNewInstance=function(e,r){switch(e){case 2:return o.getNewInstance(r);case 0:return i.getNewInstance(r);case 1:default:return u.getNewInstance(r)}},e.prototype.createPersistentStorage=function(){return i.getNewInstance()},e.prototype.createTemporaryStorage=function(){return u.getNewInstance()},e.prototype.createMemoryStorage=function(){return o.getNewInstance()},e}();n.default.registerInternalService({name:"AGCStorageService",serviceFactory:function(e){return new s}}); | ||
"use strict";var e=require("@agconnect/api"),r=require("@agconnect/log"),t=require("@agconnect/core");function n(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var o=n(e),s=function(){function e(){this.storage={}}return e.getInstance=function(r,t){return e.memoryInsMap.has(r)&&e.memoryInsMap.get(r)||e.memoryInsMap.set(r,new e),e.memoryInsMap.get(r)},e.prototype.get=function(e){return Promise.resolve(this.storage[e])},e.prototype.remove=function(e){return delete this.storage[e],Promise.resolve()},e.prototype.set=function(e,r){return this.storage[e]=r,Promise.resolve()},e.memoryInsMap=new Map,e}(),i=function(){function e(){this.encryptImpl=void 0}return e.prototype.setEncryptImp=function(e){this.encryptImpl=e},e.prototype.decrypt=function(e){return null!=this.encryptImpl&&null!=this.encryptImpl&&null!=e&&null!=e?this.encryptImpl.decrypt(e):e},e.prototype.encrypt=function(e){return null!=this.encryptImpl&&null!=this.encryptImpl&&null!=e&&null!=e?this.encryptImpl.encrypt(e):e},e}(),a=function(){function e(){this.DB_NAME="agcLocalStorageDb",this.OBJECT_STORE_NAME="agc",this.KEY_PATH="agcStorage",this.VERSION=1,this.agcCryptImpl=new i,this.logger=r.Logger.createLogger("AGCStorageService")}return e.getInstance=function(t,n){if(!window.indexedDB)throw r.Logger.createLogger("AGCStorageService").error("Your environment doesn't support a stable version of IndexedDB."),new Error("Your environment doesn't support a stable version of IndexedDB.");e.indexedDBInsMap.has(t)&&e.indexedDBInsMap.get(t)||e.indexedDBInsMap.set(t,new e);var o=e.indexedDBInsMap.get(t);return o.agcCryptImpl.setEncryptImp(n),o},e.prototype.initIndexedDb=function(e){var r=this;return window.indexedDB?new Promise((function(t,n){var o=window.indexedDB.open(r.DB_NAME,r.VERSION),s=r;o.onupgradeneeded=function(e){var r=e.target.result;try{r.objectStoreNames.contains(s.OBJECT_STORE_NAME)||r.createObjectStore(s.OBJECT_STORE_NAME,{keyPath:s.KEY_PATH})}catch(e){n(e)}},o.onsuccess=function(r){try{t(r.target.result.transaction([s.OBJECT_STORE_NAME],e).objectStore(s.OBJECT_STORE_NAME))}catch(e){n(e)}},o.onerror=function(e){n(new Error(e.target.error))}})):Promise.reject("Your environment doesn't support a stable version of IndexedDB.")},e.prototype.get=function(e){if(!e)return Promise.reject(new Error("key is null"));var r=this;return this.initIndexedDb("readonly").then((function(t){return new Promise((function(n,o){try{var s=t.get(e);s.onsuccess=function(){var e=s.result;n(null!=e&&"value"in e?r.agcCryptImpl.decrypt(e.value):e)},s.onerror=function(e){o(e.target.error)}}catch(e){o(e)}}))})).catch((function(e){return Promise.reject(e)}))},e.prototype.set=function(e,r){if(!e||!r)return Promise.reject(new Error("key or value is null"));var t=this,n={},o={};n[t.KEY_PATH]=e,o.value=t.agcCryptImpl.encrypt(r);var s=Object.assign(o,n);return this.initIndexedDb("readwrite").then((function(r){try{var n=r.get(e);return n.onsuccess=function(){var e=n.result,t=null!=e&&"value"in e?r.put(s):r.add(s);t.onsuccess=function(){return Promise.resolve()},t.onerror=function(e){return Promise.reject(e.target.error)}},n.onerror=function(e){return t.logger.error("---get value from db error."),Promise.reject("get value from db error.")},Promise.resolve()}catch(e){return t.logger.error("---set value to db error."+e),Promise.reject("set value to db error."+e)}})).catch((function(e){return Promise.reject("init db error."+e)}))},e.prototype.remove=function(e){return e?this.initIndexedDb("readwrite").then((function(r){try{var t=r.delete(e);return t.onsuccess=function(){return Promise.resolve()},t.onerror=function(e){return Promise.reject(e.target.error)},Promise.resolve()}catch(e){return Promise.reject(e)}})).catch((function(e){return Promise.reject(e)})):Promise.reject(new Error("key is null"))},e.indexedDBInsMap=new Map,e}(),c=function(){function e(){this.agcCryptImpl=new i}return e.getInstance=function(t,n){if(!e.isSessionStorageAvailable())throw r.Logger.createLogger("AGCStorageService").error("Your environment doesn't support a stable version of sessionStorage."),new Error("Your environment doesn't support a stable version of sessionStorage.");!e.sessionMap.has(t)&&e.sessionMap.get(t)||e.sessionMap.set(t,new e);var o=e.sessionMap.get(t);return o.agcCryptImpl.setEncryptImp(n),o},e.isSessionStorageAvailable=function(){try{return sessionStorage.setItem("agctestKey","testValue"),sessionStorage.removeItem("agctestKey"),!0}catch(e){return!1}},e.prototype.get=function(e){if(!e)return Promise.reject(new Error("key is null"));try{var r=sessionStorage.getItem(e);return Promise.resolve(""===r?null:this.agcCryptImpl.decrypt(r))}catch(e){return Promise.reject(e)}},e.prototype.set=function(e,r){if(!e||!r)return Promise.reject(new Error("key or value is null"));try{return sessionStorage.setItem(e,this.agcCryptImpl.encrypt(r)),Promise.resolve()}catch(e){return Promise.reject(e)}},e.prototype.remove=function(e){if(!e)return Promise.reject(new Error("key is null"));try{return sessionStorage.removeItem(e),Promise.resolve()}catch(e){return Promise.reject(e)}},e.sessionMap=new Map,e}(),u=function(){function e(){this.agcCryptImpl=new i,this.logger=r.Logger.createLogger("AGCStorageService")}return e.getInstance=function(r,t){e.MiniProgramStorageMap.has(r)&&e.MiniProgramStorageMap.get(r)||e.MiniProgramStorageMap.set(r,new e);var n=e.MiniProgramStorageMap.get(r);return n.agcCryptImpl.setEncryptImp(t),n},e.prototype.get=function(e){var r=this;return new Promise((function(t,n){try{wx.getStorage({key:e,success:function(e){e?t(r.agcCryptImpl.decrypt(e.data)):(r.logger.log("get storage resp undefined"),t(void 0))},fail:function(e){r.logger.log("get storage failed,",e),t(void 0)}})}catch(e){r.logger.error("catch error in get:",e),n(e)}}))},e.prototype.set=function(e,r){var t=this;return new Promise((function(n,o){try{wx.setStorage({key:e,data:t.agcCryptImpl.encrypt(r),success:function(){t.logger.log("set storage success, key: ",e),n()},fail:function(e){t.logger.log("set storage failed. ",e),o(e)}})}catch(e){t.logger.error("catch error in set:",e),o(e)}}))},e.prototype.remove=function(e){var r=this;return new Promise((function(t,n){try{wx.removeStorage({key:e,success:function(){r.logger.log("remove storage success. "),t()},fail:function(e){r.logger.log("remove storage failed. ",e),n(e)}})}catch(e){r.logger.error("catch error in remove:",e),n(e)}}))},e.MiniProgramStorageMap=new Map,e}(),g="undefined"==typeof window&&"object"==typeof wx,p=function(){function e(e){this.name=t.DEFAULT_CATEGORY,e&&(this.name=e)}return e.prototype.getStorageInstance=function(e,r){var t;if(!g){switch(e){case 2:t=s.getInstance(this.name,r);break;case 0:t=a.getInstance(this.name,r);break;case 1:t=c.getInstance(this.name,r);break;default:t=s.getInstance(this.name,r)}return t}switch(e){case 2:return s.getInstance(this.name,r);default:return u.getInstance(this.name,r)}},e.prototype.createPersistentStorage=function(){return g?u.getInstance(this.name):a.getInstance(this.name)},e.prototype.createTemporaryStorage=function(){return g?u.getInstance(this.name):c.getInstance(this.name)},e.prototype.createMemoryStorage=function(){return s.getInstance(this.name)},e}();o.default.registerInternalService({name:"AGCStorageService",serviceFactory:function(e){return new p(e.name())}}); |
import { AGCStorageService } from "@agconnect/storage-types"; | ||
import Persistence = AGCStorageService.Persistence; | ||
export declare class NodeFactoryImpl implements AGCStorageService.Factory { | ||
getStorageNewInstance(persistence?: Persistence, cryptImpl?: any): AGCStorageService.AGCStorage; | ||
private name; | ||
constructor(name: string); | ||
getStorageInstance(persistence?: Persistence, cryptImpl?: any): AGCStorageService.AGCStorage; | ||
createPersistentStorage(): AGCStorageService.AGCStorage; | ||
@@ -6,0 +8,0 @@ createTemporaryStorage(): AGCStorageService.AGCStorage; |
@@ -1,1 +0,1 @@ | ||
import t from"@agconnect/api";var n=function(){function t(){this.encryptImpl=void 0}return t.prototype.setEncryptImp=function(t){this.encryptImpl=t},t.prototype.decrypt=function(t){return null!=this.encryptImpl&&null!=this.encryptImpl&&null!=t&&null!=t?this.encryptImpl.decrypt(t):t},t.prototype.encrypt=function(t){return null!=this.encryptImpl&&null!=this.encryptImpl&&null!=t&&null!=t?this.encryptImpl.encrypt(t):t},t}(),e=require("@system.storage"),r=function(){function t(){this.agcCryptImpl=new n}return t.getNewInstance=function(n){var e=new t;return e.agcCryptImpl.setEncryptImp(n),e},t.prototype.get=function(t){var n=this;return new Promise((function(r,c){e.get({key:t,default:null,success:function(t){r(t&&""!=t?n.agcCryptImpl.decrypt(t):null)},fail:function(t,n){c(t)}})}))},t.prototype.remove=function(t){return new Promise((function(n,r){e.delete({key:t,success:function(t){n()},fail:function(t,e){200==e?n():r()}})}))},t.prototype.set=function(t,n){var r=this;return new Promise((function(c,o){e.set({key:t,value:r.agcCryptImpl.encrypt(n),success:function(t){c(t)},fail:function(t,n){o()}})}))},t}(),c=function(){function t(){}return t.prototype.getStorageNewInstance=function(t,n){return r.getNewInstance(n)},t.prototype.createPersistentStorage=function(){return r.getNewInstance()},t.prototype.createTemporaryStorage=function(){return r.getNewInstance()},t.prototype.createMemoryStorage=function(){return r.getNewInstance()},t}();t.registerInternalService({name:"AGCStorageService",serviceFactory:function(t){return new c}}); | ||
import t from"@agconnect/api";import{DEFAULT_CATEGORY as e}from"@agconnect/core";var n=function(){function t(){this.encryptImpl=void 0}return t.prototype.setEncryptImp=function(t){this.encryptImpl=t},t.prototype.decrypt=function(t){return null!=this.encryptImpl&&null!=this.encryptImpl&&null!=t&&null!=t?this.encryptImpl.decrypt(t):t},t.prototype.encrypt=function(t){return null!=this.encryptImpl&&null!=this.encryptImpl&&null!=t&&null!=t?this.encryptImpl.encrypt(t):t},t}(),r=require("@system.storage"),c=function(){function t(){this.agcCryptImpl=new n}return t.getInstance=function(e,n){!t.quickAppStoreMap.has(e)&&t.quickAppStoreMap.get(e)||t.quickAppStoreMap.set(e,new t);var r=t.quickAppStoreMap.get(e);return r.agcCryptImpl.setEncryptImp(n),r},t.prototype.get=function(t){var e=this;return new Promise((function(n,c){r.get({key:t,default:null,success:function(t){n(t&&""!=t?e.agcCryptImpl.decrypt(t):null)},fail:function(t,e){c(t)}})}))},t.prototype.remove=function(t){return new Promise((function(e,n){r.delete({key:t,success:function(t){e()},fail:function(t,r){200==r?e():n()}})}))},t.prototype.set=function(t,e){var n=this;return new Promise((function(c,p){r.set({key:t,value:n.agcCryptImpl.encrypt(e),success:function(t){c(t)},fail:function(t,e){p()}})}))},t.quickAppStoreMap=new Map,t}(),p=function(){function t(t){this.name=e,t&&(this.name=t)}return t.prototype.getStorageInstance=function(t,e){return c.getInstance(this.name,e)},t.prototype.createPersistentStorage=function(){return c.getInstance(this.name)},t.prototype.createTemporaryStorage=function(){return c.getInstance(this.name)},t.prototype.createMemoryStorage=function(){return c.getInstance(this.name)},t}();t.registerInternalService({name:"AGCStorageService",serviceFactory:function(t){return new p(t.name())}}); |
import { AGCStorageService } from "@agconnect/storage-types"; | ||
import AGCStorage = AGCStorageService.AGCStorage; | ||
export declare class IndexedDBImpl implements AGCStorage { | ||
private static indexedDBInsMap; | ||
private readonly DB_NAME; | ||
@@ -10,3 +11,3 @@ private readonly OBJECT_STORE_NAME; | ||
private logger; | ||
static getNewInstance(cryptImpl?: any): IndexedDBImpl; | ||
static getInstance(name: string, cryptImpl?: any): IndexedDBImpl; | ||
private initIndexedDb; | ||
@@ -13,0 +14,0 @@ get(key: string): Promise<any>; |
import { AGCStorageService } from "@agconnect/storage-types"; | ||
import AGCStorage = AGCStorageService.AGCStorage; | ||
export declare class Memorystorage implements AGCStorage { | ||
private static memoryInsMap; | ||
private storage; | ||
static getNewInstance(cryptImpl?: any): Memorystorage; | ||
static getInstance(name: string, cryptImpl?: any): Memorystorage; | ||
get(key: string): Promise<string | null>; | ||
@@ -7,0 +8,0 @@ remove(key: string): Promise<void>; |
import { AGCStorageService } from "@agconnect/storage-types"; | ||
import AGCStorage = AGCStorageService.AGCStorage; | ||
export declare class NodeStorage implements AGCStorage { | ||
private static nodeMap; | ||
static filePath: string; | ||
private agcCryptImpl; | ||
static getNewInstance(cryptImpl?: any): NodeStorage; | ||
static getInstance(name: string, cryptImpl?: any): NodeStorage; | ||
get(key: string): Promise<any>; | ||
@@ -8,0 +9,0 @@ set(key: string, value: any): Promise<void>; |
import { AGCStorageService } from "@agconnect/storage-types"; | ||
import AGCStorage = AGCStorageService.AGCStorage; | ||
export declare class QuickAppStorage implements AGCStorage { | ||
private static quickAppStoreMap; | ||
private agcCryptImpl; | ||
static getNewInstance(cryptImpl?: any): QuickAppStorage; | ||
static getInstance(name: string, cryptImpl?: any): QuickAppStorage; | ||
get(key: string): Promise<string | null>; | ||
@@ -7,0 +8,0 @@ remove(key: string): Promise<void>; |
import { AGCStorageService } from "@agconnect/storage-types"; | ||
import AGCStorage = AGCStorageService.AGCStorage; | ||
export declare class SessionImpl implements AGCStorage { | ||
private static sessionMap; | ||
private agcCryptImpl; | ||
static getNewInstance(cryptImpl?: any): SessionImpl; | ||
static getInstance(name: string, cryptImpl?: any): SessionImpl; | ||
private static isSessionStorageAvailable; | ||
get(key: string): Promise<any>; | ||
@@ -7,0 +9,0 @@ set(key: string, value: any): Promise<void>; |
{ | ||
"name": "@agconnect/storage", | ||
"version": "1.2.1", | ||
"version": "1.3.0-beta", | ||
"main": "./dist/index.node.cjs.js", | ||
"module": "./dist/index.esm.js", | ||
"quickapp": "./dist/index.quickapp.js", | ||
"quickgame": "./dist/index.quickgame.js", | ||
"description": "@agconnect/storage", | ||
@@ -11,3 +12,4 @@ "author": "https://developer.huawei.com/", | ||
"scripts": { | ||
"build": "rollup -c" | ||
"build": "rollup -c", | ||
"test:browser": "karma start --single-run" | ||
}, | ||
@@ -20,5 +22,5 @@ "files": [ | ||
"@rollup/plugin-json": "^4.0.2", | ||
"@types/node": "^14.14.6", | ||
"@types/node": "^14.14.20", | ||
"rollup-plugin-terser": "^5.3.1", | ||
"rollup-plugin-typescript2": "^0.29.0", | ||
"rollup-plugin-typescript2": "^0.30.0", | ||
"typescript": "^4.0.5" | ||
@@ -32,9 +34,9 @@ }, | ||
"dependencies": { | ||
"@agconnect/api": "1.2.1", | ||
"@agconnect/api-types": "1.2.1", | ||
"@agconnect/core": "1.2.1", | ||
"@agconnect/instance-types": "1.2.1", | ||
"@agconnect/storage-types": "1.2.1", | ||
"@agconnect/log": "1.2.1" | ||
"@agconnect/api": "1.3.0-beta", | ||
"@agconnect/api-types": "1.3.0-beta", | ||
"@agconnect/core": "1.3.0-beta", | ||
"@agconnect/instance-types": "1.3.0-beta", | ||
"@agconnect/storage-types": "1.3.0-beta", | ||
"@agconnect/log": "1.3.0-beta" | ||
} | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
23634
23
176
3
+ Added@agconnect/api@1.3.0-beta(transitive)
+ Added@agconnect/api-types@1.3.0-beta(transitive)
+ Added@agconnect/core@1.3.0-beta(transitive)
+ Added@agconnect/instance-types@1.3.0-beta(transitive)
+ Added@agconnect/log@1.3.0-beta(transitive)
+ Added@agconnect/storage-types@1.3.0-beta(transitive)
- Removed@agconnect/api@1.2.1(transitive)
- Removed@agconnect/api-types@1.2.1(transitive)
- Removed@agconnect/core@1.2.1(transitive)
- Removed@agconnect/instance-types@1.2.1(transitive)
- Removed@agconnect/log@1.2.1(transitive)
- Removed@agconnect/storage-types@1.2.1(transitive)
Updated@agconnect/api@1.3.0-beta
Updated@agconnect/core@1.3.0-beta
Updated@agconnect/log@1.3.0-beta