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

ancient-cursor

Package Overview
Dependencies
Maintainers
2
Versions
24
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ancient-cursor - npm Package Compare versions

Comparing version 0.0.7 to 0.0.8

2

lib/ApiManager.js

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

'use strict';Object.defineProperty(exports,'__esModule',{value:true});var _createClass=function(){function defineProperties(target,props){for(var i=0;i<props.length;i++){var descriptor=props[i];descriptor.enumerable=descriptor.enumerable||false;descriptor.configurable=true;if('value'in descriptor)descriptor.writable=true;Object.defineProperty(target,descriptor.key,descriptor)}}return function(Constructor,protoProps,staticProps){if(protoProps)defineProperties(Constructor.prototype,protoProps);if(staticProps)defineProperties(Constructor,staticProps);return Constructor}}();var _lodash=require('lodash');var _lodash2=_interopRequireDefault(_lodash);function _interopRequireDefault(obj){return obj&&obj.__esModule?obj:{default:obj}}function _classCallCheck(instance,Constructor){if(!(instance instanceof Constructor)){throw new TypeError('Cannot call a class as a function')}}var ApiManager=function(){function ApiManager(adapterFindApi,adapterSend){_classCallCheck(this,ApiManager);this.adapterFindApi=adapterFindApi;this.adapterSend=adapterSend;this.relations={}}_createClass(ApiManager,[{key:'findApi',value:function findApi(apiQuery){return this.adapterFindApi(apiQuery)}},{key:'receiveQuery',value:function receiveQuery(clientId,apiQuery,query,cursorId){var _this=this;return this.findApi(apiQuery).then(function(api){_lodash2.default.set(_this.relations,[clientId,cursorId],apiQuery);api.receiveQuery(clientId,query,cursorId,function(clientId,bundles){_this.adapterSend(clientId,bundles)});return api})}},{key:'clientDisconnected',value:function clientDisconnected(clientId){var _this2=this;var cursors=_lodash2.default.get(this.relations,[clientId]);var promises=[];for(var cursorId in cursors){promises.push(function(clientId,cursorId){return new Promise(function(){return _this2.cursorDestroyed(clientId,cursorId)})}(clientId,cursorId))}return promises}},{key:'cursorDestroyed',value:function cursorDestroyed(clientId,cursorId){var _this3=this;var apiQuery=_lodash2.default.get(this.relations,[clientId,cursorId]);return this.findApi(apiQuery).then(function(api){api.cursorDestroyed(clientId,cursorId,function(clientId,bundles){_this3.adapterSend(clientId,bundles)})})}}]);return ApiManager}();exports.default=ApiManager;
'use strict';Object.defineProperty(exports,'__esModule',{value:true});var _createClass=function(){function defineProperties(target,props){for(var i=0;i<props.length;i++){var descriptor=props[i];descriptor.enumerable=descriptor.enumerable||false;descriptor.configurable=true;if('value'in descriptor)descriptor.writable=true;Object.defineProperty(target,descriptor.key,descriptor)}}return function(Constructor,protoProps,staticProps){if(protoProps)defineProperties(Constructor.prototype,protoProps);if(staticProps)defineProperties(Constructor,staticProps);return Constructor}}();var _lodash=require('lodash');var _lodash2=_interopRequireDefault(_lodash);function _interopRequireDefault(obj){return obj&&obj.__esModule?obj:{default:obj}}function _classCallCheck(instance,Constructor){if(!(instance instanceof Constructor)){throw new TypeError('Cannot call a class as a function')}}var ApiManager=function(){function ApiManager(adapterFindApi,adapterSend){_classCallCheck(this,ApiManager);this.adapterFindApi=adapterFindApi;this.adapterSend=adapterSend;this.relations={}}_createClass(ApiManager,[{key:'findApi',value:function findApi(apiQuery){return this.adapterFindApi(apiQuery)}},{key:'receiveQuery',value:function receiveQuery(channelId,apiQuery,query,cursorId){var _this=this;return this.findApi(apiQuery).then(function(api){_lodash2.default.set(_this.relations,[channelId,cursorId],apiQuery);api.receiveQuery(channelId,query,cursorId,function(channelId,bundles){_this.adapterSend(channelId,bundles)});return api})}},{key:'channelDisconnected',value:function channelDisconnected(channelId){var _this2=this;var cursors=_lodash2.default.get(this.relations,[channelId]);var promises=[];var apis={};for(var cursorId in cursors){if(!apis[cursors[cursorId]]){apis[cursors[cursorId]]=true;promises.push(function(channelId,cursorId){return new Promise(function(){return _this2.findApi(cursors[cursorId]).then(function(api){_lodash2.default.set(_this2.relations,[channelId,cursorId],cursors[cursorId]);if(typeof api.channelDisconnected=='function'){api.channelDisconnected(channelId,function(channelId,bundles){_this2.adapterSend(channelId,bundles)})}return api})})}(channelId,cursorId))}promises.push(function(channelId,cursorId){return new Promise(function(){return _this2.cursorDestroyed(channelId,cursorId)})}(channelId,cursorId))}delete this.relations[channelId];return promises}},{key:'cursorDestroyed',value:function cursorDestroyed(channelId,cursorId){var _this3=this;var apiQuery=_lodash2.default.get(this.relations,[channelId,cursorId]);return this.findApi(apiQuery).then(function(api){if(typeof api.cursorDestroyed=='function'){api.cursorDestroyed(channelId,cursorId,function(channelId,bundles){_this3.adapterSend(channelId,bundles)})}})}}]);return ApiManager}();exports.default=ApiManager;
//# sourceMappingURL=ApiManager.js.map

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

