-
Notifications
You must be signed in to change notification settings - Fork 1
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
0 parents
commit 75cf153
Showing
7 changed files
with
283 additions
and
0 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,22 @@ | ||
node_modules | ||
bower_components | ||
lib-cov | ||
*.seed | ||
*.log | ||
*.out | ||
*.pid | ||
npm-debug.log | ||
*~ | ||
*# | ||
.DS_STORE | ||
.netbeans | ||
nbproject | ||
.idea | ||
.node_history | ||
dist | ||
tmp | ||
coverage | ||
|
||
|
||
# Ignore built ts files | ||
dist/**/* |
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,4 @@ | ||
# spikenail-pubsub-redis | ||
|
||
This package enables Redis as PubSub engine for Spikenail framework | ||
|
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,41 @@ | ||
{ | ||
"name": "spikenail-pubsub-redis", | ||
"version": "0.1.0", | ||
"description": "Redis PubSub for Spikenail framework", | ||
"main": "index.js", | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/spikenail/spikenail-pubsub-redis.git" | ||
}, | ||
"author": "Igor Lesnenko", | ||
"license": "MIT", | ||
"bugs": { | ||
"url": "https://github.com/spikenail/spikenail-pubsub-redis/issues" | ||
}, | ||
"scripts": { | ||
"compile": "tsc", | ||
"pretest": "npm run compile", | ||
"test": "npm run testonly -- && npm run integration --", | ||
"posttest": "npm run lint", | ||
"lint": "tslint --type-check --project ./tsconfig.json ./src/**/*.ts", | ||
"watch": "tsc -w", | ||
"testonly": "mocha --reporter spec --full-trace ./dist/test/tests.js ", | ||
"integration": "npm run compile && mocha --reporter spec --full-trace ./dist/test/integration-tests.js ", | ||
"benchmark": "npm run compile && mocha --reporter spec --full-trace ./dist/test/benchmark.js ", | ||
"coverage": "node ./node_modules/istanbul/lib/cli.js cover _mocha -- --full-trace ./dist/test/tests.js", | ||
"postcoverage": "remap-istanbul --input coverage/coverage.raw.json --type lcovonly --output coverage/lcov.info", | ||
"prepublish": "npm run test" | ||
}, | ||
"homepage": "https://github.com/spikenail/spikenail-pubsub-redis#readme", | ||
"devDependencies": { | ||
"@types/graphql": "^0.11.5", | ||
"@types/ioredis": "0.0.25", | ||
"@types/node": "^8.0.34", | ||
"typescript": "^2.5.3" | ||
}, | ||
"dependencies": { | ||
"graphql": "^0.11.7", | ||
"graphql-redis-subscriptions": "github:spikenail/graphql-redis-subscriptions", | ||
"ioredis": "^3.1.4" | ||
} | ||
} |
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,59 @@ | ||
import { RedisPubSub as RedisPubSub } from 'graphql-redis-subscriptions'; | ||
import * as Redis from 'ioredis'; | ||
|
||
export class PubSub { | ||
|
||
public pubsub: any; | ||
|
||
constructor(config: Object) { | ||
let defaults = { | ||
host: '127.0.0.1', | ||
port: '6379', | ||
retry_strategy: options => { | ||
// reconnect after | ||
return Math.max(options.attempt * 100, 3000); | ||
} | ||
}; | ||
|
||
let options = Object.assign({}, defaults, config); | ||
|
||
this.pubsub = new RedisPubSub({ | ||
connection: options | ||
}); | ||
} | ||
|
||
/** | ||
* Publish data | ||
* | ||
* @param path | ||
* @param data | ||
* @returns {Promise<boolean>} | ||
*/ | ||
async publish(path: Array<string>, data: Object) { | ||
let topic = this.pathToChannel(path); | ||
return await this.pubsub.publish(topic, data); | ||
} | ||
|
||
/** | ||
* Path to channel | ||
* | ||
* @param path | ||
* @returns {string} | ||
*/ | ||
pathToChannel(path: Array<string>) { | ||
return path.join('.'); | ||
} | ||
|
||
/** | ||
* Path to subscription channel | ||
* | ||
* @param path | ||
* @returns {string} | ||
*/ | ||
pathToSubscriptionChannel(path: Array<string>) { | ||
return path.join('.'); | ||
} | ||
} | ||
|
||
|
||
|
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 @@ | ||
export { PubSub } from './PubSub'; |
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,20 @@ | ||
{ | ||
"compilerOptions": { | ||
"target": "es5", | ||
"module": "commonjs", | ||
"moduleResolution": "node", | ||
"sourceMap": true, | ||
"noImplicitAny": false, | ||
"rootDir": "./src", | ||
"outDir": "./dist", | ||
"allowSyntheticDefaultImports": true, | ||
"pretty": true, | ||
"removeComments": true, | ||
"declaration": true, | ||
"lib": ["es6","esnext"] | ||
}, | ||
"exclude": [ | ||
"node_modules", | ||
"dist" | ||
] | ||
} |
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,136 @@ | ||
{ | ||
"rules": { | ||
"align": [ | ||
false, | ||
"parameters", | ||
"arguments", | ||
"statements" | ||
], | ||
"ban": false, | ||
"class-name": true, | ||
"curly": [true, "ignore-same-line"], | ||
"eofline": true, | ||
"forin": true, | ||
"indent": [ | ||
true, | ||
"spaces" | ||
], | ||
"interface-name": false, | ||
"jsdoc-format": true, | ||
"label-position": true, | ||
"max-line-length": [ | ||
true, | ||
140 | ||
], | ||
"member-access": true, | ||
"member-ordering": [ | ||
true, | ||
"public-before-private", | ||
"static-before-instance" | ||
], | ||
"no-any": false, | ||
"no-arg": true, | ||
"no-bitwise": true, | ||
"no-conditional-assignment": true, | ||
"no-consecutive-blank-lines": false, | ||
"no-console": [ | ||
true, | ||
"log", | ||
"debug", | ||
"info", | ||
"time", | ||
"timeEnd", | ||
"trace" | ||
], | ||
"no-construct": true, | ||
"no-parameter-properties": true, | ||
"no-debugger": true, | ||
"no-duplicate-variable": true, | ||
"no-empty": true, | ||
"no-eval": true, | ||
"no-inferrable-types": false, | ||
"no-internal-module": true, | ||
"no-null-keyword": false, | ||
"no-require-imports": false, | ||
"no-shadowed-variable": true, | ||
"no-switch-case-fall-through": true, | ||
"no-trailing-whitespace": true, | ||
"no-unused-expression": true, | ||
"no-unused-variable": true, | ||
"no-use-before-declare": true, | ||
"no-var-keyword": true, | ||
"no-var-requires": true, | ||
"object-literal-sort-keys": false, | ||
"one-line": [ | ||
true, | ||
"check-open-brace", | ||
"check-catch", | ||
"check-else", | ||
"check-finally", | ||
"check-whitespace" | ||
], | ||
"quotemark": [ | ||
true, | ||
"single", | ||
"avoid-escape" | ||
], | ||
"radix": true, | ||
"semicolon": [ | ||
true, | ||
"always" | ||
], | ||
"switch-default": true, | ||
"trailing-comma": [ | ||
true, | ||
{ | ||
"multiline": "always", | ||
"singleline": "never" | ||
} | ||
], | ||
"triple-equals": [ | ||
true, | ||
"allow-null-check" | ||
], | ||
"typedef": [ | ||
false, | ||
"call-signature", | ||
"parameter", | ||
"arrow-parameter", | ||
"property-declaration", | ||
"variable-declaration", | ||
"member-variable-declaration" | ||
], | ||
"typedef-whitespace": [ | ||
true, | ||
{ | ||
"call-signature": "nospace", | ||
"index-signature": "nospace", | ||
"parameter": "nospace", | ||
"property-declaration": "nospace", | ||
"variable-declaration": "nospace" | ||
}, | ||
{ | ||
"call-signature": "space", | ||
"index-signature": "space", | ||
"parameter": "space", | ||
"property-declaration": "space", | ||
"variable-declaration": "space" | ||
} | ||
], | ||
"variable-name": [ | ||
true, | ||
"check-format", | ||
"allow-leading-underscore", | ||
"ban-keywords", | ||
"allow-pascal-case" | ||
], | ||
"whitespace": [ | ||
true, | ||
"check-branch", | ||
"check-decl", | ||
"check-operator", | ||
"check-separator", | ||
"check-type" | ||
] | ||
} | ||
} |