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.1.12 to 1.3.3

388

lib/object.database.node.js

@@ -80,3 +80,3 @@ (function webpackUniversalModuleDefinition(root, factory) {

module.exports = require("babel-runtime/helpers/classCallCheck");
module.exports = require("babel-runtime/regenerator");

@@ -87,3 +87,3 @@ /***/ }),

module.exports = require("babel-runtime/helpers/typeof");
module.exports = require("babel-runtime/helpers/asyncToGenerator");

@@ -94,3 +94,3 @@ /***/ }),

module.exports = require("babel-runtime/regenerator");
module.exports = require("babel-runtime/helpers/classCallCheck");

@@ -101,3 +101,3 @@ /***/ }),

module.exports = require("babel-runtime/core-js/get-iterator");
module.exports = require("babel-runtime/helpers/typeof");

@@ -108,3 +108,3 @@ /***/ }),

module.exports = require("babel-runtime/helpers/asyncToGenerator");
module.exports = require("babel-runtime/core-js/get-iterator");

@@ -122,11 +122,15 @@ /***/ }),

var _regenerator = __webpack_require__(2);
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__(4);
var _asyncToGenerator2 = __webpack_require__(1);
var _asyncToGenerator = _interopRequireDefault(_asyncToGenerator2).default;
var _classCallCheck2 = __webpack_require__(0);
var _classCallCheck2 = __webpack_require__(2);

@@ -141,4 +145,4 @@ var _classCallCheck = _interopRequireDefault(_classCallCheck2).default;

/** Implementing the following methods enables to connect any DBMS to a ObjectDB
* The default behaviour for a ObjectDB object is to save itself in files.
/** Storage
* Storage is the link between a Database & ObjectDB
*/