'use strict';Object.defineProperty(exports,'__esModule',{value:true});var _createClass=function(){function defineProperties(target,props){for(var i=0;i<props.length;i++){var descriptor=props[i];descriptor.enumerable=descriptor.enumerable||false;descriptor.configurable=true;if('value'in descriptor)descriptor.writable=true;Object.defineProperty(target,descriptor.key,descriptor)}}return function(Constructor,protoProps,staticProps){if(protoProps)defineProperties(Constructor.prototype,protoProps);if(staticProps)defineProperties(Constructor,staticProps);return Constructor}}();var _lodash=require('lodash');var _lodash2=_interopRequireDefault(_lodash);var _events=require('events');var _events2=_interopRequireDefault(_events);function _interopRequireDefault(obj){return obj&&obj.__esModule?obj:{default:obj}}function _classCallCheck(instance,Constructor){if(!(instance instanceof Constructor)){throw new TypeError('Cannot call a class as a function')}}var Cursor=function(){function Cursor(query,data,adapterDestroyed,id){_classCallCheck(this,Cursor);this.query=query;this.data=data;this.adapterDestroyed=adapterDestroyed;this.id=id;this.emitter=new _events2.default}_createClass(Cursor,[{key:'set',value:function set(path,current){var _path=_lodash2.default.toPath(path);var oldByPath=_lodash2.default.get(this.data,_path);if(!_path.length)this.data=current;else this.data=_lodash2.default.set(this.data||{},_path,current);this.emitter.emit('changed',{old:oldByPath,path:_path,action:'set','arguments':_lodash2.default.toArray(arguments)})}},{key:'splice',value:function splice(path,start,deleteCount){for(var _len=arguments.length,items=Array(_len>3?_len-3:0),_key=3;_key<_len;_key++){items[_key-3]=arguments[_key]}var _path=_lodash2.default.toPath(path);var oldByPath=_lodash2.default.clone(_lodash2.default.get(this.data,_path));var data=this.get(_path);if(!_lodash2.default.isArray(data))throw new Error('Data by path is not an array.');data.splice.apply(data,[start,deleteCount].concat(items));this.emitter.emit('changed',{old:oldByPath,path:_path,action:'splice','arguments':_lodash2.default.toArray(arguments)})}},{key:'get',value:function get(){var path=arguments.length>0&&arguments[0]!==undefined?arguments[0]:null;var handler=arguments[1];this.on(path,handler);return _lodash2.default.isNull(path)?this.data:_lodash2.default.get(this.data,path)}},{key:'on',value:function on(){var _this=this;var path=arguments.length>0&&arguments[0]!==undefined?arguments[0]:null;var handler=arguments[1];var eventPath=_lodash2.default.toPath(path);if(typeof handler=='function'){var listener=function listener(changes){var isClone,oldValue,currentValue;var eventPathLocal=eventPath.slice(changes.path.length);if(changes.path.length<=eventPath.length){if(_lodash2.default.isEqual(changes.path,eventPath.slice(0,changes.path.length))){isClone=true;oldValue=eventPathLocal.length?_lodash2.default.get(changes.old,eventPathLocal):changes.old;currentValue=eventPath.length?_lodash2.default.get(_this.data,eventPath):_this.data}else return}else{if(_lodash2.default.isEqual(eventPath,changes.path.slice(0,eventPath.length))){isClone=false;oldValue=currentValue=eventPath.length?_lodash2.default.get(_this.data,eventPath):_this.data}else return}handler(oldValue,currentValue,stop,changes,isClone,_this)};var stop=function stop(){return _this.emitter.removeListener('changed',listener)};this.emitter.on('changed',listener);return stop}}},{key:'destroy',value:function destroy(){if(typeof this.adapterDestroyed=='function'){this.adapterDestroyed(this)}}}]);return Cursor}();exports.default=Cursor;
'use strict';Object.defineProperty(exports,'__esModule',{value:true});var _createClass=function(){function defineProperties(target,props){for(var i=0;i<props.length;i++){var descriptor=props[i];descriptor.enumerable=descriptor.enumerable||false;descriptor.configurable=true;if('value'in descriptor)descriptor.writable=true;Object.defineProperty(target,descriptor.key,descriptor)}}return function(Constructor,protoProps,staticProps){if(protoProps)defineProperties(Constructor.prototype,protoProps);if(staticProps)defineProperties(Constructor,staticProps);return Constructor}}();var _lodash=require('lodash');var _lodash2=_interopRequireDefault(_lodash);var _events=require('events');var _events2=_interopRequireDefault(_events);function _interopRequireDefault(obj){return obj&&obj.__esModule?obj:{default:obj}}function _classCallCheck(instance,Constructor){if(!(instance instanceof Constructor)){throw new TypeError('Cannot call a class as a function')}}var Cursor=function(){function Cursor(query,data,adapterDestroyed,id){_classCallCheck(this,Cursor);this.query=query;this.data=data;this.adapterDestroyed=adapterDestroyed;this.id=id;this.emitter=new _events2.default}_createClass(Cursor,[{key:'set',value:function set(path,current){var _path=_lodash2.default.toPath(path);var oldByPath=_lodash2.default.get(this.data,_path);if(!_path.length)this.data=current;else this.data=_lodash2.default.set(this.data||{},_path,current);this.emitter.emit('changed',{old:oldByPath,path:_path,action:'set','arguments':_lodash2.default.toArray(arguments)})}},{key:'splice',value:function splice(path,start,deleteCount){for(var _len=arguments.length,items=Array(_len>3?_len-3:0),_key=3;_key<_len;_key++){items[_key-3]=arguments[_key]}var _path=_lodash2.default.toPath(path);var oldByPath=_lodash2.default.clone(_lodash2.default.get(this.data,_path));var data=this.get(_path);if(!_lodash2.default.isArray(data))throw new Error('Data by path is not an array.');data.splice.apply(data,[start,deleteCount].concat(items));this.emitter.emit('changed',{old:oldByPath,path:_path,action:'splice','arguments':_lodash2.default.toArray(arguments)})}},{key:'get',value:function get(){var path=arguments.length>0&&arguments[0]!==undefined?arguments[0]:null;var handler=arguments[1];this.on(path,handler);return _lodash2.default.isNull(path)?this.data:_lodash2.default.get(this.data,path)}},{key:'_generateListener',value:function _generateListener(path,handler){var _this=this;var eventPath=_lodash2.default.toPath(path);var stop,listener;if(typeof handler=='function'){listener=function listener(changes){var isClone,oldValue,currentValue;var eventPathLocal=eventPath.slice(changes.path.length);if(changes.path.length<=eventPath.length){if(_lodash2.default.isEqual(changes.path,eventPath.slice(0,changes.path.length))){isClone=true;oldValue=eventPathLocal.length?_lodash2.default.get(changes.old,eventPathLocal):changes.old;currentValue=eventPath.length?_lodash2.default.get(_this.data,eventPath):_this.data}else return}else{if(_lodash2.default.isEqual(eventPath,changes.path.slice(0,eventPath.length))){isClone=false;oldValue=currentValue=eventPath.length?_lodash2.default.get(_this.data,eventPath):_this.data}else return}handler(oldValue,currentValue,stop,changes,isClone,_this)};stop=function stop(){return _this.emitter.removeListener('changed',listener)}}return{listener:listener,stop:stop}}},{key:'on',value:function on(){var path=arguments.length>0&&arguments[0]!==undefined?arguments[0]:null;var handler=arguments[1];var _generateListener2=this._generateListener(path,handler),listener=_generateListener2.listener,stop=_generateListener2.stop;if(listener)this.emitter.on('changed',listener);return stop}},{key:'once',value:function once(){var path=arguments.length>0&&arguments[0]!==undefined?arguments[0]:null;var handler=arguments[1];var _generateListener3=this._generateListener(path,handler),listener=_generateListener3.listener,stop=_generateListener3.stop;if(listener)this.emitter.once('changed',listener);return stop}},{key:'destroy',value:function destroy(){if(typeof this.adapterDestroyed=='function'){this.adapterDestroyed(this)}}}]);return Cursor}();exports.default=Cursor;
//# sourceMappingURL=Cursor.js.map
{
"name": "ancient-cursor",
"version": "0.0.7",
"version": "0.0.8",
"description": "Utilities for tracking changes of complex or plain remote data.",

@@ -5,0 +5,0 @@ "keywords": [

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

'use strict';var _chai=require('chai');var _lib=require('../lib');var _react=require('./react');var _react2=_interopRequireDefault(_react);var _lodash=require('lodash');var _lodash2=_interopRequireDefault(_lodash);var _mingo=require('mingo');var _mingo2=_interopRequireDefault(_mingo);function _interopRequireDefault(obj){return obj&&obj.__esModule?obj:{default:obj}}function _toConsumableArray(arr){if(Array.isArray(arr)){for(var i=0,arr2=Array(arr.length);i<arr.length;i++){arr2[i]=arr[i]}return arr2}else{return Array.from(arr)}}require('source-map-support').install();describe('AncientSouls/Cursor',function(){describe('Cursor',function(){it('get by path',function(){var document={any:[{custom:{many:'data'}}]};var cursor=new _lib.Cursor(true,document);_chai.assert.equal(cursor.get('any.0.custom.many'),'data')});it('get handle path current set changes',function(done){var document={any:[{custom:{many:'a'}}]};var cursor=new _lib.Cursor(true,document);var changesPattern={old:{many:'a'},path:['any','0','custom'],action:'set',arguments:['any.0.custom',{many:'b'}]};cursor.on('any.0.custom.many',function(old,current,stop,changes,isClone){_chai.assert.equal(old,'a');_chai.assert.equal(current,'b');_chai.assert.deepEqual(changes,changesPattern);_chai.assert.isTrue(isClone)});cursor.on('any.0.custom',function(old,current,stop,changes,isClone){_chai.assert.deepEqual(old,{many:'a'});_chai.assert.deepEqual(current,{many:'b'});_chai.assert.deepEqual(changes,changesPattern);_chai.assert.isTrue(isClone)});cursor.on('any.0',function(old,current,stop,changes,isClone){_chai.assert.deepEqual(old,{custom:{many:'b'}});_chai.assert.deepEqual(current,{custom:{many:'b'}});_chai.assert.deepEqual(changes,changesPattern);_chai.assert.isFalse(isClone);done()});cursor.set('any.0.custom',{many:'b'})});it('set',function(){var cursor=new _lib.Cursor(true,{a:[{b:'x'},{c:'y'},{d:'z'}]});cursor.set('a.0.b','z');_chai.assert.deepEqual(cursor.get('a.0'),{b:'z'});cursor.set('',{x:'y'});_chai.assert.deepEqual(cursor.get(),{x:'y'})});it('splice',function(done){var cursor=new _lib.Cursor(true,{a:[{b:'x'},{c:'y'},{d:'z'}],e:'f'});cursor.on('a.1',function(old,current,stop,changes,isClone){_chai.assert.deepEqual(old,{c:'y'});_chai.assert.deepEqual(current,{e:'q'});_chai.assert.isTrue(isClone);setTimeout(done,100)});cursor.on('a.0',function(old,current,stop,changes,isClone){_chai.assert.deepEqual(old,current);_chai.assert.isTrue(isClone)});cursor.on('e',function(old,current,stop,changes,isClone){throw new Error('It should not be')});cursor.splice('a',1,1,{e:'q'});_chai.assert.equal(cursor.get('a.1.e'),'q')});it('destroy',function(){var cursor=new _lib.Cursor(true,{a:[{b:'x'},{c:'y'},{d:'z'}],e:'f'});cursor.destroy()});it('destroy',function(){var cursor=new _lib.Cursor(true,{a:[{b:'x'},{c:'y'},{d:'z'}],e:'f'});cursor.destroy()})});describe('BundleQueuesManager',function(){it('set',function(done){var cm=new _lib.CursorsManager(_lib.Cursor);var bqm=new(Function.prototype.bind.apply(_lib.BundleQueuesManager,[null].concat(_toConsumableArray((0,_lib.generateAdapterForBundleQueuesManager)(cm).adapters))));var c=cm.new('any',{'some':'thing'});bqm.useBundle({id:5,cursor:c.id,type:'set',path:'some',value:'nothing'},function(){bqm.useBundle({id:1,cursor:c.id,type:'set',path:'some',value:'result'},function(){bqm.useBundle({id:0,cursor:c.id,type:'set',path:'some',value:'other'},function(){_chai.assert.deepEqual(c.get('some'),'result');done()})})})});it('unset',function(done){var cm=new _lib.CursorsManager(_lib.Cursor);var bqm=new(Function.prototype.bind.apply(_lib.BundleQueuesManager,[null].concat(_toConsumableArray((0,_lib.generateAdapterForBundleQueuesManager)(cm).adapters))));var c=cm.new('any',{'some':'thing'});bqm.useBundle({id:5,cursor:c.id,type:'set',path:'some',value:'nothing'},function(){bqm.useBundle({id:1,cursor:c.id,type:'unset',path:'some'},function(){bqm.useBundle({id:0,cursor:c.id,type:'set',path:'some',value:'other'},function(){_chai.assert.deepEqual(c.get('some'),undefined);done()})})})});it('splice',function(done){var cm=new _lib.CursorsManager(_lib.Cursor);var bqm=new(Function.prototype.bind.apply(_lib.BundleQueuesManager,[null].concat(_toConsumableArray((0,_lib.generateAdapterForBundleQueuesManager)(cm).adapters))));var c=cm.new('any',{'some':['things','and','others']});bqm.useBundle({id:1,cursor:c.id,type:'splice',path:'some',start:3,deleteCount:1,items:['nothing']},function(){bqm.useBundle({id:0,cursor:c.id,type:'splice',path:'some',start:2,deleteCount:0,items:['some']},function(){_chai.assert.deepEqual(c.get('some'),['things','and','some','nothing']);done()})})})});describe('ApiManager',function(){it('api instance must receive queries and send bundles',function(done){var counter=1;var interval;var manager=new _lib.ApiManager(function adapterFindApi(apiQuery){_chai.assert.equal(apiQuery,'a');function sendBundles(clientId,bundles){manager.adapterSend(clientId,bundles)};return new Promise(function(resolve){return resolve({receiveQuery:function receiveQuery(clientId,query,cursorId,sendBundles){_chai.assert.equal(clientId,2);_chai.assert.equal(query,null);_chai.assert.equal(cursorId,3);interval=setInterval(function(){sendBundles(clientId,++counter)},100)},cursorDestroyed:function cursorDestroyed(clientId,cursorId,sendBundles){_chai.assert.equal(clientId,2);_chai.assert.equal(cursorId,3);clearInterval(interval);done()}})})},function adapterSend(clientId,bundles){_chai.assert.equal(clientId,2);_chai.assert.equal(bundles,counter);if(counter>3){manager.clientDisconnected(clientId)}});manager.receiveQuery(2,'a',null,3)})});describe('CursorsManager',function(){it('just should works',function(){var manager=new _lib.CursorsManager(_lib.Cursor);var cursor=manager.new('any','thing');var id0=cursor.id;_chai.assert.equal(manager.cursors[cursor.id],cursor);cursor.destroy();_chai.assert.notProperty(manager.cursors,cursor.id);manager.renew(cursor,'other','something');var id1=cursor.id;_chai.assert.notEqual(id0,id1);_chai.assert.equal(cursor.query,'other');_chai.assert.equal(cursor.data,'something')})});describe('concepts',function(){it('fake primitive server-client with one api provider',function(){var server=function(){var cursor=new _lib.Cursor(undefined,{a:{b:[{c:'d'},{e:'f'}]}});var clientCursors={};cursor.on(null,function(old,current,stop){var bundles={};for(var c in clientCursors){var currentPerCursor=_lodash2.default.get(current,clientCursors[c].query);if(!_lodash2.default.isEqual(clientCursors[c].old,currentPerCursor)){clientCursors[c].old=currentPerCursor;bundles[c]={id:clientCursors[c].bundlesCounter,type:'set',cursor:c,path:'',value:currentPerCursor};clientCursors[c].bundlesCounter++}}client.changes(bundles)});var server={api:{cursor:cursor,clientCursors:clientCursors},request:function request(clientCursorId,query){var result=_lodash2.default.cloneDeep(cursor.get(query));if(!clientCursors[clientCursorId]){clientCursors[clientCursorId]={bundlesCounter:0,query:query,old:result}}return _lodash2.default.cloneDeep(result)}};return server}();var client=function(){var cm=new _lib.CursorsManager(_lib.Cursor);var bqm=new(Function.prototype.bind.apply(_lib.BundleQueuesManager,[null].concat(_toConsumableArray((0,_lib.generateAdapterForBundleQueuesManager)(cm).adapters))));return{api:{cm:cm,needData:function needData(query){var cursor=cm.new(query);var data=server.request(cursor.id,query);cursor.set(null,data);return cursor}},changes:function changes(bundles){for(var b in bundles){if(cm.cursors[bundles[b].cursor]){bqm.useBundle(bundles[b])}}}}}();var cursor1=client.api.needData('a');var cursor2=client.api.needData('a.b[0]');_chai.assert.deepEqual(cursor1.get(),server.api.cursor.get('a'));_chai.assert.deepEqual(cursor2.get('c'),server.api.cursor.get('a.b[0].c'));server.api.cursor.set('a.b[0].c','j');_chai.assert.deepEqual(cursor1.get(),server.api.cursor.get('a'));_chai.assert.deepEqual(cursor2.get('c'),server.api.cursor.get('a.b[0].c'));server.api.cursor.splice('a.b',0,1,'abrvalk');_chai.assert.deepEqual(cursor1.get(),server.api.cursor.get('a'));_chai.assert.deepEqual(cursor2.get(),server.api.cursor.get('a.b[0]'))});(0,_react2.default)()})});
'use strict';var _chai=require('chai');var _lib=require('../lib');var _react=require('./react');var _react2=_interopRequireDefault(_react);var _lodash=require('lodash');var _lodash2=_interopRequireDefault(_lodash);var _mingo=require('mingo');var _mingo2=_interopRequireDefault(_mingo);function _interopRequireDefault(obj){return obj&&obj.__esModule?obj:{default:obj}}function _toConsumableArray(arr){if(Array.isArray(arr)){for(var i=0,arr2=Array(arr.length);i<arr.length;i++){arr2[i]=arr[i]}return arr2}else{return Array.from(arr)}}require('source-map-support').install();describe('AncientSouls/Cursor',function(){describe('Cursor',function(){it('get by path',function(){var document={any:[{custom:{many:'data'}}]};var cursor=new _lib.Cursor(true,document);_chai.assert.equal(cursor.get('any.0.custom.many'),'data')});it('get handle path current set changes',function(done){var document={any:[{custom:{many:'a'}}]};var cursor=new _lib.Cursor(true,document);var changesPattern={old:{many:'a'},path:['any','0','custom'],action:'set',arguments:['any.0.custom',{many:'b'}]};cursor.on('any.0.custom.many',function(old,current,stop,changes,isClone){_chai.assert.equal(old,'a');_chai.assert.equal(current,'b');_chai.assert.deepEqual(changes,changesPattern);_chai.assert.isTrue(isClone)});cursor.on('any.0.custom',function(old,current,stop,changes,isClone){_chai.assert.deepEqual(old,{many:'a'});_chai.assert.deepEqual(current,{many:'b'});_chai.assert.deepEqual(changes,changesPattern);_chai.assert.isTrue(isClone)});cursor.on('any.0',function(old,current,stop,changes,isClone){_chai.assert.deepEqual(old,{custom:{many:'b'}});_chai.assert.deepEqual(current,{custom:{many:'b'}});_chai.assert.deepEqual(changes,changesPattern);_chai.assert.isFalse(isClone);done()});cursor.set('any.0.custom',{many:'b'})});it('set',function(){var cursor=new _lib.Cursor(true,{a:[{b:'x'},{c:'y'},{d:'z'}]});cursor.set('a.0.b','z');_chai.assert.deepEqual(cursor.get('a.0'),{b:'z'});cursor.set('',{x:'y'});_chai.assert.deepEqual(cursor.get(),{x:'y'})});it('splice',function(done){var cursor=new _lib.Cursor(true,{a:[{b:'x'},{c:'y'},{d:'z'}],e:'f'});cursor.on('a.1',function(old,current,stop,changes,isClone){_chai.assert.deepEqual(old,{c:'y'});_chai.assert.deepEqual(current,{e:'q'});_chai.assert.isTrue(isClone);setTimeout(done,100)});cursor.on('a.0',function(old,current,stop,changes,isClone){_chai.assert.deepEqual(old,current);_chai.assert.isTrue(isClone)});cursor.on('e',function(old,current,stop,changes,isClone){throw new Error('It should not be')});cursor.splice('a',1,1,{e:'q'});_chai.assert.equal(cursor.get('a.1.e'),'q')});it('destroy',function(){var cursor=new _lib.Cursor(true,{a:[{b:'x'},{c:'y'},{d:'z'}],e:'f'});cursor.destroy()});it('destroy',function(){var cursor=new _lib.Cursor(true,{a:[{b:'x'},{c:'y'},{d:'z'}],e:'f'});cursor.destroy()});it('once',function(done){var cursor=new _lib.Cursor(true,'a');cursor.on('',function(old,current){if(current=='c')done()});cursor.once('',function(old,current){_chai.assert.equal(current,'b')});cursor.set('','b');cursor.set('','c')})});describe('BundleQueuesManager',function(){it('set',function(done){var cm=new _lib.CursorsManager(_lib.Cursor);var bqm=new(Function.prototype.bind.apply(_lib.BundleQueuesManager,[null].concat(_toConsumableArray((0,_lib.generateAdapterForBundleQueuesManager)(cm).adapters))));var c=cm.new('any',{'some':'thing'});bqm.useBundle({id:5,cursor:c.id,type:'set',path:'some',value:'nothing'},function(){bqm.useBundle({id:1,cursor:c.id,type:'set',path:'some',value:'result'},function(){bqm.useBundle({id:0,cursor:c.id,type:'set',path:'some',value:'other'},function(){_chai.assert.deepEqual(c.get('some'),'result');done()})})})});it('unset',function(done){var cm=new _lib.CursorsManager(_lib.Cursor);var bqm=new(Function.prototype.bind.apply(_lib.BundleQueuesManager,[null].concat(_toConsumableArray((0,_lib.generateAdapterForBundleQueuesManager)(cm).adapters))));var c=cm.new('any',{'some':'thing'});bqm.useBundle({id:5,cursor:c.id,type:'set',path:'some',value:'nothing'},function(){bqm.useBundle({id:1,cursor:c.id,type:'unset',path:'some'},function(){bqm.useBundle({id:0,cursor:c.id,type:'set',path:'some',value:'other'},function(){_chai.assert.deepEqual(c.get('some'),undefined);done()})})})});it('splice',function(done){var cm=new _lib.CursorsManager(_lib.Cursor);var bqm=new(Function.prototype.bind.apply(_lib.BundleQueuesManager,[null].concat(_toConsumableArray((0,_lib.generateAdapterForBundleQueuesManager)(cm).adapters))));var c=cm.new('any',{'some':['things','and','others']});bqm.useBundle({id:1,cursor:c.id,type:'splice',path:'some',start:3,deleteCount:1,items:['nothing']},function(){bqm.useBundle({id:0,cursor:c.id,type:'splice',path:'some',start:2,deleteCount:0,items:['some']},function(){_chai.assert.deepEqual(c.get('some'),['things','and','some','nothing']);done()})})})});describe('ApiManager',function(){it('api instance must receive queries and send bundles',function(done){var counter=1;var interval;var disconnected=false;var manager=new _lib.ApiManager(function adapterFindApi(apiQuery){_chai.assert.equal(apiQuery,'a');function sendBundles(channelId,bundles){manager.adapterSend(channelId,bundles)};return new Promise(function(resolve){return resolve({receiveQuery:function receiveQuery(channelId,query,cursorId,sendBundles){_chai.assert.equal(channelId,2);_chai.assert.equal(query,null);_chai.assert.equal(cursorId,3);interval=setInterval(function(){sendBundles(channelId,++counter)},100)},cursorDestroyed:function cursorDestroyed(channelId,cursorId,sendBundles){_chai.assert.equal(channelId,2);_chai.assert.equal(cursorId,3);clearInterval(interval);_chai.assert.equal(disconnected,true);done()},channelDisconnected:function channelDisconnected(channelId,sendBundles){_chai.assert.equal(disconnected,false);disconnected=true}})})},function adapterSend(channelId,bundles){_chai.assert.equal(channelId,2);_chai.assert.equal(bundles,counter);if(counter>3){manager.channelDisconnected(channelId)}});manager.receiveQuery(2,'a',null,3)})});describe('CursorsManager',function(){it('just should works',function(){var manager=new _lib.CursorsManager(_lib.Cursor);var cursor=manager.new('any','thing');var id0=cursor.id;_chai.assert.equal(manager.cursors[cursor.id],cursor);cursor.destroy();_chai.assert.notProperty(manager.cursors,cursor.id);manager.renew(cursor,'other','something');var id1=cursor.id;_chai.assert.notEqual(id0,id1);_chai.assert.equal(cursor.query,'other');_chai.assert.equal(cursor.data,'something')})});describe('concepts',function(){it('fake primitive server-channel with one api provider',function(){var server=function(){var cursor=new _lib.Cursor(undefined,{a:{b:[{c:'d'},{e:'f'}]}});var channelCursors={};cursor.on(null,function(old,current,stop){var bundles={};for(var c in channelCursors){var currentPerCursor=_lodash2.default.get(current,channelCursors[c].query);if(!_lodash2.default.isEqual(channelCursors[c].old,currentPerCursor)){channelCursors[c].old=currentPerCursor;bundles[c]={id:channelCursors[c].bundlesCounter,type:'set',cursor:c,path:'',value:currentPerCursor};channelCursors[c].bundlesCounter++}}channel.changes(bundles)});var server={api:{cursor:cursor,channelCursors:channelCursors},request:function request(channelCursorId,query){var result=_lodash2.default.cloneDeep(cursor.get(query));if(!channelCursors[channelCursorId]){channelCursors[channelCursorId]={bundlesCounter:0,query:query,old:result}}return _lodash2.default.cloneDeep(result)}};return server}();var channel=function(){var cm=new _lib.CursorsManager(_lib.Cursor);var bqm=new(Function.prototype.bind.apply(_lib.BundleQueuesManager,[null].concat(_toConsumableArray((0,_lib.generateAdapterForBundleQueuesManager)(cm).adapters))));return{api:{cm:cm,needData:function needData(query){var cursor=cm.new(query);var data=server.request(cursor.id,query);cursor.set(null,data);return cursor}},changes:function changes(bundles){for(var b in bundles){if(cm.cursors[bundles[b].cursor]){bqm.useBundle(bundles[b])}}}}}();var cursor1=channel.api.needData('a');var cursor2=channel.api.needData('a.b[0]');_chai.assert.deepEqual(cursor1.get(),server.api.cursor.get('a'));_chai.assert.deepEqual(cursor2.get('c'),server.api.cursor.get('a.b[0].c'));server.api.cursor.set('a.b[0].c','j');_chai.assert.deepEqual(cursor1.get(),server.api.cursor.get('a'));_chai.assert.deepEqual(cursor2.get('c'),server.api.cursor.get('a.b[0].c'));server.api.cursor.splice('a.b',0,1,'abrvalk');_chai.assert.deepEqual(cursor1.get(),server.api.cursor.get('a'));_chai.assert.deepEqual(cursor2.get(),server.api.cursor.get('a.b[0]'))});(0,_react2.default)()})});
//# sourceMappingURL=index.js.map

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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