@wabot-dev/framework 0.1.0-beta.50 → 0.1.0-beta.52
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,8 @@
|
|
|
1
1
|
import { randomBytes } from 'node:crypto';
|
|
2
2
|
|
|
3
3
|
const DIGITS = '0123456789';
|
|
4
|
-
const
|
|
4
|
+
const ALPHA_NUMERIC_CHARSET = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
|
|
5
|
+
const ALPHA_NUMERIC_LOWER_CASE_CHARSET = 'abcdefghijklmnopqrstuvwxyz0123456789';
|
|
5
6
|
class Random {
|
|
6
7
|
static slug(name, options) {
|
|
7
8
|
const base = name
|
|
@@ -11,15 +12,24 @@ class Random {
|
|
|
11
12
|
.replace(/[^a-z0-9\-]/g, '') // remove non-alphanumeric except hyphens
|
|
12
13
|
.replace(/\-+/g, '-') // collapse multiple hyphens
|
|
13
14
|
.replace(/^\-+|\-+$/g, ''); // trim hyphens from ends
|
|
14
|
-
const random = this.
|
|
15
|
+
const random = this.alphaNumericLowerCase(options.randomLength);
|
|
15
16
|
return `${base}-${random}`;
|
|
16
17
|
}
|
|
17
|
-
static
|
|
18
|
+
static alphaNumeric(length) {
|
|
18
19
|
const bytes = randomBytes(length);
|
|
19
20
|
let result = '';
|
|
20
21
|
for (let i = 0; i < length; i++) {
|
|
21
|
-
const index = bytes[i] %
|
|
22
|
-
result +=
|
|
22
|
+
const index = bytes[i] % ALPHA_NUMERIC_CHARSET.length;
|
|
23
|
+
result += ALPHA_NUMERIC_CHARSET[index];
|
|
24
|
+
}
|
|
25
|
+
return result;
|
|
26
|
+
}
|
|
27
|
+
static alphaNumericLowerCase(length) {
|
|
28
|
+
const bytes = randomBytes(length);
|
|
29
|
+
let result = '';
|
|
30
|
+
for (let i = 0; i < length; i++) {
|
|
31
|
+
const index = bytes[i] % ALPHA_NUMERIC_LOWER_CASE_CHARSET.length;
|
|
32
|
+
result += ALPHA_NUMERIC_LOWER_CASE_CHARSET[index];
|
|
23
33
|
}
|
|
24
34
|
return result;
|
|
25
35
|
}
|
|
@@ -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
|
@@ -149,7 +149,8 @@ declare class Random {
|
|
|
149
149
|
static slug(name: string, options: {
|
|
150
150
|
randomLength: number;
|
|
151
151
|
}): string;
|
|
152
|
-
static
|
|
152
|
+
static alphaNumeric(length: number): string;
|
|
153
|
+
static alphaNumericLowerCase(length: number): string;
|
|
153
154
|
static numberCode(length: number): string;
|
|
154
155
|
}
|
|
155
156
|
|
|
@@ -356,6 +357,7 @@ interface IJobEvent extends IStorableData {
|
|
|
356
357
|
}
|
|
357
358
|
type IJobEventListener = (event: IJobEvent) => void | Promise<void>;
|
|
358
359
|
declare class JobsEventsHub {
|
|
360
|
+
private logger;
|
|
359
361
|
private jobsEventsListener;
|
|
360
362
|
notifyJobCreated(job: Job): void;
|
|
361
363
|
listenJobsEvents(listener: IJobEventListener): void;
|