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

blue-rings

Package Overview
Dependencies
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

blue-rings - npm Package Compare versions

Comparing version 2.0.0 to 2.0.1

3

index.coffee.md

@@ -24,2 +24,3 @@ counter = require './crdt-counter'

type: (type) ->
return if @__type?
@__type = type

@@ -55,3 +56,3 @@ switch type

merge: ([type,rest...]) ->
@type type if not @__type
@type type
msg = @__value.merge rest

@@ -58,0 +59,0 @@ msg[1].unshift type

@@ -28,2 +28,5 @@ // Generated by CoffeeScript 2.3.1

type(type) {
if (this.__type != null) {
return;
}
this.__type = type;

@@ -75,5 +78,3 @@ switch (type) {

var msg;
if (!this.__type) {
this.type(type);
}
this.type(type);
msg = this.__value.merge(rest);

@@ -80,0 +81,0 @@ msg[1].unshift(type);

{
"name": "blue-rings",
"version": "2.0.0",
"version": "2.0.1",
"description": "Blue Rings: distributed counters",

@@ -25,3 +25,3 @@ "main": "index.js",

"author": "",
"license": "ISC",
"license": "Unlicense",
"bugs": {

@@ -28,0 +28,0 @@ "url": "https://gitlab.com/shimaore/blue-rings/issues"

@@ -1,3 +0,3 @@

Blue Rings: distributed counters
--------------------------------
Blue Rings: distributed counters and registers
----------------------------------------------

@@ -11,2 +11,4 @@ The goal is to provide distributed counters usable for billing, with:

The module also provides "last-writer wins" text registers.
API

@@ -46,13 +48,6 @@ ---

Here is an example for a service storing Big Rationals (arbitrary precision fractions).
Here is an example for a service storing Big Integers (arbitrary precision integers).
```
bigRat = require 'big-rational'
big_rational_values =
deserialize: (t) -> bigRat t
serialize: (n) -> n.toString()
add: (n1,n2) -> n1.add n2
zero: bigRat.zero
options.Value = big_rational_values
options.Value = BlueRings.bigint
const ring = BlueRings(options);

@@ -72,2 +67,8 @@ ```

`ring.setup_text(name,expire) →`
`ring.update_text (name,text) → [coherent,new_value]`
`ring.get_text(name) → [coherent,value]`
This implements a Last Writer Wins text register, keeping it until `expire`.
`ring.statistics() -> {recv,recv_tickets,sent,sent_tickets}`

@@ -74,0 +75,0 @@

@@ -113,3 +113,70 @@ {expect} = chai = require 'chai'

it 'should accumulate values across two servers (with setup in the middle)', ->
port1 = port++
port2 = port++
m1 = M
host: 'α'
pub: tcp port1
subscribe_to: [
tcp port2
]
Value: Value
connect_delay: 0
after -> m1.end()
m2 = M
host: 'β'
pub: tcp port2
subscribe_to: [
tcp port1
]
Value: Value
connect_delay: 0
after -> m2.end()
await Promise.all [m1.bound,m2.bound,m1.connected,m2.connected]
NAME = 'ant'
m1.setup_counter NAME, Date.now()+8000
v= m1.update_counter NAME, Value.accept 3
v.should.have.property 0, true
v.should.have.property 1, Value.accept 3
await sleep 5
v = m2.get_counter(NAME)
v.should.have.property 0, true
v.should.have.property 1, Value.accept 3
v = m1.update_counter NAME, Value.accept 7
v.should.have.property 0, true
v.should.have.property 1, Value.accept 10
await sleep 5
v = m2.get_counter(NAME)
v.should.have.property 0, true
v.should.have.property 1, Value.accept 10
m1.setup_counter NAME, Date.now()+8000
v = m2.update_counter NAME, Value.accept 42
v.should.have.property 0, true
v.should.have.property 1, Value.accept 52
await sleep 5
v = m1.get_counter(NAME)
v.should.have.property 0, true
v.should.have.property 1, Value.accept 52
v = m2.get_counter(NAME)
v.should.have.property 0, true
v.should.have.property 1, Value.accept 52
v = m2.update_counter NAME, Value.accept -30
v.should.have.property 0, true
v.should.have.property 1, Value.accept 22
await sleep 5
v = m1.get_counter(NAME)
v.should.have.property 0, true
v.should.have.property 1, Value.accept 22
v = m2.get_counter(NAME)
v.should.have.property 0, true
v.should.have.property 1, Value.accept 22
it 'should accumulate values across two disconnected servers', ->

@@ -116,0 +183,0 @@ port1 = port++

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