nats-hemera
Advanced tools
Comparing version 0.4.6 to 0.4.7
@@ -0,0 +0,0 @@ 'use strict'; |
@@ -0,0 +0,0 @@ "use strict"; |
@@ -66,3 +66,5 @@ 'use strict'; | ||
ctx.log.info({ outbound: ctx }); | ||
ctx.log.info({ | ||
outbound: ctx | ||
}); | ||
@@ -87,3 +89,5 @@ ctx.emit('onClientPreRequest', ctx); | ||
ctx.log.info({ inbound: ctx }); | ||
ctx.log.info({ | ||
inbound: ctx | ||
}); | ||
@@ -90,0 +94,0 @@ ctx.emit('onClientPostRequest', ctx); |
@@ -99,10 +99,8 @@ 'use strict'; | ||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } | ||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } /*! | ||
* hemera | ||
* Copyright(c) 2016 Dustin Deus (deusdustin@gmail.com) | ||
* MIT Licensed | ||
*/ | ||
/*! | ||
* hemera | ||
* Copyright(c) 2016 Dustin Deus (deusdustin@gmail.com) | ||
* MIT Licensed | ||
*/ | ||
/** | ||
@@ -1099,2 +1097,3 @@ * Module Dependencies | ||
get: function get() { | ||
return this._topics; | ||
@@ -1101,0 +1100,0 @@ } |
'use strict'; | ||
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); | ||
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); /*! | ||
* hemera | ||
* Copyright(c) 2016 Dustin Deus (deusdustin@gmail.com) | ||
* MIT Licensed | ||
*/ | ||
/*! | ||
* hemera | ||
* Copyright(c) 2016 Dustin Deus (deusdustin@gmail.com) | ||
* MIT Licensed | ||
*/ | ||
var _lodash = require('lodash'); | ||
@@ -12,0 +10,0 @@ |
'use strict'; | ||
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); | ||
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); /*! | ||
* hemera | ||
* Copyright(c) 2016 Dustin Deus (deusdustin@gmail.com) | ||
* MIT Licensed | ||
*/ | ||
/*! | ||
* hemera | ||
* Copyright(c) 2016 Dustin Deus (deusdustin@gmail.com) | ||
* MIT Licensed | ||
*/ | ||
var _lodash = require('lodash'); | ||
@@ -12,0 +10,0 @@ |
@@ -1,3 +0,1 @@ | ||
// @flow | ||
/*! | ||
@@ -14,4 +12,2 @@ * hemera | ||
_request: any; | ||
/** | ||
@@ -36,3 +32,3 @@ * Creates an instance of ClientRequest. | ||
*/ | ||
get payload(): any { | ||
get payload() { | ||
@@ -49,3 +45,3 @@ return this._request.value | ||
*/ | ||
get error(): any { | ||
get error() { | ||
@@ -61,3 +57,3 @@ return this._request.error | ||
*/ | ||
set payload(value: any) { | ||
set payload(value) { | ||
@@ -73,3 +69,3 @@ this._request.value = value | ||
*/ | ||
set error(error: Error) { | ||
set error(error) { | ||
@@ -76,0 +72,0 @@ this._request.error = error |
@@ -1,3 +0,1 @@ | ||
// @flow | ||
/*! | ||
@@ -14,4 +12,2 @@ * hemera | ||
_response: any; | ||
/** | ||
@@ -35,3 +31,3 @@ * Creates an instance of ClientResponse. | ||
*/ | ||
get payload(): any { | ||
get payload() { | ||
@@ -47,3 +43,3 @@ return this._response.value | ||
*/ | ||
set payload(value: any) { | ||
set payload(value) { | ||
@@ -59,3 +55,3 @@ this._response.value = value | ||
*/ | ||
set error(error: Error) { | ||
set error(error) { | ||
@@ -72,3 +68,3 @@ this._response.error = error | ||
*/ | ||
get error(): any { | ||
get error() { | ||
@@ -75,0 +71,0 @@ return this._response.error |
@@ -1,3 +0,1 @@ | ||
// @flow | ||
/*! | ||
@@ -4,0 +2,0 @@ * hemera |
@@ -1,3 +0,1 @@ | ||
// @flow | ||
/*! | ||
@@ -12,3 +10,3 @@ * hemera | ||
static encode(msg: any) { | ||
static encode(msg) { | ||
@@ -66,3 +64,3 @@ try { | ||
val.count++ | ||
return | ||
return | ||
} else if (parent) { | ||
@@ -69,0 +67,0 @@ |
@@ -1,3 +0,1 @@ | ||
// @flow | ||
/*! | ||
@@ -4,0 +2,0 @@ * hemera |
@@ -1,3 +0,1 @@ | ||
// @flow | ||
/*! | ||
@@ -14,8 +12,4 @@ * hemera | ||
_stack: Array<Function>; | ||
_type: string; | ||
_server: boolean; | ||
constructor(type, server) { | ||
constructor(type: string, server?: boolean) { | ||
this._stack = [] | ||
@@ -33,3 +27,3 @@ this._type = type | ||
*/ | ||
add(handler: Function) { | ||
add(handler) { | ||
@@ -47,3 +41,3 @@ this._stack.push(handler) | ||
*/ | ||
addRange(handlers: Array<Function> ) { | ||
addRange(handlers) { | ||
@@ -60,3 +54,3 @@ this._stack = this._stack.concat(handlers) | ||
*/ | ||
invoke(ctx: Hemera, cb: Function) { | ||
invoke(ctx, cb) { | ||
@@ -90,3 +84,3 @@ const each = (item, next, prevValue, i) => { | ||
*/ | ||
static serial(array: Array<Function> , method: Function, callback: Function) { | ||
static serial(array, method, callback) { | ||
@@ -93,0 +87,0 @@ if (!array.length) { |
@@ -1,3 +0,1 @@ | ||
// @flow | ||
/*! | ||
@@ -12,7 +10,7 @@ * hemera | ||
module.exports.onClientPreRequest = [function onClientPreRequest(next: Function) { | ||
module.exports.onClientPreRequest = [function onClientPreRequest(next) { | ||
let ctx: Hemera = this | ||
let ctx = this | ||
let pattern: Pattern = this._pattern | ||
let pattern = this._pattern | ||
@@ -41,3 +39,3 @@ let prevCtx = this._prevContext | ||
// request | ||
let request: Request = { | ||
let request = { | ||
id: pattern.requestId$ || Util.randomId(), | ||
@@ -51,3 +49,3 @@ parentId: ctx.request$.id, | ||
// build msg | ||
let message: ActMessage = { | ||
let message = { | ||
pattern: cleanPattern, | ||
@@ -62,3 +60,5 @@ meta: ctx.meta$, | ||
ctx.log.info({ outbound: ctx }) | ||
ctx.log.info({ | ||
outbound: ctx | ||
}) | ||
@@ -70,6 +70,6 @@ ctx.emit('onClientPreRequest', ctx) | ||
module.exports.onClientPostRequest = [function onClientPostRequest(next: Function) { | ||
module.exports.onClientPostRequest = [function onClientPostRequest(next) { | ||
let ctx: Hemera = this | ||
let pattern: Pattern = this._pattern | ||
let ctx = this | ||
let pattern = this._pattern | ||
let msg = ctx._response.payload | ||
@@ -84,3 +84,5 @@ | ||
ctx.log.info({ inbound: ctx }) | ||
ctx.log.info({ | ||
inbound: ctx | ||
}) | ||
@@ -92,9 +94,9 @@ ctx.emit('onClientPostRequest', ctx) | ||
module.exports.onServerPreRequest = [function onServerPreRequest(req: any, res: any, next: Function) { | ||
module.exports.onServerPreRequest = [function onServerPreRequest(req, res, next) { | ||
let ctx: Hemera = this | ||
let ctx = this | ||
let m = ctx._decoder.decode.call(ctx, ctx._request.payload) | ||
if(m.error) { | ||
if (m.error) { | ||
@@ -122,5 +124,5 @@ return res.send(m.error) | ||
module.exports.onServerPreHandler = [function onServerPreHandler(req: any, res: any, next: Function) { | ||
module.exports.onServerPreHandler = [function onServerPreHandler(req, res, next) { | ||
let ctx: Hemera = this | ||
let ctx = this | ||
@@ -133,5 +135,5 @@ ctx.emit('onServerPreHandler', ctx) | ||
module.exports.onServerPreResponse = [function onServerPreResponse(req: any, res: any, next: Function) { | ||
module.exports.onServerPreResponse = [function onServerPreResponse(req, res, next) { | ||
let ctx: Hemera = this | ||
let ctx = this | ||
@@ -138,0 +140,0 @@ ctx.emit('onServerPreResponse', ctx) |
127
lib/index.js
@@ -1,3 +0,1 @@ | ||
// @flow | ||
/*! | ||
@@ -37,3 +35,3 @@ * hemera | ||
var defaultConfig: Config = { | ||
var defaultConfig = { | ||
timeout: 2000, | ||
@@ -54,40 +52,2 @@ debug: false, | ||
context$: Context; | ||
meta$: Meta; | ||
delegate$: Delegate; | ||
plugin$: Plugin; | ||
trace$: Trace; | ||
request$: Request; | ||
log: any; | ||
_config: Config; | ||
_router: any; | ||
_heavy: any; | ||
_transport: NatsTransport; | ||
_topics: { | ||
[id: string]: boolean | ||
}; | ||
_plugins: { | ||
[id: string]: Plugin | ||
}; | ||
_exposition: any; | ||
_extensions: { | ||
[id: string]: Extension | ||
}; | ||
_shouldCrash: boolean; | ||
_replyTo: string; | ||
_request: any; | ||
_response: any; | ||
_pattern: any; | ||
_actMeta: any; | ||
_prevContext: Hemera; | ||
_cleanPattern: any; | ||
_message: any; | ||
_encoder: Encoder; | ||
_decoder: Decoder; | ||
/** | ||
@@ -101,3 +61,3 @@ * Creates an instance of Hemera | ||
*/ | ||
constructor(transport: Nats, params: Config) { | ||
constructor(transport, params) { | ||
@@ -214,5 +174,3 @@ super() | ||
*/ | ||
get plugins(): { | ||
[id: string]: any | ||
} { | ||
get plugins() { | ||
@@ -229,3 +187,3 @@ return this._plugins | ||
*/ | ||
get router(): any { | ||
get router() { | ||
@@ -242,3 +200,3 @@ return this._router | ||
*/ | ||
get load(): any { | ||
get load() { | ||
@@ -255,3 +213,3 @@ return this._heavy.load | ||
*/ | ||
get exposition(): any { | ||
get exposition() { | ||
@@ -270,3 +228,3 @@ return this._exposition | ||
*/ | ||
expose(key: string, object: mixed) { | ||
expose(key, object) { | ||
@@ -293,3 +251,3 @@ let pluginName = this.plugin$.attributes.name | ||
*/ | ||
get transport(): Nats { | ||
get transport() { | ||
@@ -306,5 +264,4 @@ return this._transport.driver | ||
*/ | ||
get topics(): { | ||
[id: string]: any | ||
} { | ||
get topics() { | ||
return this._topics | ||
@@ -322,3 +279,3 @@ } | ||
*/ | ||
ext(type: string, handler: Function): void { | ||
ext(type, handler) { | ||
@@ -344,3 +301,3 @@ if (!this._extensions[type]) { | ||
*/ | ||
use(params: PluginDefinition) { | ||
use(params) { | ||
@@ -378,3 +335,3 @@ if (this._plugins[params.attributes.name]) { | ||
*/ | ||
setOption(key: string, value: any) { | ||
setOption(key, value) { | ||
@@ -390,3 +347,3 @@ this.plugin$.options[key] = value | ||
*/ | ||
setConfig(key: string, value: any) { | ||
setConfig(key, value) { | ||
@@ -415,3 +372,3 @@ this._config[key] = value | ||
*/ | ||
ready(cb: Function) { | ||
ready(cb) { | ||
@@ -437,5 +394,5 @@ this._transport.driver.on('connect', () => { | ||
let result: ServerResponse = this._response | ||
let result = this._response | ||
let message: Message = { | ||
let message = { | ||
meta: this.meta$ || {}, | ||
@@ -448,3 +405,3 @@ trace: this.trace$ || {}, | ||
let endTime: number = Util.nowHrTime() | ||
let endTime = Util.nowHrTime() | ||
message.request.duration = endTime - message.request.timestamp | ||
@@ -475,5 +432,5 @@ message.trace.duration = endTime - message.request.timestamp | ||
let self: Hemera = this; | ||
let self = this; | ||
self._extensions.onServerPreResponse.invoke(self, function (err: Error, value: any) { | ||
self._extensions.onServerPreResponse.invoke(self, function (err, value) { | ||
@@ -545,5 +502,5 @@ // check if an error was already catched | ||
*/ | ||
subscribe(topic: string, subToMany: boolean, maxMessages: number) { | ||
subscribe(topic, subToMany, maxMessages) { | ||
let self: Hemera = this | ||
let self = this | ||
@@ -556,6 +513,6 @@ // avoid duplicate subscribers of the emit stream | ||
let handler = (request: any, replyTo: string) => { | ||
let handler = (request, replyTo) => { | ||
// create new execution context | ||
let ctx: Hemera = this.createContext() | ||
let ctx = this.createContext() | ||
ctx._shouldCrash = false | ||
@@ -568,5 +525,5 @@ ctx._replyTo = replyTo | ||
self._extensions.onServerPreRequest.invoke(ctx, function (err: Error, value: any) { | ||
self._extensions.onServerPreRequest.invoke(ctx, function (err, value) { | ||
let self: Hemera = this | ||
let self = this | ||
@@ -597,3 +554,3 @@ if (err) { | ||
self._extensions.onServerPreHandler.invoke(ctx, function (err: Error, value: any) { | ||
self._extensions.onServerPreHandler.invoke(ctx, function (err, value) { | ||
@@ -629,3 +586,3 @@ if (err) { | ||
// execute RPC action | ||
action(self._request.payload.pattern, (err: Error, resp) => { | ||
action(self._request.payload.pattern, (err, resp) => { | ||
@@ -706,5 +663,3 @@ if (err) { | ||
*/ | ||
add(pattern: { | ||
[id: string]: any | ||
}, cb: Function) { | ||
add(pattern, cb) { | ||
@@ -745,3 +700,3 @@ let hasCallback = _.isFunction(cb) | ||
// remove objects (rules) from pattern and extract schema | ||
_.each(pattern, function (v: string, k: any) { | ||
_.each(pattern, function (v, k) { | ||
@@ -758,3 +713,3 @@ if (_.isObject(v)) { | ||
// create message object which represent the object behind the matched pattern | ||
let actMeta: ActMeta = { | ||
let actMeta = { | ||
schema: schema, | ||
@@ -796,5 +751,3 @@ pattern: origPattern, | ||
*/ | ||
act(pattern: { | ||
[id: string]: number | ||
}, cb: Function) { | ||
act(pattern, cb) { | ||
@@ -827,5 +780,5 @@ // check for use quick syntax for JSON objects | ||
ctx._extensions.onClientPreRequest.invoke(ctx, function onPreRequest(err: Error) { | ||
ctx._extensions.onClientPreRequest.invoke(ctx, function onPreRequest(err) { | ||
let self: Hemera = this | ||
let self = this | ||
@@ -877,3 +830,3 @@ let hasCallback = _.isFunction(cb) | ||
// send request | ||
let sid = self._transport.sendRequest(pattern.topic, self._request.payload, (response: any) => { | ||
let sid = self._transport.sendRequest(pattern.topic, self._request.payload, (response) => { | ||
@@ -900,3 +853,3 @@ let res = self._decoder.decode.call(ctx, response) | ||
self._extensions.onClientPostRequest.invoke(ctx, function (err: Error) { | ||
self._extensions.onClientPostRequest.invoke(ctx, function (err) { | ||
@@ -972,5 +925,3 @@ if (err) { | ||
*/ | ||
handleTimeout(sid: number, pattern: { | ||
[id: string]: number | ||
}, cb: Function) { | ||
handleTimeout(sid, pattern, cb) { | ||
@@ -1023,3 +974,3 @@ // handle timeout | ||
var ctx: Hemera = Object.create(self) | ||
var ctx = Object.create(self) | ||
@@ -1034,3 +985,3 @@ return ctx | ||
*/ | ||
list(params: any) { | ||
list(params) { | ||
@@ -1037,0 +988,0 @@ return this._router.list(params) |
@@ -1,3 +0,1 @@ | ||
// @flow | ||
/*! | ||
@@ -14,4 +12,2 @@ * hemera | ||
_request: any; | ||
/** | ||
@@ -24,3 +20,3 @@ * Creates an instance of ServerRequest. | ||
*/ | ||
constructor(payload: any) { | ||
constructor(payload) { | ||
@@ -38,3 +34,3 @@ this._request = {} | ||
*/ | ||
get payload(): any { | ||
get payload() { | ||
@@ -51,3 +47,3 @@ return this._request.value | ||
*/ | ||
get error(): any { | ||
get error() { | ||
@@ -63,3 +59,3 @@ return this._request.error | ||
*/ | ||
set payload(value: any) { | ||
set payload(value) { | ||
@@ -75,3 +71,3 @@ this._request.value = value | ||
*/ | ||
set error(error: Error) { | ||
set error(error) { | ||
@@ -78,0 +74,0 @@ this._request.error = error |
@@ -1,3 +0,1 @@ | ||
// @flow | ||
/*! | ||
@@ -16,5 +14,2 @@ * hemera | ||
next: Function; | ||
_response: any; | ||
/** | ||
@@ -39,3 +34,3 @@ * Creates an instance of ServerResponse. | ||
*/ | ||
end(value: any) { | ||
end(value) { | ||
@@ -63,3 +58,3 @@ if (value instanceof Error) { | ||
*/ | ||
send(value: any) { | ||
send(value) { | ||
@@ -87,3 +82,3 @@ if (value instanceof Error) { | ||
*/ | ||
get payload(): any { | ||
get payload() { | ||
@@ -99,3 +94,3 @@ return this._response.value | ||
*/ | ||
set payload(value: any) { | ||
set payload(value) { | ||
@@ -111,3 +106,3 @@ this._response.value = value | ||
*/ | ||
set error(error: Error) { | ||
set error(error) { | ||
@@ -124,3 +119,3 @@ this._response.error = error | ||
*/ | ||
get error(): any { | ||
get error() { | ||
@@ -127,0 +122,0 @@ return this._response.error |
@@ -1,3 +0,1 @@ | ||
// @flow | ||
/*! | ||
@@ -51,3 +49,3 @@ * hemera | ||
return _.pickBy(obj, function (val, prop: string) { | ||
return _.pickBy(obj, function (val, prop) { | ||
return !_.includes(prop, '$') | ||
@@ -54,0 +52,0 @@ }) |
{ | ||
"name": "nats-hemera", | ||
"author": "Dustin Deus (https://github.com/StarpTech)", | ||
"version": "0.4.6", | ||
"version": "0.4.7", | ||
"main": "build/index.js", | ||
@@ -37,3 +37,3 @@ "homepage": "https://hemerajs.github.io/hemera/", | ||
"scripts": { | ||
"lint": "eslint ./src ./test && flow", | ||
"lint": "eslint ./src ./test", | ||
"build": "babel ./lib --out-dir ./build --copy-files --source-maps", | ||
@@ -61,9 +61,5 @@ "prepublish": "npm run build" | ||
"babel-plugin-syntax-flow": "^6.18.0", | ||
"babel-plugin-transform-flow-comments": "^6.22.0", | ||
"babel-plugin-transform-flow-strip-types": "^6.22.0", | ||
"babel-preset-env": "^1.1.8", | ||
"babel-register": "^6.22.0", | ||
"eslint": "^3.13.1", | ||
"eslint-plugin-flowtype": "^2.30.0", | ||
"flow-bin": "^0.38.0" | ||
"eslint": "^3.13.1" | ||
}, | ||
@@ -70,0 +66,0 @@ "nyc": { |
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 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 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 not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
6
172961
51
3222