Socket
Socket
Sign inDemoInstall

reduxed-chrome-storage

Package Overview
Dependencies
Maintainers
1
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

reduxed-chrome-storage - npm Package Compare versions

Comparing version 2.4.0 to 2.4.5

8

dist/index.d.ts

@@ -25,4 +25,2 @@ import { StoreCreator, StoreEnhancer, Reducer } from 'redux';

* or the chrome namespace within Manifest V3 chrome extension.
* One may pass the chrome namespace within Manifest V3 to make this library
* use Promise-based APIs under the hood.
* If this option is supplied, the previous two are ignored

@@ -33,8 +31,4 @@ * @param obj.changeListener a function to be called whenever the state changes,

* 2) the previous state.
* This option only makes sense in Manifest V3 service workers
* or event-driven background scripts.
* If this option is supplied, the async store creator returned by the factory
* is not supposed to be immediately used for store creation;
* its only purpose in this case is to hold the arguments to be passed
* to the original `createStore` upon a one-time store creation
* is not supposed to be immediately used for store creation
* @param obj.errorListener a function to be called whenever an error occurs

@@ -41,0 +35,0 @@ * during chrome.storage update, receives two parameters:

73

dist/index.esm.js
/**
* @license
* ReduxedChromeStorage v2.4.0
* ReduxedChromeStorage v2.4.5
* https://github.com/hindmost/reduxed-chrome-storage

@@ -192,2 +192,3 @@ * Copyright (c) Savr Goryaev aka hindmost

const usageSize = (data) => new TextEncoder().encode(Object.entries(data).map(([key, val]) => key + JSON.stringify(val)).join('')).length;
class WrappedStorage {

@@ -199,4 +200,2 @@ constructor({ namespace, area, key }) {

this.key = key || 'reduxed';
this.keyLen = this.key.length;
this.lastSize = 0;
this.listeners = [];

@@ -213,3 +212,2 @@ this.errorListeners = [];

return;
this.lastSize = JSON.stringify(newValue).length;
// call external chrome.storage.onChanged listeners

@@ -232,28 +230,27 @@ for (const fn of this.listeners) {

}
getErrorMessage() {
callbackOnLoad(data, callback, all) {
callback(!this.ns.runtime.lastError && (all ? data : data && data[this.key]));
}
callbackOnSave(data, area) {
if (!this.ns.runtime.lastError)
return;
const { message } = this.ns.runtime.lastError;
return message || '';
}
callbackOnLoad(data, callback) {
data = !this.ns.runtime.lastError && data && data[this.key];
if (!this.lastSize && data) {
this.lastSize = JSON.stringify(data).length;
if (!message || !data || !area) {
this.fireErrorListeners(message || '', false);
return;
}
callback(data);
}
checkQuotaPerItem(msg, area, data) {
const b = this.areaName === StorageAreaName.sync &&
area && area.QUOTA_BYTES_PER_ITEM && data &&
JSON.stringify(data).length + this.keyLen > area.QUOTA_BYTES_PER_ITEM;
b && this.fireErrorListeners(msg);
return b;
area.QUOTA_BYTES_PER_ITEM &&
usageSize({ [this.key]: data }) > area.QUOTA_BYTES_PER_ITEM;
if (b) {
this.fireErrorListeners(message, true);
return;
}
this.load((allData) => {
const b = typeof allData === 'object' &&
area.QUOTA_BYTES > 0 &&
usageSize(Object.assign(Object.assign({}, allData), { [this.key]: data })) > area.QUOTA_BYTES;
this.fireErrorListeners(message, b);
}, true);
}
checkQuota(msg, area, data, total) {
const b = !this.ns.runtime.lastError &&
area && area.QUOTA_BYTES && data && total > 0 && this.lastSize > 0 &&
JSON.stringify(data).length - this.lastSize > area.QUOTA_BYTES - total;
this.fireErrorListeners(msg, b);
}
}

@@ -266,6 +263,6 @@

}
load(fn) {
load(fn, all) {
typeof fn === 'function' &&
this.areaApi.get(this.key, data => {
this.callbackOnLoad(data, fn);
this.areaApi.get(all ? null : this.key, data => {
this.callbackOnLoad(data, fn, all);
});

@@ -275,8 +272,3 @@ }

this.areaApi.set({ [this.key]: data }, () => {
const message = this.getErrorMessage();
typeof message !== 'undefined' &&
!this.checkQuotaPerItem(message, this.areaApi, data) &&
this.areaApi.getBytesInUse(null, total => {
this.checkQuota(message, this.areaApi, data, total);
});
this.callbackOnSave(data, this.areaApi);
});

@@ -299,8 +291,3 @@ }

this.areaApi.set({ [this.key]: data }).then(() => {
const message = this.getErrorMessage();
typeof message !== 'undefined' &&
!this.checkQuotaPerItem(message, this.areaApi, data) &&
this.areaApi.getBytesInUse(null).then(total => {
this.checkQuota(message, this.areaApi, data, total);
});
this.callbackOnSave(data, this.areaApi);
});

@@ -333,4 +320,2 @@ }

* or the chrome namespace within Manifest V3 chrome extension.
* One may pass the chrome namespace within Manifest V3 to make this library
* use Promise-based APIs under the hood.
* If this option is supplied, the previous two are ignored

@@ -341,8 +326,4 @@ * @param obj.changeListener a function to be called whenever the state changes,

* 2) the previous state.
* This option only makes sense in Manifest V3 service workers
* or event-driven background scripts.
* If this option is supplied, the async store creator returned by the factory
* is not supposed to be immediately used for store creation;
* its only purpose in this case is to hold the arguments to be passed
* to the original `createStore` upon a one-time store creation
* is not supposed to be immediately used for store creation
* @param obj.errorListener a function to be called whenever an error occurs

@@ -349,0 +330,0 @@ * during chrome.storage update, receives two parameters:

/**
* @license
* ReduxedChromeStorage v2.4.0
* ReduxedChromeStorage v2.4.5
* https://github.com/hindmost/reduxed-chrome-storage

@@ -216,2 +216,8 @@ * Copyright (c) Savr Goryaev aka hindmost

var usageSize = function (data) { return new TextEncoder().encode(Object.entries(data).map(function (ref) {
var key = ref[0];
var val = ref[1];
return key + JSON.stringify(val);
}).join('')).length; };
var WrappedStorage = function WrappedStorage(ref) {

@@ -226,4 +232,2 @@ var namespace = ref.namespace;

this.key = key || 'reduxed';
this.keyLen = this.key.length;
this.lastSize = 0;
this.listeners = [];

@@ -244,3 +248,2 @@ this.errorListeners = [];

{ return; }
this$1$1.lastSize = JSON.stringify(newValue).length;
// call external chrome.storage.onChanged listeners

@@ -267,3 +270,9 @@ for (var i = 0, list = this$1$1.listeners; i < list.length; i += 1) {

};
WrappedStorage.prototype.getErrorMessage = function getErrorMessage () {
WrappedStorage.prototype.callbackOnLoad = function callbackOnLoad (data, callback, all) {
callback(!this.ns.runtime.lastError && (all ? data : data && data[this.key]));
};
WrappedStorage.prototype.callbackOnSave = function callbackOnSave (data, area) {
var this$1$1 = this;
var obj;
if (!this.ns.runtime.lastError)

@@ -273,24 +282,22 @@ { return; }

var message = ref.message;
return message || '';
};
WrappedStorage.prototype.callbackOnLoad = function callbackOnLoad (data, callback) {
data = !this.ns.runtime.lastError && data && data[this.key];
if (!this.lastSize && data) {
this.lastSize = JSON.stringify(data).length;
if (!message || !data || !area) {
this.fireErrorListeners(message || '', false);
return;
}
callback(data);
};
WrappedStorage.prototype.checkQuotaPerItem = function checkQuotaPerItem (msg, area, data) {
var b = this.areaName === StorageAreaName.sync &&
area && area.QUOTA_BYTES_PER_ITEM && data &&
JSON.stringify(data).length + this.keyLen > area.QUOTA_BYTES_PER_ITEM;
b && this.fireErrorListeners(msg);
return b;
area.QUOTA_BYTES_PER_ITEM &&
usageSize(( obj = {}, obj[this.key] = data, obj )) > area.QUOTA_BYTES_PER_ITEM;
if (b) {
this.fireErrorListeners(message, true);
return;
}
this.load(function (allData) {
var obj;
var b = typeof allData === 'object' &&
area.QUOTA_BYTES > 0 &&
usageSize(Object.assign(Object.assign({}, allData), ( obj = {}, obj[this$1$1.key] = data, obj ))) > area.QUOTA_BYTES;
this$1$1.fireErrorListeners(message, b);
}, true);
};
WrappedStorage.prototype.checkQuota = function checkQuota (msg, area, data, total) {
var b = !this.ns.runtime.lastError &&
area && area.QUOTA_BYTES && data && total > 0 && this.lastSize > 0 &&
JSON.stringify(data).length - this.lastSize > area.QUOTA_BYTES - total;
this.fireErrorListeners(msg, b);
};

@@ -310,8 +317,8 @@ var WrappedChromeStorage = /*@__PURE__*/(function (WrappedStorage) {

WrappedChromeStorage.prototype.constructor = WrappedChromeStorage;
WrappedChromeStorage.prototype.load = function load (fn) {
WrappedChromeStorage.prototype.load = function load (fn, all) {
var this$1$1 = this;
typeof fn === 'function' &&
this.areaApi.get(this.key, function (data) {
this$1$1.callbackOnLoad(data, fn);
this.areaApi.get(all ? null : this.key, function (data) {
this$1$1.callbackOnLoad(data, fn, all);
});

@@ -324,8 +331,3 @@ };

this.areaApi.set(( obj = {}, obj[this.key] = data, obj ), function () {
var message = this$1$1.getErrorMessage();
typeof message !== 'undefined' &&
!this$1$1.checkQuotaPerItem(message, this$1$1.areaApi, data) &&
this$1$1.areaApi.getBytesInUse(null, function (total) {
this$1$1.checkQuota(message, this$1$1.areaApi, data, total);
});
this$1$1.callbackOnSave(data, this$1$1.areaApi);
});

@@ -363,8 +365,3 @@ };

this.areaApi.set(( obj = {}, obj[this.key] = data, obj )).then(function () {
var message = this$1$1.getErrorMessage();
typeof message !== 'undefined' &&
!this$1$1.checkQuotaPerItem(message, this$1$1.areaApi, data) &&
this$1$1.areaApi.getBytesInUse(null).then(function (total) {
this$1$1.checkQuota(message, this$1$1.areaApi, data, total);
});
this$1$1.callbackOnSave(data, this$1$1.areaApi);
});

@@ -399,4 +396,2 @@ };

* or the chrome namespace within Manifest V3 chrome extension.
* One may pass the chrome namespace within Manifest V3 to make this library
* use Promise-based APIs under the hood.
* If this option is supplied, the previous two are ignored

@@ -407,8 +402,4 @@ * @param obj.changeListener a function to be called whenever the state changes,

* 2) the previous state.
* This option only makes sense in Manifest V3 service workers
* or event-driven background scripts.
* If this option is supplied, the async store creator returned by the factory
* is not supposed to be immediately used for store creation;
* its only purpose in this case is to hold the arguments to be passed
* to the original `createStore` upon a one-time store creation
* is not supposed to be immediately used for store creation
* @param obj.errorListener a function to be called whenever an error occurs

@@ -415,0 +406,0 @@ * during chrome.storage update, receives two parameters:

/**
* @license
* ReduxedChromeStorage v2.4.0
* ReduxedChromeStorage v2.4.5
* https://github.com/hindmost/reduxed-chrome-storage

@@ -11,2 +11,2 @@ * Copyright (c) Savr Goryaev aka hindmost

!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t="undefined"!=typeof globalThis?globalThis:t||self).reduxedChromeStorage=e()}(this,(function(){"use strict";function t(e){return null==e||"object"!=typeof e?e:Array.isArray(e)?e.map((function(e){return t(e)})):Object.keys(e).reduce((function(r,n){return r[n]=t(e[n]),r}),{})}function e(t,r){if(t===r)return!0;if(null==t||"object"!=typeof t||null==r||"object"!=typeof r)return!1;var n=Object.keys(t),i=Object.keys(r);if(n.length!==i.length)return!1;for(var o=0,s=n;s.length>o;o+=1){var a=s[o];if(-1>=i.indexOf(a)||!e(t[a],r[a]))return!1}return!0}function r(e,n){return Array.isArray(n)?t(n):"object"!=typeof e||Array.isArray(e)||"object"!=typeof n?void 0!==n?n:e:Object.keys(e).concat(Object.keys(n).filter((function(t){return!e[t]}))).reduce((function(t,i){return t[i]=r(e[i],n[i]),t}),{})}var n,i=function(t){var e=t.reducer,r=t.storage,n=t.bufferLife,i=t.initialState,o=t.enhancer;this.createStore=t.createStore,this.storage=r,this.reducer=e,this.enhancer=o,this.buffLife=n?Math.min(Math.max(n,0),2e3):100,this.state0=i,this.state=null,this.buffStore=null,this.lastState=null,this.listeners=[],this.inited=!1,this.dispatch=this.dispatch.bind(this),this.subscribe=this.subscribe.bind(this)};i.prototype.init=function(){var t=this;if(this.inited)return new Promise((function(e){e(t)}));var n=this._createStore().getState();return this.storage.subscribe((function(r,n){if(!e(r,t.state)){t._setState(r);for(var i=0,o=t.listeners;o.length>i;i+=1){(0,o[i])(n)}}})),this.inited=!0,new Promise((function(i){t.storage.load((function(o){var s=o?r(n,o):n;t.state0&&(s=r(s,t.state0)),t._setState(s),e(s,o)||t._send2Storage(s),i(t)}))}))},i.prototype.initFrom=function(t){return this._setState(t),this.inited=!0,this},i.prototype.uninit=function(){var t=this;return new Promise((function(e){e(t)}))},i.prototype._createStore=function(t){return this.createStore(this.reducer,t,this.enhancer)},i.prototype._send2Storage=function(t){this.storage.save(t)},i.prototype._setState=function(e){e&&(this.state=t(e))},i.prototype.getState=function(){return this.state},i.prototype.subscribe=function(t){var e=this;return"function"==typeof t&&this.listeners.push(t),function(){"function"==typeof t&&(e.listeners=e.listeners.filter((function(e){return e!==t})))}},i.prototype.dispatch=function(t){var r=this;this.buffStore||(this.buffStore=this._createStore(this.state),this.lastState=this.buffStore.getState(),setTimeout((function(){r.buffStore=null}),this.buffLife));var n=this.buffStore,i=n.subscribe((function(){var t=r.buffStore||n,o=t&&t.getState();e(o,r.lastState)||(r._send2Storage(o),r.lastState=o,i(),n=null)}));return n.dispatch(t)},i.prototype.replaceReducer=function(t){return"function"==typeof t&&(this.reducer=t),this},i.prototype[Symbol.observable]=function(){var t,e=this.getState,r=this.subscribe;return(t={subscribe:function(t){if("object"!=typeof t||null===t)throw new TypeError("Expected the observer to be an object.");function n(){t.next&&t.next(e())}return n(),{unsubscribe:r(n)}}})[Symbol.observable]=function(){return this},t},function(t){t.local="local",t.sync="sync"}(n||(n={}));var o=function(t){var e=t.area,r=t.key;this.ns=t.namespace,this.areaName=e===n.sync?n.sync:n.local,this.key=r||"reduxed",this.keyLen=this.key.length,this.lastSize=0,this.listeners=[],this.errorListeners=[]};o.prototype.init=function(){var t=this;this.ns.storage.onChanged.addListener((function(e,r){if(r===t.areaName&&t.key in e){var n=e[t.key],i=n.newValue,o=n.oldValue;if(i){t.lastSize=JSON.stringify(i).length;for(var s=0,a=t.listeners;a.length>s;s+=1){(0,a[s])(i,o)}}}}))},o.prototype.subscribe=function(t){"function"==typeof t&&this.listeners.push(t)},o.prototype.subscribeForError=function(t){"function"==typeof t&&this.errorListeners.push(t)},o.prototype.fireErrorListeners=function(t,e){for(var r=0,n=this.errorListeners;n.length>r;r+=1){(0,n[r])(t,e)}},o.prototype.getErrorMessage=function(){if(this.ns.runtime.lastError)return this.ns.runtime.lastError.message||""},o.prototype.callbackOnLoad=function(t,e){t=!this.ns.runtime.lastError&&t&&t[this.key],!this.lastSize&&t&&(this.lastSize=JSON.stringify(t).length),e(t)},o.prototype.checkQuotaPerItem=function(t,e,r){var i=this.areaName===n.sync&&e&&e.QUOTA_BYTES_PER_ITEM&&r&&JSON.stringify(r).length+this.keyLen>e.QUOTA_BYTES_PER_ITEM;return i&&this.fireErrorListeners(t),i},o.prototype.checkQuota=function(t,e,r,n){var i=!this.ns.runtime.lastError&&e&&e.QUOTA_BYTES&&r&&n>0&&this.lastSize>0&&JSON.stringify(r).length-this.lastSize>e.QUOTA_BYTES-n;this.fireErrorListeners(t,i)};var s,a=function(t){function e(e){t.call(this,{namespace:e.namespace,area:e.area,key:e.key}),this.areaApi=this.ns.storage[this.areaName]}return t&&(e.__proto__=t),(e.prototype=Object.create(t&&t.prototype)).constructor=e,e.prototype.load=function(t){var e=this;"function"==typeof t&&this.areaApi.get(this.key,(function(r){e.callbackOnLoad(r,t)}))},e.prototype.save=function(t){var e,r=this;this.areaApi.set(((e={})[this.key]=t,e),(function(){var e=r.getErrorMessage();void 0!==e&&!r.checkQuotaPerItem(e,r.areaApi,t)&&r.areaApi.getBytesInUse(null,(function(n){r.checkQuota(e,r.areaApi,t,n)}))}))},e}(o),c=function(t){function e(e){t.call(this,{namespace:e.namespace,area:e.area,key:e.key}),this.areaApi=this.ns.storage[this.areaName]}return t&&(e.__proto__=t),(e.prototype=Object.create(t&&t.prototype)).constructor=e,e.prototype.load=function(t){var e=this;"function"==typeof t&&this.areaApi.get(this.key).then((function(r){e.callbackOnLoad(r,t)}))},e.prototype.save=function(t){var e,r=this;this.areaApi.set((e={},e[this.key]=t,e)).then((function(){var e=r.getErrorMessage();void 0!==e&&!r.checkQuotaPerItem(e,r.areaApi,t)&&r.areaApi.getBytesInUse(null).then((function(n){r.checkQuota(e,r.areaApi,t,n)}))}))},e}(o);return function(t){t.chrome="chrome",t.browser="browser"}(s||(s={})),function(t){var e=t.createStore,r=t.namespace,n=t.chromeNs,o=t.browserNs,u=t.changeListener,f=t.errorListener,h=t.storageArea,p=t.storageKey,l=t.bufferLife;if("function"!=typeof e)throw Error("Missing 'createStore' property/option");var y=o||r===s.browser?new c({namespace:o||browser,area:h,key:p}):new a({namespace:n||chrome,area:h,key:p});return y.init(),"function"==typeof f&&y.subscribeForError(f),function(t,r,n){if("function"!=typeof t)throw Error("Missing 'reducer' parameter");if("function"==typeof r&&"function"==typeof n)throw Error("Multiple 'enhancer' parameters unallowed");"function"==typeof r&&void 0===n&&(n=r,r=void 0);var o=new i({createStore:e,storage:y,bufferLife:l,reducer:t,initialState:r,enhancer:n});return"function"!=typeof u?o.init():(y.subscribe((function(t,e){u(o.initFrom(t),e)})),o.uninit())}}}));
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t="undefined"!=typeof globalThis?globalThis:t||self).reduxedChromeStorage=e()}(this,(function(){"use strict";function t(e){return null==e||"object"!=typeof e?e:Array.isArray(e)?e.map((function(e){return t(e)})):Object.keys(e).reduce((function(r,n){return r[n]=t(e[n]),r}),{})}function e(t,r){if(t===r)return!0;if(null==t||"object"!=typeof t||null==r||"object"!=typeof r)return!1;var n=Object.keys(t),i=Object.keys(r);if(n.length!==i.length)return!1;for(var o=0,s=n;s.length>o;o+=1){var a=s[o];if(-1>=i.indexOf(a)||!e(t[a],r[a]))return!1}return!0}function r(e,n){return Array.isArray(n)?t(n):"object"!=typeof e||Array.isArray(e)||"object"!=typeof n?void 0!==n?n:e:Object.keys(e).concat(Object.keys(n).filter((function(t){return!e[t]}))).reduce((function(t,i){return t[i]=r(e[i],n[i]),t}),{})}var n,i=function(t){var e=t.reducer,r=t.storage,n=t.bufferLife,i=t.initialState,o=t.enhancer;this.createStore=t.createStore,this.storage=r,this.reducer=e,this.enhancer=o,this.buffLife=n?Math.min(Math.max(n,0),2e3):100,this.state0=i,this.state=null,this.buffStore=null,this.lastState=null,this.listeners=[],this.inited=!1,this.dispatch=this.dispatch.bind(this),this.subscribe=this.subscribe.bind(this)};i.prototype.init=function(){var t=this;if(this.inited)return new Promise((function(e){e(t)}));var n=this._createStore().getState();return this.storage.subscribe((function(r,n){if(!e(r,t.state)){t._setState(r);for(var i=0,o=t.listeners;o.length>i;i+=1){(0,o[i])(n)}}})),this.inited=!0,new Promise((function(i){t.storage.load((function(o){var s=o?r(n,o):n;t.state0&&(s=r(s,t.state0)),t._setState(s),e(s,o)||t._send2Storage(s),i(t)}))}))},i.prototype.initFrom=function(t){return this._setState(t),this.inited=!0,this},i.prototype.uninit=function(){var t=this;return new Promise((function(e){e(t)}))},i.prototype._createStore=function(t){return this.createStore(this.reducer,t,this.enhancer)},i.prototype._send2Storage=function(t){this.storage.save(t)},i.prototype._setState=function(e){e&&(this.state=t(e))},i.prototype.getState=function(){return this.state},i.prototype.subscribe=function(t){var e=this;return"function"==typeof t&&this.listeners.push(t),function(){"function"==typeof t&&(e.listeners=e.listeners.filter((function(e){return e!==t})))}},i.prototype.dispatch=function(t){var r=this;this.buffStore||(this.buffStore=this._createStore(this.state),this.lastState=this.buffStore.getState(),setTimeout((function(){r.buffStore=null}),this.buffLife));var n=this.buffStore,i=n.subscribe((function(){var t=r.buffStore||n,o=t&&t.getState();e(o,r.lastState)||(r._send2Storage(o),r.lastState=o,i(),n=null)}));return n.dispatch(t)},i.prototype.replaceReducer=function(t){return"function"==typeof t&&(this.reducer=t),this},i.prototype[Symbol.observable]=function(){var t,e=this.getState,r=this.subscribe;return(t={subscribe:function(t){if("object"!=typeof t||null===t)throw new TypeError("Expected the observer to be an object.");function n(){t.next&&t.next(e())}return n(),{unsubscribe:r(n)}}})[Symbol.observable]=function(){return this},t},function(t){t.local="local",t.sync="sync"}(n||(n={}));var o=function(t){return(new TextEncoder).encode(Object.entries(t).map((function(t){return t[0]+JSON.stringify(t[1])})).join("")).length},s=function(t){var e=t.area,r=t.key;this.ns=t.namespace,this.areaName=e===n.sync?n.sync:n.local,this.key=r||"reduxed",this.listeners=[],this.errorListeners=[]};s.prototype.init=function(){var t=this;this.ns.storage.onChanged.addListener((function(e,r){if(r===t.areaName&&t.key in e){var n=e[t.key],i=n.newValue,o=n.oldValue;if(i)for(var s=0,a=t.listeners;a.length>s;s+=1){(0,a[s])(i,o)}}}))},s.prototype.subscribe=function(t){"function"==typeof t&&this.listeners.push(t)},s.prototype.subscribeForError=function(t){"function"==typeof t&&this.errorListeners.push(t)},s.prototype.fireErrorListeners=function(t,e){for(var r=0,n=this.errorListeners;n.length>r;r+=1){(0,n[r])(t,e)}},s.prototype.callbackOnLoad=function(t,e,r){e(!this.ns.runtime.lastError&&(r?t:t&&t[this.key]))},s.prototype.callbackOnSave=function(t,e){var r,i=this;if(this.ns.runtime.lastError){var s=this.ns.runtime.lastError.message;if(s&&t&&e)this.areaName===n.sync&&e.QUOTA_BYTES_PER_ITEM&&o(((r={})[this.key]=t,r))>e.QUOTA_BYTES_PER_ITEM?this.fireErrorListeners(s,!0):this.load((function(r){var n,a="object"==typeof r&&e.QUOTA_BYTES>0&&o(Object.assign(Object.assign({},r),((n={})[i.key]=t,n)))>e.QUOTA_BYTES;i.fireErrorListeners(s,a)}),!0);else this.fireErrorListeners(s||"",!1)}};var a,c=function(t){function e(e){t.call(this,{namespace:e.namespace,area:e.area,key:e.key}),this.areaApi=this.ns.storage[this.areaName]}return t&&(e.__proto__=t),(e.prototype=Object.create(t&&t.prototype)).constructor=e,e.prototype.load=function(t,e){var r=this;"function"==typeof t&&this.areaApi.get(e?null:this.key,(function(n){r.callbackOnLoad(n,t,e)}))},e.prototype.save=function(t){var e,r=this;this.areaApi.set(((e={})[this.key]=t,e),(function(){r.callbackOnSave(t,r.areaApi)}))},e}(s),u=function(t){function e(e){t.call(this,{namespace:e.namespace,area:e.area,key:e.key}),this.areaApi=this.ns.storage[this.areaName]}return t&&(e.__proto__=t),(e.prototype=Object.create(t&&t.prototype)).constructor=e,e.prototype.load=function(t){var e=this;"function"==typeof t&&this.areaApi.get(this.key).then((function(r){e.callbackOnLoad(r,t)}))},e.prototype.save=function(t){var e,r=this;this.areaApi.set((e={},e[this.key]=t,e)).then((function(){r.callbackOnSave(t,r.areaApi)}))},e}(s);return function(t){t.chrome="chrome",t.browser="browser"}(a||(a={})),function(t){var e=t.createStore,r=t.namespace,n=t.chromeNs,o=t.browserNs,s=t.changeListener,f=t.errorListener,h=t.storageArea,p=t.storageKey,l=t.bufferLife;if("function"!=typeof e)throw Error("Missing 'createStore' property/option");var y=o||r===a.browser?new u({namespace:o||browser,area:h,key:p}):new c({namespace:n||chrome,area:h,key:p});return y.init(),"function"==typeof f&&y.subscribeForError(f),function(t,r,n){if("function"!=typeof t)throw Error("Missing 'reducer' parameter");if("function"==typeof r&&"function"==typeof n)throw Error("Multiple 'enhancer' parameters unallowed");"function"==typeof r&&void 0===n&&(n=r,r=void 0);var o=new i({createStore:e,storage:y,bufferLife:l,reducer:t,initialState:r,enhancer:n});return"function"!=typeof s?o.init():(y.subscribe((function(t,e){s(o.initFrom(t),e)})),o.uninit())}}}));

@@ -23,4 +23,2 @@ export declare enum StorageAreaName {

export declare type StorageGetKeys = string | string[] | StorageData | null;
export declare type StorageUsageCallback = (data: number) => void;
export declare type StorageUsageKeys = string | string[] | null;
export interface StorageAreaQuotas {

@@ -35,3 +33,2 @@ QUOTA_BYTES: number;

clear(): void;
getBytesInUse(keys: StorageUsageKeys, callback: StorageUsageCallback): void;
}

@@ -42,3 +39,2 @@ export interface StorageAreaPromised extends StorageAreaQuotas {

clear(): void;
getBytesInUse(keys: StorageUsageKeys): Promise<number>;
}

@@ -45,0 +41,0 @@ export interface ApisNamespace {

import { ExtendedStore } from './store';
export declare type ChangeListener = (store: ExtendedStore, oldState?: any) => void;
export declare type ErrorListener = (message?: string, exceeded?: boolean) => void;
export declare type ErrorListener = (message: string, exceeded: boolean) => void;
{
"name": "reduxed-chrome-storage",
"version": "2.4.0",
"version": "2.4.5",
"description": "Redux-compatible interface to chrome.storage. Unified way to use Redux in all modern browser extensions. The only way to get Redux working in Manifest V3 Chrome extensions",

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

@@ -28,2 +28,3 @@ # Reduxed Chrome Storage

browserNs?: ...,
errorListener?: ...,
storageArea?: ...,

@@ -63,2 +64,25 @@ storageKey?: ...,

### Storage API errors listening along with size/limits control:
```js
import { createStore } from 'redux';
import storeCreatorFactory from 'reduxed-chrome-storage';
import reducer from './reducer';
const errorListener = (message: string, exceeded: boolean) => {
...
};
const options = {
createStore: createStore,
errorListener: errorListener,
namespace?: ...,
chromeNs?: ...,
browserNs?: ...,
storageArea?: ...,
storageKey?: ...,
bufferLife?: ...
};
storeCreatorFactory(options)(reducer);
```
### State change listening (special case - only makes sense in Manifest V3 service workers):

@@ -81,2 +105,3 @@

browserNs?: ...,
errorListener?: ...,
storageArea?: ...,

@@ -83,0 +108,0 @@ storageKey?: ...,

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