Socket
Socket
Sign inDemoInstall

@walletconnect/keyvaluestorage

Package Overview
Dependencies
Maintainers
8
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.1-rc.1-1c715f7f to 1.0.2-canary-e580314

dist/cjs/browser/lib/indexedDb.d.ts

4

dist/cjs/browser/index.d.ts

@@ -1,4 +0,6 @@

import { IKeyValueStorage } from "../shared";
import { IKeyValueStorage, KeyValueStorageOptions } from "../shared";
export declare class KeyValueStorage implements IKeyValueStorage {
private readonly localStorage;
constructor(opts?: KeyValueStorageOptions);
private useEntries;
getKeys(): Promise<string[]>;

@@ -5,0 +7,0 @@ getEntries<T = any>(): Promise<[string, T][]>;

@@ -5,12 +5,21 @@ "use strict";

const tslib_1 = require("tslib");
const localStorage_1 = tslib_1.__importDefault(require("localStorage"));
const safe_json_utils_1 = require("safe-json-utils");
const safe_json_1 = require("@walletconnect/safe-json");
const localStorage_1 = tslib_1.__importDefault(require("./lib/localStorage"));
const indexedDb_1 = require("./lib/indexedDb");
const shared_1 = require("../shared");
class KeyValueStorage {
constructor() {
this.localStorage = localStorage_1.default;
constructor(opts) {
if (opts === null || opts === void 0 ? void 0 : opts.useIndexedDb) {
this.localStorage = new indexedDb_1.IndexedDb();
}
else {
this.localStorage = localStorage_1.default;
}
}
useEntries() {
return this.localStorage.entries || this.localStorage;
}
getKeys() {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
return Object.keys(this.localStorage);
return Object.keys(this.useEntries());
});

@@ -20,3 +29,3 @@ }

return tslib_1.__awaiter(this, void 0, void 0, function* () {
return Object.entries(this.localStorage).map(shared_1.parseEntry);
return Object.entries(this.useEntries()).map(shared_1.parseEntry);
});

@@ -26,7 +35,7 @@ }

return tslib_1.__awaiter(this, void 0, void 0, function* () {
const item = this.localStorage.getItem(key);
const item = yield this.localStorage.getItem(key);
if (item === null) {
return undefined;
}
return safe_json_utils_1.safeJsonParse(item);
return (0, safe_json_1.safeJsonParse)(item);
});

@@ -36,3 +45,3 @@ }

return tslib_1.__awaiter(this, void 0, void 0, function* () {
this.localStorage.setItem(key, safe_json_utils_1.safeJsonStringify(value));
this.localStorage.setItem(key, (0, safe_json_1.safeJsonStringify)(value));
});

@@ -39,0 +48,0 @@ }

@@ -5,3 +5,3 @@ "use strict";

const tslib_1 = require("tslib");
const safe_json_utils_1 = require("safe-json-utils");
const safe_json_1 = require("@walletconnect/safe-json");
const db_1 = tslib_1.__importDefault(require("./db"));

@@ -43,3 +43,3 @@ const DB_NAME = "walletconnect.db";

yield this.initilization();
const entries = (yield this.database.find()).map((item) => [item.id, safe_json_utils_1.safeJsonParse(item.value)]);
const entries = (yield this.database.find()).map((item) => [item.id, (0, safe_json_1.safeJsonParse)(item.value)]);
return entries;

@@ -55,3 +55,3 @@ });

}
return safe_json_utils_1.safeJsonParse(item.value);
return (0, safe_json_1.safeJsonParse)(item.value);
});

@@ -64,7 +64,7 @@ }

if (item) {
item.value = safe_json_utils_1.safeJsonStringify(value);
item.value = (0, safe_json_1.safeJsonStringify)(value);
this.database.update(item);
}
else {
this.database.insert({ id: key, value: safe_json_utils_1.safeJsonStringify(value) });
this.database.insert({ id: key, value: (0, safe_json_1.safeJsonStringify)(value) });
}

@@ -71,0 +71,0 @@ yield this.persist();

@@ -6,3 +6,3 @@ "use strict";

const async_storage_1 = tslib_1.__importDefault(require("@react-native-async-storage/async-storage"));
const safe_json_utils_1 = require("safe-json-utils");
const safe_json_1 = require("@walletconnect/safe-json");
const shared_1 = require("../shared");

