Socket
Socket
Sign inDemoInstall

arpeggio

Package Overview
Dependencies
8
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.0.1 to 0.0.2

lib/adapter.js

25

lib/arpeggio.js
'use strict';
var _connection = require('./connection');
var _adapter = require('./adapter');
var connection = _interopRequireWildcard(_connection);
var adapter = _interopRequireWildcard(_adapter);
var _designer = require('./designer');
var designer = _interopRequireWildcard(_designer);
var _SingleModel = require('./baseModels/SingleModel');
var _EdgeModel = require('./baseModels/EdgeModel');
var _CollectionModel = require('./baseModels/CollectionModel');

@@ -19,4 +13,11 @@

function init(config) {
return connection.configure(config);
var assert = require('assert');
var config;
function init(_config) {
assert(_config.adapter, 'Arpeggio: .adapter must be set');
config = _config;
return adapter.init(_config.adapter);
}

@@ -26,7 +27,5 @@

init: init,
design: designer.design,
getConnection: connection.getConnection,
config: config,
SingleModel: _SingleModel.SingleModel,
EdgeModel: _EdgeModel.EdgeModel,
CollectionModel: _CollectionModel.CollectionModel
};

@@ -10,9 +10,9 @@ 'use strict';

var _connection = require('../connection');
var _adapter = require('../adapter');
var connection = _interopRequireWildcard(_connection);
var adapter = _interopRequireWildcard(_adapter);
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }
function _asyncToGenerator(fn) { return function () { var gen = fn.apply(this, arguments); return new Promise(function (resolve, reject) { function step(key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { return Promise.resolve(value).then(function (value) { return step("next", value); }, function (err) { return step("throw", err); }); } } return step("next"); }); }; }
function _asyncToGenerator(fn) { return function () { var gen = fn.apply(this, arguments); return new Promise(function (resolve, reject) { function step(key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { return Promise.resolve(value).then(function (value) { step("next", value); }, function (err) { step("throw", err); }); } } return step("next"); }); }; }

@@ -33,5 +33,4 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

this.baseModel = baseModel;
this.table = new baseModel().table;
this.rawQuery = new baseModel().rawQuery;
this.connection = connection.getConnection();
this.type = new baseModel().type;
this.adapter = adapter.getAdapter();
}

@@ -42,7 +41,11 @@

