@adonisjs/events 8.4.9-5 → 9.0.0-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.
- package/README.md +1 -4
- package/build/chunk-VVJERWW5.js +402 -0
- package/build/{src/emitter.d.ts → emitter-253440aa.d.ts} +54 -5
- package/build/factories/main.d.ts +17 -1
- package/build/factories/main.js +16 -9
- package/build/index.d.ts +27 -2
- package/build/index.js +36 -10
- package/build/src/types.d.ts +12 -10
- package/build/src/types.js +0 -9
- package/package.json +35 -25
- package/build/factories/emitter.d.ts +0 -12
- package/build/factories/emitter.js +0 -21
- package/build/src/base_event.d.ts +0 -21
- package/build/src/base_event.js +0 -36
- package/build/src/debug.d.ts +0 -3
- package/build/src/debug.js +0 -10
- package/build/src/emitter.js +0 -320
- package/build/src/events_buffer.d.ts +0 -47
- package/build/src/events_buffer.js +0 -126
|
@@ -1,126 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* @adonisjs/events
|
|
3
|
-
*
|
|
4
|
-
* (c) AdonisJS
|
|
5
|
-
*
|
|
6
|
-
* For the full copyright and license information, please view the LICENSE
|
|
7
|
-
* file that was distributed with this source code.
|
|
8
|
-
*/
|
|
9
|
-
import is from '@sindresorhus/is';
|
|
10
|
-
import { AssertionError } from 'node:assert';
|
|
11
|
-
/**
|
|
12
|
-
* Exposes API to filter, find events from the events buffer.
|
|
13
|
-
*/
|
|
14
|
-
export class EventsBuffer {
|
|
15
|
-
/**
|
|
16
|
-
* Buffered events
|
|
17
|
-
*/
|
|
18
|
-
#events = [];
|
|
19
|
-
/**
|
|
20
|
-
* Track emitted event
|
|
21
|
-
*/
|
|
22
|
-
add(event, data) {
|
|
23
|
-
this.#events.push({ event: event, data });
|
|
24
|
-
}
|
|
25
|
-
/**
|
|
26
|
-
* Get all the emitted events
|
|
27
|
-
*/
|
|
28
|
-
all() {
|
|
29
|
-
return this.#events;
|
|
30
|
-
}
|
|
31
|
-
/**
|
|
32
|
-
* Returns the size of captured events
|
|
33
|
-
*/
|
|
34
|
-
size() {
|
|
35
|
-
return this.#events.length;
|
|
36
|
-
}
|
|
37
|
-
/**
|
|
38
|
-
* Find if an event was emitted
|
|
39
|
-
*/
|
|
40
|
-
exists(finder) {
|
|
41
|
-
return !!this.find(finder);
|
|
42
|
-
}
|
|
43
|
-
/**
|
|
44
|
-
* Get selected events
|
|
45
|
-
*/
|
|
46
|
-
filter(finder) {
|
|
47
|
-
if (typeof finder === 'function' && !is.class_(finder)) {
|
|
48
|
-
return this.#events.filter(finder);
|
|
49
|
-
}
|
|
50
|
-
return this.#events.filter((event) => event.event === finder);
|
|
51
|
-
}
|
|
52
|
-
/**
|
|
53
|
-
* Find a specific event
|
|
54
|
-
*/
|
|
55
|
-
find(finder) {
|
|
56
|
-
if (typeof finder === 'function' && !is.class_(finder)) {
|
|
57
|
-
return (this.#events.find(finder) || null);
|
|
58
|
-
}
|
|
59
|
-
return (this.#events.find((event) => event.event === finder) || null);
|
|
60
|
-
}
|
|
61
|
-
/**
|
|
62
|
-
* Assert a given event has been emitted
|
|
63
|
-
*/
|
|
64
|
-
assertEmitted(finder) {
|
|
65
|
-
const hasEvent = this.exists(finder);
|
|
66
|
-
if (!hasEvent) {
|
|
67
|
-
const isClass = is.class_(finder);
|
|
68
|
-
const message = typeof finder === 'function' && !isClass
|
|
69
|
-
? `Expected callback to find an emitted event`
|
|
70
|
-
: isClass
|
|
71
|
-
? `Expected "${finder.name}" event to be emitted`
|
|
72
|
-
: `Expected "${String(finder)}" event to be emitted`;
|
|
73
|
-
throw new AssertionError({
|
|
74
|
-
message: message,
|
|
75
|
-
expected: true,
|
|
76
|
-
actual: false,
|
|
77
|
-
operator: 'strictEqual',
|
|
78
|
-
stackStartFn: this.assertEmitted,
|
|
79
|
-
});
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
/**
|
|
83
|
-
* Assert a given event has been not been emitted
|
|
84
|
-
*/
|
|
85
|
-
assertNotEmitted(finder) {
|
|
86
|
-
const hasEvent = this.exists(finder);
|
|
87
|
-
if (hasEvent) {
|
|
88
|
-
const isClass = is.class_(finder);
|
|
89
|
-
const message = typeof finder === 'function' && !isClass
|
|
90
|
-
? `Expected callback to not find any event`
|
|
91
|
-
: isClass
|
|
92
|
-
? `Expected "${finder.name}" event to be not emitted`
|
|
93
|
-
: `Expected "${String(finder)}" event to be not emitted`;
|
|
94
|
-
throw new AssertionError({
|
|
95
|
-
message: message,
|
|
96
|
-
expected: false,
|
|
97
|
-
actual: true,
|
|
98
|
-
operator: 'strictEqual',
|
|
99
|
-
stackStartFn: this.assertNotEmitted,
|
|
100
|
-
});
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
/**
|
|
104
|
-
* Assert a given event has been not been emitted
|
|
105
|
-
*/
|
|
106
|
-
assertNoneEmitted() {
|
|
107
|
-
const eventsSize = this.size();
|
|
108
|
-
if (eventsSize > 0) {
|
|
109
|
-
throw new AssertionError(Object.assign({
|
|
110
|
-
message: `Expected zero events to be emitted. Instead received "${eventsSize}" event(s)`,
|
|
111
|
-
expected: 0,
|
|
112
|
-
actual: eventsSize,
|
|
113
|
-
operator: 'strictEqual',
|
|
114
|
-
stackStartFn: this.assertNoneEmitted,
|
|
115
|
-
}, {
|
|
116
|
-
showDiff: true,
|
|
117
|
-
}));
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
/**
|
|
121
|
-
* Flush events collected within memory
|
|
122
|
-
*/
|
|
123
|
-
flush() {
|
|
124
|
-
this.#events = [];
|
|
125
|
-
}
|
|
126
|
-
}
|