@wabot-dev/framework 0.1.0-beta.51 → 0.1.0-beta.53
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.
|
@@ -4,6 +4,24 @@ const DIGITS = '0123456789';
|
|
|
4
4
|
const ALPHA_NUMERIC_CHARSET = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
|
|
5
5
|
const ALPHA_NUMERIC_LOWER_CASE_CHARSET = 'abcdefghijklmnopqrstuvwxyz0123456789';
|
|
6
6
|
class Random {
|
|
7
|
+
static integer(options) {
|
|
8
|
+
const { min, max } = options;
|
|
9
|
+
if (min > max) {
|
|
10
|
+
throw new RangeError('min must be less than or equal to max');
|
|
11
|
+
}
|
|
12
|
+
const range = max - min + 1;
|
|
13
|
+
if (range <= 0) {
|
|
14
|
+
throw new RangeError('Range must be a positive number');
|
|
15
|
+
}
|
|
16
|
+
const byteSize = 6; // gives us up to 2^48
|
|
17
|
+
const maxGeneratedValue = Math.pow(2, byteSize * 8) - 1;
|
|
18
|
+
const maxAcceptable = maxGeneratedValue - (maxGeneratedValue % range);
|
|
19
|
+
let randomNumber;
|
|
20
|
+
do {
|
|
21
|
+
randomNumber = parseInt(randomBytes(byteSize).toString('hex'), 16);
|
|
22
|
+
} while (randomNumber >= maxAcceptable);
|
|
23
|
+
return min + (randomNumber % range);
|
|
24
|
+
}
|
|
7
25
|
static slug(name, options) {
|
|
8
26
|
const base = name
|
|
9
27
|
.toLowerCase()
|
|
@@ -1,17 +1,29 @@
|
|
|
1
1
|
import { __decorate } from 'tslib';
|
|
2
2
|
import { singleton } from '../../core/injection/index.js';
|
|
3
|
+
import { Logger } from '../../core/logger/Logger.js';
|
|
3
4
|
|
|
4
5
|
let JobsEventsHub = class JobsEventsHub {
|
|
6
|
+
logger = new Logger('wabot:jobs-events-hub');
|
|
5
7
|
jobsEventsListener = null;
|
|
6
8
|
notifyJobCreated(job) {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
9
|
+
const timer = setTimeout(async () => {
|
|
10
|
+
if (!this.jobsEventsListener) {
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
try {
|
|
14
|
+
await this.jobsEventsListener({
|
|
15
|
+
jobId: job.id,
|
|
16
|
+
commandName: job.commandName,
|
|
17
|
+
type: 'created',
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
catch (err) {
|
|
21
|
+
this.logger.error(err);
|
|
22
|
+
}
|
|
23
|
+
finally {
|
|
24
|
+
clearTimeout(timer);
|
|
25
|
+
}
|
|
26
|
+
}, 1000);
|
|
15
27
|
}
|
|
16
28
|
listenJobsEvents(listener) {
|
|
17
29
|
this.jobsEventsListener = listener;
|
package/dist/src/index.d.ts
CHANGED
|
@@ -146,6 +146,10 @@ declare class Password {
|
|
|
146
146
|
}
|
|
147
147
|
|
|
148
148
|
declare class Random {
|
|
149
|
+
static integer(options: {
|
|
150
|
+
min: number;
|
|
151
|
+
max: number;
|
|
152
|
+
}): number;
|
|
149
153
|
static slug(name: string, options: {
|
|
150
154
|
randomLength: number;
|
|
151
155
|
}): string;
|
|
@@ -357,6 +361,7 @@ interface IJobEvent extends IStorableData {
|
|
|
357
361
|
}
|
|
358
362
|
type IJobEventListener = (event: IJobEvent) => void | Promise<void>;
|
|
359
363
|
declare class JobsEventsHub {
|
|
364
|
+
private logger;
|
|
360
365
|
private jobsEventsListener;
|
|
361
366
|
notifyJobCreated(job: Job): void;
|
|
362
367
|
listenJobsEvents(listener: IJobEventListener): void;
|