Socket
Socket
Sign inDemoInstall

@walletconnect/keyvaluestorage

Package Overview
Dependencies
Maintainers
10
Versions
20
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@walletconnect/keyvaluestorage - npm Package Compare versions

Comparing version 1.0.2-canary.758d7ff to 1.0.2-canary.fd2778a

2

dist/index.es.js

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

import{safeJsonStringify as z,safeJsonParse as m}from"@walletconnect/safe-json";import d from"fs";function k(){try{const t=require("unstorage"),e=require("unstorage/drivers/fs-lite");return{db:t,driver:e}}catch{throw new Error(`To use WalletConnect server side, you'll need to install the "unstorage" dependency. If you are seeing this error during a build / in an SSR environment, you can add "unstorage" as a devDependency to make this error go away.`)}}let o;const n=class{constructor(t){this.writeActionsQueue={state:"idle",actions:[]},o||(o=k()),t?.dbName===":memory:"?this.database=o.db.createStorage():this.database=o.db.createStorage({driver:o.driver({base:t?.dbName})})}static create(t){const e=t.dbName;return e===":memory:"?new n(t):(n.instances[e]||(n.instances[e]=new n(t)),n.instances[e])}async getKeys(){return this.database.getKeys()}async getEntries(){return(await this.database.getItems(await this.database.getKeys())).map(t=>[t.key,t.value])}async onWriteAction(t){const{key:e,value:i,action:a}=t;let s=()=>({});const r=new Promise(c=>s=c);this.writeActionsQueue.actions.push({key:e,value:i,action:a,callback:s}),this.writeActionsQueue.state==="idle"&&this.startWriteActions(),await r}async startWriteActions(){if(this.writeActionsQueue.actions.length===0){this.writeActionsQueue.state="idle";return}for(this.writeActionsQueue.state="active";this.writeActionsQueue.actions.length>0;){const t=this.writeActionsQueue.actions.shift();if(!t)continue;const{key:e,value:i,action:a,callback:s}=t;switch(a){case"setItem":await this.database.setItem(e),await this.database.setItem(e,z(i));break;case"removeItem":await this.database.removeItem(e);break}s()}this.writeActionsQueue.state="idle"}async getItem(t){const e=await this.database.getItem(t);if(e!==null)return e}async setItem(t,e){await this.onWriteAction({key:t,value:e,action:"setItem"})}async removeItem(t){await this.onWriteAction({key:t,action:"removeItem"})}};let b=n;b.instances={};const $="wc_storage_version",h=".to_migrate",p=".migrated",f=":memory:",v=1,S=async(t,e,i)=>{var a;if(t===f){i();return}console.log("\u{1F6A2} migrate: start",t);const s=$,r=await e.getItem(s);if(r&&r>=v){console.log("\u{1F6A2} migrate: already migrated"),i();return}const c=await Q(`${t}${h}`);if(!c){console.log("\u{1F6A2} migrate: old db file not fount"),i();return}const l=m(c);if(!l){console.log("\u{1F6A2} migrate: old db is empty"),i();return}console.log("\u{1F6A2} migrate: reading old file");const g=(a=l?.collections)==null?void 0:a[0];console.log("\u{1F6A2} migrate: collection",l.collections.length,g.data.length);const u=g?.data;if(!u||!u.length){console.log("\u{1F6A2} migrate: no data in collection"),i();return}for(;u.length;){const y=u.shift();if(!y){console.log("\u{1F6A2} migrate: no item");continue}const{id:w,value:F}=y;console.log("\u{1F6A2} migrate: item",w),await e.setItem(w,m(F))}await e.setItem(s,v),console.log("\u{1F6A2} migrate: done"),A(`${t}${h}`,`${t}${p}`),i()},Q=async t=>await new Promise(e=>{d.readFile(t,{encoding:"utf8"},(i,a)=>{i&&(console.log("\u{1F6A2} migrate: error reading old file",i),e(void 0)),e(a)})}),K=t=>{t!==f&&(console.log("\u{1F6A2} beforeMigrate: start",typeof t),d.existsSync(t)&&(d.lstatSync(t).isDirectory()||(console.log("\u{1F6A2} beforeMigrate: exists",t),A(t,`${t}${h}`))))},A=(t,e)=>{try{console.log("\u{1F6A2} beforeMigrate: renaming",t),d.renameSync(t,e),console.log("\u{1F6A2} beforeMigrate: renamed",`${e}`)}catch(i){console.log("\u{1F6A2} beforeMigrate: error renaming",i)}},M="walletconnect.db";class I{constructor(e){this.initialized=!1,this.isInitialized=()=>{this.initialized=!0,console.log("isInitialized dd",this.initialized)};const i=e?.database||e?.table||M;K(i),this.database=b.create({dbName:i}),S(i,this.database,this.isInitialized)}async getKeys(){return await this.initilization(),this.database.getKeys()}async getEntries(){return await this.initilization(),this.database.getEntries()}async getItem(e){return await this.initilization(),this.database.getItem(e)}async setItem(e,i){await this.initilization(),await this.database.setItem(e,i)}async removeItem(e){await this.initilization(),await this.database.removeItem(e)}async initilization(){this.initialized||await new Promise(e=>{const i=setInterval(()=>{this.initialized&&(clearInterval(i),e())},20)})}}class W{}function E(t){var e;return[t[0],m((e=t[1])!=null?e:"")]}export{W as IKeyValueStorage,I as KeyValueStorage,I as default,E as parseEntry};
import{createStorage as w}from"unstorage";import{createStore as I,get as u,set as p,del as b,keys as v,clear as S}from"idb-keyval";import{safeJsonStringify as m,safeJsonParse as y}from"@walletconnect/safe-json";function P(i){return i}const k="idb-keyval";var x=(i={})=>{const e=i.base&&i.base.length>0?`${i.base}:`:"",t=s=>e+s;let n;return i.dbName&&i.storeName&&(n=I(i.dbName,i.storeName)),{name:k,options:i,async hasItem(s){return!(typeof await u(t(s),n)>"u")},async getItem(s){return await u(t(s),n)??null},setItem(s,o){return p(t(s),o,n)},removeItem(s){return b(t(s),n)},getKeys(){return v(n)},clear(){return S(n)}}};const z="WALLET_CONNECT_V2_INDEXED_DB",D="keyvaluestorage";class E{constructor(){this.indexedDb=w({driver:x({dbName:z,storeName:D})})}async getKeys(){return this.indexedDb.getKeys()}async getEntries(){return(await this.indexedDb.getItems(await this.indexedDb.getKeys())).map(e=>[e.key,e.value])}async getItem(e){const t=await this.indexedDb.getItem(e);if(t!==null)return t}async setItem(e,t){await this.indexedDb.setItem(e,m(t))}async removeItem(e){await this.indexedDb.removeItem(e)}}var g=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{},l={exports:{}};(function(){let i;function e(){}i=e,i.prototype.getItem=function(t){return this.hasOwnProperty(t)?String(this[t]):null},i.prototype.setItem=function(t,n){this[t]=String(n)},i.prototype.removeItem=function(t){delete this[t]},i.prototype.clear=function(){const t=this;Object.keys(t).forEach(function(n){t[n]=void 0,delete t[n]})},i.prototype.key=function(t){return t=t||0,Object.keys(this)[t]},i.prototype.__defineGetter__("length",function(){return Object.keys(this).length}),typeof g<"u"&&g.localStorage?l.exports=g.localStorage:typeof window<"u"&&window.localStorage?l.exports=window.localStorage:l.exports=new e})();function _(i){var e;return[i[0],y((e=i[1])!=null?e:"")]}class F{constructor(){this.localStorage=l.exports}async getKeys(){return Object.keys(this.localStorage)}async getEntries(){return Object.entries(this.localStorage).map(_)}async getItem(e){const t=this.localStorage.getItem(e);if(t!==null)return y(t)}async setItem(e,t){this.localStorage.setItem(e,m(t))}async removeItem(e){this.localStorage.removeItem(e)}}const K="wc_storage_version",d=1,N=async(i,e,t)=>{console.log("\u{1F6A2} migrate: start");const n=K,s=await e.getItem(n);if(s&&s>=d){console.log("\u{1F6A2} migrate: already migrated"),t(e);return}console.log("\u{1F6A2} migrate: start");const o=await i.getKeys();if(!o.length){console.log("\u{1F6A2} migrate: no keys"),t(e);return}const c=[];for(;o.length;){const a=o.shift();if(!a)continue;const r=a.toLowerCase();if(r.includes("wc@")||r.includes("walletconnect")||r.includes("wc_")||r.includes("wallet_connect")){const f=await i.getItem(a);await e.setItem(a,f),c.push(a)}else console.log("\u{1F6A2} migrate: skipping key",a)}await e.setItem(n,d),console.log("\u{1F6A2} migrate: complete"),console.log("cleanup: keys",c.length),t(e),A(i,c)},A=async(i,e)=>{if(!e.length){console.log("\u{1F9F9} cleanup: no keys",e.length);return}console.log("\u{1F9F9} cleanup: start"),e.forEach(async t=>{await i.removeItem(t)}),console.log("\u{1F9F9} cleanup: complete")};class h{constructor(){this.initialized=!1,this.isInitialized=t=>{this.storage=t,this.initialized=!0,console.log("store-migration: complete",this.initialized,this.storage)};const e=new F;this.storage=e;try{const t=new E;N(e,t,this.isInitialized)}catch{this.initialized=!0}}async getKeys(){return await this.initilization(),this.storage.getKeys()}async getEntries(){return await this.initilization(),this.storage.getEntries()}async getItem(e){return await this.initilization(),this.storage.getItem(e)}async setItem(e,t){return await this.initilization(),this.storage.setItem(e,t)}async removeItem(e){return await this.initilization(),this.storage.removeItem(e)}async initilization(){this.initialized||await new Promise(e=>{const t=setInterval(()=>{this.initialized&&(clearInterval(t),e())},20)})}}export{h as KeyValueStorage,h as default};
//# sourceMappingURL=index.es.js.map
{
"name": "@walletconnect/keyvaluestorage",
"description": "Isomorphic Key-Value Storage",
"version": "1.0.2-canary.758d7ff",
"version": "1.0.2-canary.fd2778a",
"author": "WalletConnect, Inc. <walletconnect.com>",

@@ -6,0 +6,0 @@ "license": "MIT",

Sorry, the diff of this file is not supported yet

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