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

object.database

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

object.database - npm Package Compare versions

Comparing version 1.3.3 to 1.4.0

LICENSE

1192

lib/object.database.node.js

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

(function webpackUniversalModuleDefinition(root, factory) {
if(typeof exports === 'object' && typeof module === 'object')
module.exports = factory();
else if(typeof define === 'function' && define.amd)
define([], factory);
else if(typeof exports === 'object')
exports["ObjectDatabase"] = factory();
else
root["ObjectDatabase"] = factory();
})(typeof self !== 'undefined' ? self : this, function() {
return /******/ (function(modules) { // webpackBootstrap
/******/ // The module cache
/******/ var installedModules = {};
/******/
/******/ // The require function
/******/ function __webpack_require__(moduleId) {
/******/
/******/ // Check if module is in cache
/******/ if(installedModules[moduleId]) {
/******/ return installedModules[moduleId].exports;
/******/ }
/******/ // Create a new module (and put it into the cache)
/******/ var module = installedModules[moduleId] = {
/******/ i: moduleId,
/******/ l: false,
/******/ exports: {}
/******/ };
/******/
/******/ // Execute the module function
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
/******/
/******/ // Flag the module as loaded
/******/ module.l = true;
/******/
/******/ // Return the exports of the module
/******/ return module.exports;
/******/ }
/******/
/******/
/******/ // expose the modules object (__webpack_modules__)
/******/ __webpack_require__.m = modules;
/******/
/******/ // expose the module cache
/******/ __webpack_require__.c = installedModules;
/******/
/******/ // define getter function for harmony exports
/******/ __webpack_require__.d = function(exports, name, getter) {
/******/ if(!__webpack_require__.o(exports, name)) {
/******/ Object.defineProperty(exports, name, {
/******/ configurable: false,
/******/ enumerable: true,
/******/ get: getter
/******/ });
/******/ }
/******/ };
/******/
/******/ // getDefaultExport function for compatibility with non-harmony modules
/******/ __webpack_require__.n = function(module) {
/******/ var getter = module && module.__esModule ?
/******/ function getDefault() { return module['default']; } :
/******/ function getModuleExports() { return module; };
/******/ __webpack_require__.d(getter, 'a', getter);
/******/ return getter;
/******/ };
/******/
/******/ // Object.prototype.hasOwnProperty.call
/******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
/******/
/******/ // __webpack_public_path__
/******/ __webpack_require__.p = "";
/******/
/******/ // Load entry module and return exports
/******/ return __webpack_require__(__webpack_require__.s = 7);
/******/ })
/************************************************************************/
/******/ ([
/* 0 */
/***/ (function(module, exports) {
module.exports = require("babel-runtime/regenerator");
/***/ }),
/* 1 */
/***/ (function(module, exports) {
module.exports = require("babel-runtime/helpers/asyncToGenerator");
/***/ }),
/* 2 */
/***/ (function(module, exports) {
module.exports = require("babel-runtime/helpers/classCallCheck");
/***/ }),
/* 3 */
/***/ (function(module, exports) {
module.exports = require("babel-runtime/helpers/typeof");
/***/ }),
/* 4 */
/***/ (function(module, exports) {
module.exports = require("babel-runtime/core-js/get-iterator");
/***/ }),
/* 5 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
var _stringify = __webpack_require__(11);
var _JSON$stringify = _interopRequireDefault(_stringify).default;
var _regenerator = __webpack_require__(0);
var _regeneratorRuntime = _interopRequireDefault(_regenerator).default;
var _asyncToGenerator2 = __webpack_require__(1);
var _asyncToGenerator = _interopRequireDefault(_asyncToGenerator2).default;
var _classCallCheck2 = __webpack_require__(2);
var _classCallCheck = _interopRequireDefault(_classCallCheck2).default;
var _createClass2 = __webpack_require__(6);
var _createClass = _interopRequireDefault(_createClass2).default;
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
/** Storage
* Storage is the link between a Database & ObjectDB
*/
var Storage = function () {
function Storage() {
_classCallCheck(this, Storage);
// Live version db
this.memory = {};
}
/** To be implemented
* Retrieve value from @key in db
*
* @param key
* @returns {Promise.<value>}
*/
_createClass(Storage, [{
key: 'get',
value: function () {
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(key) {
return _regeneratorRuntime.wrap(function _callee$(_context) {
while (1) {
switch (_context.prev = _context.next) {
case 0:
case 'end':
return _context.stop();
}
}
}, _callee, this);
}));
function get(_x) {
return _ref.apply(this, arguments);
}
return get;
}()
}, {
key: 'set',
/** To be implemented
* Save @value for @key in db
*
* @param key
* @param value
* @returns {Promise.<void>}
*/
value: function () {
var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(key, value) {
return _regeneratorRuntime.wrap(function _callee2$(_context2) {
while (1) {
switch (_context2.prev = _context2.next) {
case 0:
case 'end':
return _context2.stop();
}
}
}, _callee2, this);
}));
function set(_x2, _x3) {
return _ref2.apply(this, arguments);
}
return set;
}()
}, {
key: 'del',
/** To be implemented
* Delete value for @key in db
*
* @param key
* @returns {Promise.<void>}
*/
value: function () {
var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3(key) {
return _regeneratorRuntime.wrap(function _callee3$(_context3) {
while (1) {
switch (_context3.prev = _context3.next) {
case 0:
case 'end':
return _context3.stop();
}
}
}, _callee3, this);
}));
function del(_x4) {
return _ref3.apply(this, arguments);
}
return del;
}()
}, {
key: '_fetch',
/** Gets the value for @key in database
* If @key is unknown, saves it in @memory
*
* @param key
* @returns {Promise.<*>}
* @private
*/
value: function () {
var _ref4 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4(key) {
var value;
return _regeneratorRuntime.wrap(function _callee4$(_context4) {
while (1) {
switch (_context4.prev = _context4.next) {
case 0:
_context4.next = 2;
return this.get(key);
case 2:
value = _context4.sent;
if (!(value === undefined)) {
_context4.next = 5;
break;
}
return _context4.abrupt('return');
case 5:
if (!(typeof value !== 'string')) {
_context4.next = 7;
break;
}
return _context4.abrupt('return');
case 7:
// Otherwise, save to in-memory storage
this.memory[key] = JSON.parse(value);
// And return the value
return _context4.abrupt('return', this._get(key));
case 9:
case 'end':
return _context4.stop();
}
}
}, _callee4, this);
}));
function _fetch(_x5) {
return _ref4.apply(this, arguments);
}
return _fetch;
}()
/** Gets the value for @key in the @memory
* @param key
* @returns {*}
*/
}, {
key: '_get',
value: function _get(key) {
return this.memory[key];
}
/** Set key-value in database
* @param key
* @param value
* @returns {boolean}
*/
}, {
key: '_set',
value: function _set(key, value) {
var _this = this;
// Save old value for rollback
var oldValue = this.memory[key];
// Save to built-in memory
this.memory[key] = value;
// Save to db
_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee5() {
return _regeneratorRuntime.wrap(function _callee5$(_context5) {
while (1) {
switch (_context5.prev = _context5.next) {
case 0:
_context5.prev = 0;
// Make value JSON compatible
value = _JSON$stringify(value);
// Then save to database
_context5.next = 4;
return _this.set(key, value);
case 4:
_context5.next = 10;
break;
case 6:
_context5.prev = 6;
_context5.t0 = _context5['catch'](0);
// Fail, rollback
_this.memory[key] = oldValue;
console.error(_context5.t0);
case 10:
case 'end':
return _context5.stop();
}
}
}, _callee5, _this, [[0, 6]]);
}))();
}
/** Removes key-value in database
* @param key
* @returns {boolean}
*/
}, {
key: '_del',
value: function _del(key) {
var _this2 = this;
// Save old value for rollback
var oldValue = this.memory[key];
// Delete from local memory
this.memory[key] = undefined;
// rm from db
_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee6() {
return _regeneratorRuntime.wrap(function _callee6$(_context6) {
while (1) {
switch (_context6.prev = _context6.next) {
case 0:
_context6.prev = 0;
_context6.next = 3;
return _this2.del(key);
case 3:
_context6.next = 9;
break;
case 5:
_context6.prev = 5;
_context6.t0 = _context6['catch'](0);
// Fail, rollback
_this2.memory[key] = oldValue;
console.error(_context6.t0);
case 9:
case 'end':
return _context6.stop();
}
}
}, _callee6, _this2, [[0, 5]]);
}))();
}
}]);
return Storage;
}();
exports.default = Storage;
/***/ }),
/* 6 */
/***/ (function(module, exports) {
module.exports = require("babel-runtime/helpers/createClass");
/***/ }),
/* 7 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
/*
https://github.com/webpack/webpack/issues/2030
For module to be importable must be require + exports; no import
*/
var ObjectDB = __webpack_require__(8).default;
var Storage = __webpack_require__(5).default;
var LocalStorage = __webpack_require__(12).default;
module.exports = {
ObjectDB: ObjectDB,
Storage: Storage,
LocalStorage: LocalStorage
};
/***/ }),
/* 8 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
var _typeof2 = __webpack_require__(3);
var _typeof = _interopRequireDefault(_typeof2).default;
var _regenerator = __webpack_require__(0);
var _regeneratorRuntime = _interopRequireDefault(_regenerator).default;
var _getIterator2 = __webpack_require__(4);
var _getIterator = _interopRequireDefault(_getIterator2).default;
var _asyncToGenerator2 = __webpack_require__(1);
var _asyncToGenerator = _interopRequireDefault(_asyncToGenerator2).default;
var _ObjectDBProxy = __webpack_require__(9);
var ObjectDBProxy = _interopRequireDefault(_ObjectDBProxy).default;
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
/** Loads an ObjectDB into the Storage
* In order to prevent delays & promises when getting & setting values, the Storage has a in-memory copy
* of any variable that was set inside a ObjectDB. These values are to be loaded before using an ObjectDB.
*
* @param namespace: Entry index to read/write
* @param storage: Storage instance
* @returns {Promise.<Proxy>}: Promise of loading the ObjectDB
* @constructor
*/
var ObjectDBProxyPromise = function () {
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(namespace, storage) {
var odbFieldsID, odbFields, odbProxy, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, propertyID;
return _regeneratorRuntime.wrap(function _callee$(_context) {
while (1) {
switch (_context.prev = _context.next) {
case 0:
// Fetch properties field before hand
odbFieldsID = namespace + '.o';
_context.next = 3;
return storage._fetch(odbFieldsID);
case 3:
odbFields = _context.sent;
odbProxy = ObjectDBProxy(namespace, storage);
if (!(odbFields !== undefined)) {
_context.next = 32;
break;
}
// Iterate
_iteratorNormalCompletion = true;
_didIteratorError = false;
_iteratorError = undefined;
_context.prev = 9;
_iterator = _getIterator(odbFields);
case 11:
if (_iteratorNormalCompletion = (_step = _iterator.next()).done) {
_context.next = 18;
break;
}
propertyID = _step.value;
_context.next = 15;
return fetchProperty(odbProxy.__self, propertyID);
case 15:
_iteratorNormalCompletion = true;
_context.next = 11;
break;
case 18:
_context.next = 24;
break;
case 20:
_context.prev = 20;
_context.t0 = _context['catch'](9);
_didIteratorError = true;
_iteratorError = _context.t0;
case 24:
_context.prev = 24;
_context.prev = 25;
if (!_iteratorNormalCompletion && _iterator.return) {
_iterator.return();
}
case 27:
_context.prev = 27;
if (!_didIteratorError) {
_context.next = 30;
break;
}
throw _iteratorError;
case 30:
return _context.finish(27);
case 31:
return _context.finish(24);
case 32:
return _context.abrupt('return', odbProxy);
case 33:
case 'end':
return _context.stop();
}
}
}, _callee, undefined, [[9, 20, 24, 32], [25,, 27, 31]]);
}));
return function ObjectDBProxyPromise(_x, _x2) {
return _ref.apply(this, arguments);
};
}();
/** Loads a property to the in-memory storage
* (for non-blocking i/o & fast variable access)
*
* @param odb: ObjectDB instance
* @param property: Property name
* @returns {Promise.<*>}: Promise of value
*/
var fetchProperty = function () {
var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(odb, property) {
var propertyID, propertyFieldsID, propertyFields, propertyValue;
return _regeneratorRuntime.wrap(function _callee2$(_context2) {
while (1) {
switch (_context2.prev = _context2.next) {
case 0:
propertyID = odb.namespace + '.p.' + property;
propertyFieldsID = propertyID + '.o';
// If _get returns, means it's already in-memory #references
propertyFields = odb.storage._get(propertyFieldsID);
propertyValue = odb.storage._get(propertyID);
// If was never registered before, fetch from database
if (!(propertyFields === undefined && propertyValue === undefined)) {
_context2.next = 19;
break;
}
_context2.next = 7;
return odb.storage._fetch(propertyFieldsID);
case 7:
propertyFields = _context2.sent;
_context2.next = 10;
return odb.storage._fetch(propertyID);
case 10:
propertyValue = _context2.sent;
if (!(propertyFields !== undefined)) {
_context2.next = 15;
break;
}
_context2.next = 14;
return ObjectDBProxyPromise(propertyID, odb.storage);
case 14:
return _context2.abrupt('return', _context2.sent);
case 15:
if (!((typeof propertyValue === 'undefined' ? 'undefined' : _typeof(propertyValue)) === 'object')) {
_context2.next = 19;
break;
}
_context2.next = 18;
return ObjectDBProxyPromise(propertyValue.ref, odb.storage);
case 18:
return _context2.abrupt('return', _context2.sent);
case 19:
case 'end':
return _context2.stop();
}
}
}, _callee2, undefined);
}));
return function fetchProperty(_x3, _x4) {
return _ref2.apply(this, arguments);
};
}();
exports.default = ObjectDBProxyPromise;
/***/ }),
/* 9 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
var _getIterator2 = __webpack_require__(4);
var _getIterator = _interopRequireDefault(_getIterator2).default;
var _typeof2 = __webpack_require__(3);
var _typeof = _interopRequireDefault(_typeof2).default;
var _ObjectDB = __webpack_require__(10);
var ObjectDB = _interopRequireDefault(_ObjectDB).default;
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
/** Creates a new Proxied ObjectDB
* Uses a Proxy to trap changes on itself
*
* --- example ---
* let test = ObjectDB('test', ...);
*
* test.var1 = "var1";
* test.var2 = "test2"
* --------------
*
* Running the example will save to Storage (Database).
*
* @param namespace: Entry index to read/write
* @param storage: Storage instance
* @returns {Proxy} Proxied ObjectDB
*/
var ObjectDBProxy = function ObjectDBProxy(namespace, storage) {
var odb = new ObjectDB(namespace, storage);
// Get holder for property names #.o
var odbFieldsID = odb.namespace + '.o';
var odbFields = odb.storage._get(odbFieldsID);
// Define odb nsp as Object
if (odbFields === undefined) odb.storage._set(odbFieldsID, []);
// Means an object === array in db
// Listens for any modification
return new Proxy(odb, {
defineProperty: function defineProperty(odb, property, value) {
return proxySet(odb, property, value);
},
set: function set(odb, property, value) {
return proxySet(odb, property, value);
},
get: function get(odb, property) {
return proxyGet(odb, property);
},
deleteProperty: function deleteProperty(odb, property) {
return proxyDeleteProperty(odb, property);
},
enumerate: function enumerate(odb) {
return proxyOwnKeys(odb);
},
ownKeys: function ownKeys(odb) {
return proxyOwnKeys(odb);
},
has: function has(odb, property) {
return proxyHas(odb, property);
},
getOwnPropertyDescriptor: function getOwnPropertyDescriptor(odb, property) {
return proxyGetOwnPropertyDescriptor(odb, property);
}
});
};
/** Trigger for @set #Proxy
*
* @param odb: ObjectDB parent of the property
* @param property: Property name/key to set
* @param value: Value to set
* @returns {boolean}
*/
var proxySet = function proxySet(odb, property, value) {
// Decline on ObjectDB methods
if (property === 'then') return false;
if (property === 'clear') return false;
if (property === '__self') return false;
if (value === undefined || value === null) eraseProperty(odb, property);else saveProperty(odb, property, value);
return true;
};
/** Trigger for @get #Proxy
*
* @param odb: ObjectDB parent of the property
* @param property: Property name/key to get value from
* @returns {*}: If the property is a Primitive, it retrieves it from the Storage & returns it. Otherwise,
* if it's an Object, it returns the ObjectDBProxy() for that Object (thus allowing to chain requests)
*/
var proxyGet = function proxyGet(odb, property) {
if (property === 'then') return; // https://stackoverflow.com/questions/48318843
if (property === 'clear') return function () {
return clear(odb);
};
if (property === '__self') return odb; // Useful to reach ObjectDB from the Proxy
// Retrieve property from odb
var propertyID = odb.namespace + '.p.' + property;
var propertyFieldsID = propertyID + '.o'; // If Object
var propertyFields = odb.storage._get(propertyFieldsID); // !=null ==> object
var propertyValue = odb.storage._get(propertyID); // !=null ==> property
// If it's an object, load ObjectDB
if (propertyFields !== undefined) return ObjectDBProxy(propertyID, odb.storage);
//Maybe it's a reference, load ObjectDB
if ((typeof propertyValue === 'undefined' ? 'undefined' : _typeof(propertyValue)) === 'object') return ObjectDBProxy(propertyValue.ref, odb.storage);
//Then it's a Primitive value
return propertyValue;
};
/** Trigger for @deleteProperty #Proxy
*
* @param odb: ObjectDB parent of the property
* @param property: Property name/key to delete
* @returns {boolean}
*/
var proxyDeleteProperty = function proxyDeleteProperty(odb, property) {
// Decline on ObjectDB methods
if (property === 'clear') return false;
if (property === 'then') return false;
if (property === '__self') return false;
eraseProperty(odb, property);
return true;
};
/** Erases a property from the Storage
*
* @param odb: ObjectDB parent of the property
* @param property: Property name/key to delete
*/
var eraseProperty = function eraseProperty(odb, property) {
// Parent reference holder of properties
var odbFieldsID = odb.namespace + '.o';
var odbFields = odb.storage._get(odbFieldsID);
var updatedFields = odbFields ? odbFields : [];
// Property that is going to be removed
var oldPropertyID = odb.namespace + '.p.' + property;
var oldPropertyFieldsID = oldPropertyID + '.o'; // If object
var oldPropertyFields = odb.storage._get(oldPropertyFieldsID);
if (oldPropertyFields) {
// If it's an Object
var p = ObjectDBProxy(oldPropertyID, odb.storage);
// Erase everything, erase all the fields
var _iteratorNormalCompletion = true;
var _didIteratorError = false;
var _iteratorError = undefined;
try {
for (var _iterator = _getIterator(oldPropertyFields), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
var removePropertyID = _step.value;
p[removePropertyID] = undefined;
} // Remove the field index as well
} catch (err) {
_didIteratorError = true;
_iteratorError = err;
} finally {
try {
if (!_iteratorNormalCompletion && _iterator.return) {
_iterator.return();
}
} finally {
if (_didIteratorError) {
throw _iteratorError;
}
}
}
odb.storage._del(oldPropertyFieldsID);
} // If it's a primitive / reference
else odb.storage._del(oldPropertyID);
// Remove property from odbFields & update
updatedFields = updatedFields.filter(function (e) {
return e !== property;
});
odb.storage._set(odbFieldsID, updatedFields);
};
/** Saves @property to the Storage
*
* @param odb: ObjectDB parent of the property
* @param property: Property name/key to set
* @param value: Value to set
*/
var saveProperty = function saveProperty(odb, property, value) {
// Make room for new value
eraseProperty(odb, property);
// Parent reference holder of properties
var odbFieldsID = odb.namespace + '.o';
var odbFields = odb.storage._get(odbFieldsID);
var updatedFields = odbFields ? odbFields : [];
// Property that is going to be saved with @value
var newPropertyID = odb.namespace + '.p.' + property;
if (value instanceof ObjectDB) {
// If reference
// Check that ref doesn't point to other
if (value.__self.storage !== odb.storage) throw new Error('Cannot cross Storages');
// Save the reference to the database
var ref = { ref: value.__self.namespace };
odb.storage._set(newPropertyID, ref);
} // If object -> save as ObjectDB #recursion
else if ((typeof value === 'undefined' ? 'undefined' : _typeof(value)) === 'object') {
var p = ObjectDBProxy(newPropertyID, odb.storage);
// Calls saveProperty on all the props
for (var copyPropertyID in value) {
if (value.hasOwnProperty(copyPropertyID)) p[copyPropertyID] = value[copyPropertyID];
}
} // Then it's a Primitive value, save it
else odb.storage._set(newPropertyID, value);
// Register new property / update
updatedFields.push(property);
odb.storage._set(odbFieldsID, updatedFields);
};
/** Erases all the properties from @odb
*
* @param odb: ObjectDB instance
*/
var clear = function clear(odb) {
var odbFieldsID = odb.namespace + '.o';
var odbFields = odb.storage._get(odbFieldsID);
var _iteratorNormalCompletion2 = true;
var _didIteratorError2 = false;
var _iteratorError2 = undefined;
try {
for (var _iterator2 = _getIterator(odbFields), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
var odbField = _step2.value;
eraseProperty(odb, odbField);
}
} catch (err) {
_didIteratorError2 = true;
_iteratorError2 = err;
} finally {
try {
if (!_iteratorNormalCompletion2 && _iterator2.return) {
_iterator2.return();
}
} finally {
if (_didIteratorError2) {
throw _iteratorError2;
}
}
}
};
/** Returns whether property exists in @odb
*
* @param odb: ObjectDB parent of the property
* @param property: Property to check existence
*/
var proxyHas = function proxyHas(odb, property) {
var odbFieldsID = odb.namespace + '.o';
var odbFields = odb.storage._get(odbFieldsID);
return odbFields.includes(property);
};
/** Returns property fields names of @odb
*
* @param odb: ObjectDB instance
*/
var proxyOwnKeys = function proxyOwnKeys(odb) {
var odbFieldsID = odb.namespace + '.o';
var odbFields = odb.storage._get(odbFieldsID);
return odbFields;
};
/** Returns a property descriptor
*
* @param odb: ObjectDB parent of the property
* @param property: Property to be described
* @returns {*}: Property descriptor
*/
var proxyGetOwnPropertyDescriptor = function proxyGetOwnPropertyDescriptor(odb, property) {
var value = proxyGet(odb, property);
return value ? {
value: value,
writable: true,
enumerable: true,
configurable: true
} : undefined;
};
exports.default = ObjectDBProxy;
/***/ }),
/* 10 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
var _classCallCheck2 = __webpack_require__(2);
var _classCallCheck = _interopRequireDefault(_classCallCheck2).default;
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
/** ObjectDB
* Base structure of Object-Database
*/
var ObjectDB =
/**
* @param namespace: Entry index to read/write
* @param storage: Storage instance
*/
function ObjectDB(namespace, storage) {
_classCallCheck(this, ObjectDB);
this.storage = storage;
this.namespace = namespace; //Identity
};
exports.default = ObjectDB;
/***/ }),
/* 11 */
/***/ (function(module, exports) {
module.exports = require("babel-runtime/core-js/json/stringify");
/***/ }),
/* 12 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
var _regenerator = __webpack_require__(0);
var _regeneratorRuntime = _interopRequireDefault(_regenerator).default;
var _asyncToGenerator2 = __webpack_require__(1);
var _asyncToGenerator = _interopRequireDefault(_asyncToGenerator2).default;
var _getPrototypeOf = __webpack_require__(13);
var _Object$getPrototypeOf = _interopRequireDefault(_getPrototypeOf).default;
var _classCallCheck2 = __webpack_require__(2);
var _classCallCheck = _interopRequireDefault(_classCallCheck2).default;
var _createClass2 = __webpack_require__(6);
var _createClass = _interopRequireDefault(_createClass2).default;
var _possibleConstructorReturn2 = __webpack_require__(14);
var _possibleConstructorReturn = _interopRequireDefault(_possibleConstructorReturn2).default;
var _inherits2 = __webpack_require__(15);
var _inherits = _interopRequireDefault(_inherits2).default;
var _nodeLocalstorage = __webpack_require__(16);
var NodeLocalStorage = _interopRequireDefault(_nodeLocalstorage).default;
var _Storage2 = __webpack_require__(5);
var Storage = _interopRequireDefault(_Storage2).default;
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
/** LocalStorage
* Storage that makes ObjectDB to work with files
*/
var LocalStorage = function (_Storage) {
_inherits(LocalStorage, _Storage);
/**
* @param storageName: Name of the storage to use
* @param storageQuota: Limit of data it can carry (MBytes)
*/
function LocalStorage() {
var storageName = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'localStorage';
var storageQuota = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 5;
_classCallCheck(this, LocalStorage);
// Surrogate storage that we create, basically chooses between browser or own localStorage
var _this = _possibleConstructorReturn(this, (LocalStorage.__proto__ || _Object$getPrototypeOf(LocalStorage)).call(this));
if (storageName !== 'localStorage' || typeof localStorage === 'undefined' || localStorage === null) _this.surrogate = new NodeLocalStorage.LocalStorage(storageName, storageQuota * 1024 * 1024);else _this.surrogate = localStorage; // Use localStorage provided by the browser
return _this;
}
_createClass(LocalStorage, [{
key: 'get',
value: function () {
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(key) {
return _regeneratorRuntime.wrap(function _callee$(_context) {
while (1) {
switch (_context.prev = _context.next) {
case 0:
return _context.abrupt('return', this.surrogate.getItem(key));
case 1:
case 'end':
return _context.stop();
}
}
}, _callee, this);
}));
function get(_x3) {
return _ref.apply(this, arguments);
}
return get;
}()
}, {
key: 'set',
value: function () {
var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(key, value) {
return _regeneratorRuntime.wrap(function _callee2$(_context2) {
while (1) {
switch (_context2.prev = _context2.next) {
case 0:
this.surrogate.setItem(key, value);
case 1:
case 'end':
return _context2.stop();
}
}
}, _callee2, this);
}));
function set(_x4, _x5) {
return _ref2.apply(this, arguments);
}
return set;
}()
}, {
key: 'del',
value: function () {
var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3(key) {
return _regeneratorRuntime.wrap(function _callee3$(_context3) {
while (1) {
switch (_context3.prev = _context3.next) {
case 0:
this.surrogate.removeItem(key);
case 1:
case 'end':
return _context3.stop();
}
}
}, _callee3, this);
}));
function del(_x6) {
return _ref3.apply(this, arguments);
}
return del;
}()
}]);
return LocalStorage;
}(Storage);
exports.default = LocalStorage;
/***/ }),
/* 13 */
/***/ (function(module, exports) {
module.exports = require("babel-runtime/core-js/object/get-prototype-of");
/***/ }),
/* 14 */
/***/ (function(module, exports) {
module.exports = require("babel-runtime/helpers/possibleConstructorReturn");
/***/ }),
/* 15 */
/***/ (function(module, exports) {
module.exports = require("babel-runtime/helpers/inherits");
/***/ }),
/* 16 */
/***/ (function(module, exports) {
module.exports = require("node-localstorage");
/***/ })
/******/ ]);
});
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.ObjectDatabase=t():e.ObjectDatabase=t()}(global,function(){return function(e){var t={};function r(n){if(t[n])return t[n].exports;var u=t[n]={i:n,l:!1,exports:{}};return e[n].call(u.exports,u,u.exports,r),u.l=!0,u.exports}return r.m=e,r.c=t,r.d=function(e,t,n){r.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:n})},r.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},r.t=function(e,t){if(1&t&&(e=r(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var n=Object.create(null);if(r.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var u in e)r.d(n,u,function(t){return e[t]}.bind(null,u));return n},r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,"a",t),t},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r.p="",r(r.s=16)}([function(e,t){e.exports=require("babel-runtime/helpers/classCallCheck")},function(e,t){e.exports=require("babel-runtime/helpers/asyncToGenerator")},function(e,t){e.exports=require("babel-runtime/regenerator")},function(e,t){e.exports=require("babel-runtime/helpers/createClass")},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var n=i(r(12)).default,u=i(r(2)).default,a=i(r(1)).default,o=i(r(0)).default,s=i(r(3)).default;function i(e){return e&&e.__esModule?e:{default:e}}var c=function(){function e(){o(this,e),this.memory={}}return s(e,[{key:"get",value:function(){var e=a(u.mark(function e(t){return u.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:case"end":return e.stop()}},e,this)}));return function(t){return e.apply(this,arguments)}}()},{key:"set",value:function(){var e=a(u.mark(function e(t,r){return u.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:case"end":return e.stop()}},e,this)}));return function(t,r){return e.apply(this,arguments)}}()},{key:"del",value:function(){var e=a(u.mark(function e(t){return u.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:case"end":return e.stop()}},e,this)}));return function(t){return e.apply(this,arguments)}}()},{key:"_fetch",value:function(){var e=a(u.mark(function e(t){var r;return u.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.get(t);case 2:if(void 0!==(r=e.sent)){e.next=5;break}return e.abrupt("return");case 5:if("string"==typeof r){e.next=7;break}return e.abrupt("return");case 7:return this.memory[t]=JSON.parse(r),e.abrupt("return",this._get(t));case 9:case"end":return e.stop()}},e,this)}));return function(t){return e.apply(this,arguments)}}()},{key:"_get",value:function(e){return this.memory[e]}},{key:"_set",value:function(e,t){var r=this,o=this.memory[e];this.memory[e]=t,a(u.mark(function a(){return u.wrap(function(u){for(;;)switch(u.prev=u.next){case 0:return u.prev=0,t=n(t),u.next=4,r.set(e,t);case 4:u.next=10;break;case 6:u.prev=6,u.t0=u.catch(0),r.memory[e]=o,console.error(u.t0);case 10:case"end":return u.stop()}},a,r,[[0,6]])}))()}},{key:"_del",value:function(e){var t=this,r=this.memory[e];this.memory[e]=void 0,a(u.mark(function n(){return u.wrap(function(n){for(;;)switch(n.prev=n.next){case 0:return n.prev=0,n.next=3,t.del(e);case 3:n.next=9;break;case 5:n.prev=5,n.t0=n.catch(0),t.memory[e]=r,console.error(n.t0);case 9:case"end":return n.stop()}},n,t,[[0,5]])}))()}}]),e}();t.default=c},function(e,t){e.exports=require("babel-runtime/core-js/get-iterator")},function(e,t){e.exports=require("babel-runtime/helpers/typeof")},function(e,t){e.exports=require("node-localstorage")},function(e,t){e.exports=require("babel-runtime/helpers/inherits")},function(e,t){e.exports=require("babel-runtime/helpers/possibleConstructorReturn")},function(e,t){e.exports=require("babel-runtime/core-js/object/get-prototype-of")},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var n=p(r(2)).default,u=p(r(1)).default,a=p(r(10)).default,o=p(r(0)).default,s=p(r(3)).default,i=p(r(9)).default,c=p(r(8)).default,f=p(r(7)).default,l=p(r(4)).default;function p(e){return e&&e.__esModule?e:{default:e}}var d=function(e){function t(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"localStorage",r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:5;o(this,t);var n=i(this,(t.__proto__||a(t)).call(this));return"localStorage"!==e||"undefined"==typeof localStorage||null===localStorage?n.surrogate=new f.LocalStorage(e,1024*r*1024):n.surrogate=localStorage,n}return c(t,l),s(t,[{key:"get",value:function(){var e=u(n.mark(function e(t){return n.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",this.surrogate.getItem(t));case 1:case"end":return e.stop()}},e,this)}));return function(t){return e.apply(this,arguments)}}()},{key:"set",value:function(){var e=u(n.mark(function e(t,r){return n.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:this.surrogate.setItem(t,r);case 1:case"end":return e.stop()}},e,this)}));return function(t,r){return e.apply(this,arguments)}}()},{key:"del",value:function(){var e=u(n.mark(function e(t){return n.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:this.surrogate.removeItem(t);case 1:case"end":return e.stop()}},e,this)}));return function(t){return e.apply(this,arguments)}}()}]),t}();t.default=d},function(e,t){e.exports=require("babel-runtime/core-js/json/stringify")},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var n,u=r(0),a=(n=u,n&&n.__esModule?n:{default:n}).default;t.default=function e(t,r){a(this,e),this.storage=r,this.namespace=t}},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var n=o(r(5)).default,u=o(r(6)).default,a=o(r(13)).default;function o(e){return e&&e.__esModule?e:{default:e}}var s=function(e,t){var r=new a(e,t),n=r.namespace+".o";return void 0===r.storage._get(n)&&r.storage._set(n,[]),new Proxy(r,{defineProperty:function(e,t,r){return i(e,t,r)},set:function(e,t,r){return i(e,t,r)},get:function(e,t){return c(e,t)},deleteProperty:function(e,t){return f(e,t)},enumerate:function(e){return h(e)},ownKeys:function(e){return h(e)},has:function(e,t){return v(e,t)},getOwnPropertyDescriptor:function(e,t){return g(e,t)}})},i=function(e,t,r){return"then"!==t&&("clear"!==t&&("__self"!==t&&(void 0===r||null===r?l(e,t):p(e,t,r),!0)))},c=function(e,t){if("then"!==t){if("clear"===t)return function(){return d(e)};if("__self"===t)return e;var r=e.namespace+".p."+t,n=r+".o",a=e.storage._get(n),o=e.storage._get(r);return void 0!==a?s(r,e.storage):"object"===(void 0===o?"undefined":u(o))?s(o.ref,e.storage):o}},f=function(e,t){return"clear"!==t&&("then"!==t&&("__self"!==t&&(l(e,t),!0)))},l=function(e,t){var r=e.namespace+".o",u=e.storage._get(r),a=u||[],o=e.namespace+".p."+t,i=o+".o",c=e.storage._get(i);if(c){var f=s(o,e.storage),l=!0,p=!1,d=void 0;try{for(var v,h=n(c);!(l=(v=h.next()).done);l=!0){f[v.value]=void 0}}catch(e){p=!0,d=e}finally{try{!l&&h.return&&h.return()}finally{if(p)throw d}}e.storage._del(i)}else e.storage._del(o);a=a.filter(function(e){return e!==t}),e.storage._set(r,a)},p=function(e,t,r){l(e,t);var n=e.namespace+".o",o=e.storage._get(n),i=o||[],c=e.namespace+".p."+t;if(r instanceof a){if(r.__self.storage!==e.storage)throw new Error("Cannot cross Storages");var f={ref:r.__self.namespace};e.storage._set(c,f)}else if("object"===(void 0===r?"undefined":u(r))){var p=s(c,e.storage);for(var d in r)r.hasOwnProperty(d)&&(p[d]=r[d])}else e.storage._set(c,r);i.push(t),e.storage._set(n,i)},d=function(e){var t=e.namespace+".o",r=e.storage._get(t),u=!0,a=!1,o=void 0;try{for(var s,i=n(r);!(u=(s=i.next()).done);u=!0){var c=s.value;l(e,c)}}catch(e){a=!0,o=e}finally{try{!u&&i.return&&i.return()}finally{if(a)throw o}}},v=function(e,t){var r=e.namespace+".o";return e.storage._get(r).includes(t)},h=function(e){var t=e.namespace+".o";return e.storage._get(t)},g=function(e,t){var r=c(e,t);return r?{value:r,writable:!0,enumerable:!0,configurable:!0}:void 0};t.default=s},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var n=i(r(6)).default,u=i(r(2)).default,a=i(r(5)).default,o=i(r(1)).default,s=i(r(14)).default;function i(e){return e&&e.__esModule?e:{default:e}}var c,f,l=(c=o(u.mark(function e(t,r){var n,o,i,c,f,l,d,v,h;return u.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return n=t+".o",e.next=3,r._fetch(n);case 3:if(o=e.sent,i=s(t,r),void 0===o){e.next=32;break}c=!0,f=!1,l=void 0,e.prev=9,d=a(o);case 11:if(c=(v=d.next()).done){e.next=18;break}return h=v.value,e.next=15,p(i.__self,h);case 15:c=!0,e.next=11;break;case 18:e.next=24;break;case 20:e.prev=20,e.t0=e.catch(9),f=!0,l=e.t0;case 24:e.prev=24,e.prev=25,!c&&d.return&&d.return();case 27:if(e.prev=27,!f){e.next=30;break}throw l;case 30:return e.finish(27);case 31:return e.finish(24);case 32:return e.abrupt("return",i);case 33:case"end":return e.stop()}},e,void 0,[[9,20,24,32],[25,,27,31]])})),function(e,t){return c.apply(this,arguments)}),p=(f=o(u.mark(function e(t,r){var a,o,s,i;return u.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(a=t.namespace+".p."+r,o=a+".o",s=t.storage._get(o),i=t.storage._get(a),void 0!==s||void 0!==i){e.next=19;break}return e.next=7,t.storage._fetch(o);case 7:return s=e.sent,e.next=10,t.storage._fetch(a);case 10:if(i=e.sent,void 0===s){e.next=15;break}return e.next=14,l(a,t.storage);case 14:return e.abrupt("return",e.sent);case 15:if("object"!==(void 0===i?"undefined":n(i))){e.next=19;break}return e.next=18,l(i.ref,t.storage);case 18:return e.abrupt("return",e.sent);case 19:case"end":return e.stop()}},e,void 0)})),function(e,t){return f.apply(this,arguments)});t.default=l},function(e,t,r){"use strict";var n=r(15).default,u=r(4).default,a=r(11).default;e.exports={ObjectDB:n,Storage:u,LocalStorage:a}}])});
//# sourceMappingURL=object.database.node.map
{
"name": "object.database",
"version": "1.3.3",
"version": "1.4.0",
"description": "object.database",

@@ -12,10 +12,11 @@ "main": "lib/object.database.node.js",

"devDependencies": {
"babel-core": "^6.26.0",
"babel-loader": "^7.1.2",
"babel-core": "^6.26.3",
"babel-loader": "^7.1.4",
"babel-plugin-transform-es2015-modules-commonjs-simple": "^6.7.4",
"babel-plugin-transform-runtime": "^6.23.0",
"babel-polyfill": "^6.26.0",
"babel-preset-env": "^1.6.1",
"webpack": "^3.8.1",
"webpack-node-externals": "^1.6.0"
"babel-preset-env": "^1.7.0",
"webpack": "^4.12.0",
"webpack-cli": "^3.0.3",
"webpack-node-externals": "^1.7.2"
},

@@ -22,0 +23,0 @@ "dependencies": {

@@ -8,2 +8,3 @@ const path = require('path');

const configuration = {
mode: 'production',
entry: {

@@ -10,0 +11,0 @@ [`${name}.${target}`]: path.resolve(__dirname, 'src/index.js'),

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