Socket
Socket
Sign inDemoInstall

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.4 to 0.0.5

doc/ApiManager.js.html

6

CHANGELOG.md

@@ -0,1 +1,7 @@

#### 0.0.5 (2017-9-8)
##### Refactor
* **client** Rename channels to clients
#### 0.0.4 (2017-9-7)

@@ -2,0 +8,0 @@

72

lib/ApiManager.js

@@ -1,72 +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')}}/**
* Interface for Api instance returnable from custom `adapterFindApi`.
* @interface Api
* @memberof module:ancient-cursor
*//**
* @function
* @memberof module:ancient-cursor
* @name Api#receiveQuery
* @param {UniqueId} channelId
* @param {Query} query
* @param {UniqueId} cursorId
* @param {Api~sendBundles} sendBundles
*//**
* @function
* @memberof module:ancient-cursor
* @name Api#channelDisconnected
* @param {UniqueId} channelId
* @param {Api~sendBundles} sendBundles
*//**
* @function
* @memberof module:ancient-cursor
* @name Api#cursorDestroyed
* @param {UniqueId} channelId
* @param {UniqueId} cursorId
* @param {Api~sendBundles} sendBundles
*//**
* @callback ApiManager~sendBundles
* @memberof module:ancient-cursor
* @param {UniqueId} channelId
* @param {Bundle[]} bundles
*//**
* Manager of many api for sync data with cursors.
* @class
* @memberof module:ancient-cursor
*/var ApiManager=function(){/**
* @constructs ApiManager
* @param {ApiManager~adapterFindApi} adapterFindApi
* @param {ApiManager~adapterSend} adapterSend
*/function ApiManager(adapterFindApi,adapterSend){_classCallCheck(this,ApiManager);this.adapterFindApi=adapterFindApi;this.adapterSend=adapterSend;this.relations={}}/**
* Find api object.
* @param {Query} apiQuery
* @returns {Promise} - {@link ApiObject}
*/_createClass(ApiManager,[{key:'findApi',value:function findApi(apiQuery){return this.adapterFindApi(apiQuery)}/**
* Receive some query from some channelId, with possible need to sync result with some cursorId on channel cursors namespace.
* @param {UniqueId} channelId
* @param {Query} apiQuery
* @param {Query} query
* @param {UniqueId} cursorId
* @returns {Promise} - {@link ApiObject}
*/},{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})}/**
* Call channelDisconnected method apply cursorDestroyed for each cursor used in current channelId.
* @param {UniqueId} channelId
*/},{key:'channelDisconnected',value:function channelDisconnected(channelId){var _this2=this;var cursors=_lodash2.default.get(this.relations,[channelId]);var promises=[];for(var cursorId in cursors){promises.push(function(channelId,cursorId){return new Promise(function(){return _this2.cursorDestroyed(channelId,cursorId)})}(channelId,cursorId))}return promises}/**
* Call cursorDestroyed method into api serving for current cursor sync.
* @param {UniqueId} channelId
* @param {UniqueId} cursorId
*/},{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){api.cursorDestroyed(channelId,cursorId,function(channelId,bundles){_this3.adapterSend(channelId,bundles)})})}}]);return ApiManager}();/**
* @callback ApiManager~adapterFindApi
* @memberof module:ancient-cursor
* @param {Query} apiQuery
* @returns {Promise} - {@link ApiObject}
* @description
* Must be sended into `ApiManager` into constructor. Used for found api instance by apiQuery, from custom application storage logic.
*//**
* @callback ApiManager~adapterSend
* @memberof module:ancient-cursor
* @param {UniqueId} channelId
* @param {Bundle[]} bundles
* @description
* 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;
'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;
//# sourceMappingURL=ApiManager.js.map

@@ -1,21 +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}}();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.
* @class
* @memberof module:ancient-cursor
*/var BundlesQueue=function(){/**
* @constructs BundlesQueue
*/function BundlesQueue(){_classCallCheck(this,BundlesQueue);this.nextId=0;this.handling=false;this.queue={}}/**
* Add received bundles into queue.
* @param {number} id
* @param task - Any data for your _handler.
*/_createClass(BundlesQueue,[{key:'addBundle',value:function addBundle(id,task){this.queue[id]=task;this.handleNext()}/**
* Handle next possible bundle from queue.
* Do not do anything if there is no next mandatory bundle in queue.
* It is called automatically current each {@link BundlesQueue#addBundle}
*/},{key:'handleNext',value:function handleNext(){var _this=this;/**
* @todo May be need protect from call stack, as timeout 0 or some think as...
*/if(this.handling)return;if(this.queue[this.nextId]){this.handling=true;this._handler(this.nextId,this.queue[this.nextId],function(){_this.handling=false;delete _this.queue[_this.nextId];_this.nextId++;_this.handleNext()})}}/**
* 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}();exports.default=BundlesQueue;
'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')}}var BundlesQueue=function(){function BundlesQueue(){_classCallCheck(this,BundlesQueue);this.nextId=0;this.handling=false;this.queue={}}_createClass(BundlesQueue,[{key:'addBundle',value:function addBundle(id,task){this.queue[id]=task;this.handleNext()}},{key:'handleNext',value:function handleNext(){var _this=this;if(this.handling)return;if(this.queue[this.nextId]){this.handling=true;this._handler(this.nextId,this.queue[this.nextId],function(){_this.handling=false;delete _this.queue[_this.nextId];_this.nextId++;_this.handleNext()})}}},{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,49 +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')}}/**
* One query capsule.
* @class
* @memberof module:ancient-cursor
*/var Cursor=function(){/**
* @constructs Cursor
* @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?
* @param data - Any data by resolved query.
*/function Cursor(query,data,manager,id){_classCallCheck(this,Cursor);this.query=query;this.data=data;this.manager=manager;this.id=id;this.emitter=new _events2.default}/**
* Way to change data changes in specified path.
* @param {string|string[]} path
* @param current
*/_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)})}/**
* Way to change array data in specified path. Unlike the standard splice, all arguments are required, except items.
* @param {string|string[]} path
* @param {number} start
* @param {number} deleteCount
* @param {...*} [items]
*/},{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)})}/**
* Getter from data. Handler can observe changes by current path in data.
* @param {string|string[]} path
* @param {Cursor~handler} [handler] - Notify you about changes in data by path.
* @return data - Returns someting from data by spcefied path.
*/},{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)}/**
* Handle event changed, as get handler argument, but returns stop method.
* @param {string|string[]} path
* @param {Cursor~handler} [handler] - Notify you about changes in data by path.
* @return {Function} stop
*/},{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}}/**
* Destroy current cursor.
* If cursor constructed from CursorsManager, then call `this.manager.cursorDestroyed` method. It remove cursor from `this.manager.cursors` and unset `this.id`.
* Has no other effects.
*/},{key:'destroy',value:function destroy(){if(this.manager){this.manager.cursorDestroyed(this)}}}]);return Cursor}();/**
* @callback Cursor~handler
* @memberof module:ancient-cursor
* @param old - Link to this data old the change.
* @param current - Link to this data current the change.
* @param {Function} stop
* @param {Object} changes
* @param changes.old
* @param {string[]} changes.path
* @param {string} changes.action
* @param {Array} changes.arguments
* @param {boolean} isClone - True if changed path deeper then event path. For details, read attention.
* @param {Cursor} cursor
* @description
* **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;
'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,manager,id){_classCallCheck(this,Cursor);this.query=query;this.data=data;this.manager=manager;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(this.manager){this.manager.cursorDestroyed(this)}}}]);return Cursor}();exports.default=Cursor;
//# sourceMappingURL=Cursor.js.map

@@ -1,33 +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}}();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.
* @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.
* @param query
* @param data
*/_createClass(CursorsManager,[{key:'new',value:function _new(query,data){var cursor=new this.Cursor(query,data,this,this.nextId);this.cursors[this.nextId]=cursor;this.nextId++;if(typeof this.adapterCustorConstructed=='function'){this.adapterCustorConstructed(cursor)}return cursor}/**
* Resume destroyed cursor into `this.cursors`. Define new id for cursor. You can reset query and default data. Call `this.adapterCustorConstructed` method.
* @param {Cursor} cursor
* @param [query]
* @param [data]
* @throws Cursor must be destroyed.
* @description
* > If cursor not destroyed, throw error.
*/},{key:'renew',value:function renew(cursor,query,data){if(!cursor.hasOwnProperty('id')){cursor.id=this.nextId++;this.cursors[cursor.id]=cursor;if(query)cursor.query=query;if(arguments.length==3)cursor.set('',data);if(typeof this.adapterCustorConstructed=='function'){this.adapterCustorConstructed(cursor)}return cursor}else{throw new Error('Cursor must be destroyed.')}}/**
* Calls if used `cursor.destroy` method. Call `this.adapterCursorDestroyed` method. Remove cursor from `this.cursors` hash.
* @param {Cursor} cursor
*/},{key:'cursorDestroyed',value:function cursorDestroyed(cursor){delete this.cursors[cursor.id];delete cursor.id;if(typeof this.adapterCursorDestroyed=='function'){this.adapterCursorDestroyed(cursor)}}}]);return CursorsManager}();/**
* @callback CursorManager~adapterCursorDestroyed
* @memberof module:ancient-cursor
* @param {Cursor} cursor
* @description
* Can be sended into `ApiManager` into constructor. Used for handle cursor destroyed event. For example you can send it information to some api within `ApiManager`.
*//**
* @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;
'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')}}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}_createClass(CursorsManager,[{key:'new',value:function _new(query,data){var cursor=new this.Cursor(query,data,this,this.nextId);this.cursors[this.nextId]=cursor;this.nextId++;if(typeof this.adapterCustorConstructed=='function'){this.adapterCustorConstructed(cursor)}return cursor}},{key:'renew',value:function renew(cursor,query,data){if(!cursor.hasOwnProperty('id')){cursor.id=this.nextId++;this.cursors[cursor.id]=cursor;if(query)cursor.query=query;if(arguments.length==3)cursor.set('',data);if(typeof this.adapterCustorConstructed=='function'){this.adapterCustorConstructed(cursor)}return cursor}else{throw new Error('Cursor must be destroyed.')}}},{key:'cursorDestroyed',value:function cursorDestroyed(cursor){delete this.cursors[cursor.id];delete cursor.id;if(typeof this.adapterCursorDestroyed=='function'){this.adapterCursorDestroyed(cursor)}}}]);return CursorsManager}();exports.default=CursorsManager;
//# sourceMappingURL=CursorsManager.js.map

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

'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
* @property {number} cursor - id of cursor on current client
* @property {string} type - set, unset or splice string
* @property {string|string[]} path
* @property {*=} value - if used set type
* @property {number} start - if used splice type
* @property {number} deleteCount - if used splice type
* @property {Array} items - if used splice type
*//**
* Attention! If the executers object does not have the correct executer type, an error will be thrown.
* @param {Bundle} bundle
* @param {Object} executers
* @param {parseBundle~parser} executers.* - executers for each possible bundle
* @param {Cursor} cursor
* @throws Uncaught TypeError: executers[bundle.type] is not a function
*/function executeBundle(bundle,cursor,executers){executers[bundle.type](bundle,cursor)}/**
* @param {Bundle} bundle
* @param {Cursor} cursor
*/function executeBundleSet(bundle,cursor){cursor.set(bundle.path,bundle.value)}/**
* @param {Bundle} bundle
* @param {Cursor} cursor
*/function executeBundleUnset(bundle,cursor){cursor.set(bundle.path,undefined)}/**
* @param {Bundle} bundle
* @param {Cursor} cursor
*/function executeBundleSplice(bundle,cursor){cursor.splice.apply(cursor,[bundle.path,bundle.start,bundle.deleteCount].concat(_toConsumableArray(bundle.items)))}/**
* Default executers object.
*/var executers=exports.executers={set:executeBundleSet,unset:executeBundleUnset,splice:executeBundleSplice};
'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)}}exports.Cursor=_Cursor2.default;exports.BundlesQueue=_BundlesQueue2.default;exports.CursorsManager=_CursorsManager2.default;exports.ApiManager=_ApiManager2.default;function executeBundle(bundle,cursor,executers){executers[bundle.type](bundle,cursor)}function executeBundleSet(bundle,cursor){cursor.set(bundle.path,bundle.value)}function executeBundleUnset(bundle,cursor){cursor.set(bundle.path,undefined)}function executeBundleSplice(bundle,cursor){cursor.splice.apply(cursor,[bundle.path,bundle.start,bundle.deleteCount].concat(_toConsumableArray(bundle.items)))}var executers=exports.executers={set:executeBundleSet,unset:executeBundleUnset,splice:executeBundleSplice};
//# sourceMappingURL=index.js.map
{
"name": "ancient-cursor",
"version": "0.0.4",
"version": "0.0.5",
"description": "Utilities for tracking changes of complex or plain remote data.",

@@ -58,3 +58,3 @@ "keywords": [

"scripts": {
"compile": "babel --presets es2015,react -d ./ src/ -s --minified",
"compile": "babel --presets es2015,react -d ./ src/ -s --minified --no-comments",
"test": "mocha tests/index.js --require source-map-support/register",

@@ -61,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/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)()})});
'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(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('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

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