@@ -28,6 +28,6 @@ class KeyValueStorage {

const item = yield this.asyncStorage.getItem(key);
if (typeof item == "undefined" || item === null) {
if (typeof item === "undefined" || item === null) {
return undefined;
}
return safe_json_utils_1.safeJsonParse(item);
return (0, safe_json_1.safeJsonParse)(item);
});

@@ -37,3 +37,3 @@ }

return tslib_1.__awaiter(this, void 0, void 0, function* () {
yield this.asyncStorage.setItem(key, safe_json_utils_1.safeJsonStringify(value));
yield this.asyncStorage.setItem(key, (0, safe_json_1.safeJsonStringify)(value));
});

@@ -40,0 +40,0 @@ }

export interface KeyValueStorageOptions {
database?: string;
table?: string;
useIndexedDb?: boolean;
}

@@ -5,0 +6,0 @@ export declare abstract class IKeyValueStorage {

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.parseEntry = void 0;
const safe_json_utils_1 = require("safe-json-utils");
const safe_json_1 = require("@walletconnect/safe-json");
function parseEntry(entry) {
var _a;
return [entry[0], safe_json_utils_1.safeJsonParse((_a = entry[1]) !== null && _a !== void 0 ? _a : "")];
return [entry[0], (0, safe_json_1.safeJsonParse)((_a = entry[1]) !== null && _a !== void 0 ? _a : "")];
}
exports.parseEntry = parseEntry;
//# sourceMappingURL=utils.js.map

@@ -1,4 +0,6 @@

import { IKeyValueStorage } from "../shared";
import { IKeyValueStorage, KeyValueStorageOptions } from "../shared";
export declare class KeyValueStorage implements IKeyValueStorage {
private readonly localStorage;
constructor(opts?: KeyValueStorageOptions);
private useEntries;
getKeys(): Promise<string[]>;

@@ -5,0 +7,0 @@ getEntries<T = any>(): Promise<[string, T][]>;

@@ -1,16 +0,25 @@

import localStorage from "localStorage";
import { safeJsonParse, safeJsonStringify } from "safe-json-utils";
import { parseEntry } from "../shared";
import { safeJsonParse, safeJsonStringify } from "@walletconnect/safe-json";
import localStorage from "./lib/localStorage";
import { IndexedDb } from "./lib/indexedDb";
import { parseEntry, } from "../shared";
export class KeyValueStorage {
constructor() {
this.localStorage = localStorage;
constructor(opts) {
if (opts === null || opts === void 0 ? void 0 : opts.useIndexedDb) {
this.localStorage = new IndexedDb();
}
else {
this.localStorage = localStorage;
}
}
useEntries() {
return this.localStorage.entries || this.localStorage;
}
async getKeys() {
return Object.keys(this.localStorage);
return Object.keys(this.useEntries());
}
async getEntries() {
return Object.entries(this.localStorage).map(parseEntry);
return Object.entries(this.useEntries()).map(parseEntry);
}
async getItem(key) {
const item = this.localStorage.getItem(key);
const item = await this.localStorage.getItem(key);
if (item === null) {

@@ -17,0 +26,0 @@ return undefined;

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

import { safeJsonParse, safeJsonStringify } from "safe-json-utils";
import { safeJsonParse, safeJsonStringify } from "@walletconnect/safe-json";
import Db from "./db";

@@ -3,0 +3,0 @@ const DB_NAME = "walletconnect.db";

import AsyncStorage from "@react-native-async-storage/async-storage";
import { safeJsonParse, safeJsonStringify } from "safe-json-utils";
import { safeJsonParse, safeJsonStringify } from "@walletconnect/safe-json";
import { parseEntry } from "../shared";

@@ -18,3 +18,3 @@ export class KeyValueStorage {

const item = await this.asyncStorage.getItem(key);
if (typeof item == "undefined" || item === null) {
if (typeof item === "undefined" || item === null) {
return undefined;

@@ -21,0 +21,0 @@ }

export interface KeyValueStorageOptions {
database?: string;
table?: string;
useIndexedDb?: boolean;
}

@@ -5,0 +6,0 @@ export declare abstract class IKeyValueStorage {

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

import { safeJsonParse } from "safe-json-utils";
import { safeJsonParse } from "@walletconnect/safe-json";
export function parseEntry(entry) {

@@ -3,0 +3,0 @@ var _a;

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

!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define("KeyValueStorage",[],e):"object"==typeof exports?exports.KeyValueStorage=e():t.KeyValueStorage=e()}(this,(function(){return function(t){var e={};function n(r){if(e[r])return e[r].exports;var o=e[r]={i:r,l:!1,exports:{}};return t[r].call(o.exports,o,o.exports,n),o.l=!0,o.exports}return n.m=t,n.c=e,n.d=function(t,e,r){n.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:r})},n.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},n.t=function(t,e){if(1&e&&(t=n(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var o in t)n.d(r,o,function(e){return t[e]}.bind(null,o));return r},n.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return n.d(e,"a",e),e},n.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},n.p="",n(n.s=2)}([function(t,e,n){"use strict";n.r(e),n.d(e,"__extends",(function(){return o})),n.d(e,"__assign",(function(){return i})),n.d(e,"__rest",(function(){return u})),n.d(e,"__decorate",(function(){return a})),n.d(e,"__param",(function(){return c})),n.d(e,"__metadata",(function(){return f})),n.d(e,"__awaiter",(function(){return l})),n.d(e,"__generator",(function(){return s})),n.d(e,"__createBinding",(function(){return p})),n.d(e,"__exportStar",(function(){return y})),n.d(e,"__values",(function(){return d})),n.d(e,"__read",(function(){return _})),n.d(e,"__spread",(function(){return h})),n.d(e,"__spreadArrays",(function(){return v})),n.d(e,"__await",(function(){return b})),n.d(e,"__asyncGenerator",(function(){return g})),n.d(e,"__asyncDelegator",(function(){return m})),n.d(e,"__asyncValues",(function(){return w})),n.d(e,"__makeTemplateObject",(function(){return S})),n.d(e,"__importStar",(function(){return O})),n.d(e,"__importDefault",(function(){return j})),n.d(e,"__classPrivateFieldGet",(function(){return P})),n.d(e,"__classPrivateFieldSet",(function(){return x}));
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define("KeyValueStorage",[],e):"object"==typeof exports?exports.KeyValueStorage=e():t.KeyValueStorage=e()}(this,(function(){return function(t){var e={};function n(r){if(e[r])return e[r].exports;var o=e[r]={i:r,l:!1,exports:{}};return t[r].call(o.exports,o,o.exports,n),o.l=!0,o.exports}return n.m=t,n.c=e,n.d=function(t,e,r){n.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:r})},n.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},n.t=function(t,e){if(1&e&&(t=n(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var o in t)n.d(r,o,function(e){return t[e]}.bind(null,o));return r},n.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return n.d(e,"a",e),e},n.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},n.p="",n(n.s=2)}([function(t,e,n){"use strict";n.r(e),n.d(e,"__extends",(function(){return o})),n.d(e,"__assign",(function(){return i})),n.d(e,"__rest",(function(){return u})),n.d(e,"__decorate",(function(){return a})),n.d(e,"__param",(function(){return c})),n.d(e,"__metadata",(function(){return s})),n.d(e,"__awaiter",(function(){return l})),n.d(e,"__generator",(function(){return f})),n.d(e,"__createBinding",(function(){return d})),n.d(e,"__exportStar",(function(){return y})),n.d(e,"__values",(function(){return p})),n.d(e,"__read",(function(){return h})),n.d(e,"__spread",(function(){return v})),n.d(e,"__spreadArrays",(function(){return _})),n.d(e,"__await",(function(){return b})),n.d(e,"__asyncGenerator",(function(){return g})),n.d(e,"__asyncDelegator",(function(){return w})),n.d(e,"__asyncValues",(function(){return m})),n.d(e,"__makeTemplateObject",(function(){return S})),n.d(e,"__importStar",(function(){return O})),n.d(e,"__importDefault",(function(){return j})),n.d(e,"__classPrivateFieldGet",(function(){return P})),n.d(e,"__classPrivateFieldSet",(function(){return x}));
/*! *****************************************************************************

@@ -16,2 +16,2 @@ Copyright (c) Microsoft Corporation.

***************************************************************************** */
var r=function(t,e){return(r=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])})(t,e)};function o(t,e){function n(){this.constructor=t}r(t,e),t.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)}var i=function(){return(i=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t}).apply(this,arguments)};function u(t,e){var n={};for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&e.indexOf(r)<0&&(n[r]=t[r]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(r=Object.getOwnPropertySymbols(t);o<r.length;o++)e.indexOf(r[o])<0&&Object.prototype.propertyIsEnumerable.call(t,r[o])&&(n[r[o]]=t[r[o]])}return n}function a(t,e,n,r){var o,i=arguments.length,u=i<3?e:null===r?r=Object.getOwnPropertyDescriptor(e,n):r;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)u=Reflect.decorate(t,e,n,r);else for(var a=t.length-1;a>=0;a--)(o=t[a])&&(u=(i<3?o(u):i>3?o(e,n,u):o(e,n))||u);return i>3&&u&&Object.defineProperty(e,n,u),u}function c(t,e){return function(n,r){e(n,r,t)}}function f(t,e){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(t,e)}function l(t,e,n,r){return new(n||(n=Promise))((function(o,i){function u(t){try{c(r.next(t))}catch(t){i(t)}}function a(t){try{c(r.throw(t))}catch(t){i(t)}}function c(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(u,a)}c((r=r.apply(t,e||[])).next())}))}function s(t,e){var n,r,o,i,u={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function a(i){return function(a){return function(i){if(n)throw new TypeError("Generator is already executing.");for(;u;)try{if(n=1,r&&(o=2&i[0]?r.return:i[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,i[1])).done)return o;switch(r=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return u.label++,{value:i[1],done:!1};case 5:u.label++,r=i[1],i=[0];continue;case 7:i=u.ops.pop(),u.trys.pop();continue;default:if(!(o=u.trys,(o=o.length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){u=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]<o[3])){u.label=i[1];break}if(6===i[0]&&u.label<o[1]){u.label=o[1],o=i;break}if(o&&u.label<o[2]){u.label=o[2],u.ops.push(i);break}o[2]&&u.ops.pop(),u.trys.pop();continue}i=e.call(t,u)}catch(t){i=[6,t],r=0}finally{n=o=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,a])}}}function p(t,e,n,r){void 0===r&&(r=n),t[r]=e[n]}function y(t,e){for(var n in t)"default"===n||e.hasOwnProperty(n)||(e[n]=t[n])}function d(t){var e="function"==typeof Symbol&&Symbol.iterator,n=e&&t[e],r=0;if(n)return n.call(t);if(t&&"number"==typeof t.length)return{next:function(){return t&&r>=t.length&&(t=void 0),{value:t&&t[r++],done:!t}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")}function _(t,e){var n="function"==typeof Symbol&&t[Symbol.iterator];if(!n)return t;var r,o,i=n.call(t),u=[];try{for(;(void 0===e||e-- >0)&&!(r=i.next()).done;)u.push(r.value)}catch(t){o={error:t}}finally{try{r&&!r.done&&(n=i.return)&&n.call(i)}finally{if(o)throw o.error}}return u}function h(){for(var t=[],e=0;e<arguments.length;e++)t=t.concat(_(arguments[e]));return t}function v(){for(var t=0,e=0,n=arguments.length;e<n;e++)t+=arguments[e].length;var r=Array(t),o=0;for(e=0;e<n;e++)for(var i=arguments[e],u=0,a=i.length;u<a;u++,o++)r[o]=i[u];return r}function b(t){return this instanceof b?(this.v=t,this):new b(t)}function g(t,e,n){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var r,o=n.apply(t,e||[]),i=[];return r={},u("next"),u("throw"),u("return"),r[Symbol.asyncIterator]=function(){return this},r;function u(t){o[t]&&(r[t]=function(e){return new Promise((function(n,r){i.push([t,e,n,r])>1||a(t,e)}))})}function a(t,e){try{(n=o[t](e)).value instanceof b?Promise.resolve(n.value.v).then(c,f):l(i[0][2],n)}catch(t){l(i[0][3],t)}var n}function c(t){a("next",t)}function f(t){a("throw",t)}function l(t,e){t(e),i.shift(),i.length&&a(i[0][0],i[0][1])}}function m(t){var e,n;return e={},r("next"),r("throw",(function(t){throw t})),r("return"),e[Symbol.iterator]=function(){return this},e;function r(r,o){e[r]=t[r]?function(e){return(n=!n)?{value:b(t[r](e)),done:"return"===r}:o?o(e):e}:o}}function w(t){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var e,n=t[Symbol.asyncIterator];return n?n.call(t):(t=d(t),e={},r("next"),r("throw"),r("return"),e[Symbol.asyncIterator]=function(){return this},e);function r(n){e[n]=t[n]&&function(e){return new Promise((function(r,o){(function(t,e,n,r){Promise.resolve(r).then((function(e){t({value:e,done:n})}),e)})(r,o,(e=t[n](e)).done,e.value)}))}}}function S(t,e){return Object.defineProperty?Object.defineProperty(t,"raw",{value:e}):t.raw=e,t}function O(t){if(t&&t.__esModule)return t;var e={};if(null!=t)for(var n in t)Object.hasOwnProperty.call(t,n)&&(e[n]=t[n]);return e.default=t,e}function j(t){return t&&t.__esModule?t:{default:t}}function P(t,e){if(!e.has(t))throw new TypeError("attempted to get private field on non-instance");return e.get(t)}function x(t,e,n){if(!e.has(t))throw new TypeError("attempted to set private field on non-instance");return e.set(t,n),n}},function(t,e,n){"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.safeJsonParse=function(t){if("string"!=typeof t)throw new Error("Cannot safe json parse value of type "+typeof t);try{return JSON.parse(t)}catch(e){return t}},e.safeJsonStringify=function(t){return"string"==typeof t?t:JSON.stringify(t,(t,e)=>void 0===e?null:e)}},function(t,e,n){"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.KeyValueStorage=void 0;const r=n(0),o=r.__importDefault(n(3)),i=n(1),u=n(5);class a{constructor(){this.localStorage=o.default}getKeys(){return r.__awaiter(this,void 0,void 0,(function*(){return Object.keys(this.localStorage)}))}getEntries(){return r.__awaiter(this,void 0,void 0,(function*(){return Object.entries(this.localStorage).map(u.parseEntry)}))}getItem(t){return r.__awaiter(this,void 0,void 0,(function*(){const e=this.localStorage.getItem(t);if(null!==e)return i.safeJsonParse(e)}))}setItem(t,e){return r.__awaiter(this,void 0,void 0,(function*(){this.localStorage.setItem(t,i.safeJsonStringify(e))}))}removeItem(t){return r.__awaiter(this,void 0,void 0,(function*(){this.localStorage.removeItem(t)}))}}e.KeyValueStorage=a,e.default=a},function(t,e,n){(function(e){!function(){"use strict";var n;function r(){}(n=r).prototype.getItem=function(t){return this.hasOwnProperty(t)?String(this[t]):null},n.prototype.setItem=function(t,e){this[t]=String(e)},n.prototype.removeItem=function(t){delete this[t]},n.prototype.clear=function(){var t=this;Object.keys(t).forEach((function(e){t[e]=void 0,delete t[e]}))},n.prototype.key=function(t){return t=t||0,Object.keys(this)[t]},n.prototype.__defineGetter__("length",(function(){return Object.keys(this).length})),e.localStorage?t.exports=localStorage:t.exports=new r}()}).call(this,n(4))},function(t,e){var n;n=function(){return this}();try{n=n||new Function("return this")()}catch(t){"object"==typeof window&&(n=window)}t.exports=n},function(t,e,n){"use strict";Object.defineProperty(e,"__esModule",{value:!0});const r=n(0);r.__exportStar(n(6),e),r.__exportStar(n(7),e)},function(t,e,n){"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.IKeyValueStorage=void 0;e.IKeyValueStorage=class{}},function(t,e,n){"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.parseEntry=void 0;const r=n(1);e.parseEntry=function(t){var e;return[t[0],r.safeJsonParse(null!==(e=t[1])&&void 0!==e?e:"")]}}])}));
var r=function(t,e){return(r=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])})(t,e)};function o(t,e){function n(){this.constructor=t}r(t,e),t.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)}var i=function(){return(i=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t}).apply(this,arguments)};function u(t,e){var n={};for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&e.indexOf(r)<0&&(n[r]=t[r]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(r=Object.getOwnPropertySymbols(t);o<r.length;o++)e.indexOf(r[o])<0&&Object.prototype.propertyIsEnumerable.call(t,r[o])&&(n[r[o]]=t[r[o]])}return n}function a(t,e,n,r){var o,i=arguments.length,u=i<3?e:null===r?r=Object.getOwnPropertyDescriptor(e,n):r;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)u=Reflect.decorate(t,e,n,r);else for(var a=t.length-1;a>=0;a--)(o=t[a])&&(u=(i<3?o(u):i>3?o(e,n,u):o(e,n))||u);return i>3&&u&&Object.defineProperty(e,n,u),u}function c(t,e){return function(n,r){e(n,r,t)}}function s(t,e){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(t,e)}function l(t,e,n,r){return new(n||(n=Promise))((function(o,i){function u(t){try{c(r.next(t))}catch(t){i(t)}}function a(t){try{c(r.throw(t))}catch(t){i(t)}}function c(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(u,a)}c((r=r.apply(t,e||[])).next())}))}function f(t,e){var n,r,o,i,u={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function a(i){return function(a){return function(i){if(n)throw new TypeError("Generator is already executing.");for(;u;)try{if(n=1,r&&(o=2&i[0]?r.return:i[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,i[1])).done)return o;switch(r=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return u.label++,{value:i[1],done:!1};case 5:u.label++,r=i[1],i=[0];continue;case 7:i=u.ops.pop(),u.trys.pop();continue;default:if(!(o=u.trys,(o=o.length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){u=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]<o[3])){u.label=i[1];break}if(6===i[0]&&u.label<o[1]){u.label=o[1],o=i;break}if(o&&u.label<o[2]){u.label=o[2],u.ops.push(i);break}o[2]&&u.ops.pop(),u.trys.pop();continue}i=e.call(t,u)}catch(t){i=[6,t],r=0}finally{n=o=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,a])}}}function d(t,e,n,r){void 0===r&&(r=n),t[r]=e[n]}function y(t,e){for(var n in t)"default"===n||e.hasOwnProperty(n)||(e[n]=t[n])}function p(t){var e="function"==typeof Symbol&&Symbol.iterator,n=e&&t[e],r=0;if(n)return n.call(t);if(t&&"number"==typeof t.length)return{next:function(){return t&&r>=t.length&&(t=void 0),{value:t&&t[r++],done:!t}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")}function h(t,e){var n="function"==typeof Symbol&&t[Symbol.iterator];if(!n)return t;var r,o,i=n.call(t),u=[];try{for(;(void 0===e||e-- >0)&&!(r=i.next()).done;)u.push(r.value)}catch(t){o={error:t}}finally{try{r&&!r.done&&(n=i.return)&&n.call(i)}finally{if(o)throw o.error}}return u}function v(){for(var t=[],e=0;e<arguments.length;e++)t=t.concat(h(arguments[e]));return t}function _(){for(var t=0,e=0,n=arguments.length;e<n;e++)t+=arguments[e].length;var r=Array(t),o=0;for(e=0;e<n;e++)for(var i=arguments[e],u=0,a=i.length;u<a;u++,o++)r[o]=i[u];return r}function b(t){return this instanceof b?(this.v=t,this):new b(t)}function g(t,e,n){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var r,o=n.apply(t,e||[]),i=[];return r={},u("next"),u("throw"),u("return"),r[Symbol.asyncIterator]=function(){return this},r;function u(t){o[t]&&(r[t]=function(e){return new Promise((function(n,r){i.push([t,e,n,r])>1||a(t,e)}))})}function a(t,e){try{(n=o[t](e)).value instanceof b?Promise.resolve(n.value.v).then(c,s):l(i[0][2],n)}catch(t){l(i[0][3],t)}var n}function c(t){a("next",t)}function s(t){a("throw",t)}function l(t,e){t(e),i.shift(),i.length&&a(i[0][0],i[0][1])}}function w(t){var e,n;return e={},r("next"),r("throw",(function(t){throw t})),r("return"),e[Symbol.iterator]=function(){return this},e;function r(r,o){e[r]=t[r]?function(e){return(n=!n)?{value:b(t[r](e)),done:"return"===r}:o?o(e):e}:o}}function m(t){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var e,n=t[Symbol.asyncIterator];return n?n.call(t):(t=p(t),e={},r("next"),r("throw"),r("return"),e[Symbol.asyncIterator]=function(){return this},e);function r(n){e[n]=t[n]&&function(e){return new Promise((function(r,o){(function(t,e,n,r){Promise.resolve(r).then((function(e){t({value:e,done:n})}),e)})(r,o,(e=t[n](e)).done,e.value)}))}}}function S(t,e){return Object.defineProperty?Object.defineProperty(t,"raw",{value:e}):t.raw=e,t}function O(t){if(t&&t.__esModule)return t;var e={};if(null!=t)for(var n in t)Object.hasOwnProperty.call(t,n)&&(e[n]=t[n]);return e.default=t,e}function j(t){return t&&t.__esModule?t:{default:t}}function P(t,e){if(!e.has(t))throw new TypeError("attempted to get private field on non-instance");return e.get(t)}function x(t,e,n){if(!e.has(t))throw new TypeError("attempted to set private field on non-instance");return e.set(t,n),n}},function(t,e,n){"use strict";n.r(e),n.d(e,"safeJsonParse",(function(){return r})),n.d(e,"safeJsonStringify",(function(){return o}));function r(t){if("string"!=typeof t)throw new Error("Cannot safe json parse value of type "+typeof t);try{return(t=>{const e=t.replace(/([\[:])?(\d{17,}|(?:[9](?:[1-9]07199254740991|0[1-9]7199254740991|00[8-9]199254740991|007[2-9]99254740991|007199[3-9]54740991|0071992[6-9]4740991|00719925[5-9]740991|007199254[8-9]40991|0071992547[5-9]0991|00719925474[1-9]991|00719925474099[2-9])))([,\}\]])/g,'$1"$2n"$3');return JSON.parse(e,(t,e)=>"string"==typeof e&&e.match(/^\d+n$/)?BigInt(e.substring(0,e.length-1)):e)})(t)}catch(e){return t}}function o(t){return"string"==typeof t?t:(e=t,JSON.stringify(e,(t,e)=>"bigint"==typeof e?e.toString()+"n":e)||"");var e}},function(t,e,n){"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.KeyValueStorage=void 0;const r=n(0),o=n(1),i=r.__importDefault(n(3)),u=n(5),a=n(6);class c{constructor(t){(null==t?void 0:t.useIndexedDb)?this.localStorage=new u.IndexedDb:this.localStorage=i.default}useEntries(){return this.localStorage.entries||this.localStorage}getKeys(){return r.__awaiter(this,void 0,void 0,(function*(){return Object.keys(this.useEntries())}))}getEntries(){return r.__awaiter(this,void 0,void 0,(function*(){return Object.entries(this.useEntries()).map(a.parseEntry)}))}getItem(t){return r.__awaiter(this,void 0,void 0,(function*(){const e=yield this.localStorage.getItem(t);if(null!==e)return(0,o.safeJsonParse)(e)}))}setItem(t,e){return r.__awaiter(this,void 0,void 0,(function*(){this.localStorage.setItem(t,(0,o.safeJsonStringify)(e))}))}removeItem(t){return r.__awaiter(this,void 0,void 0,(function*(){this.localStorage.removeItem(t)}))}}e.KeyValueStorage=c,e.default=c},function(t,e,n){"use strict";(function(e){!function(){let n;function r(){}n=r,n.prototype.getItem=function(t){return this.hasOwnProperty(t)?String(this[t]):null},n.prototype.setItem=function(t,e){this[t]=String(e)},n.prototype.removeItem=function(t){delete this[t]},n.prototype.clear=function(){const t=this;Object.keys(t).forEach((function(e){t[e]=void 0,delete t[e]}))},n.prototype.key=function(t){return t=t||0,Object.keys(this)[t]},n.prototype.__defineGetter__("length",(function(){return Object.keys(this).length})),void 0!==e&&e.localStorage?t.exports=e.localStorage:"undefined"!=typeof window&&window.localStorage?t.exports=window.localStorage:t.exports=new r}()}).call(this,n(4))},function(t,e){var n;n=function(){return this}();try{n=n||new Function("return this")()}catch(t){"object"==typeof window&&(n=window)}t.exports=n},function(t,e,n){"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.IndexedDb=void 0;const r=n(0),o=n(1),i="WALLET_CONNECT_V2_INDEXED_DB",u="keyvaluestorage";e.IndexedDb=class{constructor(){this.db={},this.initialized=!1,this.entries={};const t=window.indexedDB.open(i,1);t.onsuccess=()=>r.__awaiter(this,void 0,void 0,(function*(){this.db=t.result,this.loadEntries(),this.initialized=!0})),t.onupgradeneeded=()=>{t.result.createObjectStore(u,{autoIncrement:!1})},t.onerror=t=>{console.error("IndexedDB error: "+i,t)}}loadEntries(){this.db.transaction(u,"readonly").objectStore(u).getAllKeys().onsuccess=t=>{const e=t.target.result;if(!(null==e?void 0:e.length))return;const n=this.db.transaction(u,"readonly").objectStore(u);e.forEach(t=>{n.get(t).onsuccess=e=>{const n=e.target.result;this.entries[t]=(0,o.safeJsonStringify)(n)}})}}get length(){return Object.keys(this.entries).length}toInitialize(){return r.__awaiter(this,void 0,void 0,(function*(){this.initialized||(yield new Promise(t=>{const e=setInterval(()=>{this.initialized&&(clearInterval(e),t())},20)}))}))}setItem(t,e){return r.__awaiter(this,void 0,void 0,(function*(){return yield this.toInitialize(),new Promise((n,r)=>{var i;const a=null===(i=this.db)||void 0===i?void 0:i.transaction(u,"readwrite"),c=null==a?void 0:a.objectStore(u);null==c||c.put((0,o.safeJsonParse)(e),t),a.oncomplete=()=>{this.entries[t]=e,n()},a.onerror=t=>r(t)})}))}getItem(t){return r.__awaiter(this,void 0,void 0,(function*(){return yield this.toInitialize(),new Promise(e=>{var n;const r=null===(n=this.db)||void 0===n?void 0:n.transaction(u,"readonly"),i=null==r?void 0:r.objectStore(u),a=null==i?void 0:i.get(t);a.onsuccess=()=>e(a.result?(0,o.safeJsonStringify)(a.result):null),a.onerror=()=>e(null)})}))}removeItem(t){return r.__awaiter(this,void 0,void 0,(function*(){return yield this.toInitialize(),new Promise((e,n)=>{var r;const o=null===(r=this.db)||void 0===r?void 0:r.transaction(u,"readwrite");(null==o?void 0:o.objectStore(u)).delete(t).onsuccess=()=>e(),o.onerror=t=>n(t)})}))}key(t=0){return Object.keys(this.entries)[t]}clear(){this.db.transaction(u,"readwrite").objectStore(u).clear()}}},function(t,e,n){"use strict";Object.defineProperty(e,"__esModule",{value:!0});const r=n(0);r.__exportStar(n(7),e),r.__exportStar(n(8),e)},function(t,e,n){"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.IKeyValueStorage=void 0;e.IKeyValueStorage=class{}},function(t,e,n){"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.parseEntry=void 0;const r=n(1);e.parseEntry=function(t){var e;return[t[0],(0,r.safeJsonParse)(null!==(e=t[1])&&void 0!==e?e:"")]}}])}));
{
"name": "@walletconnect/keyvaluestorage",
"description": "Isomorphic Key-Value Storage",
"version": "1.0.1-rc.1-1c715f7f",
"version": "1.0.2-canary-e580314",
"author": "WalletConnect, Inc. <walletconnect.com>",

@@ -39,7 +39,9 @@ "license": "MIT",

"test": "rm -rf ./test/dbs/* && env TS_NODE_PROJECT=\"tsconfig.cjs.json\" mocha --timeout 5000 --exit -r ts-node/register ./test/**/*.test.ts",
"lint": "eslint -c '../../.eslintrc' --fix './src/**/*.ts'"
"npm-publish:latest": "npm publish --access public --tag latest",
"npm-publish:canary": "npm publish --access public --tag canary",
"prepublishOnly": "npm run test && npm run build"
},
"dependencies": {
"localStorage": "^1.0.4",
"safe-json-utils": "^1.1.1"
"@walletconnect/safe-json": "^1.0.1",
"tslib": "1.14.1"
},

@@ -62,3 +64,3 @@ "peerDependencies": {

"@types/node": "^14.14.7",
"@walletconnect/time": "^1.0.1",
"@walletconnect/time": "^1.0.2",
"chai": "^4.3.6",

@@ -73,4 +75,3 @@ "classic-level": "^1.2.0",

"ts-node": "^10.9.1",
"tslib": "^1.10.0",
"typescript": "^3.7.5",
"typescript": "^4.9.5",
"webpack": "^4.41.6",

@@ -77,0 +78,0 @@ "webpack-cli": "^3.3.11"

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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