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

@adonisjs/events

Package Overview
Dependencies
Maintainers
2
Versions
61
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@adonisjs/events - npm Package Compare versions

Comparing version 2.0.3 to 3.0.0

4

build/adonis-typings/events.d.ts

@@ -5,7 +5,7 @@ declare module '@ioc:Adonis/Core/Event' {

*/
export type EventHandler<T extends any = any> = ((data: T) => Promise<void> | void);
export type EventHandler<T extends any = any> = (data: T) => Promise<void> | void;
/**
* Shape of catch all events handler
*/
export type AnyHandler<T extends any = any> = ((event: string | symbol, data: T) => Promise<void> | void);
export type AnyHandler<T extends any = any> = (event: string | symbol, data: T) => Promise<void> | void;
export type EventData<T extends any, K extends any> = K extends keyof T ? T[K] : any;

@@ -12,0 +12,0 @@ /**

/*
* @adonisjs/events
*
* (c) Harminder Virk <virk@adonisjs.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
* @adonisjs/events
*
* (c) Harminder Virk <virk@adonisjs.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
"use strict";
/*
* @adonisjs/events
*
* (c) Harminder Virk <virk@adonisjs.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
* @adonisjs/events
*
* (c) Harminder Virk <virk@adonisjs.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
Object.defineProperty(exports, "__esModule", { value: true });

@@ -11,0 +11,0 @@ const Emitter_1 = require("../src/Emitter");

@@ -11,5 +11,10 @@ /// <reference path="../../adonis-typings/events.d.ts" />

transport: EmitterTransportContract;
private iocResolver;
constructor(container: IocContract);
private iocResolver?;
constructor(container?: IocContract);
/**
* Returns reference to the IoC resolver. Do not call this method until
* handler is not a string
*/
private getResolver;
/**
* Define event handler for a given event

@@ -16,0 +21,0 @@ */

"use strict";
/*
* @adonisjs/events
*
* (c) Harminder Virk <virk@adonisjs.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
* @adonisjs/events
*
* (c) Harminder Virk <virk@adonisjs.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
var __importDefault = (this && this.__importDefault) || function (mod) {

@@ -26,7 +26,19 @@ return (mod && mod.__esModule) ? mod : { "default": mod };

this.transport = new emittery_1.default();
this.iocResolver = new IocResolver_1.IocResolver(container);
if (container) {
this.iocResolver = new IocResolver_1.IocResolver(container);
}
}
/**
* Returns reference to the IoC resolver. Do not call this method until
* handler is not a string
*/
getResolver(handler) {
if (!this.iocResolver) {
throw new Error(`Cannot resolve string based event handler "${handler}". IoC container is not provided to the event emitter`);
}
return this.iocResolver;
}
on(event, handler) {
if (typeof (handler) === 'string') {
handler = this.iocResolver.getEventHandler(event, handler);
if (typeof handler === 'string') {
handler = this.getResolver(handler).getEventHandler(event, handler);
}

@@ -38,5 +50,5 @@ this.transport.on(event, handler);

this.transport.once(event).then((data) => {
if (typeof (handler) === 'string') {
this.iocResolver.getEventHandler(event, handler)(data);
this.iocResolver.removeEventHandler(event, handler);
if (typeof handler === 'string') {
this.getResolver(handler).getEventHandler(event, handler)(data);
this.getResolver(handler).removeEventHandler(event, handler);
}

@@ -53,4 +65,4 @@ else {

onAny(handler) {
if (typeof (handler) === 'string') {
handler = this.iocResolver.getAnyHandler(handler);
if (typeof handler === 'string') {
handler = this.getResolver(handler).getAnyHandler(handler);
}

@@ -64,4 +76,4 @@ this.transport.onAny(handler);

off(event, handler) {
if (typeof (handler) === 'string') {
const offHandler = this.iocResolver.removeEventHandler(event, handler);
if (typeof handler === 'string') {
const offHandler = this.getResolver(handler).removeEventHandler(event, handler);
if (offHandler) {

@@ -78,4 +90,4 @@ this.transport.off(event, offHandler);

offAny(handler) {
if (typeof (handler) === 'string') {
const offHandler = this.iocResolver.removeAnyHandler(handler);
if (typeof handler === 'string') {
const offHandler = this.getResolver(handler).removeAnyHandler(handler);
if (offHandler) {

@@ -111,3 +123,5 @@ this.transport.offAny(offHandler);

namespace(namespace) {
this.iocResolver.namespace(namespace);
if (this.iocResolver) {
this.iocResolver.namespace(namespace);
}
return this;

@@ -114,0 +128,0 @@ }

@@ -13,5 +13,2 @@ import { Emitter } from '../Emitter';

get events(): {
/**
* Clear in memory events
*/
event: string;

@@ -18,0 +15,0 @@ data: any;

"use strict";
/*
* @adonisjs/events
*
* (c) Harminder Virk <virk@adonisjs.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
* @adonisjs/events
*
* (c) Harminder Virk <virk@adonisjs.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
Object.defineProperty(exports, "__esModule", { value: true });

@@ -11,0 +11,0 @@ exports.FakeEmitter = void 0;

@@ -10,5 +10,23 @@ /// <reference path="../../adonis-typings/events.d.ts" />

export declare class IocResolver {
/**
* A reference to the event handlers resolved from the IoC container and
* cached. It is a map of
*
* [event, [namespace, resolvedHandler]]
*/
private eventHandlers;
/**
* A reference to the catch all event handlers. They can be plain callbacks or reference
* to an IoC container namespace
*/
private anyHandlers;
/**
* Reference to AdonisJS IoC container resolver. It looks for listeners inside the
* `App/Listeners` namespace or the namespace defined inside `eventListeners`
* property
*/
private containerResolver;
/**
* A custom base namespace defined directly on the event class.
*/
private listenersBaseNamespace?;

@@ -15,0 +33,0 @@ constructor(container: IocContract);

"use strict";
/*
* @adonisjs/events
*
* (c) Harminder Virk <virk@adonisjs.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
* @adonisjs/events
*
* (c) Harminder Virk <virk@adonisjs.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
Object.defineProperty(exports, "__esModule", { value: true });

@@ -19,3 +19,13 @@ exports.IocResolver = void 0;

constructor(container) {
/**
* A reference to the event handlers resolved from the IoC container and
* cached. It is a map of
*
* [event, [namespace, resolvedHandler]]
*/
this.eventHandlers = new Map();
/**
* A reference to the catch all event handlers. They can be plain callbacks or reference
* to an IoC container namespace
*/
this.anyHandlers = new Map();

@@ -22,0 +32,0 @@ this.containerResolver = container.getResolver(undefined, 'eventListeners', 'App/Listeners');

"use strict";
/*
* @adonisjs/events
*
* (c) Harminder Virk <virk@adonisjs.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
* @adonisjs/events
*
* (c) Harminder Virk <virk@adonisjs.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
Object.defineProperty(exports, "__esModule", { value: true });

@@ -23,16 +23,9 @@ exports.MemoryTransport = void 0;

}
on(_, __) {
}
async once(_) {
}
onAny(__) {
}
_off(_, __) {
}
offAny(__) {
}
off(_, __) {
}
clearListeners(_) {
}
on(_, __) { }
async once(_) { }
onAny(__) { }
_off(_, __) { }
offAny(__) { }
off(_, __) { }
clearListeners(_) { }
listenerCount(_) {

@@ -39,0 +32,0 @@ return 0;

"use strict";
/*
* @adonisjs/events
*
* (c) Harminder Virk <virk@adonisjs.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
* @adonisjs/events
*
* (c) Harminder Virk <virk@adonisjs.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
Object.defineProperty(exports, "__esModule", { value: true });

@@ -11,0 +11,0 @@ var Emitter_1 = require("./src/Emitter");

{
"name": "@adonisjs/events",
"version": "2.0.3",
"description": "Event emitter with asynchronous events",
"main": "build/providers/EventProvider.js",
"files": [
"build/src",
"build/providers",
"build/adonis-typings",
"build/standalone.d.ts",
"build/standalone.js"
],
"scripts": {
"mrm": "mrm --preset=@adonisjs/mrm-preset",
"pretest": "npm run lint",
"test": "node japaFile.js",
"lint": "eslint . --ext=.ts",
"clean": "del build",
"compile": "npm run lint && npm run clean && tsc",
"build": "npm run compile",
"commit": "git-cz",
"release": "np",
"version": "npm run build"
},
"keywords": [
"emitter",
"events"
],
"author": "virk,adonisjs",
"license": "MIT",
"devDependencies": {
"@adonisjs/fold": "^6.3.5",
"@adonisjs/mrm-preset": "^2.3.0",
"@types/node": "^14.0.13",
"commitizen": "^4.1.2",
"cz-conventional-changelog": "^3.2.0",
"del-cli": "^3.0.1",
"doctoc": "^1.4.0",
"eslint": "^7.2.0",
"eslint-plugin-adonis": "^1.0.10",
"husky": "^4.2.5",
"japa": "^3.1.1",
"mrm": "^2.3.3",
"np": "^6.2.4",
"ts-node": "^8.10.2",
"typescript": "^3.9.5"
},
"nyc": {
"exclude": [
"test"
],
"extension": [
".ts"
]
},
"husky": {
"hooks": {
"pre-commit": "doctoc README.md --title='## Table of contents' && git add README.md",
"commit-msg": "node ./node_modules/@adonisjs/mrm-preset/validateCommit/conventional/validate.js"
}
},
"config": {
"commitizen": {
"path": "cz-conventional-changelog"
}
},
"np": {
"contents": ".",
"anyBranch": false
},
"dependencies": {
"emittery": "^0.7.0"
},
"peerDependencies": {
"@adonisjs/fold": "^6.0.0"
},
"directories": {
"doc": "docs",
"test": "test"
},
"repository": {
"type": "git",
"url": "git+https://github.com/adonisjs/events.git"
},
"bugs": {
"url": "https://github.com/adonisjs/events/issues"
},
"homepage": "https://github.com/adonisjs/events#readme"
"name": "@adonisjs/events",
"version": "3.0.0",
"description": "Event emitter with asynchronous events",
"main": "build/providers/EventProvider.js",
"files": [
"build/src",
"build/providers",
"build/adonis-typings",
"build/standalone.d.ts",
"build/standalone.js"
],
"scripts": {
"mrm": "mrm --preset=@adonisjs/mrm-preset",
"pretest": "npm run lint",
"test": "node japaFile.js",
"lint": "eslint . --ext=.ts",
"clean": "del build",
"compile": "npm run lint && npm run clean && tsc",
"build": "npm run compile",
"commit": "git-cz",
"release": "np",
"version": "npm run build",
"format": "prettier --write ."
},
"keywords": [
"emitter",
"events"
],
"author": "virk,adonisjs",
"license": "MIT",
"devDependencies": {
"@adonisjs/fold": "^6.3.5",
"@adonisjs/mrm-preset": "^2.3.6",
"@types/node": "^14.0.14",
"commitizen": "^4.1.2",
"cz-conventional-changelog": "^3.2.0",
"del-cli": "^3.0.1",
"doctoc": "^1.4.0",
"eslint": "^7.4.0",
"eslint-config-prettier": "^6.11.0",
"eslint-plugin-adonis": "^1.0.14",
"eslint-plugin-prettier": "^3.1.4",
"husky": "^4.2.5",
"japa": "^3.1.1",
"mrm": "^2.3.3",
"np": "^6.2.5",
"npm-audit-html": "^1.4.1",
"prettier": "^2.0.5",
"ts-node": "^8.10.2",
"typescript": "^3.9.6"
},
"nyc": {
"exclude": [
"test"
],
"extension": [
".ts"
]
},
"husky": {
"hooks": {
"pre-commit": "doctoc README.md --title='## Table of contents' && git add README.md && npm audit --production --json | ./node_modules/.bin/npm-audit-html && git add npm-audit.html",
"commit-msg": "node ./node_modules/@adonisjs/mrm-preset/validateCommit/conventional/validate.js"
}
},
"config": {
"commitizen": {
"path": "cz-conventional-changelog"
}
},
"np": {
"contents": ".",
"anyBranch": false
},
"dependencies": {
"emittery": "^0.7.0"
},
"directories": {
"doc": "docs",
"test": "test"
},
"repository": {
"type": "git",
"url": "git+https://github.com/adonisjs/events.git"
},
"bugs": {
"url": "https://github.com/adonisjs/events/issues"
},
"homepage": "https://github.com/adonisjs/events#readme"
}

@@ -30,2 +30,3 @@ <div align="center">

- [API](#api)
- [Audit report](#audit-report)

@@ -170,2 +171,5 @@ <!-- END doctoc generated TOC please keep comment here to allow auto update -->

## Audit report
[Click here](https://htmlpreview.github.io/?https://github.com/adonisjs/events/blob/develop/npm-audit.html) to see the latest npm audit report.
[circleci-image]: https://img.shields.io/circleci/project/github/adonisjs/events/master.svg?style=for-the-badge&logo=circleci

@@ -172,0 +176,0 @@ [circleci-url]: https://circleci.com/gh/adonisjs/events "circleci"

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