ancient-cursor
Advanced tools
Comparing version 0.0.3 to 0.0.4
@@ -0,1 +1,9 @@ | ||
#### 0.0.4 (2017-9-7) | ||
##### Bug Fixes | ||
* **exports** Fix index import/export | ||
* **test** Fix test name | ||
* **jsdoc** JSDoc fixes | ||
#### 0.0.3 (2017-9-6) | ||
@@ -2,0 +10,0 @@ |
@@ -1,6 +0,8 @@ | ||
'use strict';Object.defineProperty(exports,'__esModule',{value:true});exports.ApiManager=undefined;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')}}/** | ||
'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')}}/** | ||
* Interface for Api instance returnable from custom `adapterFindApi`. | ||
* @interface Api | ||
* @memberof module:ancient-cursor | ||
*//** | ||
* @function | ||
* @memberof module:ancient-cursor | ||
* @name Api#receiveQuery | ||
@@ -13,2 +15,3 @@ * @param {UniqueId} channelId | ||
* @function | ||
* @memberof module:ancient-cursor | ||
* @name Api#channelDisconnected | ||
@@ -19,2 +22,3 @@ * @param {UniqueId} channelId | ||
* @function | ||
* @memberof module:ancient-cursor | ||
* @name Api#cursorDestroyed | ||
@@ -26,2 +30,3 @@ * @param {UniqueId} channelId | ||
* @callback ApiManager~sendBundles | ||
* @memberof module:ancient-cursor | ||
* @param {UniqueId} channelId | ||
@@ -31,3 +36,5 @@ * @param {Bundle[]} bundles | ||
* Manager of many api for sync data with cursors. | ||
*/var ApiManager=exports.ApiManager=function(){/** | ||
* @class | ||
* @memberof module:ancient-cursor | ||
*/var ApiManager=function(){/** | ||
* @constructs ApiManager | ||
@@ -56,2 +63,3 @@ * @param {ApiManager~adapterFindApi} adapterFindApi | ||
* @callback ApiManager~adapterFindApi | ||
* @memberof module:ancient-cursor | ||
* @param {Query} apiQuery | ||
@@ -63,2 +71,3 @@ * @returns {Promise} - {@link ApiObject} | ||
* @callback ApiManager~adapterSend | ||
* @memberof module:ancient-cursor | ||
* @param {UniqueId} channelId | ||
@@ -68,3 +77,3 @@ * @param {Bundle[]} bundles | ||
* Must be sended into `ApiManager` into constructor. Used for send bundles from api to cursor into current and channelId within custom application logic. | ||
*/ | ||
*/exports.default=ApiManager; | ||
//# sourceMappingURL=ApiManager.js.map |
'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}}();function _classCallCheck(instance,Constructor){if(!(instance instanceof Constructor)){throw new TypeError('Cannot call a class as a function')}}/** | ||
* Queue of bundles execution. | ||
* You must override _handler, for parse bandles for your cursors. | ||
*/var BundlesQueue=exports.BundlesQueue=function(){/** | ||
* @class | ||
* @memberof module:ancient-cursor | ||
*/var BundlesQueue=function(){/** | ||
* @constructs BundlesQueue | ||
@@ -18,3 +20,3 @@ */function BundlesQueue(){_classCallCheck(this,BundlesQueue);this.nextId=0;this.handling=false;this.queue={}}/** | ||
* You must overrided this method, which would somehow handle each bandle. | ||
*/},{key:'_handler',value:function _handler(id,task,done){throw new Error('Method _handler must be overrided.')}}]);return BundlesQueue}(); | ||
*/},{key:'_handler',value:function _handler(id,task,done){throw new Error('Method _handler must be overrided.')}}]);return BundlesQueue}();exports.default=BundlesQueue; | ||
//# sourceMappingURL=BundlesQueue.js.map |
@@ -1,4 +0,6 @@ | ||
'use strict';Object.defineProperty(exports,'__esModule',{value:true});exports.Cursor=undefined;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')}}/** | ||
'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')}}/** | ||
* One query capsule. | ||
*/var Cursor=exports.Cursor=function(){/** | ||
* @class | ||
* @memberof module:ancient-cursor | ||
*/var Cursor=function(){/** | ||
* @constructs Cursor | ||
@@ -33,2 +35,3 @@ * @param query - Query resolves current cursor .We keep it just in case. Suddenly, to work with data, you need to compare them with the query? | ||
* @callback Cursor~handler | ||
* @memberof module:ancient-cursor | ||
* @param old - Link to this data old the change. | ||
@@ -46,3 +49,3 @@ * @param current - Link to this data current the change. | ||
* **Attention!** If the path leads to a higher level of data from the changed, the link to the data `old` the change will lead to the same location as link `current` the change. If the path leads to a changed level or deeper, then `old` and `current` will differ. | ||
*/ | ||
*/exports.default=Cursor; | ||
//# sourceMappingURL=Cursor.js.map |
'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}}();function _classCallCheck(instance,Constructor){if(!(instance instanceof Constructor)){throw new TypeError('Cannot call a class as a function')}}/** | ||
* A small registrar of cursors. Sends into Cursor constructor unique id and link to current manager. | ||
*/var CursorsManager=exports.CursorsManager=function(){function CursorsManager(){var Cursor=arguments.length>0&&arguments[0]!==undefined?arguments[0]:Cursor;var adapterCursorDestroyed=arguments[1];var adapterCustorConstructed=arguments[2];_classCallCheck(this,CursorsManager);this.Cursor=Cursor;this.cursors={};this.nextId=0;this.adapterCursorDestroyed=adapterCursorDestroyed;this.adapterCustorConstructed=adapterCustorConstructed}/** | ||
* @class | ||
* @memberof module:ancient-cursor | ||
*/var CursorsManager=function(){function CursorsManager(){var Cursor=arguments.length>0&&arguments[0]!==undefined?arguments[0]:Cursor;var adapterCursorDestroyed=arguments[1];var adapterCustorConstructed=arguments[2];_classCallCheck(this,CursorsManager);this.Cursor=Cursor;this.cursors={};this.nextId=0;this.adapterCursorDestroyed=adapterCursorDestroyed;this.adapterCustorConstructed=adapterCustorConstructed}/** | ||
* Constructs new {@link CursorsManager#Cursor} with unique id within current manager. Set constructed cursor into `this.cursors`. Call `this.adapterCustorConstructed` method. | ||
@@ -20,2 +22,3 @@ * @param query | ||
* @callback CursorManager~adapterCursorDestroyed | ||
* @memberof module:ancient-cursor | ||
* @param {Cursor} cursor | ||
@@ -26,6 +29,7 @@ * @description | ||
* @callback CursorManager~adapterCustorConstructed | ||
* @memberof module:ancient-cursor | ||
* @param {Cursor} cursor | ||
* @description | ||
* Can be sended into `ApiManager` into constructor. Used for handle cursor constructed event. For example you can send it information to some api within `ApiManager`. | ||
*/ | ||
*/exports.default=CursorsManager; | ||
//# sourceMappingURL=CursorsManager.js.map |
@@ -1,2 +0,4 @@ | ||
'use strict';Object.defineProperty(exports,'__esModule',{value:true});exports.executers=exports.ApiManager=exports.CursorsManager=exports.BundlesQueue=exports.Cursor=undefined;exports.executeBundle=executeBundle;exports.executeBundleSet=executeBundleSet;exports.executeBundleUnset=executeBundleUnset;exports.executeBundleSplice=executeBundleSplice;var _repl=require('repl');var _repl2=_interopRequireDefault(_repl);var _lodash=require('lodash');var _lodash2=_interopRequireDefault(_lodash);var _events=require('events');var _events2=_interopRequireDefault(_events);var _Cursor=require('./Cursor');var _BundlesQueue=require('./BundlesQueue');var _CursorsManager=require('./CursorsManager');var _ApiManager=require('./ApiManager');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)}}exports.Cursor=_Cursor.Cursor;exports.BundlesQueue=_BundlesQueue.BundlesQueue;exports.CursorsManager=_CursorsManager.CursorsManager;exports.ApiManager=_ApiManager.ApiManager;/** | ||
'use strict';Object.defineProperty(exports,'__esModule',{value:true});exports.executers=exports.ApiManager=exports.CursorsManager=exports.BundlesQueue=exports.Cursor=undefined;exports.executeBundle=executeBundle;exports.executeBundleSet=executeBundleSet;exports.executeBundleUnset=executeBundleUnset;exports.executeBundleSplice=executeBundleSplice;var _repl=require('repl');var _repl2=_interopRequireDefault(_repl);var _lodash=require('lodash');var _lodash2=_interopRequireDefault(_lodash);var _events=require('events');var _events2=_interopRequireDefault(_events);var _Cursor=require('./Cursor');var _Cursor2=_interopRequireDefault(_Cursor);var _BundlesQueue=require('./BundlesQueue');var _BundlesQueue2=_interopRequireDefault(_BundlesQueue);var _CursorsManager=require('./CursorsManager');var _CursorsManager2=_interopRequireDefault(_CursorsManager);var _ApiManager=require('./ApiManager');var _ApiManager2=_interopRequireDefault(_ApiManager);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)}}/** | ||
* @module ancient-cursor | ||
*/exports.Cursor=_Cursor2.default;exports.BundlesQueue=_BundlesQueue2.default;exports.CursorsManager=_CursorsManager2.default;exports.ApiManager=_ApiManager2.default;/** | ||
* @typedef {Object} Bundle | ||
@@ -3,0 +5,0 @@ * @property {number} cursor - id of cursor on current client |
{ | ||
"name": "ancient-cursor", | ||
"version": "0.0.3", | ||
"version": "0.0.4", | ||
"description": "Utilities for tracking changes of complex or plain remote data.", | ||
@@ -59,3 +59,2 @@ "keywords": [ | ||
"compile": "babel --presets es2015,react -d ./ src/ -s --minified", | ||
"compile-w": "babel --presets es2015,react -d ./ src/ -s --minified -w", | ||
"test": "mocha tests/index.js --require source-map-support/register", | ||
@@ -62,0 +61,0 @@ "jsdoc": "git submodule update --init --recursive -f && cd ./doc && git checkout gh-pages && cd ../ && npm i && rm -f -r ./doc/*/ && find ./doc ! -name '.git' -type f -exec rm -rf {} + && jsdoc ./src/lib/*.js ./README.md -r -d ./doc -t ./node_modules/minami -c ./jsdoc.conf.json", |
@@ -1,2 +0,2 @@ | ||
'use strict';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 _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 _classCallCheck(instance,Constructor){if(!(instance instanceof Constructor)){throw new TypeError('Cannot call a class as a function')}}function _possibleConstructorReturn(self,call){if(!self){throw new ReferenceError('this hasn\'t been initialised - super() hasn\'t been called')}return call&&(typeof call==='object'||typeof call==='function')?call:self}function _inherits(subClass,superClass){if(typeof superClass!=='function'&&superClass!==null){throw new TypeError('Super expression must either be null or a function, not '+typeof superClass)}subClass.prototype=Object.create(superClass&&superClass.prototype,{constructor:{value:subClass,enumerable:false,writable:true,configurable:true}});if(superClass)Object.setPrototypeOf?Object.setPrototypeOf(subClass,superClass):subClass.__proto__=superClass}require('source-map-support').install();var BundlesQueue=function(_BundlesQueueProto){_inherits(BundlesQueue,_BundlesQueueProto);function BundlesQueue(){_classCallCheck(this,BundlesQueue);return _possibleConstructorReturn(this,(BundlesQueue.__proto__||Object.getPrototypeOf(BundlesQueue)).apply(this,arguments))}_createClass(BundlesQueue,[{key:'_handler',value:function _handler(id,task,done){task();done()}}]);return BundlesQueue}(_lib.BundlesQueue);describe('AncientSouls/Graph',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('BundlesQueue',function(){it('only nextId bundle can be handled',function(){var testString='';var queue=new BundlesQueue;queue.addBundle(2,function(){return testString+='c'});queue.addBundle(1,function(){return testString+='b'});queue.addBundle(0,function(){return testString+='a'});queue.addBundle(3,function(){return testString+='d'});_chai.assert.equal(testString,'abcd')})});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(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);done()}})})},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('bundles',function(){it('set',function(){var manager=new _lib.CursorsManager(_lib.Cursor);var cursor=manager.new('any',{'some':'thing'});(0,_lib.executeBundle)({cursor:cursor.id,type:'set',path:'some',value:'other'},cursor,_lib.executers);_chai.assert.deepEqual(cursor.get('some'),'other')});it('unset',function(){var manager=new _lib.CursorsManager(_lib.Cursor);var cursor=manager.new('any',{'some':'thing'});(0,_lib.executeBundle)({cursor:cursor.id,type:'unset',path:'some'},cursor,_lib.executers);_chai.assert.deepEqual(cursor.get('some'),undefined)});it('splice',function(){var manager=new _lib.CursorsManager(_lib.Cursor);var cursor=manager.new('any',{'some':['things','and','others']});(0,_lib.executeBundle)({cursor:cursor.id,type:'splice',path:'some',start:2,deleteCount:0,items:['some']},cursor,_lib.executers);_chai.assert.deepEqual(cursor.get('some'),['things','and','some','others'])})});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 ClientBundlesQueue=function(_BundlesQueueProto2){_inherits(ClientBundlesQueue,_BundlesQueueProto2);function ClientBundlesQueue(cursor){_classCallCheck(this,ClientBundlesQueue);var _this2=_possibleConstructorReturn(this,(ClientBundlesQueue.__proto__||Object.getPrototypeOf(ClientBundlesQueue)).call(this));_this2.cursor=cursor;return _this2}_createClass(ClientBundlesQueue,[{key:'_handler',value:function _handler(id,task,done){(0,_lib.executeBundle)(task,this.cursor,_lib.executers);done()}}]);return ClientBundlesQueue}(_lib.BundlesQueue);var manager=new _lib.CursorsManager(function(_Cursor){_inherits(_class,_Cursor);function _class(){_classCallCheck(this,_class);var _this3=_possibleConstructorReturn(this,(_class.__proto__||Object.getPrototypeOf(_class)).apply(this,arguments));_this3.bundlesQueue=new ClientBundlesQueue(_this3);return _this3}return _class}(_lib.Cursor));return{api:{manager:manager,needData:function needData(query){var cursor=manager.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(manager.cursors[bundles[b].cursor]){manager.cursors[bundles[b].cursor].bundlesQueue.addBundle(bundles[b].id,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 _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 _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 _classCallCheck(instance,Constructor){if(!(instance instanceof Constructor)){throw new TypeError('Cannot call a class as a function')}}function _possibleConstructorReturn(self,call){if(!self){throw new ReferenceError('this hasn\'t been initialised - super() hasn\'t been called')}return call&&(typeof call==='object'||typeof call==='function')?call:self}function _inherits(subClass,superClass){if(typeof superClass!=='function'&&superClass!==null){throw new TypeError('Super expression must either be null or a function, not '+typeof superClass)}subClass.prototype=Object.create(superClass&&superClass.prototype,{constructor:{value:subClass,enumerable:false,writable:true,configurable:true}});if(superClass)Object.setPrototypeOf?Object.setPrototypeOf(subClass,superClass):subClass.__proto__=superClass}require('source-map-support').install();var BundlesQueue=function(_BundlesQueueProto){_inherits(BundlesQueue,_BundlesQueueProto);function BundlesQueue(){_classCallCheck(this,BundlesQueue);return _possibleConstructorReturn(this,(BundlesQueue.__proto__||Object.getPrototypeOf(BundlesQueue)).apply(this,arguments))}_createClass(BundlesQueue,[{key:'_handler',value:function _handler(id,task,done){task();done()}}]);return BundlesQueue}(_lib.BundlesQueue);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('BundlesQueue',function(){it('only nextId bundle can be handled',function(){var testString='';var queue=new BundlesQueue;queue.addBundle(2,function(){return testString+='c'});queue.addBundle(1,function(){return testString+='b'});queue.addBundle(0,function(){return testString+='a'});queue.addBundle(3,function(){return testString+='d'});_chai.assert.equal(testString,'abcd')})});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(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);done()}})})},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('bundles',function(){it('set',function(){var manager=new _lib.CursorsManager(_lib.Cursor);var cursor=manager.new('any',{'some':'thing'});(0,_lib.executeBundle)({cursor:cursor.id,type:'set',path:'some',value:'other'},cursor,_lib.executers);_chai.assert.deepEqual(cursor.get('some'),'other')});it('unset',function(){var manager=new _lib.CursorsManager(_lib.Cursor);var cursor=manager.new('any',{'some':'thing'});(0,_lib.executeBundle)({cursor:cursor.id,type:'unset',path:'some'},cursor,_lib.executers);_chai.assert.deepEqual(cursor.get('some'),undefined)});it('splice',function(){var manager=new _lib.CursorsManager(_lib.Cursor);var cursor=manager.new('any',{'some':['things','and','others']});(0,_lib.executeBundle)({cursor:cursor.id,type:'splice',path:'some',start:2,deleteCount:0,items:['some']},cursor,_lib.executers);_chai.assert.deepEqual(cursor.get('some'),['things','and','some','others'])})});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 ClientBundlesQueue=function(_BundlesQueueProto2){_inherits(ClientBundlesQueue,_BundlesQueueProto2);function ClientBundlesQueue(cursor){_classCallCheck(this,ClientBundlesQueue);var _this2=_possibleConstructorReturn(this,(ClientBundlesQueue.__proto__||Object.getPrototypeOf(ClientBundlesQueue)).call(this));_this2.cursor=cursor;return _this2}_createClass(ClientBundlesQueue,[{key:'_handler',value:function _handler(id,task,done){(0,_lib.executeBundle)(task,this.cursor,_lib.executers);done()}}]);return ClientBundlesQueue}(_lib.BundlesQueue);var manager=new _lib.CursorsManager(function(_Cursor){_inherits(_class,_Cursor);function _class(){_classCallCheck(this,_class);var _this3=_possibleConstructorReturn(this,(_class.__proto__||Object.getPrototypeOf(_class)).apply(this,arguments));_this3.bundlesQueue=new ClientBundlesQueue(_this3);return _this3}return _class}(_lib.Cursor));return{api:{manager:manager,needData:function needData(query){var cursor=manager.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(manager.cursors[bundles[b].cursor]){manager.cursors[bundles[b].cursor].bundlesQueue.addBundle(bundles[b].id,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)()})}); | ||
//# 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
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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Native code
Supply chain riskContains native code (e.g., compiled binaries or shared libraries). Including native code can obscure malicious behavior.
Found 14 instances in 1 package
Mixed license
License(Experimental) Package contains multiple licenses.
Found 1 instance in 1 package
0
1
88026
23
291