New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

node-ral

Package Overview
Dependencies
Maintainers
1
Versions
96
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

node-ral - npm Package Compare versions

Comparing version 0.0.34 to 0.0.35

0

benchmark/config/config.js

@@ -0,0 +0,0 @@ /*

@@ -0,0 +0,0 @@ /*

@@ -0,0 +0,0 @@ /*

@@ -0,0 +0,0 @@ /*

@@ -0,0 +0,0 @@ function showMem () {

@@ -0,0 +0,0 @@ /*

@@ -0,0 +0,0 @@ /*

72

lib/config.js

@@ -39,16 +39,16 @@ /*

*/
var enableUpdate = function(interval, all, cb){
var enableUpdate = function (interval, all, cb) {
interval = interval || ctx.updateInterval;
if (updateInterval){
if (updateInterval) {
clearInterval(updateInterval);
}
updateInterval = setInterval(function(){
configUpdater.update(function(err, confs){
updateInterval = setInterval(function () {
configUpdater.update(function (err, confs) {
cb && cb(err, confs);
if (!err){
_.map(confs, function(conf){
if (!err) {
_.map(confs, function (conf) {
config[conf.serviceID] = conf;
contextCache[conf.serviceID] = {};
});
}else{
} else {
logger.warning('config update failed: ' + err.message);

@@ -60,4 +60,4 @@ }

var disableUpdate = function(){
if (updateInterval){
var disableUpdate = function () {
if (updateInterval) {
clearInterval(updateInterval);

@@ -68,3 +68,3 @@ updateInterval = null;

var isAutoUpdateEnabled = function(){
var isAutoUpdateEnabled = function () {
return updateInterval ? true : false;

@@ -91,3 +91,3 @@ };

function info(property) {
return ['[', serviceID, '] config error => ', '[', property , ']'].join('');
return ['[', serviceID, '] config error => ', '[', property, ']'].join('');
}

@@ -125,4 +125,4 @@

_.map(clone, function (serviceInfo, serviceID) {
if (normalizerManager.needUpdate(serviceInfo)){
updateNeededRawConf[serviceID] = serviceInfo;
if (normalizerManager.needUpdate(serviceInfo)) {
updateNeededRawConf[serviceID] = rawConf[serviceID];
needUpdate = true;

@@ -134,6 +134,6 @@ }

});
if (needUpdate){
if (needUpdate) {
logger.notice('config auto update was started');
enableUpdate();
}else{
} else {
logger.notice('config auto update wase disabled');

@@ -150,7 +150,7 @@ }

*/
function load(confPath){
function load(confPath) {
function _load(confPath) {
var confFromFile = {};
function _loadByFile(confPath){
function _loadByFile(confPath) {
//load js or json as config

@@ -161,12 +161,12 @@ var ext = path.extname(confPath);

if (ext === '.js') {
logger.trace('load config from ' +confPath);
logger.trace('load config from ' + confPath);
data = require(confPath);
} else if (ext === '.json') {
logger.trace('load config from ' +confPath);
logger.trace('load config from ' + confPath);
var content = fs.readFileSync(confPath);
data = JSON.parse(content.toString());
}
if (name === 'idc'){
if (name === 'idc') {
ctx.currentIDC = data.idc.toString();
}else{
} else {
_.extend(confFromFile, data);

@@ -176,3 +176,3 @@ }

function _loadByFolder(confPath){
function _loadByFolder(confPath) {
var files = ralUtil.readdirSync(confPath);

@@ -192,6 +192,6 @@ files.map(_loadByFile);

confPath = path.normalize(confPath);
try{
try {
//load raw conf
rawConf = _load(confPath);
_.map(rawConf, function(value, key){
_.map(rawConf, function (value, key) {
value.serviceID = key;

@@ -201,3 +201,3 @@ });

loadRawConf(rawConf);
}catch(err){
} catch (err) {
logger.fatal('config [' + confPath + '] load failed');

@@ -213,7 +213,7 @@ throw err;

*/
function parseContext(serviceID, options){
var serviceInfo = config[serviceID];
function parseContext(serviceID, options) {
var serviceInfo = config[serviceID];
var context = {};
context.protocol = RalModule.modules.protocol[serviceInfo.protocol];
context.balance = RalModule.modules.balance[serviceInfo.balance];
context.balance = RalModule.modules.balance[serviceInfo.balance];
var contextClass = context.balance.getContextClass();

@@ -237,6 +237,6 @@ context.balanceContext = new contextClass(serviceID, serviceInfo);

module.exports.getConf = function(name){
module.exports.getConf = function (name) {
//return a copy
if (config[name]){
var conf = ralUtil.deepClone(config[name]);
if (config[name]) {
var conf = ralUtil.deepClone(config[name]);
return conf;

@@ -246,11 +246,11 @@ }

module.exports.getConfNames = function(){
module.exports.getConfNames = function () {
return Object.keys(config);
};
module.exports.getRawConf = function(){
module.exports.getRawConf = function () {
return ralUtil.deepClone(rawConf);
};
module.exports.getUpdateNeededRawConf = function(){
module.exports.getUpdateNeededRawConf = function () {
return ralUtil.deepClone(updateNeededRawConf);

@@ -261,4 +261,2 @@ };

module.exports.disableUpdate = disableUpdate;
module.exports.isAutoUpdateEnabled = isAutoUpdateEnabled;
module.exports.isAutoUpdateEnabled = isAutoUpdateEnabled;

@@ -0,0 +0,0 @@ /*

@@ -0,0 +0,0 @@ /*

@@ -11,3 +11,3 @@ /*

module.exports.currentIDC = module.exports.IDC_ALL;
//default config update time is 300s
module.exports.updateInterval = 300000;
//default config update time is 60s
module.exports.updateInterval = 60000;

@@ -0,0 +0,0 @@ /*

@@ -16,3 +16,3 @@ /*

function HttpProtocol(){
function HttpProtocol() {
Protocol.call(this);

@@ -23,22 +23,29 @@ }

HttpProtocol.prototype.getName = function(){
HttpProtocol.prototype.getName = function () {
return 'http';
};
HttpProtocol.prototype.normalizeConfig = HttpProtocol.normalizeConfig = function(config){
HttpProtocol.prototype.normalizeConfig = HttpProtocol.normalizeConfig = function (config) {
config = Protocol.normalizeConfig(config);
if (typeof config.query !== 'object'){
config.query = urlencode.parse(config.query, {charset: config.encoding});
if (typeof config.query !== 'object') {
config.query = urlencode.parse(config.query, {
charset: config.encoding
});
}
if (config.path && config.path[0] !== '/') {
config.path = '/' + config.path;
}
return config;
};
HttpProtocol.prototype._request = function(config, callback){
HttpProtocol.prototype._request = function (config, callback) {
var response = new ResponseStream(),
query = urlencode.stringify(config.query, {charset: config.encoding}),
query = urlencode.stringify(config.query, {
charset: config.encoding
}),
path,
piped = false;
if (query){
if (query) {
path = config.path + '?' + query;
}else{
} else {
path = config.path;

@@ -58,8 +65,8 @@ }

if (config.https){
if (config.https) {
request = require('https');
opt.key = config.key;
opt.cert = config.cert;
opt.rejectUnauthorized = config.rejectUnauthorized
}else{
opt.rejectUnauthorized = config.rejectUnauthorized;
} else {
request = require('http');

@@ -69,3 +76,3 @@ }

logger.trace('request start ' + JSON.stringify(opt));
var req = request.request(opt, function(res){
var req = request.request(opt, function (res) {
if (res.statusCode >= 300 && !config.ignoreStatusCode) {

@@ -77,12 +84,12 @@ req.emit('error', new Error('Server Status Error: ' + res.statusCode));

});
if (config.payload){
if (config.payload) {
req.write(config.payload);
req.end();
}else{
} else {
//auto end if no pipe
process.nextTick(function(){
process.nextTick(function () {
piped || req.end();
});
}
req.on('pipe', function(){
req.on('pipe', function () {
piped = true;

@@ -93,4 +100,4 @@ });

function ResponseStream(){
this.writable=true;
function ResponseStream() {
this.writable = true;
this.data = null;

@@ -102,3 +109,3 @@ this.chunks = [];

ResponseStream.prototype.write=function(chunk){
ResponseStream.prototype.write = function (chunk) {
//store the data

@@ -108,3 +115,3 @@ this.chunks.push(chunk);

ResponseStream.prototype.end=function(){
ResponseStream.prototype.end = function () {
var data = null;

@@ -111,0 +118,0 @@ try {

@@ -71,2 +71,5 @@ /*

if (config.headers){
if (config.headers instanceof Array === false) {
config.headers = [config.headers];
}
config.headers.forEach(function (header) {

@@ -73,0 +76,0 @@ client.addSoapHeader(header.data, header.name, header.soapNamespace, header.soapXmlns);

@@ -0,0 +0,0 @@ /*

@@ -0,0 +0,0 @@ /*

@@ -0,0 +0,0 @@ /*

@@ -264,3 +264,3 @@ /*

retry: this._retryTimes + '/' + this.conf.retry
}
};
};

@@ -294,2 +294,3 @@

"log_path": path.dirname(require.main ? require.main.filename : __dirname) + path.sep + './logs',
"IS_OMP": 2,
"app": "ral"

@@ -318,4 +319,4 @@ },

options = ralUtil.merge(defaultOptions, options);
ctx.currentIDC = options.currentIDC;
ctx.updateInterval = options.updateInterval;
options.currentIDC && (ctx.currentIDC = options.currentIDC);
options.updateInterval && (ctx.updateInterval = options.updateInterval);
loggerGen.options = options.logger;

@@ -322,0 +323,0 @@ options.extDir.map(RalModule.load);

@@ -0,0 +0,0 @@ /*

@@ -0,0 +0,0 @@ /*

@@ -0,0 +0,0 @@ /*

{
"name": "node-ral",
"version": "0.0.34",
"version": "0.0.35",
"description": "a rpc client for node",

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

"combined-stream": "0.0.5",
"formidable": "1.0.15",
"formidable": "1.0.17",
"istanbul": "0.3.0",

@@ -44,0 +44,0 @@ "mocha": "1.21.3",

@@ -26,3 +26,3 @@ node-ral

### 安装
##### 安装

@@ -34,3 +34,3 @@ ```bash

### 创建配置
##### 创建配置

@@ -74,3 +74,3 @@ ```javascript

### 初始化
##### 初始化

@@ -92,6 +92,6 @@ ```javascript

### 调用服务
##### 调用服务
```javascript
// map.js
// index.js

@@ -114,5 +114,5 @@ var ral = require('./ral.js');

### 执行结果
##### 执行结果
执行一下 `node map.js` 我们就可以看到奥林匹克森林公园的搜索结果了
执行一下 `node index.js` 我们就可以看到奥林匹克森林公园的搜索结果了

@@ -146,2 +146,2 @@ ```

请查阅文档[WIKI](https://github.com/fex-team/node-ral/wiki)
请查阅文档[WIKI](https://github.com/fex-team/node-ral/wiki)

@@ -0,0 +0,0 @@ /*

@@ -0,0 +0,0 @@ 'use strict';

@@ -0,0 +0,0 @@ /*

@@ -0,0 +0,0 @@ /*

@@ -0,0 +0,0 @@ /*

@@ -0,0 +0,0 @@ /*

@@ -0,0 +0,0 @@ /*

@@ -0,0 +0,0 @@ /*

@@ -0,0 +0,0 @@ /*

@@ -257,6 +257,5 @@ /*

var context = SoapProtocol.normalizeConfig(soap_test);
context.method = 'GetWeather';
context.method = 'GetCityForecastByZIP';
context.payload = {
CityName: 'Beijing',
CountryName: 'China'
ZIP: 10020
};

@@ -266,3 +265,3 @@ var soapProtocol = new SoapProtocol();

res.on('data', function(data){
data.GetWeatherResult.should.be.ok;
data.GetCityForecastByZIPResult.should.be.ok;
done();

@@ -276,8 +275,7 @@ });

var context = SoapProtocol.normalizeConfig(soap_test);
context.soapService = 'GlobalWeather';
context.soapPort = 'GlobalWeatherSoap12';
context.method = 'GetWeather';
context.soapService = 'Weather';
context.soapPort = 'WeatherSoap12';
context.method = 'GetCityForecastByZIP';
context.payload = {
CityName: 'Beijing',
CountryName: 'China'
ZIP: 10020
};

@@ -287,3 +285,3 @@ var soapProtocol = new SoapProtocol();

res.on('data', function(data){
data.GetWeatherResult.should.be.ok;
data.GetCityForecastByZIPResult.should.be.ok;
done();

@@ -290,0 +288,0 @@ });

@@ -11,5 +11,5 @@ /*

https: false,
path: '/globalweather.asmx?WSDL',
path: '/WeatherWS/Weather.asmx?WSDL',
server: {
host: 'www.webservicex.net',
host: 'wsf.cdyne.com',
port: 80

@@ -16,0 +16,0 @@ }

@@ -352,10 +352,9 @@ /*

var req = RAL('SOAP', {
method: 'GetWeather',
method: 'GetCityForecastByZIP',
data: {
CityName: 'Beijing',
CountryName: 'China'
ZIP: 10020 // 纽约的邮编
}
});
req.on('data', function(data){
data.GetWeatherResult.should.be.ok;
data.GetCityForecastByZIPResult.should.be.ok;
done();

@@ -370,7 +369,6 @@ });

var req = RAL('SOAP', {
method: 'GetWeather',
timeout: 1,
method: 'GetCityForecastByZIP',
data: {
CityName: 'Beijing',
CountryName: 'China'
ZIP: 10020 // 纽约的邮编
}

@@ -377,0 +375,0 @@ });

@@ -11,3 +11,3 @@ /*

https: false,
path: '/globalweather.asmx?WSDL',
path: '/WeatherWS/Weather.asmx?WSDL',
protocol: 'soap',

@@ -20,3 +20,3 @@ pack: 'raw',

{
host: 'www.webservicex.com',
host: 'wsf.cdyne.com',
port: 80

@@ -23,0 +23,0 @@ }

@@ -0,0 +0,0 @@ /*

@@ -0,0 +0,0 @@ /*

@@ -19,7 +19,7 @@ /*

describe('config updater', function() {
describe('config updater', function () {
it('update config successful', function (done) {
config.load(__dirname + path.sep + './update/config');
configUpdater.update(function(err, conf){
configUpdater.update(function (err, conf) {
conf.SIMPLE.__from__.should.be.startWith('updater');

@@ -32,5 +32,4 @@ done();

config.load(__dirname + path.sep + './update/config');
configUpdater.update(function(err, conf){
}, true);
configUpdater.update(function(err, conf){
configUpdater.update(function (err, conf) {}, true);
configUpdater.update(function (err, conf) {
err.should.be.match(/updater still running/);

@@ -41,9 +40,9 @@ done();

it('updater will create cache folder on start', function(){
it('updater will create cache folder on start', function () {
var tmpPath = __dirname + path.sep + './tmp';
var filePath = __dirname + path.sep + './tmp/data_cache.json';
try{
try {
fs.unlinkSync(filePath);
fs.rmdirSync(tmpPath);
}catch(e){
} catch (e) {

@@ -58,7 +57,7 @@ }

it('updater will delete cache file on start', function(){
it('updater will delete cache file on start', function () {
var tmpPath = __dirname + path.sep + './tmp';
var filePath = __dirname + path.sep + './tmp/data_cache.json';
try{
if (!fs.existsSync(tmpPath)){
try {
if (!fs.existsSync(tmpPath)) {
fs.mkdirSync(tmpPath);

@@ -68,4 +67,3 @@ }

fs.closeSync(fd);
}catch(e){
}
} catch (e) {}
fs.existsSync(filePath).should.be.true;

@@ -79,3 +77,3 @@ var myUpdater = new configUpdater.Updater({

it('updater will fail when normlizer throw error', function(done){
it('updater will fail when normlizer throw error', function (done) {
var tmpPath = __dirname + path.sep + './tmp';

@@ -85,3 +83,3 @@ var filePath = __dirname + path.sep + './tmp/data_cache.json';

var fake = {
normalizeConfig: function() {
normalizeConfig: function () {
throw new Error('fake');

@@ -95,3 +93,3 @@ }

normalizeManager.setConfigNormalizer([fake]);
myUpdater.update(function(err){
myUpdater.update(function (err) {
normalizeManager.setConfigNormalizer('default');

@@ -103,12 +101,12 @@ err.message.should.be.match(/fake/);

it('auto updater should be triggered is normalizer need update', function(){
it('auto updater should be triggered is normalizer need update', function () {
var fake = {
normalizeConfig: function(config) {
normalizeConfig: function (config) {
return config;
},
needUpdate: function(){
needUpdate: function () {
return true;
}
};
normalizeManager.setConfigNormalizer([fake,'default']);
normalizeManager.setConfigNormalizer([fake, 'default']);
config.load(__dirname + path.sep + './update/config');

@@ -121,19 +119,19 @@ config.isAutoUpdateEnabled().should.be.true;

it('auto updater should work fine 1', function(done){
it('auto updater should work fine 1', function (done) {
var fake = {
normalizeConfig: function(config) {
normalizeConfig: function (config) {
return config;
},
needUpdate: function(){
needUpdate: function () {
return false;
}
};
normalizeManager.setConfigNormalizer([fake,'default']);
normalizeManager.setConfigNormalizer([fake, 'default']);
config.load(__dirname + path.sep + './update/config');
//delete config cache produced by previous tests
var filePath = __dirname + path.sep + '../tmp/config_cache.json';
try{
try {
fs.unlinkSync(filePath);
}catch(e){}
config.enableUpdate(100, false, function(err, confs){
} catch (e) {}
config.enableUpdate(100, false, function (err, confs) {
confs.should.be.eql({});

@@ -146,8 +144,8 @@ config.disableUpdate();

it('auto updater should work fine 2', function(done){
it('auto updater should work fine 2', function (done) {
var fake = {
normalizeConfig: function(config) {
normalizeConfig: function (config) {
return config;
},
needUpdate: function(){
needUpdate: function () {
//need update

@@ -157,10 +155,10 @@ return true;

};
normalizeManager.setConfigNormalizer([fake,'default']);
normalizeManager.setConfigNormalizer([fake, 'default']);
config.load(__dirname + path.sep + './update/config');
//delete config cache produced by previous tests
var filePath = __dirname + path.sep + '../tmp/config_cache.json';
try{
try {
fs.unlinkSync(filePath);
}catch(e){}
config.enableUpdate(100, false, function(err, confs){
} catch (e) {}
config.enableUpdate(100, false, function (err, confs) {
confs.SIMPLE.__from__.should.be.match(/updater/);

@@ -172,2 +170,32 @@ config.disableUpdate();

});
it('auto updater should not change raw conf', function (done) {
var fake = {
normalizeConfig: function (config) {
config._TEST_RAW_CONF_ = true;
return config;
},
needUpdate: function () {
//need update
return true;
}
};
normalizeManager.setConfigNormalizer([fake, 'default']);
config.load(__dirname + path.sep + './update/config');
//delete config cache produced by previous tests
var filePath = __dirname + path.sep + '../tmp/config_cache.json';
try {
fs.unlinkSync(filePath);
} catch (e) {}
config.enableUpdate(100, false, function (err, confs) {
confs.SIMPLE.__from__.should.be.match(/updater/);
confs.SIMPLE._TEST_RAW_CONF_.should.be.equal(true);
// add raw conf check
(config.getUpdateNeededRawConf().SIMPLE._TEST_RAW_CONF_ === undefined).should.be.true;
(config.getRawConf().SIMPLE._TEST_RAW_CONF_ === undefined).should.be.true;
config.disableUpdate();
normalizeManager.setConfigNormalizer(['default']);
done();
});
});
});

@@ -0,0 +0,0 @@ /*

@@ -0,0 +0,0 @@ /*

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 too big to display

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