object.database
Advanced tools
Comparing version 1.1.8 to 1.1.9
@@ -73,3 +73,3 @@ (function webpackUniversalModuleDefinition(root, factory) { | ||
/******/ // Load entry module and return exports | ||
/******/ return __webpack_require__(__webpack_require__.s = 3); | ||
/******/ return __webpack_require__(__webpack_require__.s = 7); | ||
/******/ }) | ||
@@ -81,3 +81,3 @@ /************************************************************************/ | ||
module.exports = require("babel-runtime/core-js/get-iterator"); | ||
module.exports = require("babel-runtime/helpers/classCallCheck"); | ||
@@ -88,6 +88,24 @@ /***/ }), | ||
module.exports = require("babel-runtime/helpers/typeof"); | ||
/***/ }), | ||
/* 2 */ | ||
/***/ (function(module, exports) { | ||
module.exports = require("babel-runtime/regenerator"); | ||
/***/ }), | ||
/* 3 */ | ||
/***/ (function(module, exports) { | ||
module.exports = require("babel-runtime/core-js/get-iterator"); | ||
/***/ }), | ||
/* 4 */ | ||
/***/ (function(module, exports) { | ||
module.exports = require("babel-runtime/helpers/asyncToGenerator"); | ||
/***/ }), | ||
/* 2 */ | ||
/* 5 */ | ||
/***/ (function(module, exports, __webpack_require__) { | ||
@@ -102,6 +120,18 @@ | ||
var _asyncToGenerator2 = __webpack_require__(1); | ||
var _regenerator = __webpack_require__(2); | ||
var _regeneratorRuntime = _interopRequireDefault(_regenerator).default; | ||
var _asyncToGenerator2 = __webpack_require__(4); | ||
var _asyncToGenerator = _interopRequireDefault(_asyncToGenerator2).default; | ||
var _classCallCheck2 = __webpack_require__(0); | ||
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 }; } | ||
@@ -112,4 +142,6 @@ | ||
*/ | ||
class Storage { | ||
constructor() { | ||
var Storage = function () { | ||
function Storage() { | ||
_classCallCheck(this, Storage); | ||
// Live version db | ||
@@ -125,117 +157,257 @@ this.memory = {}; | ||
*/ | ||
get(key) { | ||
return _asyncToGenerator(function* () {})(); | ||
} | ||
/** To be implemented | ||
* Save value 'in' key in db | ||
* | ||
* @param key: Key of the value | ||
* @param value: Value to save | ||
* @returns {Promise.<void>} | ||
*/ | ||
set(key, value) { | ||
return _asyncToGenerator(function* () {})(); | ||
} | ||
/** To be implemented | ||
* Delete value of key in db | ||
* | ||
* @param key: Key of the value | ||
* @returns {Promise.<void>} | ||
*/ | ||
del(key) { | ||
return _asyncToGenerator(function* () {})(); | ||
} | ||
_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); | ||
})); | ||
/** Gets the value for @key in distant storage | ||
* If @key is unknown, saves it in @memory | ||
* @param key | ||
* @returns {Promise.<*>} | ||
* @private | ||
*/ | ||
_fetch(key) { | ||
var _this = this; | ||
function get(_x) { | ||
return _ref.apply(this, arguments); | ||
} | ||
return _asyncToGenerator(function* () { | ||
// Retrieve value from implemented | ||
const value = yield _this.get(key); | ||
return get; | ||
}() | ||
}, { | ||
key: "set", | ||
// If the asked value does not exist | ||
if (value === undefined) return; | ||
// Save to in-memory storage | ||
_this.memory[key] = value; | ||
/** To be implemented | ||
* Save value 'in' key in db | ||
* | ||
* @param key: Key of the value | ||
* @param value: Value to save | ||
* @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); | ||
})); | ||
//And return the value | ||
return _this._get(key); | ||
})(); | ||
} | ||
function set(_x2, _x3) { | ||
return _ref2.apply(this, arguments); | ||
} | ||
/** Gets the value for @key in the @memory | ||
* @param key | ||
* @returns {*} | ||
*/ | ||
_get(key) { | ||
return this.memory[key]; | ||
} | ||
return set; | ||
}() | ||
}, { | ||
key: "del", | ||
/** Set @value for @key in database | ||
* @param key | ||
* @param value | ||
* @returns {boolean} | ||
*/ | ||
_set(key, value) { | ||
var _this2 = this; | ||
// Save to old value for rollback | ||
const oldValue = this.memory[key]; | ||
/** To be implemented | ||
* Delete value of key in db | ||
* | ||
* @param key: Key of the value | ||
* @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); | ||
})); | ||
// Save to built-in memory | ||
this.memory[key] = value; | ||
// Save to db | ||
_asyncToGenerator(function* () { | ||
try { | ||
yield _this2.set(key, value); | ||
} catch (error) { | ||
// Fail, rollback | ||
_this2.memory[key] = oldValue; | ||
console.log(error); | ||
function del(_x4) { | ||
return _ref3.apply(this, arguments); | ||
} | ||
})(); | ||
return true; | ||
} | ||
return del; | ||
}() | ||
}, { | ||
key: "_fetch", | ||
/** Removes in database | ||
* @param key | ||
* @returns {boolean} | ||
*/ | ||
_del(key) { | ||
var _this3 = this; | ||
// Save to old value for rollback | ||
const oldValue = this.memory[key]; | ||
/** Gets the value for @key in distant storage | ||
* 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); | ||
// Delete from local memory | ||
this.memory[key] = undefined; | ||
case 2: | ||
value = _context4.sent; | ||
// rm from db | ||
_asyncToGenerator(function* () { | ||
try { | ||
yield _this3.del(key); | ||
} catch (error) { | ||
// Fail, rollback | ||
_this3.memory[key] = oldValue; | ||
console.log(error); | ||
if (!(value === undefined)) { | ||
_context4.next = 5; | ||
break; | ||
} | ||
return _context4.abrupt("return"); | ||
case 5: | ||
// Save to in-memory storage | ||
this.memory[key] = value; | ||
//And return the value | ||
return _context4.abrupt("return", this._get(key)); | ||
case 7: | ||
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 @value for @key in database | ||
* @param key | ||
* @param value | ||
* @returns {boolean} | ||
*/ | ||
}, { | ||
key: "_set", | ||
value: function _set(key, value) { | ||
var _this = this; | ||
// Save to 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; | ||
_context5.next = 3; | ||
return _this.set(key, value); | ||
case 3: | ||
_context5.next = 9; | ||
break; | ||
case 5: | ||
_context5.prev = 5; | ||
_context5.t0 = _context5["catch"](0); | ||
// Fail, rollback | ||
_this.memory[key] = oldValue; | ||
console.log(_context5.t0); | ||
case 9: | ||
case "end": | ||
return _context5.stop(); | ||
} | ||
} | ||
}, _callee5, _this, [[0, 5]]); | ||
}))(); | ||
return true; | ||
} | ||
/** Removes in database | ||
* @param key | ||
* @returns {boolean} | ||
*/ | ||
}, { | ||
key: "_del", | ||
value: function _del(key) { | ||
var _this2 = this; | ||
// Save to 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.log(_context6.t0); | ||
case 9: | ||
case "end": | ||
return _context6.stop(); | ||
} | ||
} | ||
}, _callee6, _this2, [[0, 5]]); | ||
}))(); | ||
} | ||
}]); | ||
return Storage; | ||
}(); | ||
exports.default = Storage; | ||
/***/ }), | ||
/* 3 */ | ||
/* 6 */ | ||
/***/ (function(module, exports) { | ||
module.exports = require("babel-runtime/helpers/createClass"); | ||
/***/ }), | ||
/* 7 */ | ||
/***/ (function(module, exports, __webpack_require__) { | ||
@@ -251,14 +423,14 @@ | ||
const ObjectDB = __webpack_require__(4).default; | ||
const Storage = __webpack_require__(2).default; | ||
const LocalStorage = __webpack_require__(7).default; | ||
var ObjectDB = __webpack_require__(8).default; | ||
var Storage = __webpack_require__(5).default; | ||
var LocalStorage = __webpack_require__(11).default; | ||
module.exports = { | ||
ObjectDB, | ||
Storage, | ||
LocalStorage | ||
ObjectDB: ObjectDB, | ||
Storage: Storage, | ||
LocalStorage: LocalStorage | ||
}; | ||
/***/ }), | ||
/* 4 */ | ||
/* 8 */ | ||
/***/ (function(module, exports, __webpack_require__) { | ||
@@ -273,11 +445,19 @@ | ||
var _getIterator2 = __webpack_require__(0); | ||
var _typeof2 = __webpack_require__(1); | ||
var _typeof = _interopRequireDefault(_typeof2).default; | ||
var _regenerator = __webpack_require__(2); | ||
var _regeneratorRuntime = _interopRequireDefault(_regenerator).default; | ||
var _getIterator2 = __webpack_require__(3); | ||
var _getIterator = _interopRequireDefault(_getIterator2).default; | ||
var _asyncToGenerator2 = __webpack_require__(1); | ||
var _asyncToGenerator2 = __webpack_require__(4); | ||
var _asyncToGenerator = _interopRequireDefault(_asyncToGenerator2).default; | ||
var _ObjectDBProxy = __webpack_require__(5); | ||
var _ObjectDBProxy = __webpack_require__(9); | ||
@@ -297,36 +477,89 @@ var ObjectDBProxy = _interopRequireDefault(_ObjectDBProxy).default; | ||
*/ | ||
const ObjectDBProxyPromise = (() => { | ||
var _ref = _asyncToGenerator(function* (namespace, storage) { | ||
// Fetch properties field before hand | ||
const odbFieldsID = `${namespace}.o`; | ||
const odbFields = yield storage._fetch(odbFieldsID); | ||
const odbProxy = ObjectDBProxy(namespace, storage); | ||
var ObjectDBProxyPromise = function () { | ||
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(namespace, storage) { | ||
var odbFieldsID, odbFields, odbProxy, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, propertyID; | ||
if (odbFields !== undefined) { | ||
var _iteratorNormalCompletion = true; | ||
var _didIteratorError = false; | ||
var _iteratorError = undefined; | ||
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); | ||
try { | ||
for (var _iterator = _getIterator(odbFields), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { | ||
const propertyID = _step.value; | ||
case 3: | ||
odbFields = _context.sent; | ||
odbProxy = ObjectDBProxy(namespace, storage); | ||
yield fetchProperty(odbProxy.__self, propertyID); | ||
} | ||
} catch (err) { | ||
_didIteratorError = true; | ||
_iteratorError = err; | ||
} finally { | ||
try { | ||
if (!_iteratorNormalCompletion && _iterator.return) { | ||
_iterator.return(); | ||
} | ||
} finally { | ||
if (_didIteratorError) { | ||
if (!(odbFields !== undefined)) { | ||
_context.next = 32; | ||
break; | ||
} | ||
_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(); | ||
} | ||
} | ||
}return odbProxy; | ||
}); | ||
}, _callee, undefined, [[9, 20, 24, 32], [25,, 27, 31]]); | ||
})); | ||
@@ -336,3 +569,3 @@ return function ObjectDBProxyPromise(_x, _x2) { | ||
}; | ||
})(); | ||
}(); | ||
@@ -346,26 +579,69 @@ /** Loads a property to the in-memory storage | ||
*/ | ||
const fetchProperty = (() => { | ||
var _ref2 = _asyncToGenerator(function* (odb, property) { | ||
const propertyID = `${odb.namespace}.p.${property}`; | ||
const propertyFieldsID = `${propertyID}.o`; | ||
// If _get returns, means it's already in-memory #references | ||
let propertyFields = odb.storage._get(propertyFieldsID); | ||
let propertyValue = odb.storage._get(propertyID); | ||
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 | ||
// If was never registered before, fetch from database | ||
if (propertyFields === undefined && propertyValue === undefined) { | ||
propertyFields = yield odb.storage._fetch(propertyFieldsID); | ||
propertyValue = yield odb.storage._fetch(propertyID); | ||
propertyFields = odb.storage._get(propertyFieldsID); | ||
propertyValue = odb.storage._get(propertyID); | ||
// If it's an object, it has propertyFields, load ObjectDB #recusion | ||
if (propertyFields !== undefined) return yield ObjectDBProxyPromise(propertyID, odb.storage); | ||
// Maybe it's a reference, load ObjectDB of the reference | ||
if (typeof propertyValue === 'object') return yield ObjectDBProxyPromise(propertyValue.ref, odb.storage); | ||
} // Otherwise, do nothing, will prevent circular refs from reload | ||
}); | ||
// 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); | ||
}; | ||
})(); | ||
}(); | ||
@@ -375,3 +651,3 @@ exports.default = ObjectDBProxyPromise; | ||
/***/ }), | ||
/* 5 */ | ||
/* 9 */ | ||
/***/ (function(module, exports, __webpack_require__) { | ||
@@ -386,8 +662,12 @@ | ||
var _getIterator2 = __webpack_require__(0); | ||
var _getIterator2 = __webpack_require__(3); | ||
var _getIterator = _interopRequireDefault(_getIterator2).default; | ||
var _ObjectDB = __webpack_require__(6); | ||
var _typeof2 = __webpack_require__(1); | ||
var _typeof = _interopRequireDefault(_typeof2).default; | ||
var _ObjectDB = __webpack_require__(10); | ||
var ObjectDB = _interopRequireDefault(_ObjectDB).default; | ||
@@ -404,8 +684,8 @@ | ||
*/ | ||
const ObjectDBProxy = (namespace, storage) => { | ||
const odb = new ObjectDB(namespace, storage); | ||
var ObjectDBProxy = function ObjectDBProxy(namespace, storage) { | ||
var odb = new ObjectDB(namespace, storage); | ||
// Get holder for property names #.o | ||
const odbFieldsID = `${odb.namespace}.o`; | ||
const odbFields = odb.storage._get(odbFieldsID); | ||
var odbFieldsID = odb.namespace + '.o'; | ||
var odbFields = odb.storage._get(odbFieldsID); | ||
@@ -417,10 +697,26 @@ // Define odb nsp as Object | ||
return new Proxy(odb, { | ||
defineProperty: (odb, property, value) => proxySet(odb, property, value), | ||
set: (odb, property, value) => proxySet(odb, property, value), | ||
get: (odb, property) => proxyGet(odb, property), | ||
deleteProperty: (odb, property) => proxyDeleteProperty(odb, property), | ||
enumerate: odb => proxyOwnKeys(odb), | ||
ownKeys: odb => proxyOwnKeys(odb), | ||
has: (odb, property) => proxyHas(odb, property), | ||
getOwnPropertyDescriptor: (odb, property) => proxyGetOwnPropertyDescriptor(odb, property) | ||
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); | ||
} | ||
}); | ||
@@ -436,3 +732,3 @@ }; | ||
*/ | ||
const proxySet = (odb, property, value) => { | ||
var proxySet = function proxySet(odb, property, value) { | ||
// Decline on ObjectDB methods | ||
@@ -455,12 +751,14 @@ if (property === 'then') return false; | ||
*/ | ||
const proxyGet = (odb, property) => { | ||
var proxyGet = function proxyGet(odb, property) { | ||
if (property === 'then') return; // https://stackoverflow.com/questions/48318843 | ||
if (property === 'clear') return () => clear(odb); | ||
if (property === 'clear') return function () { | ||
return clear(odb); | ||
}; | ||
if (property === '__self') return odb; // Useful to reach ObjectDB from the Proxy | ||
//Property | ||
const propertyID = `${odb.namespace}.p.${property}`; | ||
const propertyFieldsID = `${propertyID}.o`; | ||
const propertyFields = odb.storage._get(propertyFieldsID); | ||
const propertyValue = odb.storage._get(propertyID); | ||
var propertyID = odb.namespace + '.p.' + property; | ||
var propertyFieldsID = propertyID + '.o'; | ||
var propertyFields = odb.storage._get(propertyFieldsID); | ||
var propertyValue = odb.storage._get(propertyID); | ||
@@ -470,3 +768,3 @@ // If it's an object, load ObjectDB | ||
//Maybe it's a reference, load ObjectDB | ||
if (typeof propertyValue === 'object') return ObjectDBProxy(propertyValue.ref, odb.storage); | ||
if ((typeof propertyValue === 'undefined' ? 'undefined' : _typeof(propertyValue)) === 'object') return ObjectDBProxy(propertyValue.ref, odb.storage); | ||
//Then it's a Primitive value | ||
@@ -482,3 +780,3 @@ return propertyValue; | ||
*/ | ||
const proxyDeleteProperty = (odb, property) => { | ||
var proxyDeleteProperty = function proxyDeleteProperty(odb, property) { | ||
// Decline on ObjectDB methods | ||
@@ -499,15 +797,15 @@ if (property === 'clear') return false; | ||
*/ | ||
const eraseProperty = (odb, property) => { | ||
var eraseProperty = function eraseProperty(odb, property) { | ||
//Parent reference holder for properties | ||
const odbFieldsID = `${odb.namespace}.o`; | ||
const odbFields = odb.storage._get(odbFieldsID); | ||
var odbFieldsID = odb.namespace + '.o'; | ||
var odbFields = odb.storage._get(odbFieldsID); | ||
//Property | ||
const oldPropertyID = `${odb.namespace}.p.${property}`; | ||
const oldPropertyFieldsID = `${oldPropertyID}.o`; | ||
const oldPropertyFields = odb.storage._get(oldPropertyFieldsID); | ||
var oldPropertyID = odb.namespace + '.p.' + property; | ||
var oldPropertyFieldsID = oldPropertyID + '.o'; | ||
var oldPropertyFields = odb.storage._get(oldPropertyFieldsID); | ||
// If it's an object | ||
if (oldPropertyFields) { | ||
const p = ObjectDBProxy(oldPropertyID, odb.storage); | ||
var p = ObjectDBProxy(oldPropertyID, odb.storage); | ||
//Erase everything, erase all the fields | ||
@@ -520,3 +818,3 @@ var _iteratorNormalCompletion = true; | ||
for (var _iterator = _getIterator(oldPropertyFields), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { | ||
const removePropertyID = _step.value; | ||
var removePropertyID = _step.value; | ||
@@ -545,3 +843,5 @@ p[removePropertyID] = undefined; | ||
//Remove property from odbFields | ||
const updatedFields = odbFields ? odbFields.filter(e => e !== property) : []; | ||
var updatedFields = odbFields ? odbFields.filter(function (e) { | ||
return e !== property; | ||
}) : []; | ||
@@ -558,3 +858,3 @@ //Update | ||
*/ | ||
const saveProperty = (odb, property, value) => { | ||
var saveProperty = function saveProperty(odb, property, value) { | ||
//Make room for new value | ||
@@ -564,6 +864,6 @@ eraseProperty(odb, property); | ||
//Parent reference holder for properties | ||
const odbFieldsID = `${odb.namespace}.o`; | ||
const odbFields = odb.storage._get(odbFieldsID); | ||
var odbFieldsID = odb.namespace + '.o'; | ||
var odbFields = odb.storage._get(odbFieldsID); | ||
//Property id that is going to be saved | ||
const newPropertyID = `${odb.namespace}.p.${property}`; | ||
var newPropertyID = odb.namespace + '.p.' + property; | ||
@@ -575,6 +875,8 @@ // If ObjectDB -> save reference | ||
} // If object -> save as ObjectDB #recursion | ||
else if (typeof value === 'object') { | ||
const p = ObjectDBProxy(newPropertyID, odb.storage); | ||
else if ((typeof value === 'undefined' ? 'undefined' : _typeof(value)) === 'object') { | ||
var p = ObjectDBProxy(newPropertyID, odb.storage); | ||
// Calls saveProperty on all the props | ||
for (const copyPropertyID in value) if (value.hasOwnProperty(copyPropertyID)) p[copyPropertyID] = value[copyPropertyID]; | ||
for (var copyPropertyID in value) { | ||
if (value.hasOwnProperty(copyPropertyID)) p[copyPropertyID] = value[copyPropertyID]; | ||
} | ||
} //Then it's Primitive value, save it | ||
@@ -584,3 +886,3 @@ else odb.storage._set(newPropertyID, value); | ||
// Register new property, update fields | ||
const updatedFields = odbFields ? odbFields : []; | ||
var updatedFields = odbFields ? odbFields : []; | ||
updatedFields.push(property); | ||
@@ -594,5 +896,5 @@ odb.storage._set(odbFieldsID, updatedFields); | ||
*/ | ||
const clear = odb => { | ||
const odbFieldsID = `${odb.namespace}.o`; | ||
const odbFields = odb.storage._get(odbFieldsID); | ||
var clear = function clear(odb) { | ||
var odbFieldsID = odb.namespace + '.o'; | ||
var odbFields = odb.storage._get(odbFieldsID); | ||
@@ -605,3 +907,3 @@ var _iteratorNormalCompletion2 = true; | ||
for (var _iterator2 = _getIterator(odbFields), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) { | ||
const odbField = _step2.value; | ||
var odbField = _step2.value; | ||
@@ -631,5 +933,5 @@ eraseProperty(odb, odbField); | ||
*/ | ||
const proxyHas = (odb, property) => { | ||
const odbFieldsID = `${odb.namespace}.o`; | ||
const odbFields = odb.storage._get(odbFieldsID); | ||
var proxyHas = function proxyHas(odb, property) { | ||
var odbFieldsID = odb.namespace + '.o'; | ||
var odbFields = odb.storage._get(odbFieldsID); | ||
@@ -643,5 +945,5 @@ return odbFields.includes(property); | ||
*/ | ||
const proxyOwnKeys = odb => { | ||
const odbFieldsID = `${odb.namespace}.o`; | ||
const odbFields = odb.storage._get(odbFieldsID); | ||
var proxyOwnKeys = function proxyOwnKeys(odb) { | ||
var odbFieldsID = odb.namespace + '.o'; | ||
var odbFields = odb.storage._get(odbFieldsID); | ||
@@ -657,4 +959,4 @@ return odbFields; | ||
*/ | ||
const proxyGetOwnPropertyDescriptor = (odb, property) => { | ||
const value = proxyGet(odb, property); | ||
var proxyGetOwnPropertyDescriptor = function proxyGetOwnPropertyDescriptor(odb, property) { | ||
var value = proxyGet(odb, property); | ||
@@ -672,3 +974,3 @@ return value ? { | ||
/***/ }), | ||
/* 6 */ | ||
/* 10 */ | ||
/***/ (function(module, exports, __webpack_require__) { | ||
@@ -682,2 +984,9 @@ | ||
}); | ||
var _classCallCheck2 = __webpack_require__(0); | ||
var _classCallCheck = _interopRequireDefault(_classCallCheck2).default; | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
/** ObjectDB Unit (Proxy) | ||
@@ -704,18 +1013,19 @@ * | ||
*/ | ||
class ObjectDB { | ||
/** ObjectDB | ||
* | ||
* @param namespace: ID for storage | ||
* @param storage: Storage instance | ||
*/ | ||
constructor(namespace, storage) { | ||
this.storage = storage; | ||
this.namespace = namespace; //Identity | ||
} | ||
} | ||
var ObjectDB = | ||
/** ObjectDB | ||
* | ||
* @param namespace: ID for storage | ||
* @param storage: Storage instance | ||
*/ | ||
function ObjectDB(namespace, storage) { | ||
_classCallCheck(this, ObjectDB); | ||
this.storage = storage; | ||
this.namespace = namespace; //Identity | ||
}; | ||
exports.default = ObjectDB; | ||
/***/ }), | ||
/* 7 */ | ||
/* 11 */ | ||
/***/ (function(module, exports, __webpack_require__) { | ||
@@ -730,13 +1040,33 @@ | ||
var _stringify = __webpack_require__(8); | ||
var _stringify = __webpack_require__(12); | ||
var _JSON$stringify = _interopRequireDefault(_stringify).default; | ||
var _nodeLocalstorage = __webpack_require__(9); | ||
var _getPrototypeOf = __webpack_require__(13); | ||
var _Object$getPrototypeOf = _interopRequireDefault(_getPrototypeOf).default; | ||
var _classCallCheck2 = __webpack_require__(0); | ||
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 LocalStorage = _interopRequireDefault(_nodeLocalstorage).default; | ||
var _Storage = __webpack_require__(2); | ||
var _Storage2 = __webpack_require__(5); | ||
var Storage = _interopRequireDefault(_Storage).default; | ||
var Storage = _interopRequireDefault(_Storage2).default; | ||
@@ -747,3 +1077,5 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
*/ | ||
class Default extends Storage { | ||
var Default = function (_Storage) { | ||
_inherits(Default, _Storage); | ||
/** Tries to get a storage to work | ||
@@ -757,32 +1089,46 @@ * If @storageName param is left by default, it will try to access the localStorage of the browser. | ||
*/ | ||
constructor(storageName = 'localStorage', storageQuota = 5) { | ||
super(); | ||
this.name = storageName; | ||
this.quota = storageQuota; | ||
function Default() { | ||
var storageName = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'localStorage'; | ||
var storageQuota = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 5; | ||
_classCallCheck(this, Default); | ||
var _this = _possibleConstructorReturn(this, (Default.__proto__ || _Object$getPrototypeOf(Default)).call(this)); | ||
_this.name = storageName; | ||
_this.quota = storageQuota; | ||
//Surrogate storage | ||
if (storageName !== 'localStorage' || typeof localStorage === 'undefined' || localStorage === null) this.surrogate = new LocalStorage.LocalStorage(storageName, storageQuota * 1024 * 1024);else this.surrogate = localStorage; | ||
if (storageName !== 'localStorage' || typeof localStorage === 'undefined' || localStorage === null) _this.surrogate = new LocalStorage.LocalStorage(storageName, storageQuota * 1024 * 1024);else _this.surrogate = localStorage; | ||
return _this; | ||
} | ||
get(key) { | ||
const val = this.surrogate.getItem(key); | ||
_createClass(Default, [{ | ||
key: 'get', | ||
value: function get(key) { | ||
var val = this.surrogate.getItem(key); | ||
return val === null ? undefined : JSON.parse(val); | ||
} | ||
return val === null ? undefined : JSON.parse(val); | ||
} | ||
}, { | ||
key: 'set', | ||
value: function set(key, value) { | ||
value = _JSON$stringify(value); | ||
set(key, value) { | ||
value = _JSON$stringify(value); | ||
this.surrogate.setItem(key, value); | ||
} | ||
}, { | ||
key: 'del', | ||
value: function del(key) { | ||
this.surrogate.removeItem(key); | ||
} | ||
}]); | ||
this.surrogate.setItem(key, value); | ||
} | ||
return Default; | ||
}(Storage); | ||
del(key) { | ||
this.surrogate.removeItem(key); | ||
} | ||
} | ||
exports.default = Default; | ||
/***/ }), | ||
/* 8 */ | ||
/* 12 */ | ||
/***/ (function(module, exports) { | ||
@@ -793,5 +1139,23 @@ | ||
/***/ }), | ||
/* 9 */ | ||
/* 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"); | ||
@@ -798,0 +1162,0 @@ |
{ | ||
"name": "object.database", | ||
"version": "1.1.8", | ||
"version": "1.1.9", | ||
"description": "object.database", | ||
@@ -5,0 +5,0 @@ "main": "lib/object.database.node.js", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
130300
1357