-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
284 additions
and
129 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,138 @@ | ||
[![npm](https://img.shields.io/npm/v/kronos-interceptor.svg)](https://www.npmjs.com/package/kronos-interceptor) | ||
[![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg)](https://github.com/Kronos-Integration/kronos-interceptor) | ||
[![Build Status](https://secure.travis-ci.org/Kronos-Integration/kronos-interceptor.png)](http://travis-ci.org/Kronos-Integration/kronos-interceptor) | ||
[![bithound](https://www.bithound.io/github/Kronos-Integration/kronos-interceptor/badges/score.svg)](https://www.bithound.io/github/Kronos-Integration/kronos-interceptor) | ||
[![codecov.io](http://codecov.io/github/Kronos-Integration/kronos-interceptor/coverage.svg?branch=master)](http://codecov.io/github/Kronos-Integration/kronos-interceptor?branch=master) | ||
[![Coverage Status](https://coveralls.io/repos/Kronos-Integration/kronos-interceptor/badge.svg)](https://coveralls.io/r/Kronos-Integration/kronos-interceptor) | ||
[![Code Climate](https://codeclimate.com/github/Kronos-Integration/kronos-interceptor/badges/gpa.svg)](https://codeclimate.com/github/Kronos-Integration/kronos-interceptor) | ||
[![Known Vulnerabilities](https://snyk.io/test/github/Kronos-Integration/kronos-interceptor/badge.svg)](https://snyk.io/test/github/Kronos-Integration/kronos-interceptor) | ||
[![GitHub Issues](https://img.shields.io/github/issues/Kronos-Integration/kronos-interceptor.svg?style=flat-square)](https://github.com/Kronos-Integration/kronos-interceptor/issues) | ||
[![Stories in Ready](https://badge.waffle.io/Kronos-Integration/kronos-interceptor.svg?label=ready&title=Ready)](http://waffle.io/Kronos-Integration/kronos-interceptor) | ||
[![Dependency Status](https://david-dm.org/Kronos-Integration/kronos-interceptor.svg)](https://david-dm.org/Kronos-Integration/kronos-interceptor) | ||
[![devDependency Status](https://david-dm.org/Kronos-Integration/kronos-interceptor/dev-status.svg)](https://david-dm.org/Kronos-Integration/kronos-interceptor#info=devDependencies) | ||
[![docs](http://inch-ci.org/github/Kronos-Integration/kronos-interceptor.svg?branch=master)](http://inch-ci.org/github/Kronos-Integration/kronos-interceptor) | ||
[![downloads](http://img.shields.io/npm/dm/kronos-interceptor.svg?style=flat-square)](https://npmjs.org/package/kronos-interceptor) | ||
[![Commitizen friendly](https://img.shields.io/badge/commitizen-friendly-brightgreen.svg)](http://commitizen.github.io/cz-cli/) | ||
|
||
|
||
kronos-interceptor | ||
===== | ||
introspects / modifies requests as they pass between endpoints | ||
|
||
```javascript | ||
|
||
interceptor1.connected = interceptor2 | ||
|
||
promise = interceptor1.receive(request); | ||
``` | ||
|
||
# API Reference | ||
|
||
* <a name="rejectingReceiver"></a> | ||
|
||
## rejectingReceiver() | ||
rejecting receiver used to signal a not present connection | ||
when used always delivers a rejecting promise | ||
|
||
**Kind**: global function | ||
|
||
* <a name="ConnectorMixin"></a> | ||
|
||
## ConnectorMixin() | ||
Mixin to make endpoints/interceptors connectable | ||
Forms a single linked list | ||
|
||
**Kind**: global function | ||
|
||
* <a name="injectNext"></a> | ||
|
||
## injectNext(endpoint) | ||
Injects a endpoint after ourselfs. | ||
|
||
**Kind**: global function | ||
|
||
| Param | Type | Description | | ||
| --- | --- | --- | | ||
| endpoint | <code>Endpoint</code> | to be injected (after ourselfs) | | ||
|
||
|
||
* <a name="removeNext"></a> | ||
|
||
## removeNext() | ||
Removes the next element from the chain | ||
|
||
**Kind**: global function | ||
|
||
* <a name="configure"></a> | ||
|
||
## configure(config) | ||
Takes attribute values from config parameters | ||
and copies them over to the object. | ||
Copying is done according to configurationAttributes | ||
Which means we loop over all configuration attributes | ||
and then for each attribute decide if we use the default, call a setter function | ||
or simply assign the attribute value | ||
|
||
**Kind**: global function | ||
|
||
| Param | Type | | ||
| --- | --- | | ||
| config | <code>Object</code> | | ||
|
||
|
||
* <a name="toJSON"></a> | ||
|
||
## toJSON() ⇒ <code>Object</code> | ||
Deliver the json representation | ||
|
||
**Kind**: global function | ||
**Returns**: <code>Object</code> - json representation | ||
|
||
* <a name="reset"></a> | ||
|
||
## reset() | ||
forget all accumulated information | ||
|
||
**Kind**: global function | ||
|
||
* <a name="receive"></a> | ||
|
||
## receive(request, oldRequest) | ||
The receive method. This method receives the request from the leading interceptor and calls the | ||
trailing interceptor | ||
|
||
**Kind**: global function | ||
|
||
| Param | Type | Description | | ||
| --- | --- | --- | | ||
| request | <code>object</code> | the request from the leading interceptor | | ||
| oldRequest | <code>object</code> | the oldRequest from the leading interceptor. This is a special case. As some interceptors are in charge of copying and creating the request objects, the step will call the interceptor chain with the both requests. At some point of the interceptor chain only the request itself will survive. But all interceptors designed to be inserted early in the interceptor chain of a sending endpoint should pass both requests to the next interceptor. | | ||
|
||
|
||
* <a name="receive"></a> | ||
|
||
## receive() | ||
Logs the time the requests takes | ||
|
||
**Kind**: global function | ||
|
||
* <a name="rejectUnlessResolvedWithin"></a> | ||
|
||
## rejectUnlessResolvedWithin() | ||
**Kind**: global function | ||
|
||
* * * | ||
|
||
install | ||
======= | ||
|
||
With [npm](http://npmjs.org) do: | ||
|
||
```shell | ||
npm install kronos-interceptor | ||
``` | ||
|
||
license | ||
======= | ||
|
||
BSD-2-Clause |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
/* jslint node: true, esnext: true */ | ||
|
||
'use strict'; | ||
|
||
/** | ||
* rejecting receiver used to signal a not present connection | ||
* when used always delivers a rejecting promise | ||
*/ | ||
function rejectingReceiver(request) { | ||
return Promise.reject(new Error('Receiver not defined')); | ||
} | ||
|
||
/** | ||
* Mixin to make endpoints/interceptors connectable | ||
* Forms a single linked list | ||
*/ | ||
|
||
function ConnectorMixin(superclass) { | ||
return class extends superclass { | ||
set connected(e) { | ||
this._connected = e; | ||
} | ||
|
||
get connected() { | ||
return this._connected; | ||
} | ||
|
||
get isConnected() { | ||
return (this._connected && this._connected != rejectingReceiver) ? true : false; | ||
} | ||
|
||
/** | ||
* Delivers the other end of the connection chain | ||
* Given: | ||
* a.connected = b | ||
* b.connected = c | ||
* then a.otherEnd === c | ||
* @return undefined if not connected at all | ||
*/ | ||
get otherEnd() { | ||
let c = this; | ||
|
||
while (c.isConnected) { | ||
c = c.connected; | ||
} | ||
return c === this ? undefined : c; | ||
} | ||
|
||
/** | ||
* Injects a endpoint after ourselfs. | ||
* @param {Endpoint} endpoint to be injected (after ourselfs) | ||
*/ | ||
injectNext(endpoint) { | ||
endpoint.connected = this.connected; | ||
this.connected = endpoint; | ||
} | ||
|
||
/** | ||
* Removes the next element from the chain | ||
*/ | ||
removeNext() { | ||
if (this.isConnected) { | ||
this.connected = this.connected.connected; | ||
} | ||
} | ||
}; | ||
} | ||
|
||
export { | ||
rejectingReceiver, | ||
ConnectorMixin | ||
}; |
Oops, something went wrong.