Skip to content

Commit

Permalink
chore: export as ES6 module to
Browse files Browse the repository at this point in the history
  • Loading branch information
arlac77 committed Nov 28, 2016
1 parent af94e95 commit ad4bd4e
Show file tree
Hide file tree
Showing 11 changed files with 284 additions and 129 deletions.
138 changes: 138 additions & 0 deletions README.md
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
18 changes: 0 additions & 18 deletions index.js

This file was deleted.

67 changes: 0 additions & 67 deletions lib/connector-mixin.js

This file was deleted.

27 changes: 11 additions & 16 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@
],
"scripts": {
"cover": "npm run build && node_modules/.bin/istanbul cover node_modules/.bin/_mocha -- -u exports tests/*_test.js",
"doc": "./node_modules/.bin/jsdoc lib/*.js",
"test": "npm run build && node_modules/.bin/mocha tests/*_test.js && markdown-doctest",
"semantic-release": "semantic-release pre && npm publish && semantic-release post",
"build": "node_modules/rollup/bin/rollup --output=indes.js -c -- src/index.js",
"build": "node_modules/rollup/bin/rollup --output=dist/index.js -c -- src/index.js",
"docs": "jsdoc2md -l off -t doc/README.hbs -f src/*.js > README.md"
},
"repository": {
Expand All @@ -25,11 +24,10 @@
"model-attributes": "^2.2.13"
},
"devDependencies": {
"chai": "^3.5.0",
"cz-conventional-changelog": "^1.2.0",
"istanbul": "^0.4.5",
"jsdoc": "3.4.2",
"kronos-test-interceptor": "^2.0.5",
"chai": "^3.5.0",
"mocha": "^3.2.0",
"semantic-release": "^6.3.3",
"jsdoc-to-markdown": "^2.0.1",
Expand All @@ -38,16 +36,13 @@
"rollup-plugin-commonjs": "^5.0.5",
"rollup-plugin-node-resolve": "^2.0.0"
},
"contributors": [
{
"name": "Torsten Link",
"email": "torstenlink@gmx.de"
},
{
"name": "Markus Felten",
"email": "markus.felten@gmx.de"
}
],
"contributors": [{
"name": "Torsten Link",
"email": "torstenlink@gmx.de"
}, {
"name": "Markus Felten",
"email": "markus.felten@gmx.de"
}],
"license": "BSD-2-Clause",
"engines": {
"node": ">=6.9.1"
Expand All @@ -58,5 +53,5 @@
}
},
"module": "src/index.js",
"main": "indes.js"
}
"main": "dist/index.js"
}
72 changes: 72 additions & 0 deletions src/ConnectorMixin.js
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
};
Loading

0 comments on commit ad4bd4e

Please sign in to comment.