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

rhea

Package Overview
Dependencies
Maintainers
1
Versions
83
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

rhea - npm Package Compare versions

Comparing version 0.1.12 to 0.2.0

2

examples/client.js

@@ -31,3 +31,3 @@ /*

if (context.receiver.source.address) {
sender.send({properties:{reply_to:context.receiver.source.address}, body:requests[0]})
sender.send({reply_to:context.receiver.source.address, body:requests[0]})
}

@@ -34,0 +34,0 @@ }

@@ -29,3 +29,3 @@ /*

container.on('message', function (context) {
if (context.message.properties && context.message.properties.id && context.message.properties.id < received) {
if (context.message.id && context.message.id < received) {
// ignore duplicate message

@@ -32,0 +32,0 @@ return;

@@ -32,3 +32,3 @@ /*

console.log('sent ' + sent);
context.sender.send({properties:{id:sent}, body:{'sequence':sent}})
context.sender.send({id:sent, body:{'sequence':sent}})
}

@@ -35,0 +35,0 @@ if (sent === total) {

@@ -43,7 +43,7 @@ /*

var request = context.message;
var reply_to = request.properties.reply_to;
var reply_to = request.reply_to;
var response = {to: reply_to};
console.log("Received: " + request.body);
if (request.properties.correlation_id) {
response.correlation_id = request.properties.correlation_id;
if (request.correlation_id) {
response.correlation_id = request.correlation_id;
}

@@ -50,0 +50,0 @@ var upper = request.body.toString().toUpperCase();

@@ -27,7 +27,7 @@ /*

var request = context.message;
var reply_to = request.properties.reply_to;
var reply_to = request.reply_to;
console.log("Received: " + request.body);
var response = {properties:{to: reply_to}, body: request.body.toString().toUpperCase()};
if (request.properties.correlation_id) {
response.correlation_id = request.properties.correlation_id;
var response = {to: reply_to, body: request.body.toString().toUpperCase()};
if (request.correlation_id) {
response.correlation_id = request.correlation_id;
}

@@ -34,0 +34,0 @@ context.connection.send(response);

@@ -28,3 +28,3 @@ /*

container.on('message', function (context) {
if (context.message.properties && context.message.properties.id && context.message.properties.id < received) {
if (context.message.id && context.message.id < received) {
// ignore duplicate message

@@ -31,0 +31,0 @@ return;

@@ -31,3 +31,3 @@ /*

console.log('sent ' + sent);
context.sender.send({properties:{id:sent}, body:{'sequence':sent}})
context.sender.send({id:sent, body:{'sequence':sent}})
}

@@ -34,0 +34,0 @@ });

@@ -187,9 +187,2 @@ /*

});
it('rpc', function(done) {
var client_output = lines(['fib(5) => 5',
'fib(10) => 55',
'Put item in remote map',
'Retrieved bar from remote map']);
while_running(done, [example('rpc/server.js')]).verify([example('rpc/client.js').produces(client_output)]);
});

@@ -196,0 +189,0 @@ it('pub-sub', function(done) {

@@ -335,2 +335,7 @@ /*

Connection.prototype._is_fatal = function (error_condition) {
var non_fatal = this.get_option('non_fatal_errors', ['amqp:connection:forced']);
return non_fatal.indexOf(error_condition) < 0;
};
Connection.prototype._handle_error = function () {

@@ -342,3 +347,5 @@ var error = this.get_error();

if (!handled) {
if (!this._is_fatal(error.condition)) {
this.open();
} else if (!handled) {
this.dispatch('error', new errors.ConnectionError(error.description, error.condition, this));

@@ -345,0 +352,0 @@ }

@@ -42,13 +42,14 @@ /*

var unwrap = function (msg, section) {
msg[def.name] = new c(section.value);
var composite = new c(section.value);
for (var i = 0; i < def.fields.length; i++) {
var f = def.fields[i];
var v = composite[f.name];
if (v !== undefined && v !== null) {
msg[f.name] = v;
}
}
};
var wrap = function (sections, msg) {
if (msg[def.name]) {
if (msg[def.name].described) {
sections.push(msg[def.name].described());
} else {
sections.push(c.create(msg[def.name]).described());
}
}
sections.push(c.create(msg).described());
};

@@ -73,19 +74,2 @@ define_section(c.descriptor, unwrap, wrap);

function define_flattened_map_section(def) {
var descriptor = {numeric:def.code};
descriptor.symbolic = 'amqp:' + def.name.replace(/_/g, '-') + ':map';
var unwrap = function (msg, section) {
var values = types.unwrap_map_simple(section);
for (var k in values) {
msg[k] = values[k];
}
};
var wrap = function (sections, msg) {
if (msg[def.name]) {
sections.push(types.described_nc(types.wrap_ulong(descriptor.numeric), types.wrap_map(msg[def.name])));
}
};
define_section(descriptor, unwrap, wrap);
}
function Section(typecode, content) {

@@ -130,4 +114,3 @@ this.typecode = typecode;

});
define_flattened_map_section({name:'application_properties', code:0x74});
//define_map_section({name:'application_properties', code:0x74});
define_map_section({name:'application_properties', code:0x74});

@@ -159,35 +142,2 @@ define_section({numeric:0x75, symbolic:'amqp:data:binary'}, function (msg, section) { msg.body = new Section(0x75, types.unwrap(section)); });

function reverse_lookup(map) {
var reversed = {};
for (var key in map) {
var values = map[key];
for (var i in values) {
reversed[values[i]] = key;
}
}
return reversed;
}
var special_sections = {'properties': ['message_id',
'user_id',
'to',
'subject',
'reply_to',
'correlation_id',
'content_type',
'content_encoding',
'absolute_expiry_time',
'creation_time',
'group_id',
'group_sequence',
'reply_to_group_id'],
'header': ['durable',
'priority',
'ttl',
'first_acquirer',
'delivery_count']
};
var special_fields = reverse_lookup(special_sections);
var section_names = ['header', 'delivery_annotations', 'message_annotations', 'properties', 'application_properties', 'body', 'footer'];
function copy(src, tgt) {

@@ -204,10 +154,2 @@ for (var k in src) {

function add_property_shortcut(o, group, name) {
Object.defineProperty(o, name,
{
get: function() { return this[group] ? this[group][name] : undefined; },
set: function(v) { if (this[group] === undefined) { this[group] = {}; } this[group][name] = v; }
});
}
function Message(o) {

@@ -223,13 +165,3 @@ if (o) {

if (typeof this[key] === 'function') continue;
var fields = special_sections[key];
if (fields) {
for (var i in fields) {
var field = fields[i];
if (this[key][field] !== undefined && this[key][field] !== null) {
o[field] = this[key][field];
}
}
} else {
o[key] = this[key];
}
o[key] = this[key];
}

@@ -247,63 +179,5 @@ return o;

for (var field in special_fields) {
add_property_shortcut(Message.prototype, special_fields[field], field);
}
function VirtualPropertySet (names, obj) {
this.values = obj;
for (var i = 0; i < names.length; i++) {
var name = names[i];
Object.defineProperty(this, name, { get: function() { return this.values[name]; }, set: function(v) { this.values[name] = v; }});
}
}
function is_application_property_name (field_name) {
return special_fields[field_name] === undefined && section_names.indexOf(field_name) < 0;
}
function get_application_property_names (msg) {
return Object.keys(msg).filter(function (f) { return typeof msg[f] !== 'function' && is_application_property_name(f); });
}
Object.defineProperty(Message.prototype, 'application_property_names', { get: function() { return get_application_property_names(this); } });
Object.defineProperty(Message.prototype, 'application_properties', {
get: function() {
return new VirtualPropertySet(this.application_property_names, this);
},
set: function(properties) {
var current = this.application_property_names;
var updated = Object.keys(properties);
for (var k in updated) {
this[k] = properties[k];
}
for (k in current) {
if (updated[k] === undefined) {
delete this[k];
}
}
}
});
function massage(msg) {
var out = undefined;
for (var key in msg) {
if (typeof msg[key] !== 'function' && section_names.indexOf(key) < 0) {
if (out === undefined) out = {};
var group = special_fields[key] || 'application_properties';
if (out[group] === undefined) {
out[group] = {};
}
out[group][key] = msg[key];
} else {
if (out !== undefined) {
out[key] = msg[key];
}
}
}
return out || msg;
}
message.encode = function(obj) {
message.encode = function(msg) {
var sections = [];
var msg = massage(obj);
wrappers.forEach(function (wrapper_fn) { wrapper_fn(sections, msg); });

@@ -310,0 +184,0 @@ var writer = new types.Writer();

@@ -41,7 +41,7 @@ /*

Client.prototype._request = function (id, name, args, callback) {
var request = {properties:{}};
request.properties.subject = name;
var request = {};
request.subject = name;
request.body = args;
request.properties.message_id = id;
request.properties.reply_to = this.receiver.remote.attach.source.address;
request.message_id = id;
request.reply_to = this.receiver.remote.attach.source.address;
this.outstanding[id] = callback;

@@ -52,9 +52,9 @@ this.sender.send(request);

Client.prototype._response = function (context) {
var id = context.message.properties.correlation_id;
var id = context.message.correlation_id;
var callback = this.outstanding[id];
if (callback) {
if (context.message.properties.subject === 'ok') {
if (context.message.subject === 'ok') {
callback(context.message.body);
} else {
callback(undefined, {name: context.message.properties.subject, description: context.message.body});
callback(undefined, {name: context.message.subject, description: context.message.body});
}

@@ -196,3 +196,3 @@ } else {

var cache = new LinkCache(this.connection.attach_sender.bind(this.connection), this.options.cache_ttl || 60000);
this._send = function (msg) { var s = cache.get(msg.properties.to); if (s) s.send(msg); };
this._send = function (msg) { var s = cache.get(msg.to); if (s) s.send(msg); };
this._clear = function () { cache.clear(); };

@@ -206,6 +206,6 @@ }

if (error) {
response.properties.subject = error.name || 'error';
response.subject = error.name || 'error';
response.body = error.description || error;
} else {
response.properties.subject = 'ok';
response.subject = 'ok';
response.body = result;

@@ -219,11 +219,11 @@ }

var request = context.message;
var response = {properties:{}};
response.properties.to = request.properties.reply_to;
response.properties.correlation_id = request.properties.message_id;
var callback = this.callbacks[request.properties.subject];
var response = {};
response.to = request.reply_to;
response.correlation_id = request.message_id;
var callback = this.callbacks[request.subject];
if (callback) {
callback(request.body, this._respond(response));
} else {
response.properties.subject = 'bad-method';
response.body = 'Unrecognised method ' + request.properties.subject;
response.subject = 'bad-method';
response.body = 'Unrecognised method ' + request.subject;
this._send(response);

@@ -230,0 +230,0 @@ }

{
"name" : "rhea",
"version": "0.1.12",
"version": "0.2.0",
"description": "reactive AMQP 1.0 library",

@@ -5,0 +5,0 @@ "homepage": "http://github.com/grs/rhea",

@@ -109,5 +109,2 @@ [![Build Status](https://travis-ci.org/grs/rhea.svg?branch=master)](https://travis-ci.org/grs/rhea)

* A rpc [client](examples/rpc/client.js) and
[server](example/rpc/server.js) (requires a broker).
* Both [node based](examples/websockets/client.js) and [web

@@ -193,2 +190,5 @@ based](examples/websockets/client.html) websocket clients along with

between a set of different host/port combinations)
* non_fatal_errors - an array of error conditions which if received
on connection close from peer should not prevent reconnect (by
default this only includes amqp:connection:forced)

@@ -315,4 +315,4 @@ If the transport is TLS, the options may additionally specify a

depends on the peer supporting so-called 'anonymous relay' semantics,
which most AMQP 1.0 brokers do. The message should contain a
properties map with a 'to' field set to the intended destination.
which most AMQP 1.0 brokers do. The message should have the 'to' field
set to the intended destination.

@@ -394,26 +394,18 @@ ##### close()

* header, an object which has the following fields:
* durable
* first_acquirer
* priority
* ttl
* delivery_count
* properties, an object which has the following fields:
* reply_to
* to
* subject
* content_type
* content_encoding
* group_id
* id
* correlation_id
* durable
* first_acquirer
* priority
* ttl
* delivery_count
* reply_to
* to
* subject
* content_type
* content_encoding
* group_id
* id
* correlation_id
* application properties, an object/map which can take arbitrary, application defined named values
* body, which can be either a string, an object or a buffer
The header, properties and application_properties can be set on the
message itself, i.e. the nesting is not necessary (it reflects the
AMQP specification however). So
e.g. {subject:'abc',colour:'green',body:'foo'} is equivalent to
{properties:{subject:'abc'},application_properties:{colour:'green'},body:'foo'}
##### close()

@@ -420,0 +412,0 @@

@@ -306,3 +306,3 @@ /*

container.on('message', function(context) {
received[context.message.properties.to] = context.message.body;
received[context.message.to] = context.message.body;
});

@@ -334,5 +334,5 @@ listener = container.listen({port:0});

});
c.send({properties:{to:'a'},body:'A'});
c.send({properties:{to:'b'},body:'B'});
c.send({to:'a',body:'A'});
c.send({to:'b',body:'B'});
});
});

@@ -67,7 +67,7 @@ /*

}));
it('sends and receives subject', transfer_test({properties:{subject:'my-subject'}}, function(message) {
assert.equal(message.properties.subject, 'my-subject');
it('sends and receives subject', transfer_test({subject:'my-subject'}, function(message) {
assert.equal(message.subject, 'my-subject');
}));
it('sends and receives message-id', transfer_test({properties:{message_id:'my-id'}}, function(message) {
assert.equal(message.properties.message_id, 'my-id');
it('sends and receives message-id', transfer_test({message_id:'my-id'}, function(message) {
assert.equal(message.message_id, 'my-id');
}));

@@ -172,3 +172,3 @@ it('sends and receives string property', transfer_test({application_properties:{colour:'red'}}, function(message) {

}));
it('get header and properties directly', transfer_test({properties:{
it('get header and properties directly', transfer_test({
message_id:'my-id',

@@ -186,4 +186,3 @@ user_id:'my-user',

group_sequence:77,
reply_to_group_id:'still-my-group'
}, header:{
reply_to_group_id:'still-my-group',
durable:true,

@@ -194,3 +193,3 @@ priority:3,

delivery_count:8
}}, function(message) {
}, function(message) {
assert.equal(message.message_id, 'my-id');

@@ -235,27 +234,21 @@ assert.equal(message.user_id, 'my-user');

}, function(message) {
assert.equal(message.properties.message_id, 'my-id');
assert.equal(message.properties.user_id, 'my-user');
assert.equal(message.properties.to, 'my-to');
assert.equal(message.properties.subject, 'my-subject');
assert.equal(message.properties.reply_to, 'my-reply-to');
assert.equal(message.properties.correlation_id, 'correlate-me');
assert.equal(message.properties.content_type, 'text');
assert.equal(message.properties.content_encoding, 'ascii');
assert.equal(message.properties.absolute_expiry_time, 123456789);
assert.equal(message.properties.creation_time, 987654321);
assert.equal(message.properties.group_id, 'my-group');
assert.equal(message.properties.group_sequence, 77);
assert.equal(message.properties.reply_to_group_id, 'still-my-group');
assert.equal(message.header.durable, true);
assert.equal(message.header.priority, 3);
assert.equal(message.header.ttl, 123456789);
assert.equal(message.header.first_acquirer, false);
assert.equal(message.header.delivery_count, 8);
assert.equal(message.message_id, 'my-id');
assert.equal(message.user_id, 'my-user');
assert.equal(message.to, 'my-to');
assert.equal(message.subject, 'my-subject');
assert.equal(message.reply_to, 'my-reply-to');
assert.equal(message.correlation_id, 'correlate-me');
assert.equal(message.content_type, 'text');
assert.equal(message.content_encoding, 'ascii');
assert.equal(message.absolute_expiry_time, 123456789);
assert.equal(message.creation_time, 987654321);
assert.equal(message.group_id, 'my-group');
assert.equal(message.group_sequence, 77);
assert.equal(message.reply_to_group_id, 'still-my-group');
assert.equal(message.durable, true);
assert.equal(message.priority, 3);
assert.equal(message.ttl, 123456789);
assert.equal(message.first_acquirer, false);
assert.equal(message.delivery_count, 8);
}));
it('get application property directly', transfer_test({application_properties:{colour:'red'}}, function(message) {
assert.equal(message.colour, 'red');
}));
it('set application property directly', transfer_test({colour:'red'}, function(message) {
assert.equal(message.application_properties.colour, 'red');
}));
it('test undefined properties and headers directly', transfer_test({body:'hello world!'}, function(message) {

@@ -262,0 +255,0 @@ assert.equal(message.body, 'hello world!');

@@ -62,3 +62,3 @@ /*

container.on('message', function (context) {
var address = context.receiver.remote.attach.target.address || context.message.properties.to;
var address = context.receiver.remote.attach.target.address || context.message.to;
broker.publish(address, context.message);

@@ -65,0 +65,0 @@ });

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