@@ -154,5 +158,5 @@ var Storage = function () {

/** To be implemented
* Retrieve value from key in db
* Retrieve value from @key in db
*
* @param key: Key of the value
* @param key
* @returns {Promise.<value>}

@@ -163,3 +167,3 @@ */

_createClass(Storage, [{
key: "get",
key: 'get',
value: function () {

@@ -171,3 +175,3 @@ var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(key) {

case 0:
case "end":
case 'end':
return _context.stop();

@@ -186,10 +190,10 @@ }

}, {
key: "set",
key: 'set',
/** To be implemented
* Save value 'in' key in db
* Save @value for @key in db
*
* @param key: Key of the value
* @param value: Value to save
* @param key
* @param value
* @returns {Promise.<void>}

@@ -203,3 +207,3 @@ */

case 0:
case "end":
case 'end':
return _context2.stop();

@@ -218,9 +222,9 @@ }

}, {
key: "del",
key: 'del',
/** To be implemented
* Delete value of key in db
* Delete value for @key in db
*
* @param key: Key of the value
* @param key
* @returns {Promise.<void>}

@@ -234,3 +238,3 @@ */

case 0:
case "end":
case 'end':
return _context3.stop();

@@ -249,7 +253,8 @@ }

}, {
key: "_fetch",
key: '_fetch',
/** Gets the value for @key in distant storage
/** Gets the value for @key in database
* If @key is unknown, saves it in @memory
*
* @param key

@@ -277,14 +282,22 @@ * @returns {Promise.<*>}

return _context4.abrupt("return");
return _context4.abrupt('return');
case 5:
if (!(typeof value !== 'string')) {
_context4.next = 7;
break;
}
// Save to in-memory storage
this.memory[key] = value;
return _context4.abrupt('return');
//And return the value
return _context4.abrupt("return", this._get(key));
case 7:
case 7:
case "end":
// 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();

@@ -309,3 +322,3 @@ }

}, {
key: "_get",
key: '_get',
value: function _get(key) {

@@ -315,3 +328,3 @@ return this.memory[key];

/** Set @value for @key in database
/** Set key-value in database
* @param key

@@ -323,7 +336,7 @@ * @param value

}, {
key: "_set",
key: '_set',
value: function _set(key, value) {
var _this = this;
// Save to old value for rollback
// Save old value for rollback
var oldValue = this.memory[key];

@@ -341,28 +354,32 @@

_context5.prev = 0;
_context5.next = 3;
// Make value JSON compatible
value = _JSON$stringify(value);
// Then save to database
_context5.next = 4;
return _this.set(key, value);
case 3:
_context5.next = 9;
case 4:
_context5.next = 10;
break;
case 5:
_context5.prev = 5;
_context5.t0 = _context5["catch"](0);
case 6:
_context5.prev = 6;
_context5.t0 = _context5['catch'](0);
// Fail, rollback
_this.memory[key] = oldValue;
console.log(_context5.t0);
case 9:
case "end":
console.error(_context5.t0);
case 10:
case 'end':
return _context5.stop();
}
}
}, _callee5, _this, [[0, 5]]);
}, _callee5, _this, [[0, 6]]);
}))();
return true;
}
/** Removes in database
/** Removes key-value in database
* @param key

@@ -373,7 +390,7 @@ * @returns {boolean}

}, {
key: "_del",
key: '_del',
value: function _del(key) {
var _this2 = this;
// Save to old value for rollback
// Save old value for rollback
var oldValue = this.memory[key];

@@ -400,9 +417,10 @@

_context6.prev = 5;
_context6.t0 = _context6["catch"](0);
_context6.t0 = _context6['catch'](0);
// Fail, rollback
_this2.memory[key] = oldValue;
console.log(_context6.t0);
console.error(_context6.t0);
case 9:
case "end":
case 'end':
return _context6.stop();

@@ -441,3 +459,3 @@ }

var Storage = __webpack_require__(5).default;
var LocalStorage = __webpack_require__(11).default;
var LocalStorage = __webpack_require__(12).default;

@@ -461,15 +479,15 @@ module.exports = {

var _typeof2 = __webpack_require__(1);
var _typeof2 = __webpack_require__(3);
var _typeof = _interopRequireDefault(_typeof2).default;
var _regenerator = __webpack_require__(2);
var _regenerator = __webpack_require__(0);
var _regeneratorRuntime = _interopRequireDefault(_regenerator).default;
var _getIterator2 = __webpack_require__(3);
var _getIterator2 = __webpack_require__(4);
var _getIterator = _interopRequireDefault(_getIterator2).default;
var _asyncToGenerator2 = __webpack_require__(4);
var _asyncToGenerator2 = __webpack_require__(1);

@@ -484,7 +502,7 @@ var _asyncToGenerator = _interopRequireDefault(_asyncToGenerator2).default;

/** Loads a namespace in the storage
/** 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 @namespace. These values are to be loaded before using an ObjectDB.
* of any variable that was set inside a ObjectDB. These values are to be loaded before using an ObjectDB.
*
* @param namespace: Index to operate
* @param namespace: Entry index to read/write
* @param storage: Storage instance

@@ -516,2 +534,3 @@ * @returns {Promise.<Proxy>}: Promise of loading the ObjectDB

// Iterate
_iteratorNormalCompletion = true;

@@ -589,7 +608,7 @@ _didIteratorError = false;

/** Loads a property to the in-memory storage
* (for non-blocking access)
* (for non-blocking i/o & fast variable access)
*
* @param odb: ObjectDB instance
* @param property: Property name
* @returns {Promise.<*>}
* @returns {Promise.<*>}: Promise of value
*/

@@ -677,7 +696,7 @@ var fetchProperty = function () {

var _getIterator2 = __webpack_require__(3);
var _getIterator2 = __webpack_require__(4);
var _getIterator = _interopRequireDefault(_getIterator2).default;
var _typeof2 = __webpack_require__(1);
var _typeof2 = __webpack_require__(3);

@@ -692,8 +711,17 @@ var _typeof = _interopRequireDefault(_typeof2).default;

/** Creates a new Persistence Unit
/** Creates a new Proxied ObjectDB
* Uses a Proxy to trap changes on itself
*
* @param namespace: Tree index to read/write
* @param storage: StorageAdapter instance
* @returns {Proxy} Proxy of the Persistence
* --- 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
*/

@@ -709,2 +737,3 @@ var ObjectDBProxy = function ObjectDBProxy(namespace, storage) {

if (odbFields === undefined) odb.storage._set(odbFieldsID, []);
// Means an object === array in db

@@ -753,3 +782,3 @@ // Listens for any modification

if (value === undefined) eraseProperty(odb, property);else saveProperty(odb, property, value);
if (value === undefined || value === null) eraseProperty(odb, property);else saveProperty(odb, property, value);

@@ -773,7 +802,7 @@ return true;

//Property
// Retrieve property from odb
var propertyID = odb.namespace + '.p.' + property;
var propertyFieldsID = propertyID + '.o';
var propertyFields = odb.storage._get(propertyFieldsID);
var propertyValue = odb.storage._get(propertyID);
var propertyFieldsID = propertyID + '.o'; // If Object
var propertyFields = odb.storage._get(propertyFieldsID); // !=null ==> object
var propertyValue = odb.storage._get(propertyID); // !=null ==> property

@@ -811,15 +840,16 @@ // If it's an object, load ObjectDB

var eraseProperty = function eraseProperty(odb, property) {
//Parent reference holder for properties
// Parent reference holder of properties
var odbFieldsID = odb.namespace + '.o';
var odbFields = odb.storage._get(odbFieldsID);
var updatedFields = odbFields ? odbFields : [];
//Property
// Property that is going to be removed
var oldPropertyID = odb.namespace + '.p.' + property;
var oldPropertyFieldsID = oldPropertyID + '.o';
var oldPropertyFieldsID = oldPropertyID + '.o'; // If object
var oldPropertyFields = odb.storage._get(oldPropertyFieldsID);
// If it's an object
if (oldPropertyFields) {
// If it's an Object
var p = ObjectDBProxy(oldPropertyID, odb.storage);
//Erase everything, erase all the fields
// Erase everything, erase all the fields
var _iteratorNormalCompletion = true;

@@ -834,3 +864,3 @@ var _didIteratorError = false;

p[removePropertyID] = undefined;
} //Remove the field index as well
} // Remove the field index as well
} catch (err) {

@@ -852,15 +882,13 @@ _didIteratorError = true;

odb.storage._del(oldPropertyFieldsID);
} //If it's a primitive / reference
} // If it's a primitive / reference
else odb.storage._del(oldPropertyID);
//Remove property from odbFields
var updatedFields = odbFields ? odbFields.filter(function (e) {
// Remove property from odbFields & update
updatedFields = updatedFields.filter(function (e) {
return e !== property;
}) : [];
//Update
});
odb.storage._set(odbFieldsID, updatedFields);
};
/** Saves @property to the storage
/** Saves @property to the Storage
*

@@ -872,15 +900,20 @@ * @param odb: ObjectDB parent of the property

var saveProperty = function saveProperty(odb, property, value) {
//Make room for new value
// Make room for new value
eraseProperty(odb, property);
//Parent reference holder for properties
// Parent reference holder of properties
var odbFieldsID = odb.namespace + '.o';
var odbFields = odb.storage._get(odbFieldsID);
//Property id that is going to be saved
var updatedFields = odbFields ? odbFields : [];
// Property that is going to be saved with @value
var newPropertyID = odb.namespace + '.p.' + property;
// If ObjectDB -> save reference
if (value instanceof ObjectDB) {
//todo check database #storage
odb.storage._set(newPropertyID, { ref: value.__self.namespace });
// 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

@@ -893,7 +926,6 @@ else if ((typeof value === 'undefined' ? 'undefined' : _typeof(value)) === 'object') {

}
} //Then it's Primitive value, save it
} // Then it's a Primitive value, save it
else odb.storage._set(newPropertyID, value);
// Register new property, update fields
var updatedFields = odbFields ? odbFields : [];
// Register new property / update
updatedFields.push(property);

@@ -990,3 +1022,3 @@ odb.storage._set(odbFieldsID, updatedFields);

var _classCallCheck2 = __webpack_require__(0);
var _classCallCheck2 = __webpack_require__(2);

@@ -997,27 +1029,8 @@ var _classCallCheck = _interopRequireDefault(_classCallCheck2).default;

/** ObjectDB Unit (Proxy)
*
* Shortly:
*
* --- example ---
* let test = ObjectDB('namespace1');
*
* test.var1 = "var1";
* test.var2 = "test2"
*
* test.obj = {
* nest: {
* val: 'toto';
* }
* }
* --------------
*
* Running the example will save to storage.
*
* It behaves like a JS object, so it's usage is seamless.
/** ObjectDB
* Base structure of Object-Database
*/
var ObjectDB =
/** ObjectDB
*
* @param namespace: ID for storage
/**
* @param namespace: Entry index to read/write
* @param storage: Storage instance

@@ -1036,2 +1049,8 @@ */

/* 11 */
/***/ (function(module, exports) {
module.exports = require("babel-runtime/core-js/json/stringify");
/***/ }),
/* 12 */
/***/ (function(module, exports, __webpack_require__) {

@@ -1046,6 +1065,10 @@

var _stringify = __webpack_require__(12);
var _regenerator = __webpack_require__(0);
var _JSON$stringify = _interopRequireDefault(_stringify).default;
var _regeneratorRuntime = _interopRequireDefault(_regenerator).default;
var _asyncToGenerator2 = __webpack_require__(1);
var _asyncToGenerator = _interopRequireDefault(_asyncToGenerator2).default;
var _getPrototypeOf = __webpack_require__(13);

@@ -1055,3 +1078,3 @@

var _classCallCheck2 = __webpack_require__(0);
var _classCallCheck2 = __webpack_require__(2);

@@ -1074,3 +1097,3 @@ var _classCallCheck = _interopRequireDefault(_classCallCheck2).default;

var LocalStorage = _interopRequireDefault(_nodeLocalstorage).default;
var NodeLocalStorage = _interopRequireDefault(_nodeLocalstorage).default;

@@ -1083,64 +1106,105 @@ var _Storage2 = __webpack_require__(5);

/** Storage that makes ObjectDB to work with files
/** LocalStorage
* Storage that makes ObjectDB to work with files
*/
var Default = function (_Storage) {
_inherits(Default, _Storage);
var LocalStorage = function (_Storage) {
_inherits(LocalStorage, _Storage);
/** Tries to get a storage to work
* If @storageName param is left by default, it will try to access the localStorage of the browser.
* If it's not being run in a browser, it will create a folder 'localStorage'.
* If @storageName param not default it will automatically try to create a new folder with this name.
*
/**
* @param storageName: Name of the storage to use
* @param storageQuota: Limit of data it can carry
* @param storageQuota: Limit of data it can carry (MBytes)
*/
function Default() {
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, Default);
_classCallCheck(this, LocalStorage);
var _this = _possibleConstructorReturn(this, (Default.__proto__ || _Object$getPrototypeOf(Default)).call(this));
// Surrogate storage that we create, basically chooses between browser or own localStorage
var _this = _possibleConstructorReturn(this, (LocalStorage.__proto__ || _Object$getPrototypeOf(LocalStorage)).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 NodeLocalStorage.LocalStorage(storageName, storageQuota * 1024 * 1024);else _this.surrogate = localStorage; // Use localStorage provided by the browser
return _this;
}
_createClass(Default, [{
_createClass(LocalStorage, [{
key: 'get',
value: function get(key) {
var val = this.surrogate.getItem(key);
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));
return val === null ? undefined : JSON.parse(val);
}
case 1:
case 'end':
return _context.stop();
}
}
}, _callee, this);
}));
function get(_x3) {
return _ref.apply(this, arguments);
}
return get;
}()
}, {
key: 'set',
value: function set(key, value) {
value = _JSON$stringify(value);
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);
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 del(key) {
this.surrogate.removeItem(key);
}
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 Default;
return LocalStorage;
}(Storage);
exports.default = Default;
exports.default = LocalStorage;
/***/ }),
/* 12 */
/***/ (function(module, exports) {
module.exports = require("babel-runtime/core-js/json/stringify");
/***/ }),
/* 13 */

@@ -1147,0 +1211,0 @@ /***/ (function(module, exports) {

{
"name": "object.database",
"version": "1.1.12",
"version": "1.3.3",
"description": "object.database",

@@ -5,0 +5,0 @@ "main": "lib/object.database.node.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