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

pg-pubsub

Package Overview
Dependencies
Maintainers
2
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.7.0 to 0.8.0

49

index.d.ts
export = PGPubsub;
/** @typedef {(payload: any) => void} PGPubsubCallback */
declare class PGPubsub extends EventEmitter {
/**
* @param {string | import('pg').ClientConfig} [conString]
* @param {{ log?: typeof console.log, retryLimit?: number }} [options]
*/

@@ -14,51 +9,11 @@ // @ts-ignore

} | undefined);
/**
* @protected
* @type {string[]}
*/
protected channels: string[];
/** @protected */
protected conFails: number;
/** @protected */
// @ts-ignore
protected retry: import("promised-retry");
/**
* @protected
* @param {boolean} [noNewConnections]
* @returns {Promise<import('pg').Client>}
*/
// @ts-ignore
protected _getDB(noNewConnections?: boolean | undefined): Promise<import('pg').Client>;
/**
* @protected
* @param {import('pg').Notification} msg
* @returns {void}
*/
// @ts-ignore
protected _processNotification(msg: import('pg').Notification): void;
/**
* @param {string} channel
* @param {PGPubsubCallback} [callback]
* @returns {Promise<void>}
*/
addChannel(channel: string, callback?: PGPubsubCallback | undefined): Promise<void>;
/**
* @param {string} channel
* @param {PGPubsubCallback} [callback]
* @returns {this}
*/
removeChannel(channel: string, callback?: PGPubsubCallback | undefined): this;
/**
* @param {string} channel
* @param {any} [data]
* @returns {Promise<void>}
*/
publish(channel: string, data?: any): Promise<void>;
/**
* @returns {Promise<void>}
*/
close(): Promise<void>;
reset(): void;
#private;
}

@@ -65,0 +20,0 @@ declare namespace PGPubsub {

59

index.js

@@ -10,3 +10,3 @@ /* eslint-disable promise/prefer-await-to-then */

const EventEmitter = require('events');
const EventEmitter = require('node:events');
const { ErrorWithCause } = require('pony-cause');

@@ -21,2 +21,8 @@

class PGPubsub extends EventEmitter {
/** @type {string[]} */
#channels = [];
/** @type {import('promised-retry')} */
#retry;
/**

@@ -32,21 +38,12 @@ * @param {string | import('pg').ClientConfig} [conString]

/**
* @protected
* @type {string[]}
*/
this.channels = [];
/** @protected */
this.conFails = 0;
/** @protected */
this.retry = pgClientRetry({
this.#retry = pgClientRetry({
clientOptions: typeof conString === 'object' ? conString : { connectionString: conString },
retryLimit,
log,
shouldReconnect: () => this.channels.length !== 0,
shouldReconnect: () => this.#channels.length !== 0,
successCallback: client => {
client.on('notification', msg => this._processNotification(msg));
client.on('notification', msg => this.#processNotification(msg));
Promise.all(this.channels.map(channel => client.query('LISTEN "' + channel + '"')))
.catch(err => {
Promise.all(this.#channels.map(channel => client.query('LISTEN "' + channel + '"')))
.catch(/** @param {unknown} err */err => {
this.emit(

@@ -69,4 +66,4 @@ 'error',

async _getDB (noNewConnections) {
return this.retry.try(!noNewConnections)
.catch(err => {
return this.#retry.try(!noNewConnections)
.catch(/** @param {unknown} err */err => {
throw new ErrorWithCause('Failed to establish database connection', { cause: err });

@@ -77,7 +74,6 @@ });

/**
* @protected
* @param {import('pg').Notification} msg
* @returns {void}
*/
_processNotification (msg) {
#processNotification (msg) {
let payload = msg.payload || '';

@@ -97,7 +93,6 @@

async addChannel (channel, callback) {
if (!this.channels.includes(channel)) {
this.channels.push(channel);
if (!this.#channels.includes(channel)) {
this.#channels.push(channel);
// TODO: Can't this possibly result in both the try() method and this method adding a LISTEN for it?
// eslint-disable-next-line promise/prefer-await-to-then
try {

@@ -122,3 +117,3 @@ const db = await this._getDB();

removeChannel (channel, callback) {
const pos = this.channels.indexOf(channel);
const pos = this.#channels.indexOf(channel);

@@ -136,6 +131,6 @@ if (pos === -1) {

if (this.listeners(channel).length === 0) {
this.channels.splice(pos, 1);
this.#channels.splice(pos, 1);
this._getDB(true)
.then(db => db.query('UNLISTEN "' + channel + '"'))
.catch(err => {
.catch(/** @param {unknown} err */err => {
this.emit(

@@ -167,12 +162,14 @@ 'error',

/**
* @returns {Promise<void>}
*/
close () {
/** @returns {Promise<void>} */
async close () {
this.removeAllListeners();
this.channels = [];
return this.retry.end();
this.#channels = [];
return this.#retry.end();
}
reset () {
return this.#retry.reset();
}
}
module.exports = PGPubsub;

@@ -12,14 +12,2 @@ export type PgClientRetryOptions = {

};
/**
* @typedef PgClientRetryOptions
* @property {string|import('pg').ClientConfig} clientOptions
* @property {typeof console.log} [log]
* @property {number} [retryLimit]
* @property {(client: import('pg').Client) => Promise<import('pg').Client>|import('pg').Client} [successCallback]
* @property {() => boolean} [shouldReconnect]
*/
/**
* @param {PgClientRetryOptions} options
* @returns {import('promised-retry')}
*/

@@ -26,0 +14,0 @@ // @ts-ignore

{
"name": "pg-pubsub",
"version": "0.7.0",
"version": "0.8.0",
"description": "A Publish/Subscribe implementation on top of PostgreSQL NOTIFY/LISTEN",

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

"engines": {
"node": "^14.17.0 || >=16.0.0"
"node": "^14.18.0 || >=16.0.0"
},

@@ -37,9 +37,9 @@ "main": "index.js",

"check:installed-check": "installed-check -i eslint-plugin-jsdoc",
"check:lint": "eslint .",
"check:types": "tsc",
"check:lint": "eslint --report-unused-disable-directives .",
"check:tsc": "tsc",
"check:type-coverage": "type-coverage --detail --strict --at-least 98 --ignore-files 'test/**/*'",
"check": "run-s clean && run-p check:*",
"clean:declarations": "rm -rf $(find . -maxdepth 2 -type f -name '*.d.ts')",
"clean:declarations": "rm -rf $(find . -maxdepth 2 -type f -name '*.d.ts*')",
"clean": "run-p clean:*",
"prepublishOnly": "run-s build",
"sync-gh-actions": "ghat",
"test:mocha": "cross-env NODE_ENV=test c8 --reporter=lcov --reporter text mocha test/**/*.spec.js",

@@ -53,39 +53,40 @@ "test-ci": "run-s test:*",

"pg-format": "^1.0.2",
"pony-cause": "^1.1.1",
"promised-retry": "^0.4.0"
"pony-cause": "^2.0.0",
"promised-retry": "^0.5.0"
},
"devDependencies": {
"@hdsydsvenskan/ts-ignore-import": "^2.0.0",
"@types/chai": "^4.3.0",
"@types/chai": "^4.3.1",
"@types/chai-as-promised": "^7.1.5",
"@types/mocha": "^9.1.0",
"@types/node": "^14.18.12",
"@types/pg": "^8.6.4",
"@types/mocha": "^9.1.1",
"@types/node": "^14.18.21",
"@types/pg": "^8.6.5",
"@types/pg-format": "^1.0.2",
"@voxpelli/eslint-config": "^13.0.3",
"@voxpelli/eslint-config": "^14.1.0",
"@voxpelli/eslint-config-jsdoc-ts": "^1.0.0",
"@voxpelli/tsconfig": "^3.2.0",
"c8": "^7.11.0",
"@voxpelli/tsconfig": "^4.0.0",
"c8": "^7.11.3",
"chai": "^4.3.6",
"chai-as-promised": "^7.1.1",
"cross-env": "^7.0.3",
"dependency-check": "^5.0.0-4",
"dotenv": "^8.2.0",
"eslint": "^8.9.0",
"eslint-config-standard": "^17.0.0-1",
"dependency-check": "^5.0.0-7",
"dotenv": "^16.0.1",
"eslint": "^8.19.0",
"eslint-config-standard": "^17.0.0",
"eslint-plugin-es": "^4.1.0",
"eslint-plugin-import": "^2.25.4",
"eslint-plugin-jsdoc": "^37.9.4",
"eslint-plugin-mocha": "^10.0.3",
"eslint-plugin-n": "^14.0.0",
"eslint-plugin-import": "^2.26.0",
"eslint-plugin-jsdoc": "^39.3.3",
"eslint-plugin-mocha": "^10.0.5",
"eslint-plugin-n": "^15.2.4",
"eslint-plugin-promise": "^6.0.0",
"eslint-plugin-security": "^1.4.0",
"eslint-plugin-unicorn": "^41.0.0",
"ghat": "^0.14.0",
"husky": "^7.0.0",
"installed-check": "^5.0.0",
"mocha": "^9.2.1",
"npm-run-all": "^4.1.5",
"eslint-plugin-security": "^1.5.0",
"eslint-plugin-sort-destructure-keys": "^1.4.0",
"eslint-plugin-unicorn": "^42.0.0",
"husky": "^8.0.1",
"installed-check": "^6.0.3",
"mocha": "^10.0.0",
"npm-run-all2": "^6.0.1",
"type-coverage": "^2.22.0",
"typescript": "~4.6.0"
}
}
# PG PubSub
A Publish/Subscribe implementation on top of [PostgreSQL NOTIFY/LISTEN](http://www.postgresql.org/docs/9.3/static/sql-notify.html)
A Publish/Subscribe implementation on top of [PostgreSQL NOTIFY/LISTEN](https://www.postgresql.org/docs/current/sql-notify.html)
[![Linting Build Status](https://github.com/voxpelli/node-pg-pubsub/workflows/Linting/badge.svg)](https://github.com/voxpelli/webpage-webmentions/actions)
[![Node CI Build Status](https://github.com/voxpelli/node-pg-pubsub/workflows/Node%20CI/badge.svg)](https://github.com/voxpelli/webpage-webmentions/actions)
[![Known Vulnerabilities](https://snyk.io/test/github/voxpelli/node-pg-pubsub/badge.svg?targetFile=package.json)](https://snyk.io/test/github/voxpelli/node-pg-pubsub?targetFile=package.json)
[![js-semistandard-style](https://img.shields.io/badge/code%20style-semistandard-brightgreen.svg?style=flat)](https://github.com/Flet/semistandard)
[![js-semistandard-style](https://img.shields.io/badge/code%20style-semistandard-brightgreen.svg)](https://github.com/voxpelli/eslint-config)
[![Types in JS](https://img.shields.io/badge/types_in_js-yes-brightgreen)](https://github.com/voxpelli/types-in-js)

@@ -18,3 +16,2 @@ ## Installation

* Node.js ^14.17.0 || >=16.0.0
* Postgres >= 9.4

@@ -21,0 +18,0 @@

Sorry, the diff of this file is not supported yet

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