{"id":17771396,"url":"https://github.com/rootslab/libra","last_synced_at":"2025-04-01T15:18:25.648Z","repository":{"id":16559231,"uuid":"19313025","full_name":"rootslab/libra","owner":"rootslab","description":"♎ Libra, a module to handle bindings between commands and Redis replies.","archived":false,"fork":false,"pushed_at":"2018-02-10T14:40:59.000Z","size":72,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-09T16:03:06.247Z","etag":null,"topics":["command-queue","redis","redis-command","spade"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":"justmarkham/scikit-learn-videos","license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/rootslab.png","metadata":{"files":{"readme":"Readme.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-04-30T12:34:48.000Z","updated_at":"2017-11-09T00:04:38.000Z","dependencies_parsed_at":"2022-09-05T15:30:19.345Z","dependency_job_id":null,"html_url":"https://github.com/rootslab/libra","commit_stats":null,"previous_names":[],"tags_count":69,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rootslab%2Flibra","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rootslab%2Flibra/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rootslab%2Flibra/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rootslab%2Flibra/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rootslab","download_url":"https://codeload.github.com/rootslab/libra/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246660075,"owners_count":20813338,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["command-queue","redis","redis-command","spade"],"created_at":"2024-10-26T21:32:37.078Z","updated_at":"2025-04-01T15:18:25.607Z","avatar_url":"https://github.com/rootslab.png","language":"JavaScript","readme":"### ♎ Libra\n\n[![NPM VERSION](http://img.shields.io/npm/v/libra.svg?style=flat)](https://www.npmjs.org/package/libra)\n[![CODACY BADGE](https://img.shields.io/codacy/b18ed7d95b0a4707a0ff7b88b30d3def.svg?style=flat)](https://www.codacy.com/public/44gatti/libra)\n[![CODECLIMATE-TEST-COVERAGE](https://img.shields.io/codeclimate/c/rootslab/libra.svg?style=flat)](https://codeclimate.com/github/rootslab/libra)\n[![LICENSE](http://img.shields.io/badge/license-MIT-blue.svg?style=flat)](https://github.com/rootslab/libra#mit-license)\n\n![NODE VERSION](https://img.shields.io/node/v/libra.svg)\n[![TRAVIS CI BUILD](http://img.shields.io/travis/rootslab/libra.svg?style=flat)](http://travis-ci.org/rootslab/libra)\n[![BUILD STATUS](http://img.shields.io/david/rootslab/libra.svg?style=flat)](https://david-dm.org/rootslab/libra)\n[![DEVDEPENDENCY STATUS](http://img.shields.io/david/dev/rootslab/libra.svg?style=flat)](https://david-dm.org/rootslab/libra#info=devDependencies)\n\n[![NPM MONTHLY](http://img.shields.io/npm/dm/libra.svg?style=flat)](http://npm-stat.com/charts.html?package=libra)\n![NPM YEARLY](https://img.shields.io/npm/dy/libra.svg)\n![NPM TOTAL](https://img.shields.io/npm/dt/libra.svg)\n\n[![NPM GRAPH](https://nodei.co/npm/libra.png?downloads=true\u0026downloadRank=true\u0026stars=true)](https://nodei.co/npm/libra/)\n\n\u003e _**♎ Libra**_, a module to handle bindings between commands and __Redis__ replies. Morover, it implements an __automatic rollback mechanism__ for subscriptions. It is heavily based on __[Train](https://github.com/rootslab/train)__ module, a __well-tested__ and fast __FIFO__ queue.\n \n\u003e __NOTE__: It accepts only commands generated/encoded by __[Syllabus](https://github.com/rootslab/syllabus)__.\n\n### Install\n\n```bash\n$ npm install libra [-g]\n// clone repo\n$ git clone git@github.com:rootslab/libra.git\n```\n\u003e __install and update devDependencies__:\n\n```bash\n $ cd libra/\n $ npm install \n # update\n $ npm update \n```\n\u003e __require__\n\n```javascript\nvar Libra = require( 'libra' );\n```\n\u003e See [examples](example/).\n\n### Run Tests\n\n```bash\n$ cd libra/\n$ npm test\n```\n\n### Run Benchmark\n\n```bash\n$ cd libra/\n$ npm run bench\n```\n\u003e __NOTE__: You should install _devDependencies_ (_Syllabus_) for running benchmarks.\n\n\n### Constructor\n\n\u003e Create an instance, argument within [ ] is optional.\n\n```javascript\nvar l = Libra( [ opt ] )\n// or\nvar l = new Libra( [ opt ] )\n```\n\n#### Options\n\n\u003e Default options are listed.\n\n```javascript\nopt = {\n    // rollback queue max size ( for Train ) \n    rollback : 64 * 1024\n    // log the last access time to the queue's head\n    , timestamps : false\n}\n```\n\n###  Properties\n\n\u003e __WARNING__: Don't mess with these properties.\n\n```javascript\n// command queue\nLibra.cqueue : Train\n\n// status properties\nLibra.status : {\n    subscription : {\n        on : 0\n        , active : 0\n        , channels : 0\n        , patterns : 0\n    }\n    , transaction : {\n        on : 0\n        , active : 0\n    }\n    , monitoring : {\n        on : 0\n        , active : 0\n    }\n    // it holds special AUTH command\n    , auth : []\n    // it holds special SELECT command\n    , select : []\n    // timestamp for the last message received\n    , last_update : 0\n}\n```\n\n\u003e __NOTE__: to avoid messy conditions Libra doesnt't allow:\n\u003e  - to send subscription commands inside transactions ( a MULTI cmd was previuosly queued ).\n\u003e  - to push commands in monitoring mode ( a MONITOR cmd was previuosly queued ), only QUIT command is allowed.\n\n### Methods\n\n\u003e Arguments within [ ] are optional.\n\n```javascript\n/*\n * Update the current auth status property. In this way the AUTH command\n * has priority over the other commands in the queue; when #pop() will be\n * called, it will return this command regardless if the command queue is\n * empty or not.\n *\n * It returns the current auth status property ( encoded AUTH command ).\n *\n * NOTE: only Syllabus AUTH command will be accepted and stored.\n */\nLibra#auth( Object syllabus_auth_command ) : Object\n\n/*\n * Update the current select status property. In this way the SELECT command\n * has priority over the other commands in the queue (after AUTH); when #pop()\n * will be called, it will return this command regardless if the command queue\n * is empty or not.\n *\n * It returns the current select status property ( encoded SELECT command ).\n *\n * NOTE: only Syllabus SELECT command will be accepted and stored.\n */\nLibra#select( Object syllabus_select_command ) : Object\n\n/*\n * Update internal subscription status ( using a un/subscription reply ), passing the command and\n * the number of current subscribed channels, received as message reply. It returns the total number\n * of subscribed channels and patterns.\n *\n * Examples: Libra#update( 'subscribe', 5 ) or Libra#update( 'unsubscribe', 3 )\n *\n * NOTE: Except for subscription commands, QUIT is the only command accepted in pubsub mode.\n */\nLibra#update( subscription_command_reply [, channels_number ] ) : Number\n\n/*\n * Get the total number of channels/patterns in status.subscriptions\n */\nLibra#subs() : Libra\n\n/*\n * Push a Syllabus command to the internal queue.\n * It returns the number of command objects currently in the queue, or -1\n * if the command wasn't allowed/pushed.\n *\n * NOTE: only Syllabus commands are accepted.\n */\nLibra#push( Object syllabus_command ) : Number\n\n/*\n * Pop a Syllabus command from the internal queue.\n * It pops the current head of the command queue.\n */\nLibra#pop() : Object\n\n/*\n * Get a element in the command queue without popping it.\n * The default position is 0.\n */\nLibra#head( [ Number pos ] ) : Object\n\n/*\n * Start rolling up.\n * From now, all items evicted from the queue could be restored, executing #rollBack().\n * Disable rollUp passing false.\n * It returns the current Libra instance.\n */\nLibra#rollUp( [ Boolean on ] ) : Libra\n\n/*\n * Do rollback; previously evicted items are restored to the head of queue.\n * Optionally, it is possible to re-enable rollUp mechanism after the rollBack,\n * passing true.\n * It returns the current Libra instance.\n * \n * NOTE: no rollBack will be done if rollUp was not already activated.\n */\nLibra#rollBack( [ Boolean on ] ) : Libra\n\n/*\n * Apply a fn to every element of the internal command queue;\n * fn will get 3 arguments: Object element, Number index, Function done.\n * After that every fn will have called done(), the callback will be launched\n * with an err argument ( if any has occurred ) and a number, representing\n * the total processed / iterated elements in the queue.\n *\n * If boolean \"evict\" was set to true, after the last fn call to done(),\n * the queue will be flushed.\n *\n * NOTE: when queue size is 0, the callback will be immediately executed\n * with arguments: ( null, 0 ).\n *\n * NOTE: on iteration, the size is fixed to the current queue size,\n * then it is possible to push other elements to the tail, these\n * added elements are not affected by iteration.\n */\nLibra#iterate( Function fn [, Object scope [, Function cback [, Boolean evict ] ] ] ) : Libra\n\n/*\n * Flush the internal queue, reset all internal status properties,\n * then disable rollback mechanism.\n * It returns the current Libra instance.\n */\nLibra#flush() : Libra\n\n/*\n * Reset all internal status properties, then disable rollback mechanism.\n * It returns the current Libra instance.\n */\nLibra#reset() : Libra\n```\n------------------------------------------------------------------------\n\n###  MIT License\n\n\u003e Copyright (c) 2013-present \u0026lt; Guglielmo Ferri : 44gatti@gmail.com \u0026gt;\n\n\u003e Permission is hereby granted, free of charge, to any person obtaining\n\u003e a copy of this software and associated documentation files (the\n\u003e 'Software'), to deal in the Software without restriction, including\n\u003e without limitation the rights to use, copy, modify, merge, publish,\n\u003e distribute, sublicense, and/or sell copies of the Software, and to\n\u003e permit persons to whom the Software is furnished to do so, subject to\n\u003e the following conditions:\n\n\u003e __The above copyright notice and this permission notice shall be\n\u003e included in all copies or substantial portions of the Software.__\n\n\u003e THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,\n\u003e EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\n\u003e MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.\n\u003e IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY\n\u003e CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,\n\u003e TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE\n\u003e SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frootslab%2Flibra","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frootslab%2Flibra","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frootslab%2Flibra/lists"}