Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@agconnect/storage

Package Overview
Dependencies
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@agconnect/storage - npm Package Compare versions

Comparing version 1.3.0 to 1.3.1-beta

dist/index.harmony.d.ts

2

dist/index.esm.js

@@ -1,1 +0,1 @@

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())}});
import e from"@agconnect/api";import{Logger as t}from"@agconnect/log";import{AGCError as r,AGCErrorCode as n}from"@agconnect/instance";import{DEFAULT_CATEGORY as o}from"@agconnect/core";var s=function(){function e(){this.storage={}}return e.getInstance=function(t,r){return e.memoryInsMap.has(t)&&e.memoryInsMap.get(t)||e.memoryInsMap.set(t,new e),e.memoryInsMap.get(t)},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,t){return this.storage[e]=t,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=t.createLogger("AGCStorageService")}return e.getInstance=function(o,s){if(!window.indexedDB)throw t.createLogger("AGCStorageService").error("Your environment doesn't support a stable version of IndexedDB."),new r(n.FAIL_TO_GET_STORAGE_SERVICE,{message:"Your environment doesn't support a stable version of IndexedDB."});e.indexedDBInsMap.has(o)&&e.indexedDBInsMap.get(o)||e.indexedDBInsMap.set(o,new e);var i=e.indexedDBInsMap.get(o);return i.agcCryptImpl.setEncryptImp(s),i},e.prototype.initIndexedDb=function(e){var t=this;return window.indexedDB?new Promise((function(r,n){var o=window.indexedDB.open(t.DB_NAME,t.VERSION),s=t;o.onupgradeneeded=function(e){var t=e.target.result;try{t.objectStoreNames.contains(s.OBJECT_STORE_NAME)||t.createObjectStore(s.OBJECT_STORE_NAME,{keyPath:s.KEY_PATH})}catch(e){n(e)}},o.onsuccess=function(t){try{r(t.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(new r(n.FAIL_TO_GET_STORAGE_SERVICE,{message:"Your environment doesn't support a stable version of IndexedDB."},"storage"))},e.prototype.get=function(e){if(!e)return Promise.reject(new Error("get key is null"));var t=this;return this.initIndexedDb("readonly").then((function(r){return new Promise((function(n,o){try{var s=r.get(e);s.onsuccess=function(){var e=s.result;n(null!=e&&"value"in e?t.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,t){if(!e||!t)return Promise.reject(new Error("set key or value is null"));var r={},n={};r[this.KEY_PATH]=e,n.value=this.agcCryptImpl.encrypt(t);var o=Object.assign(n,r);return this.initIndexedDb("readwrite").then((function(t){try{var r=t.get(e);return r.onsuccess=function(){var e=r.result,n=null!=e&&"value"in e?t.put(o):t.add(o);n.onsuccess=function(){return Promise.resolve()},n.onerror=function(e){return Promise.reject(e.target.error)}},r.onerror=function(e){return Promise.reject(e.target.error)},Promise.resolve()}catch(e){return Promise.reject(e)}})).catch((function(e){return Promise.reject(e)}))},e.prototype.remove=function(e){return e?this.initIndexedDb("readwrite").then((function(t){try{var r=t.delete(e);return r.onsuccess=function(){return Promise.resolve()},r.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("remove key is null"))},e.indexedDBInsMap=new Map,e}(),c=function(){function e(){this.agcCryptImpl=new i}return e.getInstance=function(o,s){if(!e.isSessionStorageAvailable())throw t.createLogger("AGCStorageService").error("Your environment doesn't support a stable version of sessionStorage."),new r(n.FAIL_TO_GET_STORAGE_SERVICE,{message:"Your environment doesn't support a stable version of sessionStorage."});!e.sessionMap.has(o)&&e.sessionMap.get(o)||e.sessionMap.set(o,new e);var i=e.sessionMap.get(o);return i.agcCryptImpl.setEncryptImp(s),i},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 t=sessionStorage.getItem(e);return Promise.resolve(""===t?null:this.agcCryptImpl.decrypt(t))}catch(e){return Promise.reject(e)}},e.prototype.set=function(e,t){if(!e||!t)return Promise.reject(new Error("key or value is null"));try{return sessionStorage.setItem(e,this.agcCryptImpl.encrypt(t)),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=t.createLogger("AGCStorageService")}return e.getInstance=function(t,r){e.MiniProgramStorageMap.has(t)&&e.MiniProgramStorageMap.get(t)||e.MiniProgramStorageMap.set(t,new e);var n=e.MiniProgramStorageMap.get(t);return n.agcCryptImpl.setEncryptImp(r),n},e.prototype.get=function(e){var t=this;return new Promise((function(r,n){try{wx.getStorage({key:e,success:function(e){r(e?t.agcCryptImpl.decrypt(e.data):void 0)},fail:function(e){r(void 0)}})}catch(e){t.logger.error("catch error in get:",e),n(e)}}))},e.prototype.set=function(e,t){var r=this;return new Promise((function(n,o){try{wx.setStorage({key:e,data:r.agcCryptImpl.encrypt(t),success:function(){n()},fail:function(e){r.logger.log("set storage failed. ",e),o(e)}})}catch(e){r.logger.error("catch error in set:",e),o(e)}}))},e.prototype.remove=function(e){var t=this;return new Promise((function(r,n){try{wx.removeStorage({key:e,success:function(){r()},fail:function(e){t.logger.log("remove storage failed. ",e),n(e)}})}catch(e){t.logger.error("catch error in remove:",e),n(e)}}))},e.MiniProgramStorageMap=new Map,e}(),p="undefined"==typeof window&&"object"==typeof wx,g=function(){function e(e){this.name=o,e&&(this.name=e)}return e.prototype.getStorageInstance=function(e,t){var r;if(p)return u.getInstance(this.name,t);switch(e){case 2:r=s.getInstance(this.name,t);break;case 0:r=a.getInstance(this.name,t);break;case 1:r=c.getInstance(this.name,t);break;default:r=s.getInstance(this.name,t)}return r},e.prototype.createPersistentStorage=function(){return p?u.getInstance(this.name):a.getInstance(this.name)},e.prototype.createTemporaryStorage=function(){return p?u.getInstance(this.name):c.getInstance(this.name)},e.prototype.createMemoryStorage=function(){return p?u.getInstance(this.name):s.getInstance(this.name)},e}();e.registerInternalService({name:"AGCStorageService",serviceFactory:function(e){return new g(e.name())}});

@@ -1,1 +0,1 @@

"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())}});
"use strict";var e=require("@agconnect/api"),r=require("@agconnect/log"),t=require("@agconnect/instance"),n=require("@agconnect/core");function o(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var s=o(e),i=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}(),a=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}(),c=function(){function e(){this.DB_NAME="agcLocalStorageDb",this.OBJECT_STORE_NAME="agc",this.KEY_PATH="agcStorage",this.VERSION=1,this.agcCryptImpl=new a,this.logger=r.Logger.createLogger("AGCStorageService")}return e.getInstance=function(n,o){if(!window.indexedDB)throw r.Logger.createLogger("AGCStorageService").error("Your environment doesn't support a stable version of IndexedDB."),new t.AGCError(t.AGCErrorCode.FAIL_TO_GET_STORAGE_SERVICE,{message:"Your environment doesn't support a stable version of IndexedDB."});e.indexedDBInsMap.has(n)&&e.indexedDBInsMap.get(n)||e.indexedDBInsMap.set(n,new e);var s=e.indexedDBInsMap.get(n);return s.agcCryptImpl.setEncryptImp(o),s},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(new t.AGCError(t.AGCErrorCode.FAIL_TO_GET_STORAGE_SERVICE,{message:"Your environment doesn't support a stable version of IndexedDB."},"storage"))},e.prototype.get=function(e){if(!e)return Promise.reject(new Error("get 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("set key or value is null"));var t={},n={};t[this.KEY_PATH]=e,n.value=this.agcCryptImpl.encrypt(r);var o=Object.assign(n,t);return this.initIndexedDb("readwrite").then((function(r){try{var t=r.get(e);return t.onsuccess=function(){var e=t.result,n=null!=e&&"value"in e?r.put(o):r.add(o);n.onsuccess=function(){return Promise.resolve()},n.onerror=function(e){return Promise.reject(e.target.error)}},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)}))},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("remove key is null"))},e.indexedDBInsMap=new Map,e}(),u=function(){function e(){this.agcCryptImpl=new a}return e.getInstance=function(n,o){if(!e.isSessionStorageAvailable())throw r.Logger.createLogger("AGCStorageService").error("Your environment doesn't support a stable version of sessionStorage."),new t.AGCError(t.AGCErrorCode.FAIL_TO_GET_STORAGE_SERVICE,{message:"Your environment doesn't support a stable version of sessionStorage."});!e.sessionMap.has(n)&&e.sessionMap.get(n)||e.sessionMap.set(n,new e);var s=e.sessionMap.get(n);return s.agcCryptImpl.setEncryptImp(o),s},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}(),g=function(){function e(){this.agcCryptImpl=new a,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){t(e?r.agcCryptImpl.decrypt(e.data):void 0)},fail:function(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(){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(){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}(),p="undefined"==typeof window&&"object"==typeof wx,m=function(){function e(e){this.name=n.DEFAULT_CATEGORY,e&&(this.name=e)}return e.prototype.getStorageInstance=function(e,r){var t;if(p)return g.getInstance(this.name,r);switch(e){case 2:t=i.getInstance(this.name,r);break;case 0:t=c.getInstance(this.name,r);break;case 1:t=u.getInstance(this.name,r);break;default:t=i.getInstance(this.name,r)}return t},e.prototype.createPersistentStorage=function(){return p?g.getInstance(this.name):c.getInstance(this.name)},e.prototype.createTemporaryStorage=function(){return p?g.getInstance(this.name):u.getInstance(this.name)},e.prototype.createMemoryStorage=function(){return p?g.getInstance(this.name):i.getInstance(this.name)},e}();s.default.registerInternalService({name:"AGCStorageService",serviceFactory:function(e){return new m(e.name())}});

@@ -1,1 +0,1 @@

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 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)}})}))},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)}})}))},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())}});
{
"name": "@agconnect/storage",
"version": "1.3.0",
"version": "1.3.1-beta",
"main": "./dist/index.node.cjs.js",

@@ -32,9 +32,10 @@ "module": "./dist/index.esm.js",

"dependencies": {
"@agconnect/api": "1.3.0",
"@agconnect/api-types": "1.3.0",
"@agconnect/core": "1.3.0",
"@agconnect/instance-types": "1.3.0",
"@agconnect/storage-types": "1.3.0",
"@agconnect/log": "1.3.0"
"@agconnect/api": "1.3.1-beta",
"@agconnect/api-types": "1.3.1-beta",
"@agconnect/core": "1.3.1-beta",
"@agconnect/instance": "1.3.1-beta",
"@agconnect/instance-types": "1.3.1-beta",
"@agconnect/storage-types": "1.3.1-beta",
"@agconnect/log": "1.3.1-beta"
}
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc