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

cleanup-util

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cleanup-util - npm Package Compare versions

Comparing version 0.1.0 to 0.1.1-master.3ae2d50

7

dist/index.d.ts

@@ -5,9 +5,2 @@ /// <reference types="node" />

export declare type Task = () => void;
/**
* Creates a unique identity for the specified target. If no target is specified then a the next unique identity is returned as a string of hexidecimal characters.
*
* Identities are sequential numbers represented as hexidecimal strings. If a target is specified, the target's class name is prepended to the identity so that identities read well as strings.
* @param target the target object
* @param alternateName an alternate name for the object
*/
export declare const iid: <T>(target?: T, alternateName?: string) => string;

@@ -14,0 +7,0 @@ export declare const clearIid: <T>(target?: T) => void;

112

dist/index.js
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const assert = require("assert-plus");
const dbg = require("debug");
const debug = dbg('cleanup-util');
const $cleanup = Symbol('cleanup');
const $iid = Symbol('$');
let _id = 0;
/**
* Creates a unique identity for the specified target. If no target is specified then a the next unique identity is returned as a string of hexidecimal characters.
*
* Identities are sequential numbers represented as hexidecimal strings. If a target is specified, the target's class name is prepended to the identity so that identities read well as strings.
* @param target the target object
* @param alternateName an alternate name for the object
*/
exports.iid = (target, alternateName) => {
exports.cleanupPropagationEvent = exports.addCleanupTask = exports.getIid = exports.clearIid = exports.iid = void 0;
var assert = require("assert-plus");
var dbg = require("debug");
var debug = dbg('cleanup-util');
var $cleanup = Symbol('cleanup');
var $iid = Symbol('$');
var _id = 0;
exports.iid = function (target, alternateName) {
if (target === undefined || target === null) {
return `i${(++_id).toString(16)}`;
return "i" + (++_id).toString(16);
}
const s = target;
var s = target;
if (typeof s[$iid] === 'undefined') {
const name = alternateName || s.constructor['name'] || 'anonymous';
s[$iid] = `${name} i${(++_id).toString(16)}`;
var name_1 = alternateName || s.constructor['name'] || 'anonymous';
s[$iid] = name_1 + " i" + (++_id).toString(16);
}
return s[$iid];
};
exports.clearIid = (target) => {
exports.clearIid = function (target) {
if (target === undefined || target === null) {
return;
}
const s = target;
var s = target;
if (s[$iid]) {

@@ -36,7 +30,7 @@ delete s[$iid];

};
exports.getIid = (target) => {
exports.getIid = function (target) {
if (target === undefined || target === null) {
return;
return undefined;
}
const s = target;
var s = target;
return s[$iid];

@@ -48,13 +42,13 @@ };

assert.func(task, 'task');
const s = sender;
const senderId = exports.iid(sender);
var s = sender;
var senderId = exports.iid(sender);
if (!s[$cleanup]) {
throw Error(`Invalid operation: no cleanup propagation on ${senderId}.`);
throw Error("Invalid operation: no cleanup propagation on " + senderId + ".");
}
const targetId = exports.iid(target);
var targetId = exports.iid(target);
if (!s[$cleanup][targetId]) {
throw Error(`Invalid operation: no cleanup propagation setup between ${senderId} and ${targetId}.`);
throw Error("Invalid operation: no cleanup propagation setup between " + senderId + " and " + targetId + ".");
}
s[$cleanup][targetId].push(task);
debug(`${senderId}: cleanup hook ${exports.iid(s[$cleanup])} added task ${exports.iid(task)}`);
debug(senderId + ": cleanup hook " + exports.iid(s[$cleanup]) + " added task " + exports.iid(task));
}

@@ -67,6 +61,6 @@ exports.addCleanupTask = addCleanupTask;

assert.object(target, 'target');
const s = sender;
const senderId = exports.iid(sender);
const targetId = exports.iid(target);
let origin = false;
var s = sender;
var senderId = exports.iid(sender);
var targetId = exports.iid(target);
var origin = false;
if (!s[$cleanup]) {

@@ -77,24 +71,24 @@ s[$cleanup] = {};

else if (s[$cleanup][targetId]) {
throw new Error(`Invalid operation; cleanup propagation already setup between ${senderId} and ${targetId}.`);
throw new Error("Invalid operation; cleanup propagation already setup between " + senderId + " and " + targetId + ".");
}
s[$cleanup][targetId] = [];
const cleanup = () => {
var cleanup = function () {
if (s[$cleanup] && s[$cleanup][targetId]) {
const tasks = s[$cleanup][targetId];
const len = tasks.length;
let i = len;
var tasks = s[$cleanup][targetId];
var len = tasks.length;
var i = len;
while (--i > -1) {
const task = tasks[i];
debug(`${exports.iid(s)}: cleanup hook ${targetId} running task ${exports.iid(task)}`);
var task = tasks[i];
debug(exports.iid(s) + ": cleanup hook " + targetId + " running task " + exports.iid(task));
task();
}
debug(`${exports.iid(s)}: cleanup hook ${targetId} done`);
debug(exports.iid(s) + ": cleanup hook " + targetId + " done");
delete s[$cleanup][targetId];
}
if (origin) {
setImmediate(() => {
setImmediate(function () {
if (s[$cleanup]) {
const keys = Object.keys(s[$cleanup]);
var keys = Object.keys(s[$cleanup]);
if (keys.length) {
sender.emit('error', new Error(`Memory leak detected: ${senderId} was not cleaned up by [${keys.join(',')}]`));
sender.emit('error', new Error("Memory leak detected: " + senderId + " was not cleaned up by [" + keys.join(',') + "]"));
}

@@ -106,25 +100,27 @@ delete s[$cleanup];

};
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const handler = (...args) => {
var handler = function () {
var args = [];
for (var _i = 0; _i < arguments.length; _i++) {
args[_i] = arguments[_i];
}
listener.call(sender, args);
debug(`${exports.iid(s)}: cleanup hook ${targetId} called`);
debug(exports.iid(s) + ": cleanup hook " + targetId + " called");
cleanup();
};
sender.on(event, handler);
debug(`${exports.iid(s)}: cleanup hook ${targetId} hooked`);
addCleanupTask(s, target, () => {
debug(`${exports.iid(s)}: cleanup hook ${targetId} unhooked`);
debug(exports.iid(s) + ": cleanup hook " + targetId + " hooked");
addCleanupTask(s, target, function () {
debug(exports.iid(s) + ": cleanup hook " + targetId + " unhooked");
target.removeListener(event, handler);
});
// it is possible for the reciprocal event to have a different name.
if (reciprocal) {
const reciprocalEvent = () => {
var reciprocalEvent_1 = function () {
setImmediate(cleanup);
debug(`${exports.iid(s)}: cleanup hook ${targetId} scheduled via reciprocal event}`);
debug(exports.iid(s) + ": cleanup hook " + targetId + " scheduled via reciprocal event}");
};
target.once(reciprocal, reciprocalEvent);
debug(`${exports.iid(s)}: cleanup hook ${targetId} added reciprocal event`);
addCleanupTask(s, target, () => {
debug(`${exports.iid(s)}: cleanup hook ${targetId} removing reciprocal event hook`);
target.removeListener(reciprocal, reciprocalEvent);
target.once(reciprocal, reciprocalEvent_1);
debug(exports.iid(s) + ": cleanup hook " + targetId + " added reciprocal event");
addCleanupTask(s, target, function () {
debug(exports.iid(s) + ": cleanup hook " + targetId + " removing reciprocal event hook");
target.removeListener(reciprocal, reciprocalEvent_1);
});

@@ -131,0 +127,0 @@ }

{
"name": "cleanup-util",
"version": "0.1.0",
"version": "0.1.1-master.3ae2d50",
"description": "A utility for cleaning up event handlers in nodejs.",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"files": [
"dist"
],
"keywords": [
"rabbitmq",
"amqplib",
"amqp",
"pub-sub"
"cleanup",
"events"
],

@@ -16,44 +18,51 @@ "author": "phillip@flitbit.com",

"type": "git",
"url": "git+https://github.com/flitbit/cleanup-util.git"
"url": "https://github.com/flitbit/cleanup-util"
},
"scripts": {
"build": "tsc --build tsconfig.json",
"clean": "rimraf dist .nyc_output coverage",
"lint": "eslint src --ext .js,.ts,.json",
"preversion": "npm run build",
"clean": "rimraf coverage dist tmp docs",
"prebuild": "npm run lint",
"pretest": "npm run build",
"test": "nyc mocha src/**/*.spec.ts",
"test:watch": "nodemon --watch 'src/**/*' -e ts,tsx --exec npm run test",
"ci": "npm run test",
"docs": "typedoc"
"buildall": "tsc -p tsconfig.release.json && npm run docs",
"build": "npm run buildall",
"build:watch": "tsc -w -p tsconfig.release.json",
"lint": "eslint . --ext .ts,.tsx",
"pretest": "npm run lint",
"test": "nyc mocha __tests__/**/*.spec.ts",
"test:watch": "chokidar \"*.js\" \"*.json\" \"src/**/*.ts\" \"__tests__/**/*.ts\" --command \"npm run test\" --initial",
"cilint": "eslint . --ext .ts,.tsx --format junit --output-file ./reports/eslint/eslint.xml",
"precibuild": "npm run cilint",
"cibuild": "npm run buildall",
"preci": "npm run cibuild",
"ci": "nyc mocha __tests__/**/*.spec.ts --timeout=10000 --exit --reporter mocha-junit-reporter --reporter-options mochaFile=reports/mocha/test-results.xml",
"docs": "typedoc --theme minimal && cp _config.yml docs/"
},
"devDependencies": {
"@types/assert-plus": "^1.0.4",
"@types/chai": "^4.2.9",
"@types/chai": "^4.2.11",
"@types/debug": "^4.1.5",
"@types/mocha": "^7.0.1",
"@typescript-eslint/eslint-plugin": "^2.20.0",
"@typescript-eslint/parser": "^2.20.0",
"@types/mocha": "^8.0.0",
"@types/node": "~14.0.24",
"@typescript-eslint/eslint-plugin": "~3.7.0",
"@typescript-eslint/parser": "~3.7.0",
"bent": "^7.3.7",
"chai": "^4.2.0",
"eslint": "^6.8.0",
"eslint-config-prettier": "^6.10.0",
"eslint-plugin-import": "^2.20.1",
"eslint-plugin-json": "^2.0.1",
"eslint-plugin-mocha": "^6.2.2",
"eslint-plugin-prettier": "^3.1.2",
"lodash": "^4.17.15",
"mocha": "^7.0.1",
"nodemon": "^2.0.2",
"nyc": "^15.0.0",
"prettier": "^1.19.1",
"rimraf": "^3.0.2",
"source-map-support": "^0.5.16",
"ts-node": "^8.6.2",
"typedoc": "^0.16.10",
"typescript": "^3.7.5"
"chokidar-cli": "^2.1.0",
"eslint": "^7.5.0",
"eslint-config-prettier": "~6.11.0",
"eslint-plugin-mocha": "^7.0.1",
"mocha": "^8.0.1",
"mocha-junit-reporter": "^2.0.0",
"nyc": "^15.1.0",
"prettier": "~2.0.5",
"rimraf": "~3.0.2",
"ts-loader": "^8.0.1",
"ts-node": "^8.10.2",
"typedoc": "^0.17.8",
"typescript": "~3.9.7",
"webpack": "^4.43.0",
"webpack-cli": "^3.3.12"
},
"dependencies": {
"assert-plus": "^1.0.0",
"debug": "^4.1.1"
"debug": "^4.1.1",
"tslib": "^2.0.0"
},

@@ -64,5 +73,2 @@ "nyc": {

],
"exclude": [
"src/__test__/**/*.ts"
],
"extension": [

@@ -69,0 +75,0 @@ ".ts",

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