Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

pg-pubsub

Package Overview
Dependencies
Maintainers
1
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

pg-pubsub - npm Package Compare versions

Comparing version 0.4.0 to 0.4.1

.vscode/launch.json

5

CHANGELOG.md
# Changelog
## 0.4.1 (2018-09-17)
* **Somewhat breaking change:** Logging is silenced in production by default
* **Feature:** `.close()` now returns a `Promise` that's resolved when the database has been fully shutdown
## 0.4.0 (2018-06-17)

@@ -4,0 +9,0 @@

14

index.js

@@ -18,3 +18,3 @@ 'use strict';

const PGPubsub = function (conString, options) {
const PGPubsub = function (conString, { log, retryLimit } = {}) {
EventEmitter.call(this);

@@ -34,3 +34,3 @@

options = options || {};
log = log || (process.env.NODE_ENV === 'production' ? () => {} : console.log.bind(console));

@@ -63,7 +63,5 @@ this.retry = new Retry({

},
end: db => {
if (db) { db.end(); }
},
retryLimit: options.retryLimit,
log: options.log || console.log.bind(console)
end: db => db ? db.end() : undefined,
retryLimit,
log
});

@@ -135,7 +133,7 @@ };

PGPubsub.prototype.close = function () {
this.retry.end();
this.removeAllListeners();
this.channels = [];
return this.retry.end();
};
module.exports = PGPubsub;
{
"name": "pg-pubsub",
"version": "0.4.0",
"version": "0.4.1",
"description": "A Publish/Subscribe implementation on top of PostgreSQL NOTIFY/LISTEN",

@@ -29,3 +29,3 @@ "homepage": "http://github.com/voxpelli/node-pg-pubsub",

"dependency-check": "JS_FILES=\"*.js test/*/*.js\" && dependency-check . $JS_FILES && dependency-check . $JS_FILES --unused --no-dev",
"test": "installed-check -e && eslint . && npm run --silent dependency-check && npm run --silent mocha",
"test": "installed-check -e -i eslint && eslint . && npm run --silent dependency-check && npm run --silent mocha",
"prepush": "npm test"

@@ -36,17 +36,16 @@ },

"chai-as-promised": "7.1.1",
"coveralls": "3.0.1",
"dependency-check": "3.1.0",
"coveralls": "3.0.2",
"dependency-check": "3.2.1",
"dotenv": "6.0.0",
"eslint": "4.19.1",
"eslint-config-semistandard": "12.0.1",
"eslint-config-standard": "11.0.0",
"eslint-plugin-import": "2.12.0",
"eslint-plugin-node": "6.0.1",
"eslint-plugin-promise": "3.8.0",
"eslint-plugin-standard": "3.1.0",
"eslint": "5.6.0",
"eslint-config-standard": "12.0.0",
"eslint-plugin-import": "2.14.0",
"eslint-plugin-node": "7.0.1",
"eslint-plugin-promise": "4.0.1",
"eslint-plugin-standard": "4.0.0",
"husky": "0.14.3",
"installed-check": "2.1.3",
"installed-check": "2.2.0",
"mocha": "5.2.0",
"nyc": "12.0.2"
"nyc": "13.0.1"
}
}

@@ -5,3 +5,2 @@ # PG PubSub

[![Build Status](https://travis-ci.org/voxpelli/node-pg-pubsub.svg?branch=master)](https://travis-ci.org/voxpelli/node-pg-pubsub)

@@ -25,4 +24,27 @@ [![Coverage Status](https://coveralls.io/repos/voxpelli/node-pg-pubsub/badge.svg)](https://coveralls.io/r/voxpelli/node-pg-pubsub)

Simple:
```js
var PGPubsub = require('pg-pubsub');
var pubsubInstance = new PGPubsub(uri[, options]);
```
### Options
```js
{
[log]: Function // default: silent when NODE_ENV=production, otherwise defaults to console.log(...)
}
```
### Methods
* **addChannel(channelName[, eventListener])** – starts listening on a channel and optionally adds an event listener for that event. As `PGPubsub` inherits from `EventEmitter` one also add it oneself.
* **removeChannel(channelName[, eventListener])** – either removes all event listeners and stops listeneing on the channel or removes the specified event listener and stops listening on the channel if that was the last listener attached.
* **publish(channelName, data)** – publishes the specified data JSON-encoded to the specified channel. It may be better to do this by sending the `NOTIFY channelName, '{"hello":"world"}'` query yourself using your ordinary Postgres pool, rather than relying on the single connection of this module. Returns a Promise that will become rejected or resolved depending on the success of the Postgres call.
* **close(): Promise<void>** – closes down the database connection and removes all listeners. Useful for graceful shutdowns.
* All [EventEmitter methods](http://nodejs.org/api/events.html#events_class_events_eventemitter) are inherited from `EventEmitter`
### Examples
#### Simple
```javascript

@@ -40,3 +62,3 @@ var pubsubInstance = new PGPubsub('postgres://username@localhost/database');

More advanced variant:
#### Advanced

@@ -54,15 +76,2 @@ ```javascript

## new PGPubsub([conString], [options])
* **conString** – a connection string for the Postgres database. If none is picked, then the default is the same default as for [`pg.Client()`](https://github.com/brianc/node-postgres/wiki/Client)
* **options.retryLimit** – may be set to a numeric value to limit the the number of retries that are made
## Methods
* **addChannel(channelName[, eventListener])** – starts listening on a channel and optionally adds an event listener for that event. As `PGPubsub` inherits from `EventEmitter` one also add it oneself.
* **removeChannel(channelName[, eventListener])** – either removes all event listeners and stops listeneing on the channel or removes the specified event listener and stops listening on the channel if that was the last listener attached.
* **publish(channelName, data)** – publishes the specified data JSON-encoded to the specified channel. It may be better to do this by sending the `NOTIFY channelName, '{"hello":"world"}'` query yourself using your ordinary Postgres pool, rather than relying on the single connection of this module. Returns a Promise that will become rejected or resolved depending on the success of the Postgres call.
* **close** – closes down the database connection and removes all listeners. Useful for graceful shutdowns.
* All [EventEmitter methods](http://nodejs.org/api/events.html#events_class_events_eventemitter) are inherited from `EventEmitter`
## Description

@@ -74,2 +83,14 @@

`npm test` or to watch, install `grunt-cli` then do `grunt watch`
- setup a postgres database to run the integration tests
- the easist way to do this is via docker, `docker run -it -p 5432:5432 -e POSTGRES_DB=pgpubsub_test postgres`
- `npm test`
For an all-in-one command, try:
```sh
# fire up a new DB container, run tests against it, and clean it up!
docker rm -f pgpubsub_test || true && \
docker run -itd -p 5432:5432 -e POSTGRES_DB=pgpubsub_test --name pgpubsub_test postgres && \
npm test && \
docker rm -f pgpubsub_test
```

@@ -21,6 +21,6 @@ 'use strict';

beforeEach(function () {
beforeEach(() => {
pubsubInstance = new PGPubsub(connectionDetails, {
log: function () {
if (!arguments[0].includes('Success')) {
if (typeof arguments[0] !== 'string' || !arguments[0].startsWith('Success')) {
console.log.apply(this, arguments);

@@ -35,5 +35,3 @@ }

afterEach(function () {
pubsubInstance.close();
});
afterEach(() => pubsubInstance.close());

@@ -40,0 +38,0 @@ describe('init', function () {

Sorry, the diff of this file is not supported yet

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