Socket
Socket
Sign inDemoInstall

amelisa

Package Overview
Dependencies
Maintainers
1
Versions
32
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

amelisa - npm Package Compare versions

Comparing version 0.1.25 to 0.1.27

lib/client/RemoteJoinQuery.js

6

lib/client/ClientQuery.js

@@ -64,3 +64,3 @@ 'use strict';

_this.onCollectionChange = function (op) {
if (!_this.subscribing) _this.refresh(op);
if (!_this.fetching) _this.refresh();
};

@@ -199,4 +199,6 @@

value: function refresh() {
var expression = arguments.length <= 0 || arguments[0] === undefined ? this.expression : arguments[0];
var docs = this.collection.getDocs();
var data = this.model.dbQueries.getQueryResultFromArray(docs, this.expression);
var data = this.model.dbQueries.getQueryResultFromArray(docs, expression);
if (this.isDocs) data = data.map(function (docData) {

@@ -203,0 +205,0 @@ return docData.id;

@@ -31,2 +31,10 @@ 'use strict';

var _RemoteJoinQuery = require('./RemoteJoinQuery');
var _RemoteJoinQuery2 = _interopRequireDefault(_RemoteJoinQuery);
var _UrlQuery = require('./UrlQuery');
var _UrlQuery2 = _interopRequireDefault(_UrlQuery);
var _util = require('../util');

@@ -47,6 +55,7 @@

value: function getOrCreateQuery(collectionName, expression) {
var isGraphQLQuery = collectionName.indexOf('{') > -1;
// TODO: remove whitespaces from GraphQL query
// if (isGraphQLQuery) collectionName = collectionName.replace(/ /g, '').replace(/\n/g, '')
var isUrlQuery = _UrlQuery2.default.prototype.isUrlQuery(collectionName, expression);
var isGraphQLQuery = !isUrlQuery && _RemoteGraphQLQuery2.default.prototype.isGraphQLQuery(collectionName, expression);
var isJoinQuery = !isUrlQuery && !isGraphQLQuery && this.model.dbQueries.isJoinQuery(expression);
// if (isGraphQLQuery) collectionName = RemoteGraphQLQuery.prototype.removeWhitespaces(collectionName)
if (!isGraphQLQuery && !expression) expression = this.model.dbQueries.getAllSelector();

@@ -58,3 +67,3 @@

if (!query) {
query = this.createQuery(collectionName, expression, isGraphQLQuery);
query = this.createQuery(collectionName, expression, isUrlQuery, isGraphQLQuery, isJoinQuery);

@@ -68,3 +77,7 @@ this.data[hash] = query;

key: 'createQuery',
value: function createQuery(collectionName, expression, isGraphQLQuery) {
value: function createQuery(collectionName, expression, isUrlQuery, isGraphQLQuery, isJoinQuery) {
if (isUrlQuery) {
return new _UrlQuery2.default(collectionName, expression, this.model);
}
if (isGraphQLQuery) {

@@ -76,2 +89,7 @@ return new _RemoteGraphQLQuery2.default(collectionName, expression, this.model, this);

// TODO: add local join query
if (isJoinQuery) {
return new _RemoteJoinQuery2.default(collectionName, expression, this.model, collection, this);
}
if ((0, _util.isLocalCollection)(collectionName)) {

@@ -111,2 +129,5 @@ return new _LocalQuery2.default(collectionName, expression, this.model, collection, this);

}
}, {
key: 'isQuery',
value: function isQuery(collectionName, expression) {}
}]);

@@ -113,0 +134,0 @@ return ClientQuerySet;

@@ -85,2 +85,3 @@ 'use strict';

if (value instanceof _types.NumberType) return value.get();
if (value instanceof _types.RichTextType) return value.get();
if (value instanceof _types.StringType) return value.get();

@@ -453,2 +454,8 @@

break;
case 'rich':
if (!(fieldState instanceof _types.RichTextType)) fieldState = new _types.RichTextType();
fieldState.pushDelta(value);
break;
}

@@ -455,0 +462,0 @@

@@ -523,3 +523,3 @@ 'use strict';

_context8.t0 = type;
_context8.next = _context8.t0 === 'fetch' ? 17 : _context8.t0 === 'sub' ? 20 : _context8.t0 === 'q' ? 23 : _context8.t0 === 'qdiff' ? 26 : _context8.t0 === 'ops' ? 29 : _context8.t0 === 'add' ? 32 : _context8.t0 === 'set' ? 32 : _context8.t0 === 'del' ? 32 : _context8.t0 === 'push' ? 32 : _context8.t0 === 'unshift' ? 32 : _context8.t0 === 'pop' ? 32 : _context8.t0 === 'shift' ? 32 : _context8.t0 === 'insert' ? 32 : _context8.t0 === 'remove' ? 32 : _context8.t0 === 'move' ? 32 : _context8.t0 === 'swap' ? 32 : _context8.t0 === 'arraySet' ? 32 : _context8.t0 === 'invert' ? 32 : _context8.t0 === 'increment' ? 32 : _context8.t0 === 'stringInsert' ? 32 : _context8.t0 === 'stringRemove' ? 32 : _context8.t0 === 'stringSet' ? 32 : 36;
_context8.next = _context8.t0 === 'fetch' ? 17 : _context8.t0 === 'sub' ? 20 : _context8.t0 === 'q' ? 23 : _context8.t0 === 'qdiff' ? 26 : _context8.t0 === 'ops' ? 29 : _context8.t0 === 'add' ? 32 : _context8.t0 === 'set' ? 32 : _context8.t0 === 'del' ? 32 : _context8.t0 === 'push' ? 32 : _context8.t0 === 'unshift' ? 32 : _context8.t0 === 'pop' ? 32 : _context8.t0 === 'shift' ? 32 : _context8.t0 === 'insert' ? 32 : _context8.t0 === 'remove' ? 32 : _context8.t0 === 'move' ? 32 : _context8.t0 === 'swap' ? 32 : _context8.t0 === 'arraySet' ? 32 : _context8.t0 === 'invert' ? 32 : _context8.t0 === 'increment' ? 32 : _context8.t0 === 'stringInsert' ? 32 : _context8.t0 === 'stringRemove' ? 32 : _context8.t0 === 'stringSet' ? 32 : _context8.t0 === 'rich' ? 32 : 36;
break;

@@ -1362,3 +1362,3 @@

}, {
key: 'richDiff',
key: 'rich',
value: function () {

@@ -1379,9 +1379,9 @@ var ref = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee27(path, value) {

(0, _invariant2.default)(collectionName && typeof collectionName === 'string', 'Model.richDiff collectionName is required and should be a string');
(0, _invariant2.default)(docId && typeof docId === 'string', 'Model.richDiff docId is required and should be a string');
(0, _invariant2.default)(!field || typeof field === 'string', 'Model.richDiff field should be a string');
(0, _invariant2.default)(Array.isArray(value), 'Model.richDiff value should be a array');
(0, _invariant2.default)(collectionName && typeof collectionName === 'string', 'Model.rich collectionName is required and should be a string');
(0, _invariant2.default)(docId && typeof docId === 'string', 'Model.rich docId is required and should be a string');
(0, _invariant2.default)(!field || typeof field === 'string', 'Model.rich field should be a string');
(0, _invariant2.default)(value && (typeof value === 'undefined' ? 'undefined' : (0, _typeof3.default)(value)) === 'object', 'Model.rich value should be an object');
doc = this.collectionSet.getOrCreateDoc(collectionName, docId);
return _context27.abrupt('return', doc.richDiff(field, value));
return _context27.abrupt('return', doc.rich(field, value));

@@ -1396,9 +1396,48 @@ case 11:

function richDiff(_x46, _x47) {
function rich(_x46, _x47) {
return ref.apply(this, arguments);
}
return richDiff;
return rich;
}()
}, {
key: 'draftDiff',
value: function () {
var ref = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee28(path, value) {
var _parsePath37, _parsePath38, collectionName, docId, field, doc;
return _regenerator2.default.wrap(function _callee28$(_context28) {
while (1) {
switch (_context28.prev = _context28.next) {
case 0:
_parsePath37 = (0, _util.parsePath)(path);
_parsePath38 = (0, _slicedToArray3.default)(_parsePath37, 3);
collectionName = _parsePath38[0];
docId = _parsePath38[1];
field = _parsePath38[2];
(0, _invariant2.default)(collectionName && typeof collectionName === 'string', 'Model.draftDiff collectionName is required and should be a string');
(0, _invariant2.default)(docId && typeof docId === 'string', 'Model.draftDiff docId is required and should be a string');
(0, _invariant2.default)(!field || typeof field === 'string', 'Model.draftDiff field should be a string');
(0, _invariant2.default)(Array.isArray(value), 'Model.draftDiff value should be a array');
doc = this.collectionSet.getOrCreateDoc(collectionName, docId);
return _context28.abrupt('return', doc.draftDiff(field, value));
case 11:
case 'end':
return _context28.stop();
}
}
}, _callee28, this);
}));
function draftDiff(_x48, _x49) {
return ref.apply(this, arguments);
}
return draftDiff;
}()
}, {
key: 'doc',

@@ -1416,9 +1455,9 @@ value: function doc(collectionName, docId) {

value: function () {
var ref = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee28(newProjectionHashes) {
var ref = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee29(newProjectionHashes) {
var _this3 = this;
var prevProjectionHashes, collectionNames;
return _regenerator2.default.wrap(function _callee28$(_context28) {
return _regenerator2.default.wrap(function _callee29$(_context29) {
while (1) {
switch (_context28.prev = _context28.next) {
switch (_context29.prev = _context29.next) {
case 0:

@@ -1429,10 +1468,10 @@ prevProjectionHashes = this.get('_app.projectionHashes');

if (this.storage) {
_context28.next = 4;
_context29.next = 4;
break;
}
return _context28.abrupt('return');
return _context29.abrupt('return');
case 4:
return _context28.abrupt('return', _promise2.default.all(collectionNames.map(function (collectionName) {
return _context29.abrupt('return', _promise2.default.all(collectionNames.map(function (collectionName) {
return _this3.storage.clearCollection(collectionName);

@@ -1443,9 +1482,9 @@ })));

case 'end':
return _context28.stop();
return _context29.stop();
}
}
}, _callee28, this);
}, _callee29, this);
}));
function onProjections(_x48) {
function onProjections(_x50) {
return ref.apply(this, arguments);

@@ -1477,18 +1516,18 @@ }

value: function () {
var ref = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee29(message, forceSend) {
var ref = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee30(message, forceSend) {
var _this4 = this;
return _regenerator2.default.wrap(function _callee29$(_context29) {
return _regenerator2.default.wrap(function _callee30$(_context30) {
while (1) {
switch (_context29.prev = _context29.next) {
switch (_context30.prev = _context30.next) {
case 0:
if (!(!forceSend && (!this.inited || !this.online || !message.id))) {
_context29.next = 2;
_context30.next = 2;
break;
}
return _context29.abrupt('return');
return _context30.abrupt('return');
case 2:
return _context29.abrupt('return', new _promise2.default(function (resolve, reject) {
return _context30.abrupt('return', new _promise2.default(function (resolve, reject) {
var callback = function callback(err, value) {

@@ -1514,9 +1553,9 @@ if (err) return reject(err);

case 'end':
return _context29.stop();
return _context30.stop();
}
}
}, _callee29, this);
}, _callee30, this);
}));
function send(_x49, _x50) {
function send(_x51, _x52) {
return ref.apply(this, arguments);

@@ -1545,20 +1584,20 @@ }

value: function () {
var ref = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee30(opData) {
var ref = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee31(opData) {
var op;
return _regenerator2.default.wrap(function _callee30$(_context30) {
return _regenerator2.default.wrap(function _callee31$(_context31) {
while (1) {
switch (_context30.prev = _context30.next) {
switch (_context31.prev = _context31.next) {
case 0:
op = this.createOp(opData);
return _context30.abrupt('return', this.send(op));
return _context31.abrupt('return', this.send(op));
case 2:
case 'end':
return _context30.stop();
return _context31.stop();
}
}
}, _callee30, this);
}, _callee31, this);
}));
function sendOp(_x51) {
function sendOp(_x53) {
return ref.apply(this, arguments);

@@ -1630,14 +1669,14 @@ }

value: function () {
var ref = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee31() {
var ref = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee32() {
var json, bundle;
return _regenerator2.default.wrap(function _callee31$(_context31) {
return _regenerator2.default.wrap(function _callee32$(_context32) {
while (1) {
switch (_context31.prev = _context31.next) {
switch (_context32.prev = _context32.next) {
case 0:
if (!this.onBundleReady) {
_context31.next = 3;
_context32.next = 3;
break;
}
_context31.next = 3;
_context32.next = 3;
return this.onBundleReady();

@@ -1647,7 +1686,7 @@

if (this.getBundleJsonFromDom) {
_context31.next = 5;
_context32.next = 5;
break;
}
return _context31.abrupt('return');
return _context32.abrupt('return');

@@ -1662,6 +1701,6 @@ case 5:

case 'end':
return _context31.stop();
return _context32.stop();
}
}
}, _callee31, this);
}, _callee32, this);
}));

@@ -1668,0 +1707,0 @@

@@ -671,4 +671,9 @@ 'use strict';

case 8:
itemId = array.getSetPositionIdByIndex(to);
itemId = void 0;
if (from > to) {
itemId = array.getInsertPositionIdByIndex(to);
} else {
itemId = array.getSetPositionIdByIndex(to);
}

@@ -711,3 +716,3 @@ for (i = 0; i < howMany; i++) {

case 16:
case 17:
case 'end':

@@ -1315,4 +1320,38 @@ return _context14.stop();

}, {
key: 'richDiff',
value: function richDiff(field, value) {
key: 'rich',
value: function () {
var ref = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee24(field, value) {
var op;
return _regenerator2.default.wrap(function _callee24$(_context24) {
while (1) {
switch (_context24.prev = _context24.next) {
case 0:
field = this.getFieldConsideringArrays(field);
op = this.model.createOp({
type: 'rich',
collectionName: this.collection.name,
docId: this.docId,
field: field,
value: value
});
return _context24.abrupt('return', this.onOp(op));
case 3:
case 'end':
return _context24.stop();
}
}
}, _callee24, this);
}));
function rich(_x45, _x46) {
return ref.apply(this, arguments);
}
return rich;
}()
}, {
key: 'draftDiff',
value: function draftDiff(field, value) {
var previous = this.get(field);

@@ -1421,6 +1460,6 @@ if (!Array.isArray(previous)) previous = [];

value: function () {
var ref = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee24(op) {
return _regenerator2.default.wrap(function _callee24$(_context24) {
var ref = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee25(op) {
return _regenerator2.default.wrap(function _callee25$(_context25) {
while (1) {
switch (_context24.prev = _context24.next) {
switch (_context25.prev = _context25.next) {
case 0:

@@ -1430,13 +1469,13 @@ this.applyOp(op);

this.collection.emit('change', op);
return _context24.abrupt('return', this.save());
return _context25.abrupt('return', this.save());
case 4:
case 'end':
return _context24.stop();
return _context25.stop();
}
}
}, _callee24, this);
}, _callee25, this);
}));
function onOp(_x45) {
function onOp(_x47) {
return ref.apply(this, arguments);

@@ -1450,15 +1489,15 @@ }

value: function () {
var ref = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee25() {
var ref = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee26() {
var _this2 = this;
return _regenerator2.default.wrap(function _callee25$(_context25) {
return _regenerator2.default.wrap(function _callee26$(_context26) {
while (1) {
switch (_context25.prev = _context25.next) {
switch (_context26.prev = _context26.next) {
case 0:
if (!(!this.model.storage || !this.ops.length)) {
_context25.next = 2;
_context26.next = 2;
break;
}
return _context25.abrupt('return');
return _context26.abrupt('return');

@@ -1474,6 +1513,6 @@ case 2:

case 'end':
return _context25.stop();
return _context26.stop();
}
}
}, _callee25, this);
}, _callee26, this);
}));

@@ -1490,10 +1529,10 @@

value: function () {
var ref = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee26() {
var ref = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee27() {
var _this3 = this;
return _regenerator2.default.wrap(function _callee26$(_context26) {
return _regenerator2.default.wrap(function _callee27$(_context27) {
while (1) {
switch (_context26.prev = _context26.next) {
switch (_context27.prev = _context27.next) {
case 0:
return _context26.abrupt('return', this.model.storage.saveDoc(this.collection.name, this.docId, this.ops, this.serverVersion).catch(function (err) {
return _context27.abrupt('return', this.model.storage.saveDoc(this.collection.name, this.docId, this.ops, this.serverVersion).catch(function (err) {
console.error('MutableDoc.save', _this3.collection.name, err);

@@ -1505,6 +1544,6 @@ console.log('Probably, you have not added collection ' + _this3.collection.name + '\n to store options. For IndexedDB app version should be increased also');

case 'end':
return _context26.stop();
return _context27.stop();
}
}
}, _callee26, this);
}, _callee27, this);
}));

@@ -1511,0 +1550,0 @@

@@ -86,3 +86,3 @@ 'use strict';

case 0:
if (!this.subscribing) {
if (!this.fetching) {
_context.next = 2;

@@ -92,8 +92,8 @@ break;

return _context.abrupt('return', this.subscribingPromise);
return _context.abrupt('return', this.fetchingPromise);
case 2:
this.subscribing = true;
this.fetching = true;
this.subscribingPromise = this.model.sendOp({
this.fetchingPromise = this.model.sendOp({
type: 'fetch',

@@ -103,3 +103,3 @@ collectionName: this.collection.name,

});
return _context.abrupt('return', this.subscribingPromise);
return _context.abrupt('return', this.fetchingPromise);

@@ -136,9 +136,9 @@ case 5:

return _context2.abrupt('return', options.fetch ? this.subscribingPromise : undefined);
return _context2.abrupt('return', options.fetch ? this.fetchingPromise : undefined);
case 4:
this.subscribing = true;
this.fetching = true;
this.subscribingPromise = this.sendSubscribeOp();
return _context2.abrupt('return', options.fetch ? this.subscribingPromise : undefined);
this.fetchingPromise = this.sendSubscribeOp();
return _context2.abrupt('return', options.fetch ? this.fetchingPromise : undefined);

@@ -231,3 +231,3 @@ case 7:

this.applyOps(ops);
this.subscribing = false;
this.fetching = false;
this.emit('change');

@@ -234,0 +234,0 @@ this.save();

@@ -90,3 +90,3 @@ 'use strict';

subscribe.on('change', _this.onChange);
subscribe.subscribing = false;
subscribe.fetching = false;

@@ -106,3 +106,3 @@ return subscribe.get();

_this.subscribed = 0;
_this.subscribing = false;
_this.fetching = false;
_this.subscribes = [];

@@ -228,3 +228,3 @@ _this.isDocs = false;

case 0:
if (!this.subscribing) {
if (!this.fetching) {
_context2.next = 2;

@@ -234,6 +234,6 @@ break;

return _context2.abrupt('return', this.subscribingPromise);
return _context2.abrupt('return', this.fetchingPromise);
case 2:
this.subscribing = true;
this.fetching = true;

@@ -253,4 +253,4 @@ _context2.next = 5;

this.subscribingPromise = this.model.sendOp(op);
return _context2.abrupt('return', this.subscribingPromise);
this.fetchingPromise = this.model.sendOp(op);
return _context2.abrupt('return', this.fetchingPromise);

@@ -283,3 +283,3 @@ case 9:

if (!this.subscribing) {
if (!this.fetching) {
_context3.next = 4;

@@ -289,6 +289,6 @@ break;

return _context3.abrupt('return', options.fetch ? this.subscribingPromise : undefined);
return _context3.abrupt('return', options.fetch ? this.fetchingPromise : undefined);
case 4:
this.subscribing = true;
this.fetching = true;

@@ -316,4 +316,4 @@ if (!(this.subscribed !== 1)) {

this.subscribingPromise = this.model.sendOp(op);
return _context3.abrupt('return', options.fetch ? this.subscribingPromise : undefined);
this.fetchingPromise = this.model.sendOp(op);
return _context3.abrupt('return', options.fetch ? this.fetchingPromise : undefined);

@@ -381,5 +381,15 @@ case 13:

this.subscribing = false;
this.fetching = false;
this.emit('change');
}
}, {
key: 'isGraphQLQuery',
value: function isGraphQLQuery(graphqlQuery) {
return graphqlQuery && typeof graphqlQuery === 'string' && graphqlQuery.indexOf('{') > -1;
}
}, {
key: 'removeWhitespaces',
value: function removeWhitespaces(graphqlQuery) {
return graphqlQuery.replace(/ /g, '').replace(/\n/g, '');
}
}]);

@@ -386,0 +396,0 @@ return RemoteGraphQLQuery;

@@ -66,3 +66,3 @@ 'use strict';

_this.subscribed = 0;
_this.subscribing = false;
_this.fetching = false;
return _this;

@@ -80,3 +80,3 @@ }

case 0:
if (!this.subscribing) {
if (!this.fetching) {
_context.next = 2;

@@ -86,6 +86,6 @@ break;

return _context.abrupt('return', this.subscribingPromise);
return _context.abrupt('return', this.fetchingPromise);
case 2:
this.subscribing = true;
this.fetching = true;

@@ -97,3 +97,3 @@ this.refresh();

type: 'qfetch',
collectionName: this.collection.name,
collectionName: this.collectionName,
expression: this.expression

@@ -105,4 +105,4 @@ };

this.subscribingPromise = this.model.sendOp(op);
return _context.abrupt('return', this.subscribingPromise);
this.fetchingPromise = this.model.sendOp(op);
return _context.abrupt('return', this.fetchingPromise);

@@ -135,3 +135,3 @@ case 9:

if (!this.subscribing) {
if (!this.fetching) {
_context2.next = 4;

@@ -141,6 +141,6 @@ break;

return _context2.abrupt('return', options.fetch ? this.subscribingPromise : undefined);
return _context2.abrupt('return', options.fetch ? this.fetchingPromise : undefined);
case 4:
this.subscribing = true;
this.fetching = true;

@@ -168,4 +168,4 @@ if (!(this.subscribed !== 1)) {

this.subscribingPromise = this.model.sendOp(op);
return _context2.abrupt('return', options.fetch ? this.subscribingPromise : undefined);
this.fetchingPromise = this.model.sendOp(op);
return _context2.abrupt('return', options.fetch ? this.fetchingPromise : undefined);

@@ -292,3 +292,3 @@ case 13:

this.lastServerData = data;
this.subscribing = false;
this.fetching = false;
this.setData(data);

@@ -295,0 +295,0 @@ }

@@ -23,2 +23,6 @@ 'use strict';

var _slicedToArray2 = require('babel-runtime/helpers/slicedToArray');
var _slicedToArray3 = _interopRequireDefault(_slicedToArray2);
var _typeof2 = require('babel-runtime/helpers/typeof');

@@ -28,6 +32,2 @@

var _slicedToArray2 = require('babel-runtime/helpers/slicedToArray');
var _slicedToArray3 = _interopRequireDefault(_slicedToArray2);
var _getIterator2 = require('babel-runtime/core-js/get-iterator');

@@ -65,6 +65,2 @@

var _UrlQuery = require('./UrlQuery');
var _UrlQuery2 = _interopRequireDefault(_UrlQuery);
var _util = require('../util');

@@ -101,6 +97,2 @@

if (Array.isArray(rawSubscribes) && rawSubscribes.length === 1 && Array.isArray(rawSubscribes[0])) {
rawSubscribes = rawSubscribes[0];
}
var _iteratorNormalCompletion = true;

@@ -118,11 +110,2 @@ var _didIteratorError = false;

subscribe = rawSubscribe;
} else if (Array.isArray(rawSubscribe) && typeof rawSubscribe[0] === 'string' && (rawSubscribe[0].indexOf('http') === 0 || rawSubscribe[0].indexOf('/') === 0)) {
var _rawSubscribe = (0, _slicedToArray3.default)(rawSubscribe, 3);
var url = _rawSubscribe[0];
var defaultValue = _rawSubscribe[1];
var options = _rawSubscribe[2];
subscribe = new _UrlQuery2.default(url, defaultValue, this.collectionSet.model);
subscribeOptions = options;
} else if ((typeof rawSubscribe === 'undefined' ? 'undefined' : (0, _typeof3.default)(rawSubscribe)) === 'object' && !Array.isArray(rawSubscribe)) {

@@ -138,12 +121,12 @@ this.options = rawSubscribe;

var docIdOrExpression = _parsePath2[1];
var _options = _parsePath2[2];
var options = _parsePath2[2];
var options2 = _parsePath2[3];
if (typeof docIdOrExpression === 'string') {
if (docIdOrExpression && typeof docIdOrExpression === 'string') {
subscribe = this.collectionSet.getOrCreateDoc(collectionName, docIdOrExpression);
subscribeOptions = options2 || _options;
subscribeOptions = options2 || options;
} else {
subscribe = this.querySet.getOrCreateQuery(collectionName, docIdOrExpression);
subscribeOptions = options2 || _options;
subscribeOptions = options2 || options;
}

@@ -245,3 +228,3 @@ }

var ref = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee3() {
var _this2 = this;
var _iteratorNormalCompletion2, _didIteratorError2, _iteratorError2, _iterator2, _step2, subscribe;

@@ -252,8 +235,51 @@ return _regenerator2.default.wrap(function _callee3$(_context3) {

case 0:
_iteratorNormalCompletion2 = true;
_didIteratorError2 = false;
_iteratorError2 = undefined;
_context3.prev = 3;
for (_iterator2 = (0, _getIterator3.default)(this.subscribes); !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
subscribe = _step2.value;
subscribe.removeListener('change', this.onChange);
}
_context3.next = 11;
break;
case 7:
_context3.prev = 7;
_context3.t0 = _context3['catch'](3);
_didIteratorError2 = true;
_iteratorError2 = _context3.t0;
case 11:
_context3.prev = 11;
_context3.prev = 12;
if (!_iteratorNormalCompletion2 && _iterator2.return) {
_iterator2.return();
}
case 14:
_context3.prev = 14;
if (!_didIteratorError2) {
_context3.next = 17;
break;
}
throw _iteratorError2;
case 17:
return _context3.finish(14);
case 18:
return _context3.finish(11);
case 19:
return _context3.abrupt('return', _promise2.default.all(this.subscribes.map(function (subscribe) {
subscribe.removeListener('change', _this2.onChange);
return subscribe.unsubscribe();
})));
case 1:
case 20:
case 'end':

@@ -263,3 +289,3 @@ return _context3.stop();

}
}, _callee3, this);
}, _callee3, this, [[3, 7, 11, 19], [12,, 14, 18]]);
}));

@@ -266,0 +292,0 @@

@@ -7,2 +7,6 @@ 'use strict';

var _extends2 = require('babel-runtime/helpers/extends');
var _extends3 = _interopRequireDefault(_extends2);
var _regenerator = require('babel-runtime/regenerator');

@@ -40,2 +44,10 @@

var fetchOptions = {
credentials: 'include'
};
var defaultSubscribeOptions = {
fetch: true
};
var UrlQuery = function (_EventEmitter) {

@@ -52,2 +64,3 @@ (0, _inherits3.default)(UrlQuery, _EventEmitter);

_this.model = model;
_this.fetching = false;
return _this;

@@ -78,23 +91,39 @@ }

case 2:
_context.next = 4;
return fetch(this.url);
this.fetching = true;
case 4:
_context.next = 5;
return fetch(this.url, fetchOptions);
case 5:
res = _context.sent;
if (!(res.status !== 200)) {
_context.next = 7;
_context.next = 9;
break;
}
throw new Error('UrlQuery.load: status ' + res.status + ' returned from ' + this.url);
this.fetching = false;
return _context.abrupt('return');
case 7:
_context.next = 9;
case 9:
_context.prev = 9;
_context.next = 12;
return res.json();
case 9:
case 12:
this.data = _context.sent;
_context.next = 19;
break;
case 10:
case 15:
_context.prev = 15;
_context.t0 = _context['catch'](9);
this.fetching = false;
return _context.abrupt('return');
case 19:
this.fetching = false;
case 20:
case 'end':

@@ -104,3 +133,3 @@ return _context.stop();

}
}, _callee, this);
}, _callee, this, [[9, 15]]);
}));

@@ -122,5 +151,13 @@

case 0:
if (!this.fetching) {
_context2.next = 2;
break;
}
return _context2.abrupt('return', this.fetchingPromise);
case 2:
return _context2.abrupt('return', this.load());
case 1:
case 3:
case 'end':

@@ -142,3 +179,3 @@ return _context2.stop();

value: function () {
var ref = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee3() {
var ref = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee3(options) {
return _regenerator2.default.wrap(function _callee3$(_context3) {

@@ -148,5 +185,17 @@ while (1) {

case 0:
return _context3.abrupt('return', this.load());
options = (0, _extends3.default)({}, defaultSubscribeOptions, options);
case 1:
if (!this.fetching) {
_context3.next = 3;
break;
}
return _context3.abrupt('return', options.fetch ? this.fetchingPromise : undefined);
case 3:
this.fetchingPromise = this.load();
return _context3.abrupt('return', options.fetch ? this.fetchingPromise : undefined);
case 5:
case 'end':

@@ -159,3 +208,3 @@ return _context3.stop();

function subscribe() {
function subscribe(_x) {
return ref.apply(this, arguments);

@@ -187,2 +236,7 @@ }

}()
}, {
key: 'isUrlQuery',
value: function isUrlQuery(url, defaultValue) {
return url && typeof url === 'string' && (url.indexOf('http') === 0 || url.indexOf('/') === 0);
}
}]);

@@ -189,0 +243,0 @@ return UrlQuery;

@@ -40,6 +40,6 @@ 'use strict';

function ProjectedJoinQuery(collectionName, projection, expression, store, querySet, joinFields) {
function ProjectedJoinQuery(collectionName, projection, expression, store, querySet) {
(0, _classCallCheck3.default)(this, ProjectedJoinQuery);
var _this = (0, _possibleConstructorReturn3.default)(this, (0, _getPrototypeOf2.default)(ProjectedJoinQuery).call(this, projection.dbCollectionName, expression, store, querySet, joinFields));
var _this = (0, _possibleConstructorReturn3.default)(this, (0, _getPrototypeOf2.default)(ProjectedJoinQuery).call(this, projection.dbCollectionName, expression, store, querySet));

@@ -46,0 +46,0 @@ _this.projectionCollectionName = collectionName;

@@ -23,6 +23,2 @@ 'use strict';

var _keys = require('babel-runtime/core-js/object/keys');
var _keys2 = _interopRequireDefault(_keys);
var _getPrototypeOf = require('babel-runtime/core-js/object/get-prototype-of');

@@ -61,3 +57,3 @@

function ServerJoinQuery(collectionName, expression, store, querySet, joinFields) {
function ServerJoinQuery(collectionName, expression, store, querySet) {
(0, _classCallCheck3.default)(this, ServerJoinQuery);

@@ -68,31 +64,25 @@

_this.onJoinFieldsChange = function () {
var loadedFields = [];
if (_this.loading) return;
for (var field in _this.joinFieldValues) {
var joinFieldValue = _this.joinFieldValues[field];
var doc = joinFieldValue.doc;
var fields = joinFieldValue.fields;
var _this$joinFieldValues = _this.joinFieldValues[field];
var doc = _this$joinFieldValues.doc;
var fields = _this$joinFieldValues.fields;
var value = doc.get(fields);
if (value === undefined) return;
if (loadedFields.indexOf(field) === -1) loadedFields.push(field);
if (value === undefined) value = null;
if (loadedFields.length < (0, _keys2.default)(_this.joinFieldValues).length) return;
_this.expression[field] = value;
}
if (_this.notLoad) _this.notLoad = false;
_this.load();
}
_this.load();
};
_this.notLoad = true;
_this.canLoad = false;
setTimeout(function () {
return _this.emit('loaded');
});
_this.joinFieldValues = {};
var joinFields = _this.store.dbQueries.getJoinFields(expression);
for (var field in joinFields) {

@@ -124,3 +114,4 @@ var value = joinFields[field];

value: function load() {
if (this.notLoad) return;
if (!this.canLoad) return;
(0, _get3.default)((0, _getPrototypeOf2.default)(ServerJoinQuery.prototype), 'load', this).call(this);

@@ -140,2 +131,3 @@ }

case 0:
this.loading = true;
promises = [];

@@ -152,4 +144,2 @@

doc.on('saved', _this2.onJoinFieldsChange);
_this2.onJoinFieldsChange();
});

@@ -163,6 +153,12 @@ promises.push(promise);

_context.next = 5;
_context.next = 6;
return _promise2.default.all(promises);
case 5:
case 6:
this.loading = false;
this.canLoad = true;
this.onJoinFieldsChange();
case 9:
case 'end':

@@ -169,0 +165,0 @@ return _context.stop();

@@ -118,3 +118,2 @@ 'use strict';

var isJoinQuery = this.store.dbQueries.isJoinQuery(expression);
var joinFields = isJoinQuery ? this.store.dbQueries.getJoinFields(expression) : null;

@@ -126,7 +125,7 @@ if (projection && !isJoinQuery) {

if (projection && isJoinQuery) {
return new _ProjectedJoinQuery2.default(collectionName, projection, expression, this.store, this, joinFields);
return new _ProjectedJoinQuery2.default(collectionName, projection, expression, this.store, this);
}
if (isJoinQuery) {
return new _ServerJoinQuery2.default(collectionName, expression, this.store, this, joinFields);
return new _ServerJoinQuery2.default(collectionName, expression, this.store, this);
}

@@ -133,0 +132,0 @@

@@ -547,3 +547,3 @@ 'use strict';

_context5.t0 = type;
_context5.next = _context5.t0 === 'handshake' ? 19 : _context5.t0 === 'sync' ? 22 : _context5.t0 === 'fetch' ? 34 : _context5.t0 === 'qfetch' ? 44 : _context5.t0 === 'sub' ? 54 : _context5.t0 === 'qsub' ? 64 : _context5.t0 === 'unsub' ? 74 : _context5.t0 === 'qunsub' ? 79 : _context5.t0 === 'ops' ? 84 : _context5.t0 === 'add' ? 87 : _context5.t0 === 'set' ? 87 : _context5.t0 === 'del' ? 87 : _context5.t0 === 'push' ? 87 : _context5.t0 === 'unshift' ? 87 : _context5.t0 === 'pop' ? 87 : _context5.t0 === 'shift' ? 87 : _context5.t0 === 'insert' ? 87 : _context5.t0 === 'remove' ? 87 : _context5.t0 === 'move' ? 87 : _context5.t0 === 'swap' ? 87 : _context5.t0 === 'arraySet' ? 87 : _context5.t0 === 'invert' ? 87 : _context5.t0 === 'increment' ? 87 : _context5.t0 === 'stringInsert' ? 87 : _context5.t0 === 'stringRemove' ? 87 : _context5.t0 === 'stringSet' ? 87 : 103;
_context5.next = _context5.t0 === 'handshake' ? 19 : _context5.t0 === 'sync' ? 22 : _context5.t0 === 'fetch' ? 34 : _context5.t0 === 'qfetch' ? 44 : _context5.t0 === 'sub' ? 54 : _context5.t0 === 'qsub' ? 64 : _context5.t0 === 'unsub' ? 74 : _context5.t0 === 'qunsub' ? 79 : _context5.t0 === 'ops' ? 84 : _context5.t0 === 'add' ? 87 : _context5.t0 === 'set' ? 87 : _context5.t0 === 'del' ? 87 : _context5.t0 === 'push' ? 87 : _context5.t0 === 'unshift' ? 87 : _context5.t0 === 'pop' ? 87 : _context5.t0 === 'shift' ? 87 : _context5.t0 === 'insert' ? 87 : _context5.t0 === 'remove' ? 87 : _context5.t0 === 'move' ? 87 : _context5.t0 === 'swap' ? 87 : _context5.t0 === 'arraySet' ? 87 : _context5.t0 === 'invert' ? 87 : _context5.t0 === 'increment' ? 87 : _context5.t0 === 'stringInsert' ? 87 : _context5.t0 === 'stringRemove' ? 87 : _context5.t0 === 'stringSet' ? 87 : _context5.t0 === 'rich' ? 87 : 103;
break;

@@ -550,0 +550,0 @@

@@ -34,2 +34,11 @@ 'use strict';

var _RichTextType = require('./RichTextType');
Object.defineProperty(exports, 'RichTextType', {
enumerable: true,
get: function get() {
return _interopRequireDefault(_RichTextType).default;
}
});
var _StringType = require('./StringType');

@@ -36,0 +45,0 @@

{
"name": "amelisa",
"version": "0.1.25",
"version": "0.1.27",
"description": "Data engine with offline and realtime",

@@ -5,0 +5,0 @@ "browser": "lib/web",

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