@orchestr-sh/orchestr 1.6.1 → 1.7.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 +289 -22
- package/dist/Console/Commands/EventCacheCommand.d.ts +15 -0
- package/dist/Console/Commands/EventCacheCommand.d.ts.map +1 -0
- package/dist/Console/Commands/EventCacheCommand.js +99 -0
- package/dist/Console/Commands/EventCacheCommand.js.map +1 -0
- package/dist/Console/Commands/EventClearCommand.d.ts +15 -0
- package/dist/Console/Commands/EventClearCommand.d.ts.map +1 -0
- package/dist/Console/Commands/EventClearCommand.js +71 -0
- package/dist/Console/Commands/EventClearCommand.js.map +1 -0
- package/dist/Console/Commands/EventListCommand.d.ts +19 -0
- package/dist/Console/Commands/EventListCommand.d.ts.map +1 -0
- package/dist/Console/Commands/EventListCommand.js +106 -0
- package/dist/Console/Commands/EventListCommand.js.map +1 -0
- package/dist/Console/Commands/MakeEventCommand.d.ts +27 -0
- package/dist/Console/Commands/MakeEventCommand.d.ts.map +1 -0
- package/dist/Console/Commands/MakeEventCommand.js +117 -0
- package/dist/Console/Commands/MakeEventCommand.js.map +1 -0
- package/dist/Console/Commands/MakeListenerCommand.d.ts +27 -0
- package/dist/Console/Commands/MakeListenerCommand.d.ts.map +1 -0
- package/dist/Console/Commands/MakeListenerCommand.js +157 -0
- package/dist/Console/Commands/MakeListenerCommand.js.map +1 -0
- package/dist/Console/orchestr.js +10 -0
- package/dist/Console/orchestr.js.map +1 -1
- package/dist/Contracts/Events/Dispatcher.d.ts +94 -0
- package/dist/Contracts/Events/Dispatcher.d.ts.map +1 -0
- package/dist/Contracts/Events/Dispatcher.js +9 -0
- package/dist/Contracts/Events/Dispatcher.js.map +1 -0
- package/dist/Contracts/Events/index.d.ts +7 -0
- package/dist/Contracts/Events/index.d.ts.map +1 -0
- package/dist/Contracts/Events/index.js +8 -0
- package/dist/Contracts/Events/index.js.map +1 -0
- package/dist/Database/Ensemble/Ensemble.d.ts +7 -0
- package/dist/Database/Ensemble/Ensemble.d.ts.map +1 -1
- package/dist/Database/Ensemble/Ensemble.js +119 -0
- package/dist/Database/Ensemble/Ensemble.js.map +1 -1
- package/dist/Database/Ensemble/EnsembleBuilder.d.ts.map +1 -1
- package/dist/Database/Ensemble/EnsembleBuilder.js +7 -0
- package/dist/Database/Ensemble/EnsembleBuilder.js.map +1 -1
- package/dist/Database/Ensemble/Events/ModelCreated.d.ts +11 -0
- package/dist/Database/Ensemble/Events/ModelCreated.d.ts.map +1 -0
- package/dist/Database/Ensemble/Events/ModelCreated.js +16 -0
- package/dist/Database/Ensemble/Events/ModelCreated.js.map +1 -0
- package/dist/Database/Ensemble/Events/ModelCreating.d.ts +12 -0
- package/dist/Database/Ensemble/Events/ModelCreating.d.ts.map +1 -0
- package/dist/Database/Ensemble/Events/ModelCreating.js +17 -0
- package/dist/Database/Ensemble/Events/ModelCreating.js.map +1 -0
- package/dist/Database/Ensemble/Events/ModelDeleted.d.ts +11 -0
- package/dist/Database/Ensemble/Events/ModelDeleted.d.ts.map +1 -0
- package/dist/Database/Ensemble/Events/ModelDeleted.js +16 -0
- package/dist/Database/Ensemble/Events/ModelDeleted.js.map +1 -0
- package/dist/Database/Ensemble/Events/ModelDeleting.d.ts +12 -0
- package/dist/Database/Ensemble/Events/ModelDeleting.d.ts.map +1 -0
- package/dist/Database/Ensemble/Events/ModelDeleting.js +17 -0
- package/dist/Database/Ensemble/Events/ModelDeleting.js.map +1 -0
- package/dist/Database/Ensemble/Events/ModelEvent.d.ts +17 -0
- package/dist/Database/Ensemble/Events/ModelEvent.d.ts.map +1 -0
- package/dist/Database/Ensemble/Events/ModelEvent.js +22 -0
- package/dist/Database/Ensemble/Events/ModelEvent.js.map +1 -0
- package/dist/Database/Ensemble/Events/ModelRetrieved.d.ts +11 -0
- package/dist/Database/Ensemble/Events/ModelRetrieved.d.ts.map +1 -0
- package/dist/Database/Ensemble/Events/ModelRetrieved.js +16 -0
- package/dist/Database/Ensemble/Events/ModelRetrieved.js.map +1 -0
- package/dist/Database/Ensemble/Events/ModelSaved.d.ts +11 -0
- package/dist/Database/Ensemble/Events/ModelSaved.d.ts.map +1 -0
- package/dist/Database/Ensemble/Events/ModelSaved.js +16 -0
- package/dist/Database/Ensemble/Events/ModelSaved.js.map +1 -0
- package/dist/Database/Ensemble/Events/ModelSaving.d.ts +12 -0
- package/dist/Database/Ensemble/Events/ModelSaving.d.ts.map +1 -0
- package/dist/Database/Ensemble/Events/ModelSaving.js +17 -0
- package/dist/Database/Ensemble/Events/ModelSaving.js.map +1 -0
- package/dist/Database/Ensemble/Events/ModelUpdated.d.ts +11 -0
- package/dist/Database/Ensemble/Events/ModelUpdated.d.ts.map +1 -0
- package/dist/Database/Ensemble/Events/ModelUpdated.js +16 -0
- package/dist/Database/Ensemble/Events/ModelUpdated.js.map +1 -0
- package/dist/Database/Ensemble/Events/ModelUpdating.d.ts +12 -0
- package/dist/Database/Ensemble/Events/ModelUpdating.d.ts.map +1 -0
- package/dist/Database/Ensemble/Events/ModelUpdating.js +17 -0
- package/dist/Database/Ensemble/Events/ModelUpdating.js.map +1 -0
- package/dist/Database/Ensemble/Events/index.d.ts +16 -0
- package/dist/Database/Ensemble/Events/index.d.ts.map +1 -0
- package/dist/Database/Ensemble/Events/index.js +29 -0
- package/dist/Database/Ensemble/Events/index.js.map +1 -0
- package/dist/Events/Concerns/Dispatchable.d.ts +121 -0
- package/dist/Events/Concerns/Dispatchable.d.ts.map +1 -0
- package/dist/Events/Concerns/Dispatchable.js +165 -0
- package/dist/Events/Concerns/Dispatchable.js.map +1 -0
- package/dist/Events/Contracts/Dispatcher.d.ts +144 -0
- package/dist/Events/Contracts/Dispatcher.d.ts.map +1 -0
- package/dist/Events/Contracts/Dispatcher.js +3 -0
- package/dist/Events/Contracts/Dispatcher.js.map +1 -0
- package/dist/Events/Contracts/ShouldDispatchAfterCommit.d.ts +21 -0
- package/dist/Events/Contracts/ShouldDispatchAfterCommit.d.ts.map +1 -0
- package/dist/Events/Contracts/ShouldDispatchAfterCommit.js +3 -0
- package/dist/Events/Contracts/ShouldDispatchAfterCommit.js.map +1 -0
- package/dist/Events/Decorators/HandlesEvents.d.ts +83 -0
- package/dist/Events/Decorators/HandlesEvents.d.ts.map +1 -0
- package/dist/Events/Decorators/HandlesEvents.js +105 -0
- package/dist/Events/Decorators/HandlesEvents.js.map +1 -0
- package/dist/Events/Dispatcher.d.ts +201 -0
- package/dist/Events/Dispatcher.d.ts.map +1 -0
- package/dist/Events/Dispatcher.js +359 -0
- package/dist/Events/Dispatcher.js.map +1 -0
- package/dist/Events/Event.d.ts +140 -0
- package/dist/Events/Event.d.ts.map +1 -0
- package/dist/Events/Event.js +266 -0
- package/dist/Events/Event.js.map +1 -0
- package/dist/Events/EventDiscoveryCache.d.ts +205 -0
- package/dist/Events/EventDiscoveryCache.d.ts.map +1 -0
- package/dist/Events/EventDiscoveryCache.js +310 -0
- package/dist/Events/EventDiscoveryCache.js.map +1 -0
- package/dist/Events/EventServiceProvider.d.ts +148 -0
- package/dist/Events/EventServiceProvider.d.ts.map +1 -0
- package/dist/Events/EventServiceProvider.js +258 -0
- package/dist/Events/EventServiceProvider.js.map +1 -0
- package/dist/Events/NullDispatcher.d.ts +97 -0
- package/dist/Events/NullDispatcher.d.ts.map +1 -0
- package/dist/Events/NullDispatcher.js +118 -0
- package/dist/Events/NullDispatcher.js.map +1 -0
- package/dist/Events/PendingDispatch.d.ts +119 -0
- package/dist/Events/PendingDispatch.d.ts.map +1 -0
- package/dist/Events/PendingDispatch.js +162 -0
- package/dist/Events/PendingDispatch.js.map +1 -0
- package/dist/Events/index.d.ts +12 -0
- package/dist/Events/index.d.ts.map +1 -0
- package/dist/Events/index.js +20 -0
- package/dist/Events/index.js.map +1 -0
- package/dist/Events/types.d.ts +77 -0
- package/dist/Events/types.d.ts.map +1 -0
- package/dist/Events/types.js +3 -0
- package/dist/Events/types.js.map +1 -0
- package/dist/Facades/Event.d.ts +200 -0
- package/dist/Facades/Event.d.ts.map +1 -0
- package/dist/Facades/Event.js +331 -0
- package/dist/Facades/Event.js.map +1 -0
- package/dist/Foundation/Application.d.ts +33 -0
- package/dist/Foundation/Application.d.ts.map +1 -1
- package/dist/Foundation/Application.js +40 -0
- package/dist/Foundation/Application.js.map +1 -1
- package/dist/Listeners/Contracts/ShouldQueue.d.ts +142 -0
- package/dist/Listeners/Contracts/ShouldQueue.d.ts.map +1 -0
- package/dist/Listeners/Contracts/ShouldQueue.js +20 -0
- package/dist/Listeners/Contracts/ShouldQueue.js.map +1 -0
- package/dist/Listeners/Contracts/ShouldQueueAfterCommit.d.ts +24 -0
- package/dist/Listeners/Contracts/ShouldQueueAfterCommit.d.ts.map +1 -0
- package/dist/Listeners/Contracts/ShouldQueueAfterCommit.js +3 -0
- package/dist/Listeners/Contracts/ShouldQueueAfterCommit.js.map +1 -0
- package/dist/Support/EventDiscovery.d.ts +142 -0
- package/dist/Support/EventDiscovery.d.ts.map +1 -0
- package/dist/Support/EventDiscovery.js +302 -0
- package/dist/Support/EventDiscovery.js.map +1 -0
- package/dist/Support/Testing/Fakes/EventFake.d.ts +291 -0
- package/dist/Support/Testing/Fakes/EventFake.d.ts.map +1 -0
- package/dist/Support/Testing/Fakes/EventFake.js +444 -0
- package/dist/Support/Testing/Fakes/EventFake.js.map +1 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +11 -1
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
|
@@ -0,0 +1,331 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.EventFake = exports.Event = void 0;
|
|
37
|
+
const Facade_1 = require("../Support/Facade");
|
|
38
|
+
const EventFake_1 = require("../Support/Testing/Fakes/EventFake");
|
|
39
|
+
Object.defineProperty(exports, "EventFake", { enumerable: true, get: function () { return EventFake_1.EventFake; } });
|
|
40
|
+
/**
|
|
41
|
+
* Event Facade
|
|
42
|
+
*
|
|
43
|
+
* Provides static access to the event dispatcher for listening to and dispatching events.
|
|
44
|
+
* Includes testing utilities for faking events in tests.
|
|
45
|
+
*
|
|
46
|
+
* @example
|
|
47
|
+
* ```typescript
|
|
48
|
+
* // Listen to events
|
|
49
|
+
* Event.listen(UserRegistered, SendWelcomeEmail);
|
|
50
|
+
* Event.listen('user.*', (event) => console.log(event));
|
|
51
|
+
*
|
|
52
|
+
* // Dispatch events
|
|
53
|
+
* Event.dispatch(new UserRegistered(user));
|
|
54
|
+
* Event.dispatch('user.registered', [user]);
|
|
55
|
+
*
|
|
56
|
+
* // Dispatch until first non-null response
|
|
57
|
+
* const result = Event.until(new ValidateUser(user));
|
|
58
|
+
*
|
|
59
|
+
* // Testing - Fake all events
|
|
60
|
+
* Event.fake();
|
|
61
|
+
* // Your code that dispatches events
|
|
62
|
+
* Event.assertDispatched(UserRegistered);
|
|
63
|
+
* Event.assertDispatchedTimes(UserRegistered, 2);
|
|
64
|
+
*
|
|
65
|
+
* // Fake specific events
|
|
66
|
+
* Event.fake([UserRegistered, OrderPlaced]);
|
|
67
|
+
*
|
|
68
|
+
* // Fake all except specific events
|
|
69
|
+
* Event.fakeExcept([UserDeleted]);
|
|
70
|
+
* ```
|
|
71
|
+
*/
|
|
72
|
+
class EventFacadeClass extends Facade_1.Facade {
|
|
73
|
+
static getFacadeAccessor() {
|
|
74
|
+
return 'events';
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Fake events for testing
|
|
78
|
+
*
|
|
79
|
+
* Replaces the real event dispatcher with a fake that records all
|
|
80
|
+
* dispatched events instead of calling listeners. Returns the fake
|
|
81
|
+
* instance for making assertions.
|
|
82
|
+
*
|
|
83
|
+
* @param events - Optional array of events to fake (fakes all if not provided)
|
|
84
|
+
* @returns EventFake instance for assertions
|
|
85
|
+
*
|
|
86
|
+
* @example
|
|
87
|
+
* ```typescript
|
|
88
|
+
* // Fake all events
|
|
89
|
+
* const fake = Event.fake();
|
|
90
|
+
* // Your code
|
|
91
|
+
* fake.assertDispatched(UserRegistered);
|
|
92
|
+
*
|
|
93
|
+
* // Fake specific events only
|
|
94
|
+
* Event.fake([UserRegistered, OrderPlaced]);
|
|
95
|
+
* ```
|
|
96
|
+
*/
|
|
97
|
+
static fake(events) {
|
|
98
|
+
const app = this.getFacadeApplication();
|
|
99
|
+
const fake = new EventFake_1.EventFake(app);
|
|
100
|
+
if (events && events.length > 0) {
|
|
101
|
+
// Create selective fake that only intercepts specified events
|
|
102
|
+
const eventNames = events.map(e => typeof e === 'string' ? e : e.name);
|
|
103
|
+
fake.setFakedEvents(eventNames);
|
|
104
|
+
// Store original dispatcher for pass-through
|
|
105
|
+
try {
|
|
106
|
+
const originalDispatcher = app.make('events');
|
|
107
|
+
fake.setOriginalDispatcher(originalDispatcher);
|
|
108
|
+
}
|
|
109
|
+
catch (error) {
|
|
110
|
+
// Dispatcher not registered yet, that's okay
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
// Replace the events binding with the fake
|
|
114
|
+
app.instance('events', fake);
|
|
115
|
+
this.clearResolvedInstance('events');
|
|
116
|
+
return fake;
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Fake all events except the specified ones
|
|
120
|
+
*
|
|
121
|
+
* All events will be faked except those in the provided array,
|
|
122
|
+
* which will dispatch normally.
|
|
123
|
+
*
|
|
124
|
+
* @param events - Events that should NOT be faked
|
|
125
|
+
* @returns EventFake instance for assertions
|
|
126
|
+
*
|
|
127
|
+
* @example
|
|
128
|
+
* ```typescript
|
|
129
|
+
* // Fake all events except UserDeleted
|
|
130
|
+
* Event.fakeExcept([UserDeleted]);
|
|
131
|
+
* // UserDeleted will dispatch normally, all others will be faked
|
|
132
|
+
* ```
|
|
133
|
+
*/
|
|
134
|
+
static fakeExcept(events) {
|
|
135
|
+
const app = this.getFacadeApplication();
|
|
136
|
+
const fake = new EventFake_1.EventFake(app);
|
|
137
|
+
const eventNames = events.map(e => typeof e === 'string' ? e : e.name);
|
|
138
|
+
fake.setExceptedEvents(eventNames);
|
|
139
|
+
// Store original dispatcher for pass-through
|
|
140
|
+
try {
|
|
141
|
+
const originalDispatcher = app.make('events');
|
|
142
|
+
fake.setOriginalDispatcher(originalDispatcher);
|
|
143
|
+
}
|
|
144
|
+
catch (error) {
|
|
145
|
+
// Dispatcher not registered yet, that's okay
|
|
146
|
+
}
|
|
147
|
+
// Replace the events binding with the fake
|
|
148
|
+
app.instance('events', fake);
|
|
149
|
+
this.clearResolvedInstance('events');
|
|
150
|
+
return fake;
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* Fake events only for the duration of a callback
|
|
154
|
+
*
|
|
155
|
+
* Temporarily replaces the event dispatcher with a fake, executes
|
|
156
|
+
* the callback, then restores the original dispatcher. Useful for
|
|
157
|
+
* scoping fakes to specific test blocks.
|
|
158
|
+
*
|
|
159
|
+
* @param callback - Function to execute with faked events
|
|
160
|
+
* @returns Result of the callback and the fake instance
|
|
161
|
+
*
|
|
162
|
+
* @example
|
|
163
|
+
* ```typescript
|
|
164
|
+
* const [result, fake] = await Event.fakeFor(async () => {
|
|
165
|
+
* await someService.createUser();
|
|
166
|
+
* return 'done';
|
|
167
|
+
* });
|
|
168
|
+
*
|
|
169
|
+
* fake.assertDispatched(UserRegistered);
|
|
170
|
+
* expect(result).toBe('done');
|
|
171
|
+
* ```
|
|
172
|
+
*/
|
|
173
|
+
static async fakeFor(callback) {
|
|
174
|
+
const app = this.getFacadeApplication();
|
|
175
|
+
// Store the original binding
|
|
176
|
+
const originalBinding = app.bound('events');
|
|
177
|
+
let originalDispatcher;
|
|
178
|
+
if (originalBinding) {
|
|
179
|
+
try {
|
|
180
|
+
originalDispatcher = app.make('events');
|
|
181
|
+
}
|
|
182
|
+
catch (error) {
|
|
183
|
+
// Ignore if can't resolve
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
// Create and install fake
|
|
187
|
+
const fake = this.fake();
|
|
188
|
+
try {
|
|
189
|
+
const result = await callback(fake);
|
|
190
|
+
return [result, fake];
|
|
191
|
+
}
|
|
192
|
+
finally {
|
|
193
|
+
// Restore original dispatcher
|
|
194
|
+
if (originalDispatcher) {
|
|
195
|
+
app.instance('events', originalDispatcher);
|
|
196
|
+
}
|
|
197
|
+
else {
|
|
198
|
+
// Re-register the singleton binding
|
|
199
|
+
const { Dispatcher } = await Promise.resolve().then(() => __importStar(require('../Events/Dispatcher')));
|
|
200
|
+
app.singleton('events', (container) => new Dispatcher(container));
|
|
201
|
+
}
|
|
202
|
+
this.clearResolvedInstance('events');
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
/**
|
|
206
|
+
* Assert that an event was dispatched
|
|
207
|
+
*
|
|
208
|
+
* Can only be called after Event.fake() has been called.
|
|
209
|
+
*
|
|
210
|
+
* @param event - The event name or class
|
|
211
|
+
* @param callback - Optional callback to filter events
|
|
212
|
+
*
|
|
213
|
+
* @example
|
|
214
|
+
* ```typescript
|
|
215
|
+
* Event.fake();
|
|
216
|
+
* // Your code
|
|
217
|
+
* Event.assertDispatched(UserRegistered);
|
|
218
|
+
* Event.assertDispatched(UserRegistered, (event) => event.user.email === 'test@example.com');
|
|
219
|
+
* ```
|
|
220
|
+
*/
|
|
221
|
+
static assertDispatched(event, callback) {
|
|
222
|
+
const fake = this.getFakeInstance();
|
|
223
|
+
fake.assertDispatched(event, callback);
|
|
224
|
+
}
|
|
225
|
+
/**
|
|
226
|
+
* Assert that an event was NOT dispatched
|
|
227
|
+
*
|
|
228
|
+
* Can only be called after Event.fake() has been called.
|
|
229
|
+
*
|
|
230
|
+
* @param event - The event name or class
|
|
231
|
+
* @param callback - Optional callback to filter events
|
|
232
|
+
*
|
|
233
|
+
* @example
|
|
234
|
+
* ```typescript
|
|
235
|
+
* Event.fake();
|
|
236
|
+
* // Your code
|
|
237
|
+
* Event.assertNotDispatched(UserDeleted);
|
|
238
|
+
* ```
|
|
239
|
+
*/
|
|
240
|
+
static assertNotDispatched(event, callback) {
|
|
241
|
+
const fake = this.getFakeInstance();
|
|
242
|
+
fake.assertNotDispatched(event, callback);
|
|
243
|
+
}
|
|
244
|
+
/**
|
|
245
|
+
* Assert that an event was dispatched a specific number of times
|
|
246
|
+
*
|
|
247
|
+
* Can only be called after Event.fake() has been called.
|
|
248
|
+
*
|
|
249
|
+
* @param event - The event name or class
|
|
250
|
+
* @param times - Expected number of dispatches
|
|
251
|
+
*
|
|
252
|
+
* @example
|
|
253
|
+
* ```typescript
|
|
254
|
+
* Event.fake();
|
|
255
|
+
* // Your code
|
|
256
|
+
* Event.assertDispatchedTimes(UserRegistered, 3);
|
|
257
|
+
* ```
|
|
258
|
+
*/
|
|
259
|
+
static assertDispatchedTimes(event, times) {
|
|
260
|
+
const fake = this.getFakeInstance();
|
|
261
|
+
fake.assertDispatchedTimes(event, times);
|
|
262
|
+
}
|
|
263
|
+
/**
|
|
264
|
+
* Assert that no events were dispatched
|
|
265
|
+
*
|
|
266
|
+
* Can only be called after Event.fake() has been called.
|
|
267
|
+
*
|
|
268
|
+
* @example
|
|
269
|
+
* ```typescript
|
|
270
|
+
* Event.fake();
|
|
271
|
+
* // Your code that shouldn't dispatch events
|
|
272
|
+
* Event.assertNothingDispatched();
|
|
273
|
+
* ```
|
|
274
|
+
*/
|
|
275
|
+
static assertNothingDispatched() {
|
|
276
|
+
const fake = this.getFakeInstance();
|
|
277
|
+
fake.assertNothingDispatched();
|
|
278
|
+
}
|
|
279
|
+
/**
|
|
280
|
+
* Assert that a listener is registered for an event
|
|
281
|
+
*
|
|
282
|
+
* @param event - The event name or class
|
|
283
|
+
* @param listener - Optional specific listener to check for
|
|
284
|
+
*
|
|
285
|
+
* @example
|
|
286
|
+
* ```typescript
|
|
287
|
+
* Event.fake();
|
|
288
|
+
* Event.listen(UserRegistered, SendWelcomeEmail);
|
|
289
|
+
* Event.assertListening(UserRegistered);
|
|
290
|
+
* Event.assertListening(UserRegistered, SendWelcomeEmail);
|
|
291
|
+
* ```
|
|
292
|
+
*/
|
|
293
|
+
static assertListening(event, listener) {
|
|
294
|
+
const fake = this.getFakeInstance();
|
|
295
|
+
fake.assertListening(event, listener);
|
|
296
|
+
}
|
|
297
|
+
/**
|
|
298
|
+
* Get the fake instance
|
|
299
|
+
*
|
|
300
|
+
* @returns The EventFake instance
|
|
301
|
+
* @throws Error if Event.fake() hasn't been called
|
|
302
|
+
*/
|
|
303
|
+
static getFakeInstance() {
|
|
304
|
+
const app = this.getFacadeApplication();
|
|
305
|
+
const instance = app.make('events');
|
|
306
|
+
if (!(instance instanceof EventFake_1.EventFake)) {
|
|
307
|
+
throw new Error('Event facade is not faked. Call Event.fake() before making assertions.');
|
|
308
|
+
}
|
|
309
|
+
return instance;
|
|
310
|
+
}
|
|
311
|
+
/**
|
|
312
|
+
* Check if the event dispatcher is currently faked
|
|
313
|
+
*
|
|
314
|
+
* @returns true if using EventFake
|
|
315
|
+
*/
|
|
316
|
+
static isFaked() {
|
|
317
|
+
try {
|
|
318
|
+
const app = this.getFacadeApplication();
|
|
319
|
+
const instance = app.make('events');
|
|
320
|
+
return instance instanceof EventFake_1.EventFake;
|
|
321
|
+
}
|
|
322
|
+
catch (error) {
|
|
323
|
+
return false;
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
/**
|
|
328
|
+
* Export facade with proper typing
|
|
329
|
+
*/
|
|
330
|
+
exports.Event = EventFacadeClass;
|
|
331
|
+
//# sourceMappingURL=Event.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Event.js","sourceRoot":"","sources":["../../src/Facades/Event.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,8CAA2C;AAE3C,kEAA+D;AAiVtD,0FAjVA,qBAAS,OAiVA;AA7UlB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,MAAM,gBAAiB,SAAQ,eAAM;IACzB,MAAM,CAAC,iBAAiB;QAChC,OAAO,QAAQ,CAAC;IAClB,CAAC;IACD;;;;;;;;;;;;;;;;;;;;OAoBG;IACH,MAAM,CAAC,IAAI,CAAC,MAA0D;QACpE,MAAM,GAAG,GAAG,IAAI,CAAC,oBAAoB,EAAE,CAAC;QACxC,MAAM,IAAI,GAAG,IAA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,CAAC;QACxC,MAAM,QAAQ,GAAG,GAAG,CAAC,IAAI,CAAY,QAAQ,CAAC,CAAC;QAE/C,IAAI,CAAC,CAAC,QAAQ,YAAY,qBAAS,CAAC,EAAE,CAAC;YACrC,MAAM,IAAI,KAAK,CACb,wEAAwE,CACzE,CAAC;QACJ,CAAC;QAED,OAAO,QAAQ,CAAC;IAClB,CAAC;IAED;;;;OAIG;IACH,MAAM,CAAC,OAAO;QACZ,IAAI,CAAC;YACH,MAAM,GAAG,GAAG,IAAI,CAAC,oBAAoB,EAAE,CAAC;YACxC,MAAM,QAAQ,GAAG,GAAG,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;YACpC,OAAO,QAAQ,YAAY,qBAAS,CAAC;QACvC,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,OAAO,KAAK,CAAC;QACf,CAAC;IACH,CAAC;CACF;AAED;;GAEG;AACU,QAAA,KAAK,GAAG,gBAAwD,CAAC"}
|
|
@@ -9,6 +9,7 @@ export declare class Application extends Container {
|
|
|
9
9
|
private booted;
|
|
10
10
|
private serviceProviders;
|
|
11
11
|
private loadedProviders;
|
|
12
|
+
private eventDiscoveryPaths;
|
|
12
13
|
constructor(basePath?: string);
|
|
13
14
|
/**
|
|
14
15
|
* Register the basic bindings into the container
|
|
@@ -93,5 +94,37 @@ export declare class Application extends Container {
|
|
|
93
94
|
* Determine if the application has been bootstrapped before
|
|
94
95
|
*/
|
|
95
96
|
hasBeenBootstrapped(): boolean;
|
|
97
|
+
/**
|
|
98
|
+
* Configure event discovery paths
|
|
99
|
+
*
|
|
100
|
+
* Allows customizing which directories should be scanned for event listeners
|
|
101
|
+
* during automatic discovery.
|
|
102
|
+
*
|
|
103
|
+
* @param {Object} options - Configuration options
|
|
104
|
+
* @param {string[]} options.discover - Array of directory paths to scan for listeners
|
|
105
|
+
* @returns {this} The application instance for chaining
|
|
106
|
+
*
|
|
107
|
+
* @example
|
|
108
|
+
* ```typescript
|
|
109
|
+
* app.withEvents({
|
|
110
|
+
* discover: [
|
|
111
|
+
* app.path('Listeners'),
|
|
112
|
+
* app.path('Domain/Listeners')
|
|
113
|
+
* ]
|
|
114
|
+
* })
|
|
115
|
+
* ```
|
|
116
|
+
*/
|
|
117
|
+
withEvents(options?: {
|
|
118
|
+
discover?: string[];
|
|
119
|
+
}): this;
|
|
120
|
+
/**
|
|
121
|
+
* Get the event discovery paths
|
|
122
|
+
*
|
|
123
|
+
* Returns the configured paths for event listener discovery.
|
|
124
|
+
* If no paths are configured, defaults to the 'Listeners' directory.
|
|
125
|
+
*
|
|
126
|
+
* @returns {string[]} Array of absolute directory paths
|
|
127
|
+
*/
|
|
128
|
+
getEventDiscoveryPaths(): string[];
|
|
96
129
|
}
|
|
97
130
|
//# sourceMappingURL=Application.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Application.d.ts","sourceRoot":"","sources":["../../src/Foundation/Application.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AACnD,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAGpD;;;GAGG;AACH,qBAAa,WAAY,SAAQ,SAAS;IACxC,OAAO,CAAC,QAAQ,CAAS;IACzB,OAAO,CAAC,MAAM,CAAkB;IAChC,OAAO,CAAC,gBAAgB,CAAyB;IACjD,OAAO,CAAC,eAAe,CAAmC;
|
|
1
|
+
{"version":3,"file":"Application.d.ts","sourceRoot":"","sources":["../../src/Foundation/Application.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AACnD,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAGpD;;;GAGG;AACH,qBAAa,WAAY,SAAQ,SAAS;IACxC,OAAO,CAAC,QAAQ,CAAS;IACzB,OAAO,CAAC,MAAM,CAAkB;IAChC,OAAO,CAAC,gBAAgB,CAAyB;IACjD,OAAO,CAAC,eAAe,CAAmC;IA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,eAAe,EAAE;IAIjC;;OAEG;IACH,mBAAmB,IAAI,OAAO;IAI9B;;;;;;;;;;;;;;;;;;;OAmBG;IACH,UAAU,CAAC,OAAO,GAAE;QAAE,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAA;KAAO,GAAG,IAAI;IAOvD;;;;;;;OAOG;IACH,sBAAsB,IAAI,MAAM,EAAE;CAKnC"}
|
|
@@ -12,6 +12,7 @@ class Application extends Container_1.Container {
|
|
|
12
12
|
booted = false;
|
|
13
13
|
serviceProviders = [];
|
|
14
14
|
loadedProviders = new Map();
|
|
15
|
+
eventDiscoveryPaths = [];
|
|
15
16
|
constructor(basePath = process.cwd()) {
|
|
16
17
|
super();
|
|
17
18
|
this.basePath = basePath;
|
|
@@ -187,6 +188,45 @@ class Application extends Container_1.Container {
|
|
|
187
188
|
hasBeenBootstrapped() {
|
|
188
189
|
return this.booted;
|
|
189
190
|
}
|
|
191
|
+
/**
|
|
192
|
+
* Configure event discovery paths
|
|
193
|
+
*
|
|
194
|
+
* Allows customizing which directories should be scanned for event listeners
|
|
195
|
+
* during automatic discovery.
|
|
196
|
+
*
|
|
197
|
+
* @param {Object} options - Configuration options
|
|
198
|
+
* @param {string[]} options.discover - Array of directory paths to scan for listeners
|
|
199
|
+
* @returns {this} The application instance for chaining
|
|
200
|
+
*
|
|
201
|
+
* @example
|
|
202
|
+
* ```typescript
|
|
203
|
+
* app.withEvents({
|
|
204
|
+
* discover: [
|
|
205
|
+
* app.path('Listeners'),
|
|
206
|
+
* app.path('Domain/Listeners')
|
|
207
|
+
* ]
|
|
208
|
+
* })
|
|
209
|
+
* ```
|
|
210
|
+
*/
|
|
211
|
+
withEvents(options = {}) {
|
|
212
|
+
if (options.discover) {
|
|
213
|
+
this.eventDiscoveryPaths = options.discover;
|
|
214
|
+
}
|
|
215
|
+
return this;
|
|
216
|
+
}
|
|
217
|
+
/**
|
|
218
|
+
* Get the event discovery paths
|
|
219
|
+
*
|
|
220
|
+
* Returns the configured paths for event listener discovery.
|
|
221
|
+
* If no paths are configured, defaults to the 'Listeners' directory.
|
|
222
|
+
*
|
|
223
|
+
* @returns {string[]} Array of absolute directory paths
|
|
224
|
+
*/
|
|
225
|
+
getEventDiscoveryPaths() {
|
|
226
|
+
return this.eventDiscoveryPaths.length > 0
|
|
227
|
+
? this.eventDiscoveryPaths
|
|
228
|
+
: [this.path('Listeners')];
|
|
229
|
+
}
|
|
190
230
|
}
|
|
191
231
|
exports.Application = Application;
|
|
192
232
|
//# sourceMappingURL=Application.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Application.js","sourceRoot":"","sources":["../../src/Foundation/Application.ts"],"names":[],"mappings":";;;AAAA,sDAAmD;AAEnD,gDAAkD;AAElD;;;GAGG;AACH,MAAa,WAAY,SAAQ,qBAAS;IAChC,QAAQ,CAAS;IACjB,MAAM,GAAY,KAAK,CAAC;IACxB,gBAAgB,GAAsB,EAAE,CAAC;IACzC,eAAe,GAAyB,IAAI,GAAG,EAAE,CAAC;
|
|
1
|
+
{"version":3,"file":"Application.js","sourceRoot":"","sources":["../../src/Foundation/Application.ts"],"names":[],"mappings":";;;AAAA,sDAAmD;AAEnD,gDAAkD;AAElD;;;GAGG;AACH,MAAa,WAAY,SAAQ,qBAAS;IAChC,QAAQ,CAAS;IACjB,MAAM,GAAY,KAAK,CAAC;IACxB,gBAAgB,GAAsB,EAAE,CAAC;IACzC,eAAe,GAAyB,IAAI,GAAG,EAAE,CAAC;IAClD,mBAAmB,GAAa,EAAE,CAAC;IAE3C,YAAY,WAAmB,OAAO,CAAC,GAAG,EAAE;QAC1C,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QACzB,IAAI,CAAC,oBAAoB,EAAE,CAAC;QAC5B,IAAI,CAAC,4BAA4B,EAAE,CAAC;QAEpC,2DAA2D;QAC3D,IAAA,sBAAY,EAAC,IAAI,CAAC,CAAC;IACrB,CAAC;IAED;;OAEG;IACK,oBAAo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CAAC;IAC9C,CAAC;IAED;;OAEG;IACH,OAAO;QACL,OAAO,OAAO,CAAC,GAAG,CAAC,KAAK,KAAK,MAAM,CAAC;IACtC,CAAC;IAED;;OAEG;IACH,YAAY;QACV,OAAO,IAAI,CAAC,gBAAgB,CAAC;IAC/B,CAAC;IAED;;OAEG;IACH,mBAAmB;QACjB,OAAO,IAAI,CAAC,MAAM,CAAC;IACrB,CAAC;IAED;;;;;;;;;;;;;;;;;;;OAmBG;IACH,UAAU,CAAC,UAAmC,EAAE;QAC9C,IAAI,OAAO,CAAC,QAAQ,EAAE,CAAC;YACrB,IAAI,CAAC,mBAAmB,GAAG,OAAO,CAAC,QAAQ,CAAC;QAC9C,CAAC;QACD,OAAO,IAAI,CAAC;IACd,CAAC;IAED;;;;;;;OAOG;IACH,sBAAsB;QACpB,OAAO,IAAI,CAAC,mBAAmB,CAAC,MAAM,GAAG,CAAC;YACxC,CAAC,CAAC,IAAI,CAAC,mBAAmB;YAC1B,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC,CAAC;IAC/B,CAAC;CACF;AAhQD,kCAgQC"}
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Should Queue Interface
|
|
3
|
+
*
|
|
4
|
+
* Marks a listener as queueable, allowing it to be processed asynchronously
|
|
5
|
+
* through the queue system instead of synchronously during event dispatch.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```typescript
|
|
9
|
+
* class SendWelcomeEmail implements ShouldQueue {
|
|
10
|
+
* public connection = 'redis';
|
|
11
|
+
* public queue = 'emails';
|
|
12
|
+
* public tries = 3;
|
|
13
|
+
* public timeout = 60;
|
|
14
|
+
*
|
|
15
|
+
* async handle(event: UserRegistered): Promise<void> {
|
|
16
|
+
* await this.emailService.send(event.user.email, 'Welcome!');
|
|
17
|
+
* }
|
|
18
|
+
*
|
|
19
|
+
* async failed(event: UserRegistered, error: Error): Promise<void> {
|
|
20
|
+
* console.error('Failed to send welcome email:', error);
|
|
21
|
+
* }
|
|
22
|
+
* }
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
export interface ShouldQueue {
|
|
26
|
+
/**
|
|
27
|
+
* The name of the connection the job should be sent to
|
|
28
|
+
*
|
|
29
|
+
* @example 'redis', 'database', 'sqs'
|
|
30
|
+
*/
|
|
31
|
+
connection?: string;
|
|
32
|
+
/**
|
|
33
|
+
* The name of the queue the job should be sent to
|
|
34
|
+
*
|
|
35
|
+
* @example 'emails', 'notifications', 'default'
|
|
36
|
+
*/
|
|
37
|
+
queue?: string;
|
|
38
|
+
/**
|
|
39
|
+
* The number of seconds before the job should be processed
|
|
40
|
+
*/
|
|
41
|
+
delay?: number;
|
|
42
|
+
/**
|
|
43
|
+
* The number of times the job may be attempted
|
|
44
|
+
*
|
|
45
|
+
* @default 1
|
|
46
|
+
*/
|
|
47
|
+
tries?: number;
|
|
48
|
+
/**
|
|
49
|
+
* The maximum number of seconds the job can run
|
|
50
|
+
*
|
|
51
|
+
* @default 60
|
|
52
|
+
*/
|
|
53
|
+
timeout?: number;
|
|
54
|
+
/**
|
|
55
|
+
* The number of seconds to wait before retrying the job
|
|
56
|
+
* Can be a single value or an array for progressive backoff
|
|
57
|
+
*
|
|
58
|
+
* @example
|
|
59
|
+
* ```typescript
|
|
60
|
+
* backoff = 10; // Wait 10 seconds between retries
|
|
61
|
+
* backoff = [10, 30, 60]; // Progressive backoff
|
|
62
|
+
* ```
|
|
63
|
+
*/
|
|
64
|
+
backoff?: number | number[];
|
|
65
|
+
/**
|
|
66
|
+
* Determine the connection to send the job to
|
|
67
|
+
*
|
|
68
|
+
* @returns The connection name
|
|
69
|
+
*
|
|
70
|
+
* @example
|
|
71
|
+
* ```typescript
|
|
72
|
+
* viaConnection(): string {
|
|
73
|
+
* return this.isUrgent ? 'redis' : 'database';
|
|
74
|
+
* }
|
|
75
|
+
* ```
|
|
76
|
+
*/
|
|
77
|
+
viaConnection?(): string;
|
|
78
|
+
/**
|
|
79
|
+
* Determine the queue to send the job to
|
|
80
|
+
*
|
|
81
|
+
* @returns The queue name
|
|
82
|
+
*
|
|
83
|
+
* @example
|
|
84
|
+
* ```typescript
|
|
85
|
+
* viaQueue(): string {
|
|
86
|
+
* return this.priority === 'high' ? 'priority' : 'default';
|
|
87
|
+
* }
|
|
88
|
+
* ```
|
|
89
|
+
*/
|
|
90
|
+
viaQueue?(): string;
|
|
91
|
+
/**
|
|
92
|
+
* Determine the delay for the queued job
|
|
93
|
+
*
|
|
94
|
+
* @param event - The event that triggered this listener
|
|
95
|
+
* @returns Delay in seconds
|
|
96
|
+
*
|
|
97
|
+
* @example
|
|
98
|
+
* ```typescript
|
|
99
|
+
* withDelay(event: UserRegistered): number {
|
|
100
|
+
* return event.user.isPremium ? 0 : 300; // Premium users get instant processing
|
|
101
|
+
* }
|
|
102
|
+
* ```
|
|
103
|
+
*/
|
|
104
|
+
withDelay?(event: Event): number;
|
|
105
|
+
/**
|
|
106
|
+
* Determine if the listener should be queued
|
|
107
|
+
*
|
|
108
|
+
* @param event - The event that triggered this listener
|
|
109
|
+
* @returns True if should be queued, false to execute synchronously
|
|
110
|
+
*
|
|
111
|
+
* @example
|
|
112
|
+
* ```typescript
|
|
113
|
+
* shouldQueue(event: OrderPlaced): boolean {
|
|
114
|
+
* return event.order.total > 1000; // Only queue for large orders
|
|
115
|
+
* }
|
|
116
|
+
* ```
|
|
117
|
+
*/
|
|
118
|
+
shouldQueue?(event: Event): boolean;
|
|
119
|
+
/**
|
|
120
|
+
* Handle a job failure
|
|
121
|
+
*
|
|
122
|
+
* @param event - The event that triggered this listener
|
|
123
|
+
* @param exception - The exception that caused the failure
|
|
124
|
+
*
|
|
125
|
+
* @example
|
|
126
|
+
* ```typescript
|
|
127
|
+
* async failed(event: UserRegistered, error: Error): Promise<void> {
|
|
128
|
+
* await this.logError(event.user.id, error);
|
|
129
|
+
* await this.notifyAdmin(error);
|
|
130
|
+
* }
|
|
131
|
+
* ```
|
|
132
|
+
*/
|
|
133
|
+
failed?(event: Event, exception: Error): void | Promise<void>;
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Type guard to check if a listener implements ShouldQueue
|
|
137
|
+
*
|
|
138
|
+
* @param listener - The listener to check
|
|
139
|
+
* @returns True if listener implements ShouldQueue
|
|
140
|
+
*/
|
|
141
|
+
export declare function isShouldQueue(listener: any): listener is ShouldQueue;
|
|
142
|
+
//# sourceMappingURL=ShouldQueue.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ShouldQueue.d.ts","sourceRoot":"","sources":["../../../src/Listeners/Contracts/ShouldQueue.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,MAAM,WAAW,WAAW;IAC1B;;;;OAIG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IAEpB;;;;OAIG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IAEf;;OAEG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IAEf;;;;OAIG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IAEf;;;;OAIG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;IAEjB;;;;;;;;;OASG;IACH,OAAO,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IAE5B;;;;;;;;;;;OAWG;IACH,aAAa,CAAC,IAAI,MAAM,CAAC;IAEzB;;;;;;;;;;;OAWG;IACH,QAAQ,CAAC,IAAI,MAAM,CAAC;IAEpB;;;;;;;;;;;;OAYG;IACH,SAAS,CAAC,CAAC,KAAK,EAAE,KAAK,GAAG,MAAM,CAAC;IAEjC;;;;;;;;;;;;OAYG;IACH,WAAW,CAAC,CAAC,KAAK,EAAE,KAAK,GAAG,OAAO,CAAC;IAEpC;;;;;;;;;;;;;OAaG;IACH,MAAM,CAAC,CAAC,KAAK,EAAE,KAAK,EAAE,SAAS,EAAE,KAAK,GAAG,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CAC/D;AAED;;;;;GAKG;AACH,wBAAgB,aAAa,CAAC,QAAQ,EAAE,GAAG,GAAG,QAAQ,IAAI,WAAW,CAapE"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isShouldQueue = isShouldQueue;
|
|
4
|
+
/**
|
|
5
|
+
* Type guard to check if a listener implements ShouldQueue
|
|
6
|
+
*
|
|
7
|
+
* @param listener - The listener to check
|
|
8
|
+
* @returns True if listener implements ShouldQueue
|
|
9
|
+
*/
|
|
10
|
+
function isShouldQueue(listener) {
|
|
11
|
+
return (listener !== null &&
|
|
12
|
+
typeof listener === 'object' &&
|
|
13
|
+
('connection' in listener ||
|
|
14
|
+
'queue' in listener ||
|
|
15
|
+
'tries' in listener ||
|
|
16
|
+
typeof listener.viaConnection === 'function' ||
|
|
17
|
+
typeof listener.viaQueue === 'function' ||
|
|
18
|
+
typeof listener.shouldQueue === 'function'));
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=ShouldQueue.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ShouldQueue.js","sourceRoot":"","sources":["../../../src/Listeners/Contracts/ShouldQueue.ts"],"names":[],"mappings":";;AAuJA,sCAaC;AAnBD;;;;;GAKG;AACH,SAAgB,aAAa,CAAC,QAAa;IACzC,OAAO,CACL,QAAQ,KAAK,IAAI;QACjB,OAAO,QAAQ,KAAK,QAAQ;QAC5B,CACE,YAAY,IAAI,QAAQ;YACxB,OAAO,IAAI,QAAQ;YACnB,OAAO,IAAI,QAAQ;YACnB,OAAO,QAAQ,CAAC,aAAa,KAAK,UAAU;YAC5C,OAAO,QAAQ,CAAC,QAAQ,KAAK,UAAU;YACvC,OAAO,QAAQ,CAAC,WAAW,KAAK,UAAU,CAC3C,CACF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { ShouldQueue } from './ShouldQueue';
|
|
2
|
+
/**
|
|
3
|
+
* Should Queue After Commit Interface
|
|
4
|
+
*
|
|
5
|
+
* Marker interface for queued listeners that should only be dispatched
|
|
6
|
+
* to the queue after database transactions have been committed.
|
|
7
|
+
*
|
|
8
|
+
* This combines the behavior of ShouldQueue with transaction awareness.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```typescript
|
|
12
|
+
* export class SendWelcomeEmail implements ShouldQueueAfterCommit {
|
|
13
|
+
* public tries = 3;
|
|
14
|
+
* public timeout = 30;
|
|
15
|
+
*
|
|
16
|
+
* handle(event: UserRegistered): void {
|
|
17
|
+
* // This will only run if the database transaction commits
|
|
18
|
+
* }
|
|
19
|
+
* }
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
export interface ShouldQueueAfterCommit extends ShouldQueue {
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=ShouldQueueAfterCommit.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ShouldQueueAfterCommit.d.ts","sourceRoot":"","sources":["../../../src/Listeners/Contracts/ShouldQueueAfterCommit.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAEjD;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,WAAW,sBAAuB,SAAQ,WAAW;CAE1D"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ShouldQueueAfterCommit.js","sourceRoot":"","sources":["../../../src/Listeners/Contracts/ShouldQueueAfterCommit.ts"],"names":[],"mappings":""}
|