value: function () {
var _ref = _asyncToGenerator(regeneratorRuntime.mark(function _callee(aql, params) {
var _ref = _asyncToGenerator(regeneratorRuntime.mark(function _callee() {
var _this = this;
var options = arguments.length <= 2 || arguments[2] === undefined ? {} : arguments[2];
var localParams, localOptions, result, cursor;
var _len,
args,
_key,
result,
_args = arguments;
return regeneratorRuntime.wrap(function _callee$(_context) {

@@ -52,29 +55,44 @@ while (1) {

case 0:
localParams = Object.assign({}, params);
localOptions = Object.assign({
appendTableParam: true
}, options);
result = void 0;
cursor = void 0;
_context.prev = 0;
for (_len = _args.length, args = Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = _args[_key];
}
if (localOptions.appendTableParam !== false) {
localParams['@table'] = this.table;
_context.next = 4;
return this.adapter.query(args);
case 4:
result = _context.sent;
if (!result) {
_context.next = 10;
break;
}
_context.next = 7;
return this.connection.database.query(aql, localParams);
case 7:
cursor = _context.sent;
return _context.abrupt('return', cursor.all().then(function (result) {
result.forEach(function (modelData) {
var model = new _this.baseModel();
this.cursor = result.cursor;
model.ingest(modelData);
_this.models.push(model);
});
return _this;
}));
if (!(result.results.length > 0)) {
_context.next = 10;
break;
}
case 9:
result.results.forEach(function (modelData) {
var model = new _this.baseModel();
model.ingest(modelData.data);
model.key = modelData.key;
_this.models.push(model);
});
return _context.abrupt('return', this);
case 10:
return _context.abrupt('return', false);
case 13:
_context.prev = 13;
_context.t0 = _context['catch'](0);
throw Boom.wrap(_context.t0);
case 16:
case 'end':

@@ -84,6 +102,6 @@ return _context.stop();

}
}, _callee, this);
}, _callee, this, [[0, 13]]);
}));
function query(_x, _x2, _x3) {
function query(_x) {
return _ref.apply(this, arguments);

@@ -95,7 +113,5 @@ }

}, {
key: 'save',
key: 'buildQuery',
value: function () {
var _ref2 = _asyncToGenerator(regeneratorRuntime.mark(function _callee2() {
var _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, model;
return regeneratorRuntime.wrap(function _callee2$(_context2) {

@@ -105,6 +121,32 @@ while (1) {

case 0:
return _context2.abrupt('return', this.adapter.buildQuery(this.type));
case 1:
case 'end':
return _context2.stop();
}
}
}, _callee2, this);
}));
function buildQuery() {
return _ref2.apply(this, arguments);
}
return buildQuery;
}()
}, {
key: 'save',
value: function () {
var _ref3 = _asyncToGenerator(regeneratorRuntime.mark(function _callee3() {
var _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, model;
return regeneratorRuntime.wrap(function _callee3$(_context3) {
while (1) {
switch (_context3.prev = _context3.next) {
case 0:
_iteratorNormalCompletion = true;
_didIteratorError = false;
_iteratorError = undefined;
_context2.prev = 3;
_context3.prev = 3;
_iterator = this.models[Symbol.iterator]();

@@ -114,3 +156,3 @@

if (_iteratorNormalCompletion = (_step = _iterator.next()).done) {
_context2.next = 12;
_context3.next = 12;
break;

@@ -120,3 +162,3 @@ }

model = _step.value;
_context2.next = 9;
_context3.next = 9;
return model.save();

@@ -126,18 +168,18 @@

_iteratorNormalCompletion = true;
_context2.next = 5;
_context3.next = 5;
break;
case 12:
_context2.next = 18;
_context3.next = 18;
break;
case 14:
_context2.prev = 14;
_context2.t0 = _context2['catch'](3);
_context3.prev = 14;
_context3.t0 = _context3['catch'](3);
_didIteratorError = true;
_iteratorError = _context2.t0;
_iteratorError = _context3.t0;
case 18:
_context2.prev = 18;
_context2.prev = 19;
_context3.prev = 18;
_context3.prev = 19;

@@ -149,6 +191,6 @@ if (!_iteratorNormalCompletion && _iterator.return) {

case 21:
_context2.prev = 21;
_context3.prev = 21;
if (!_didIteratorError) {
_context2.next = 24;
_context3.next = 24;
break;

@@ -160,17 +202,17 @@ }

case 24:
return _context2.finish(21);
return _context3.finish(21);
case 25:
return _context2.finish(18);
return _context3.finish(18);
case 26:
case 'end':
return _context2.stop();
return _context3.stop();
}
}
}, _callee2, this, [[3, 14, 18, 26], [19,, 21, 25]]);
}, _callee3, this, [[3, 14, 18, 26], [19,, 21, 25]]);
}));
function save() {
return _ref2.apply(this, arguments);
return _ref3.apply(this, arguments);
}

@@ -183,8 +225,8 @@

value: function () {
var _ref3 = _asyncToGenerator(regeneratorRuntime.mark(function _callee3() {
var _ref4 = _asyncToGenerator(regeneratorRuntime.mark(function _callee4() {
var _iteratorNormalCompletion2, _didIteratorError2, _iteratorError2, _iterator2, _step2, model;
return regeneratorRuntime.wrap(function _callee3$(_context3) {
return regeneratorRuntime.wrap(function _callee4$(_context4) {
while (1) {
switch (_context3.prev = _context3.next) {
switch (_context4.prev = _context4.next) {
case 0:

@@ -194,3 +236,3 @@ _iteratorNormalCompletion2 = true;

_iteratorError2 = undefined;
_context3.prev = 3;
_context4.prev = 3;
_iterator2 = this.models[Symbol.iterator]();

@@ -200,3 +242,3 @@

if (_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done) {
_context3.next = 12;
_context4.next = 12;
break;

@@ -206,3 +248,3 @@ }

model = _step2.value;
_context3.next = 9;
_context4.next = 9;
return model.destroy();

@@ -212,18 +254,18 @@

_iteratorNormalCompletion2 = true;
_context3.next = 5;
_context4.next = 5;
break;
case 12:
_context3.next = 18;
_context4.next = 18;
break;
case 14:
_context3.prev = 14;
_context3.t0 = _context3['catch'](3);
_context4.prev = 14;
_context4.t0 = _context4['catch'](3);
_didIteratorError2 = true;
_iteratorError2 = _context3.t0;
_iteratorError2 = _context4.t0;
case 18:
_context3.prev = 18;
_context3.prev = 19;
_context4.prev = 18;
_context4.prev = 19;

@@ -235,6 +277,6 @@ if (!_iteratorNormalCompletion2 && _iterator2.return) {

case 21:
_context3.prev = 21;
_context4.prev = 21;
if (!_didIteratorError2) {
_context3.next = 24;
_context4.next = 24;
break;

@@ -246,17 +288,17 @@ }

case 24:
return _context3.finish(21);
return _context4.finish(21);
case 25:
return _context3.finish(18);
return _context4.finish(18);
case 26:
case 'end':
return _context3.stop();
return _context4.stop();
}
}
}, _callee3, this, [[3, 14, 18, 26], [19,, 21, 25]]);
}, _callee4, this, [[3, 14, 18, 26], [19,, 21, 25]]);
}));
function destroy() {
return _ref3.apply(this, arguments);
return _ref4.apply(this, arguments);
}

@@ -263,0 +305,0 @@

@@ -10,9 +10,9 @@ 'use strict';

var _connection = require('../connection');
var _adapter = require('../adapter');
var connection = _interopRequireWildcard(_connection);
var adapter = _interopRequireWildcard(_adapter);
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }
function _asyncToGenerator(fn) { return function () { var gen = fn.apply(this, arguments); return new Promise(function (resolve, reject) { function step(key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { return Promise.resolve(value).then(function (value) { return step("next", value); }, function (err) { return step("throw", err); }); } } return step("next"); }); }; }
function _asyncToGenerator(fn) { return function () { var gen = fn.apply(this, arguments); return new Promise(function (resolve, reject) { function step(key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { return Promise.resolve(value).then(function (value) { step("next", value); }, function (err) { step("throw", err); }); } } return step("next"); }); }; }

@@ -31,15 +31,16 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

var SingleModel = exports.SingleModel = function () {
function SingleModel(table) {
function SingleModel(type) {
_classCallCheck(this, SingleModel);
this.adapter = adapter.getAdapter();
this.type = type;
this.isNew = true;
this.timestamps = false;
this.key = false;
this.data = {};
this.events = {};
this.prevData = {};
this.table = table;
this.children = {};
this.meta = {};
this.Joi = Joi;
this.connection = connection.getConnection();
}

@@ -51,8 +52,8 @@

var _ref = _asyncToGenerator(regeneratorRuntime.mark(function _callee() {
var key,
value,
params,
var _len,
args,
_key,
result,
cursor,
_args = arguments;
return regeneratorRuntime.wrap(function _callee$(_context) {

@@ -62,50 +63,26 @@ while (1) {

case 0:
key = void 0;
value = void 0;
params = {};
_context.prev = 0;
if (_args.length == 1) {
key = '_key';
value = _args.length <= 0 ? undefined : _args[0];
} else {
key = _args.length <= 0 ? undefined : _args[0];
value = _args.length <= 1 ? undefined : _args[1];
for (_len = _args.length, args = Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = _args[_key];
}
_context.prev = 4;
result = void 0;
_context.next = 8;
return this.connection.database.query('\n FOR i IN @@table\n FILTER i.@key == @value\n RETURN i\n ', {
'@table': this.table,
key: key,
value: value
});
case 8:
cursor = _context.sent;
_context.next = 4;
return this.adapter.read(this.type, args);
if (cursor._result.length) {
_context.next = 11;
break;
}
case 4:
result = _context.sent;
throw Boom.notFound();
case 11:
_context.next = 13;
return cursor.next();
case 13:
result = _context.sent;
this.key = result.key;
this.assignData(result.data);
this.isNew = false;
this.assignData(result);
return _context.abrupt('return', this);
case 19:
_context.prev = 19;
_context.t0 = _context['catch'](4);
case 11:
_context.prev = 11;
_context.t0 = _context['catch'](0);
throw Boom.wrap(_context.t0);
case 22:
case 14:
case 'end':

@@ -115,3 +92,3 @@ return _context.stop();

}
}, _callee, this, [[4, 19]]);
}, _callee, this, [[0, 11]]);
}));

@@ -128,5 +105,8 @@

value: function () {
var _ref2 = _asyncToGenerator(regeneratorRuntime.mark(function _callee2(aql, params) {
var options = arguments.length <= 2 || arguments[2] === undefined ? {} : arguments[2];
var localParams, localOptions, result, cursor;
var _ref2 = _asyncToGenerator(regeneratorRuntime.mark(function _callee2() {
var _len2,
args,
_key2,
_args2 = arguments;
return regeneratorRuntime.wrap(function _callee2$(_context2) {

@@ -136,43 +116,21 @@ while (1) {

case 0:
localParams = Object.assign({}, params);
localOptions = Object.assign({
appendTableParam: true
}, options);
_context2.prev = 0;
if (localOptions.appendTableParam !== false) {
localParams['@table'] = this.table;
for (_len2 = _args2.length, args = Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
args[_key2] = _args2[_key2];
}
_context2.prev = 3;
result = void 0;
_context2.next = 7;
return this.connection.database.query(aql, localParams);
case 7:
cursor = _context2.sent;
_context2.next = 4;
return this.adapter.query(this.type, args);
if (cursor._result.length) {
_context2.next = 10;
break;
}
case 4:
_context2.next = 9;
break;
throw Boom.notFound();
case 10:
_context2.next = 12;
return cursor.next();
case 12:
result = _context2.sent;
this.isNew = false;
this.assignData(result);
return _context2.abrupt('return', this);
case 18:
_context2.prev = 18;
_context2.t0 = _context2['catch'](3);
case 6:
_context2.prev = 6;
_context2.t0 = _context2['catch'](0);
throw Boom.wrap(_context2.t0);
case 21:
case 9:
case 'end':

@@ -182,6 +140,6 @@ return _context2.stop();

}
}, _callee2, this, [[3, 18]]);
}, _callee2, this, [[0, 6]]);
}));
function query(_x2, _x3, _x4) {
function query(_x2) {
return _ref2.apply(this, arguments);

@@ -193,44 +151,2 @@ }

}, {
key: 'rawQuery',
value: function () {
var _ref3 = _asyncToGenerator(regeneratorRuntime.mark(function _callee3(aql, params) {
var result, cursor;
return regeneratorRuntime.wrap(function _callee3$(_context3) {
while (1) {
switch (_context3.prev = _context3.next) {
case 0:
_context3.prev = 0;
result = void 0;
_context3.next = 4;
return this.connection.database.query(aql, params);
case 4:
cursor = _context3.sent;
_context3.next = 7;
return cursor.all();
case 7:
result = _context3.sent;
return _context3.abrupt('return', result);
case 11:
_context3.prev = 11;
_context3.t0 = _context3['catch'](0);
throw Boom.wrap(_context3.t0);
case 14:
case 'end':
return _context3.stop();
}
}
}, _callee3, this, [[0, 11]]);
}));
function rawQuery(_x6, _x7) {
return _ref3.apply(this, arguments);
}
return rawQuery;
}()
}, {
key: 'assignData',

@@ -279,42 +195,30 @@ value: function assignData(inData) {

value: function () {
var _ref4 = _asyncToGenerator(regeneratorRuntime.mark(function _callee4() {
var cursor;
return regeneratorRuntime.wrap(function _callee4$(_context4) {
var _ref3 = _asyncToGenerator(regeneratorRuntime.mark(function _callee3() {
return regeneratorRuntime.wrap(function _callee3$(_context3) {
while (1) {
switch (_context4.prev = _context4.next) {
switch (_context3.prev = _context3.next) {
case 0:
_context4.prev = 0;
_context4.next = 3;
return this.triggerEvent('beforeDestroy');
_context3.prev = 0;
_context3.next = 3;
return this.adapter.destroy(this.type, this.key);
case 3:
_context4.next = 5;
return this.connection.database.query('\n REMOVE @key in @@table\n ', {
'@table': this.table,
key: this.data._key
});
_context3.next = 8;
break;
case 5:
cursor = _context4.sent;
_context4.next = 8;
return this.triggerEvent('afterDestroy');
_context3.prev = 5;
_context3.t0 = _context3['catch'](0);
throw Boom.wrap(_context3.t0);
case 8:
return _context4.abrupt('return', this);
case 11:
_context4.prev = 11;
_context4.t0 = _context4['catch'](0);
throw Boom.notFound();
case 14:
case 'end':
return _context4.stop();
return _context3.stop();
}
}
}, _callee4, this, [[0, 11]]);
}, _callee3, this, [[0, 5]]);
}));
function destroy() {
return _ref4.apply(this, arguments);
return _ref3.apply(this, arguments);
}

@@ -327,22 +231,27 @@

value: function () {
var _ref5 = _asyncToGenerator(regeneratorRuntime.mark(function _callee5() {
var data, cursor, validated;
return regeneratorRuntime.wrap(function _callee5$(_context5) {
var _ref4 = _asyncToGenerator(regeneratorRuntime.mark(function _callee4() {
var data,
validated,
_len3,
args,
_key3,
_args4 = arguments;
return regeneratorRuntime.wrap(function _callee4$(_context4) {
while (1) {
switch (_context5.prev = _context5.next) {
switch (_context4.prev = _context4.next) {
case 0:
data = this.format();
cursor = void 0;
_context5.prev = 2;
_context4.prev = 1;
validated = void 0;
_context5.next = 6;
_context4.next = 5;
return this.triggerEvent('beforeSave');
case 6:
case 5:
this.updateTimestamps();
_context5.next = 9;
_context4.next = 8;
return this.validate();
case 9:
validated = _context5.sent;
case 8:
validated = _context4.sent;

@@ -352,52 +261,45 @@ this.data = validated;

if (!this.isNew) {
_context5.next = 17;
_context4.next = 17;
break;
}
_context5.next = 14;
return this.connection.database.query('\n INSERT @data IN @@table\n RETURN NEW\n ', {
'@table': this.table,
data: data
});
for (_len3 = _args4.length, args = Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
args[_key3] = _args4[_key3];
}
_context4.next = 14;
return this.adapter.create(this.type, args, this.data);
case 14:
cursor = _context5.sent;
_context5.next = 20;
this.key = _context4.sent;
_context4.next = 19;
break;
case 17:
_context5.next = 19;
return this.connection.database.query('\n UPDATE @key\n WITH @data IN @@table\n RETURN NEW\n ', {
'@table': this.table,
key: this.data._key,
data: data
});
_context4.next = 19;
return this.adapter.update(this.type, this.key, this.data);
case 19:
cursor = _context5.sent;
case 20:
this.isNew = false;
this.data = cursor._result[0];
_context5.next = 24;
_context4.next = 22;
return this.triggerEvent('afterSave');
case 24:
return _context5.abrupt('return', this);
case 22:
return _context4.abrupt('return', this);
case 27:
_context5.prev = 27;
_context5.t0 = _context5['catch'](2);
throw Boom.wrap(_context5.t0);
case 25:
_context4.prev = 25;
_context4.t0 = _context4['catch'](1);
throw Boom.wrap(_context4.t0);
case 30:
case 28:
case 'end':
return _context5.stop();
return _context4.stop();
}
}
}, _callee5, this, [[2, 27]]);
}, _callee4, this, [[1, 25]]);
}));
function save() {
return _ref5.apply(this, arguments);
function save(_x3) {
return _ref4.apply(this, arguments);
}

@@ -415,7 +317,7 @@

value: function () {
var _ref6 = _asyncToGenerator(regeneratorRuntime.mark(function _callee6() {
var _ref5 = _asyncToGenerator(regeneratorRuntime.mark(function _callee5() {
var rules, data, options;
return regeneratorRuntime.wrap(function _callee6$(_context6) {
return regeneratorRuntime.wrap(function _callee5$(_context5) {
while (1) {
switch (_context6.prev = _context6.next) {
switch (_context5.prev = _context5.next) {
case 0:

@@ -427,5 +329,5 @@ rules = this.rules;

};
return _context6.abrupt('return', new Promise(function (resolve, reject) {
return _context5.abrupt('return', new Promise(function (resolve, reject) {
if (!rules) {
return resolve();
return resolve(data);
}

@@ -442,10 +344,10 @@ return Joi.validate(data, rules, options, function (err, value) {

case 'end':
return _context6.stop();
return _context5.stop();
}
}
}, _callee6, this);
}, _callee5, this);
}));
function validate() {
return _ref6.apply(this, arguments);
return _ref5.apply(this, arguments);
}

@@ -476,38 +378,33 @@

}, {
key: 'keyToId',
value: function keyToId(key) {
return this.table + '/' + key;
}
}, {
key: 'triggerEvent',
value: function () {
var _ref7 = _asyncToGenerator(regeneratorRuntime.mark(function _callee7(eventName) {
return regeneratorRuntime.wrap(function _callee7$(_context7) {
var _ref6 = _asyncToGenerator(regeneratorRuntime.mark(function _callee6(eventName) {
return regeneratorRuntime.wrap(function _callee6$(_context6) {
while (1) {
switch (_context7.prev = _context7.next) {
switch (_context6.prev = _context6.next) {
case 0:
if (this.events[eventName]) {
_context7.next = 2;
_context6.next = 2;
break;
}
return _context7.abrupt('return', false);
return _context6.abrupt('return', false);
case 2:
_context7.next = 4;
_context6.next = 4;
return this[this.events[eventName]]();
case 4:
return _context7.abrupt('return', _context7.sent);
return _context6.abrupt('return', _context6.sent);
case 5:
case 'end':
return _context7.stop();
return _context6.stop();
}
}
}, _callee7, this);
}, _callee6, this);
}));
function triggerEvent(_x8) {
return _ref7.apply(this, arguments);
function triggerEvent(_x4) {
return _ref6.apply(this, arguments);
}

@@ -522,5 +419,6 @@

var currentData = Object.assign({}, this.data);
var currentData = Object.assign({
_id: this.adapter.getKey(this.key)
}, this.data);
var localData = {};
var hidden = ['_rev', '_key'];

@@ -533,7 +431,6 @@ if (currentData._key) {

if (this.hidden) {
hidden = hidden.concat(this.hidden);
this.hidden.forEach(function (h) {
delete localData[h];
});
}
hidden.forEach(function (h) {
delete localData[h];
});

@@ -556,4 +453,4 @@ var _loop = function _loop(key) {

}
for (var _key in this.meta) {
localData[_key] = this.meta[_key];
for (var _key4 in this.meta) {
localData[_key4] = this.meta[_key4];
}

@@ -560,0 +457,0 @@ return localData;

{
"name": "arpeggio",
"version": "0.0.1",
"version": "0.0.2",
"description": "extremely opinionated ORM/ODM",

@@ -15,4 +15,4 @@ "main": "lib/arpeggio.js",

"engines": {
"node": "5.0.0",
"npm": "3.3.6"
"node": "6.6.0",
"npm": "3.10.3"
},

@@ -22,9 +22,3 @@ "author": "nateupstairs",

"dependencies": {
"arangojs": "^5.0.3",
"babel-polyfill": "^6.3.14",
"babel-preset-es2015": "^6.3.13",
"babel-preset-stage-0": "^6.3.13",
"babel-register": "^6.3.13",
"boom": "^2.10.1",
"hoek": "^3.0.4",
"joi": "^6.10.1",

@@ -37,4 +31,8 @@ "lodash": "^3.10.1",

"babel-eslint": "^4.1.3",
"babel-polyfill": "^6.3.14",
"babel-preset-es2015": "^6.3.13",
"babel-preset-stage-0": "^6.3.13",
"babel-register": "^6.3.13",
"eslint": "^1.7.3"
}
}

@@ -1,9 +0,14 @@

import * as connection from './connection'
import * as designer from './designer'
import * as adapter from './adapter'
import {SingleModel as SingleModel} from './baseModels/SingleModel'
import {EdgeModel as EdgeModel} from './baseModels/EdgeModel'
import {CollectionModel as CollectionModel} from './baseModels/CollectionModel'
function init(config) {
return connection.configure(config)
const assert = require('assert')
var config
function init(_config) {
assert(_config.adapter, 'Arpeggio: .adapter must be set')
config = _config
return adapter.init(_config.adapter)
}

@@ -13,7 +18,5 @@

init: init,
design: designer.design,
getConnection: connection.getConnection,
config: config,
SingleModel: SingleModel,
EdgeModel: EdgeModel,
CollectionModel: CollectionModel
}

@@ -7,3 +7,3 @@ /**

import * as connection from '../connection'
import * as adapter from '../adapter'

@@ -15,30 +15,32 @@ export class CollectionModel {

this.baseModel = baseModel
this.table = new baseModel().table
this.rawQuery = new baseModel().rawQuery
this.connection = connection.getConnection()
this.type = new baseModel().type
this.adapter = adapter.getAdapter()
}
async query(aql, params, options = {}) {
let localParams = Object.assign({}, params)
let localOptions = Object.assign({
appendTableParam: true
}, options)
let result
let cursor
async query(...args) {
try {
let result = await this.adapter.query(args)
if (localOptions.appendTableParam !== false) {
localParams['@table'] = this.table
if (result) {
this.cursor = result.cursor
if (result.results.length > 0) {
result.results.forEach(modelData => {
let model = new this.baseModel()
model.ingest(modelData.data)
model.key = modelData.key
this.models.push(model)
})
return this
}
}
return false
}
cursor = await this.connection.database.query(aql, localParams)
catch (err) {
throw Boom.wrap(err)
}
}
return cursor.all()
.then(result => {
result.forEach(modelData => {
let model = new this.baseModel()
model.ingest(modelData)
this.models.push(model)
})
return this
})
async buildQuery() {
return this.adapter.buildQuery(this.type)
}

@@ -45,0 +47,0 @@

@@ -10,53 +10,27 @@ /**

import * as connection from '../connection'
import * as adapter from '../adapter'
export class SingleModel {
constructor(table) {
constructor(type) {
this.adapter = adapter.getAdapter()
this.type = type
this.isNew = true
this.timestamps = false
this.key = false
this.data = {}
this.events = {}
this.prevData = {}
this.table = table
this.children = {}
this.meta = {}
this.Joi = Joi
this.connection = connection.getConnection()
}
async fetch(...args) {
let key
let value
let params = {}
if (args.length == 1) {
key = '_key'
value = args[0]
}
else {
key = args[0]
value = args[1]
}
try {
let result
let cursor = await this.connection.database.query(
`
FOR i IN @@table
FILTER i.@key == @value
RETURN i
`,
{
'@table': this.table,
key: key,
value: value
}
)
let result = await this.adapter.read(this.type, args)
if (!cursor._result.length) {
throw Boom.notFound()
}
result = await cursor.next()
this.key = result.key
this.assignData(result.data)
this.isNew = false
this.assignData(result)
return this

@@ -69,22 +43,5 @@ }

async query(aql, params, options = {}) {
let localParams = Object.assign({}, params)
let localOptions = Object.assign({
appendTableParam: true
}, options)
if (localOptions.appendTableParam !== false) {
localParams['@table'] = this.table
}
async query(...args) {
try {
let result
let cursor = await this.connection.database.query(aql, localParams)
if (!cursor._result.length) {
throw Boom.notFound()
}
result = await cursor.next()
this.isNew = false
this.assignData(result)
return this
await this.adapter.query(this.type, args)
}

@@ -96,15 +53,2 @@ catch (err) {

async rawQuery(aql, params) {
try {
let result
let cursor = await this.connection.database.query(aql, params)
result = await cursor.all()
return result
}
catch (err) {
throw Boom.wrap(err)
}
}
assignData(inData) {

@@ -149,24 +93,11 @@ let data = Object.assign({}, inData)

try {
await this.triggerEvent('beforeDestroy')
let cursor = await this.connection.database.query(
`
REMOVE @key in @@table
`,
{
'@table': this.table,
key: this.data._key
}
)
await this.triggerEvent('afterDestroy')
return this
await this.adapter.destroy(this.type, this.key)
}
catch (err) {
throw Boom.notFound()
throw Boom.wrap(err)
}
}
async save() {
async save(...args) {
let data = this.format()
let cursor

@@ -181,29 +112,8 @@ try {

if (this.isNew) {
cursor = await this.connection.database.query(
`
INSERT @data IN @@table
RETURN NEW
`,
{
'@table': this.table,
data: data
}
)
this.key = await this.adapter.create(this.type, args, this.data)
}
else {
cursor = await this.connection.database.query(
`
UPDATE @key
WITH @data IN @@table
RETURN NEW
`,
{
'@table': this.table,
key: this.data._key,
data: data
}
)
await this.adapter.update(this.type, this.key, this.data)
}
this.isNew = false
this.data = cursor._result[0]
await this.triggerEvent('afterSave')

@@ -230,3 +140,3 @@ return this

if (!rules) {
return resolve()
return resolve(data)
}

@@ -259,6 +169,2 @@ return Joi.validate(data, rules, options, function(err, value) {

keyToId(key) {
return `${this.table}/${key}`
}
async triggerEvent(eventName) {

@@ -272,5 +178,6 @@ if (!this.events[eventName]) {

toJSON() {
let currentData = Object.assign({}, this.data)
let currentData = Object.assign({
_id: this.adapter.getKey(this.key)
}, this.data)
let localData = {}
let hidden = ['_rev', '_key']

@@ -283,7 +190,6 @@ if (currentData._key) {

if (this.hidden) {
hidden = hidden.concat(this.hidden)
this.hidden.forEach(h => {
delete localData[h]
})
}
hidden.forEach(h => {
delete localData[h]
})
for (let key in this.children) {

@@ -290,0 +196,0 @@ let modelData = this.children[key]

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc