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

ancient-cursor

Package Overview
Dependencies
Maintainers
3
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.9 to 0.1.0-beta

.travis.yml

2

LICENSE.md

@@ -6,2 +6,2 @@ Copyright 2017 [AncientSouls](https://ancientsouls.github.io/)

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
{
"name": "ancient-cursor",
"version": "0.0.9",
"description": "Utilities for tracking changes of complex or plain remote data.",
"keywords": [
"complex",
"plain",
"subscriptions",
"cursor",
"server",
"client",
"results",
"data",
"events",
"paths"
],
"contributors": [
{
"name": "Ivan S Glazunov",
"email": "ivansglazunov@gmail.com"
}
],
"version": "0.1.0-beta",
"description": "Abstract container of data synchronization.",
"bugs": "https://github.com/AncientSouls/Cursor/issues",
"repository": "AncientSouls/Cursor",
"license": "MIT",
"repository": {
"type": "git",
"url": "https://github.com/AncientSouls/Cursor.git"
"scripts": {
"tsc": "rm -rf ./lib ./tests && tsc ./src/*/*.ts --outDir ./ --sourceMap -d true --module CommonJS",
"test": "mocha ./tests/index.js --require source-map-support/register",
"dev-link": "npm link ancient-mixins",
"dev-test": "(rm -rf .dev && git clone -b dev https://github.com/AncientSouls/AncientSouls.github.io.git .dev && cd .dev && git submodule init && git submodule update && npm run dev-install) && npm link ./ && (cd .dev && npm run dev-use-links && npm run dev-check)"
},
"bugs": {
"url": "https://github.com/AncientSouls/Cursor/issues"
},
"main": "./lib/index.js",
"directories": {
"doc": "doc",
"lib": "lib",
"test": "tests"
},
"dependencies": {
"lodash": "^4.15.0"
"lodash": "^4.17.5",
"ancient-mixins": "AncientSouls/Mixins#develop"
},
"devDependencies": {
"babel-cli": "^6.14.0",
"babel-preset-es2015": "^6.14.0",
"babel-preset-react": "^6.24.1",
"chai": "^3.5.0",
"enzyme": "^2.9.1",
"jsdoc": "^3.4.0",
"minami": "^1.1.1",
"mingo": "^1.3.2",
"mocha": "^2.5.3",
"react": "^15.6.1",
"react-dom": "^15.6.1",
"react-komposer": "^2.0.0",
"react-test-renderer": "^15.6.1",
"source-map-support": "^0.4.2"
},
"scripts": {
"compile": "babel --presets es2015,react -d ./ src/ -s --minified --no-comments",
"test": "mocha tests/index.js --require source-map-support/register",
"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",
"test:watch": "npm run test -- --watch"
"@types/mocha": "^2.2.48",
"@types/node": "^9.4.6",
"chai": "^4.1.2",
"mocha": "^5.0.1",
"source-map-support": "^0.5.3",
"typescript": "^2.7.2"
}
}

@@ -1,61 +0,8 @@

# AncientCursor
# Ancient Souls Cursor
[![npm version](https://badge.fury.io/js/ancient-cursor.svg)](https://badge.fury.io/js/ancient-cursor)
[![GitHub release](https://img.shields.io/github/release/AncientSouls/Cursor.svg)](https://github.com/AncientSouls/Cursor)
[![Join the chat at https://gitter.im/AncientSouls/Lobby](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/AncientSouls/Lobby?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
Abstract container of data synchronization.
Utilities for tracking changes of complex or plain remote data.
## Install
```bash
npm install --save ancient-cursor
```
## Usage
There are no usage instructions yet, because the options for the end use are growing too fast.
If you want to see examples of using each individual module in the package, please see tests.
If in brief, now this package implements the following abstractions:
- Model of remote maintenance of the relevance of some custom data structure. (`Cursor` in documentation)
- The model of the management of cursors, as well as the factories of cursors. (`CursorsManager` in documentation)
- Model of the manager of a set of Api interfaces obtained from custom sources intended for receiving custom queries from cursors, maintaining a remote cursors and monitoring the moment of its destruction. (`ApiManager` in documentation)
- Model for processing the queue of bands sent from Api to the cursor, to track their sequence and prevent losses. (`BundlesQueue` in documentation)
The following statements are also true for this package:
- Completely modular, allows you to deploy models on top of any application architecture and transports.
- Completely independent of the data structure. For synchronization does not need the concept of documents or id, allows you to retrieve from any remote sources any complex data and maintain their relevance.
- Does not contain query caching, the repeated cursors synchronize the data with the remote source separately, because to implement the cache, you need to understand the structure of the specific data structures of your application. If you need a cache, you can not use cursors directly, but manage them through an interlayer like `alasql`, `backbone`, `relay`, `redux`, `minimongo` and others ...
- Does not depend to any query language, you can use as query any data transmitted anywhere. This means that this package will perfectly cope with the synchronization of data for `graphql`, structural and non-structural data, documents and any other structures from any sources.
## Reason
Too narrow the purpose of alternative implementations.
- `meteor` sync only documents by its ids into specific collection name, very limited `ddp` protocol
- `graphql` recoment sync data by marked in schema id, only for current schema and with description on client in most cases
- `backbone` sync models in collections by id
## Our plans
- So agnostic realization of channels between clients.
- The same modular implementation of the protocol of communication api and customers.
- Ready-made application examples with popular api queries and caching systems.
## Tests
Tests can be started with comand `npm install ancient-cursor && cd ./node_modules/ancient-cursor && npm run compile && npm test`. For more information lern [src/tests/index.js](https://github.com/AncientSouls/Cursor/blob/master/src/tests/index.js).
## License
The MIT License (MIT)
Copyright (c) 2016 Ivan S Glazunov <ivansglazunov@gmail.com>
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
[![GitHub Release](https://img.shields.io/github/release/AncientSouls/Cursor.svg)](https://github.com/AncientSouls/Cursor/releases)
[![NPM](https://img.shields.io/npm/v/ancient-cursor.svg)](https://www.npmjs.com/package/ancient-cursor)
[![Build Status](https://travis-ci.org/AncientSouls/Cursor.svg?branch=master)](https://travis-ci.org/AncientSouls/Cursor)
[![Read the Docs](https://img.shields.io/readthedocs/pip.svg)](https://ancientsouls.github.io/)

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

'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,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[0],counter);_chai.assert.equal(bundles[1],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)()})});
"use strict";
exports.__esModule = true;
require('source-map-support').install();
var bundle_1 = require("./bundle");
var cursor_1 = require("./cursor");
var cursors_manager_1 = require("./cursors-manager");
var childs_cursors_manager_1 = require("./childs-cursors-manager");
describe('AncientSouls/Cursor:', function () {
bundle_1["default"]();
cursor_1["default"]();
cursors_manager_1["default"]();
childs_cursors_manager_1["default"]();
});
//# sourceMappingURL=index.js.map

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