@adonisjs/events 8.4.0-0 → 8.4.2-0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,7 +1,7 @@
1
1
  import { Emitter } from './emitter.js';
2
2
  export declare class BaseEvent {
3
3
  constructor(..._: any[]);
4
- static emitter: Emitter<any>;
4
+ static emitter?: Emitter<any>;
5
5
  static useEmitter(emitter: Emitter<any>): void;
6
6
  static dispatch<T extends typeof BaseEvent>(this: T, ...args: ConstructorParameters<T>): Promise<void>;
7
7
  }
@@ -1,10 +1,14 @@
1
+ import { RuntimeException } from '@poppinss/utils';
1
2
  export class BaseEvent {
2
3
  constructor(..._) { }
3
4
  static emitter;
4
5
  static useEmitter(emitter) {
5
6
  this.emitter = emitter;
6
7
  }
7
- static dispatch(...args) {
8
+ static async dispatch(...args) {
9
+ if (!this.emitter) {
10
+ throw new RuntimeException(`Cannot dispatch "${this.name}" event. Make sure to pass emitter to the base event for dispatch method to work`);
11
+ }
8
12
  return this.emitter.emit(this, new this(...args));
9
13
  }
10
14
  }
@@ -5,7 +5,7 @@ import type { Listener, LazyImport, Constructor, ListenerMethod, AllowedEventTyp
5
5
  export declare class Emitter<EventsList extends Record<string | symbol | number, any>> {
6
6
  #private;
7
7
  get eventsListeners(): Map<AllowedEventTypes, Map<Listener<any, Constructor<any>>, ListenerMethod<any>>>;
8
- constructor(app: Application<any, any>);
8
+ constructor(app: Application<any>);
9
9
  onError(callback: (event: keyof EventsList | Constructor<any>, error: any, data: any) => void): this;
10
10
  listen<Event extends Constructor<any>>(event: Event, listeners: (ListenerClassWithHandleMethod<InstanceType<Event>> | LazyImport<ListenerClassWithHandleMethod<InstanceType<Event>>>)[]): void;
11
11
  on<Event extends Constructor<any>, ListenerClass extends Constructor<any>>(event: Event, listener: Listener<InstanceType<Event>, ListenerClass>): UnsubscribeFunction;
@@ -1,7 +1,7 @@
1
1
  import { Application } from '@adonisjs/application';
2
2
  import { Emitter } from '../src/emitter.js';
3
3
  type FactoryParameters = {
4
- app: Application<any, any>;
4
+ app: Application<any>;
5
5
  };
6
6
  export declare class EmitterFactory {
7
7
  #private;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adonisjs/events",
3
- "version": "8.4.0-0",
3
+ "version": "8.4.2-0",
4
4
  "description": "An implementation of the event emitter built on top of emittery",
5
5
  "main": "build/index.js",
6
6
  "type": "module",
@@ -39,26 +39,26 @@
39
39
  "author": "virk,adonisjs",
40
40
  "license": "MIT",
41
41
  "devDependencies": {
42
- "@adonisjs/application": "^6.6.0-0",
42
+ "@adonisjs/application": "^6.7.0-0",
43
43
  "@adonisjs/config": "^4.1.3-0",
44
44
  "@adonisjs/env": "^4.1.2-0",
45
45
  "@adonisjs/fold": "^9.9.0-0",
46
46
  "@adonisjs/logger": "^5.2.0-0",
47
- "@commitlint/cli": "^17.4.1",
48
- "@commitlint/config-conventional": "^17.4.0",
47
+ "@commitlint/cli": "^17.4.2",
48
+ "@commitlint/config-conventional": "^17.4.2",
49
49
  "@japa/assert": "^1.3.6",
50
50
  "@japa/expect-type": "^1.0.2",
51
51
  "@japa/run-failed-tests": "^1.1.0",
52
52
  "@japa/runner": "^2.2.2",
53
53
  "@japa/spec-reporter": "^1.3.2",
54
54
  "@poppinss/dev-utils": "^2.0.1",
55
- "@swc/core": "^1.3.26",
55
+ "@swc/core": "^1.3.27",
56
56
  "@types/fs-extra": "^11.0.1",
57
57
  "@types/node": "^18.11.18",
58
58
  "c8": "^7.12.0",
59
59
  "cross-env": "^7.0.3",
60
60
  "del-cli": "^5.0.0",
61
- "eslint": "^8.31.0",
61
+ "eslint": "^8.32.0",
62
62
  "eslint-config-prettier": "^8.6.0",
63
63
  "eslint-plugin-adonis": "^3.0.3",
64
64
  "eslint-plugin-prettier": "^4.2.1",
@@ -66,7 +66,7 @@
66
66
  "github-label-sync": "^2.0.1",
67
67
  "husky": "^8.0.3",
68
68
  "np": "^7.6.3",
69
- "prettier": "^2.8.2",
69
+ "prettier": "^2.8.3",
70
70
  "ts-node": "^10.9.1",
71
71
  "typescript": "^4.9.4"
72
72
  },
@@ -74,7 +74,7 @@
74
74
  "emittery": "^1.0.1"
75
75
  },
76
76
  "peerDependencies": {
77
- "@adonisjs/application": "^6.6.0-0",
77
+ "@adonisjs/application": "^6.7.0-0",
78
78
  "@adonisjs/fold": "^9.9.0-0"
79
79
  },
80
80
  "repository": {