@campxdev/server-shared 1.5.30 → 1.5.32
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/dist/common/interceptors/request.interceptor.d.ts.map +1 -1
- package/dist/common/interceptors/request.interceptor.js +3 -0
- package/dist/common/interceptors/request.interceptor.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/permissions/app-permissions/enroll-x-permissions.d.ts +1 -0
- package/dist/permissions/app-permissions/enroll-x-permissions.d.ts.map +1 -1
- package/dist/permissions/app-permissions/enroll-x-permissions.js +2 -1
- package/dist/permissions/app-permissions/enroll-x-permissions.js.map +1 -1
- package/dist/permissions/permissions.d.ts +2 -0
- package/dist/permissions/permissions.d.ts.map +1 -1
- package/dist/task-queue/index.d.ts +4 -0
- package/dist/task-queue/index.d.ts.map +1 -0
- package/dist/{event-queue → task-queue}/index.js +3 -1
- package/dist/task-queue/index.js.map +1 -0
- package/dist/task-queue/task-queue-manager.service.d.ts +25 -0
- package/dist/task-queue/task-queue-manager.service.d.ts.map +1 -0
- package/dist/task-queue/task-queue-manager.service.js +249 -0
- package/dist/task-queue/task-queue-manager.service.js.map +1 -0
- package/dist/task-queue/task-queue.constants.d.ts +3 -0
- package/dist/task-queue/task-queue.constants.d.ts.map +1 -0
- package/dist/task-queue/task-queue.constants.js +6 -0
- package/dist/task-queue/task-queue.constants.js.map +1 -0
- package/dist/task-queue/task-queue.decorator.d.ts +3 -0
- package/dist/task-queue/task-queue.decorator.d.ts.map +1 -0
- package/dist/task-queue/task-queue.decorator.js +11 -0
- package/dist/task-queue/task-queue.decorator.js.map +1 -0
- package/dist/task-queue/task-queue.module.d.ts +40 -0
- package/dist/task-queue/task-queue.module.d.ts.map +1 -0
- package/dist/task-queue/task-queue.module.js +100 -0
- package/dist/task-queue/task-queue.module.js.map +1 -0
- package/dist/task-queue/task-queue.service.d.ts +7 -0
- package/dist/task-queue/task-queue.service.d.ts.map +1 -0
- package/dist/task-queue/task-queue.service.js +28 -0
- package/dist/task-queue/task-queue.service.js.map +1 -0
- package/package.json +3 -2
- package/dist/event-queue/event-queue.module.d.ts +0 -12
- package/dist/event-queue/event-queue.module.d.ts.map +0 -1
- package/dist/event-queue/event-queue.module.js +0 -113
- package/dist/event-queue/event-queue.module.js.map +0 -1
- package/dist/event-queue/event-queue.service.d.ts +0 -16
- package/dist/event-queue/event-queue.service.d.ts.map +0 -1
- package/dist/event-queue/event-queue.service.js +0 -122
- package/dist/event-queue/event-queue.service.js.map +0 -1
- package/dist/event-queue/index.d.ts +0 -2
- package/dist/event-queue/index.d.ts.map +0 -1
- package/dist/event-queue/index.js.map +0 -1
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TASK_QUEUE_OPTIONS = exports.TASK_QUEUE_EXECUTION_METHOD = void 0;
|
|
4
|
+
exports.TASK_QUEUE_EXECUTION_METHOD = Symbol.for('TASK_QUEUE_EXECUTION_METHOD');
|
|
5
|
+
exports.TASK_QUEUE_OPTIONS = Symbol.for('TASK_QUEUE_OPTIONS');
|
|
6
|
+
//# sourceMappingURL=task-queue.constants.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"task-queue.constants.js","sourceRoot":"","sources":["../../src/task-queue/task-queue.constants.ts"],"names":[],"mappings":";;;AAAa,QAAA,2BAA2B,GAAG,MAAM,CAAC,GAAG,CAAC,6BAA6B,CAAC,CAAC;AACxE,QAAA,kBAAkB,GAAG,MAAM,CAAC,GAAG,CAAC,oBAAoB,CAAC,CAAC"}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { TASK_QUEUE_EXECUTION_METHOD } from './task-queue.constants';
|
|
2
|
+
export declare const OnTaskQueueEvent: (eventName: string, queueKey: string) => import("@nestjs/common").CustomDecorator<typeof TASK_QUEUE_EXECUTION_METHOD>;
|
|
3
|
+
//# sourceMappingURL=task-queue.decorator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"task-queue.decorator.d.ts","sourceRoot":"","sources":["../../src/task-queue/task-queue.decorator.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,2BAA2B,EAAE,MAAM,wBAAwB,CAAC;AAErE,eAAO,MAAM,gBAAgB,cAAe,MAAM,YAAY,MAAM,iFAGnE,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.OnTaskQueueEvent = void 0;
|
|
4
|
+
const common_1 = require("@nestjs/common");
|
|
5
|
+
const task_queue_constants_1 = require("./task-queue.constants");
|
|
6
|
+
const OnTaskQueueEvent = (eventName, queueKey) => {
|
|
7
|
+
const value = { eventName, queueKey };
|
|
8
|
+
return (0, common_1.SetMetadata)(task_queue_constants_1.TASK_QUEUE_EXECUTION_METHOD, value);
|
|
9
|
+
};
|
|
10
|
+
exports.OnTaskQueueEvent = OnTaskQueueEvent;
|
|
11
|
+
//# sourceMappingURL=task-queue.decorator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"task-queue.decorator.js","sourceRoot":"","sources":["../../src/task-queue/task-queue.decorator.ts"],"names":[],"mappings":";;;AAAA,2CAA6C;AAE7C,iEAAqE;AAE9D,MAAM,gBAAgB,GAAG,CAAC,SAAiB,EAAE,QAAgB,EAAE,EAAE;IACtE,MAAM,KAAK,GAAqB,EAAE,SAAS,EAAE,QAAQ,EAAE,CAAC;IACxD,OAAO,IAAA,oBAAW,EAAC,kDAA2B,EAAE,KAAK,CAAC,CAAC;AACzD,CAAC,CAAC;AAHW,QAAA,gBAAgB,oBAG3B"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { DynamicModule } from '@nestjs/common';
|
|
2
|
+
import { SharedService } from '../shared-module';
|
|
3
|
+
export type SQSDetails = {
|
|
4
|
+
region: string;
|
|
5
|
+
accessKeyId: string;
|
|
6
|
+
secretAccessKey: string;
|
|
7
|
+
};
|
|
8
|
+
type QueueConfig = {
|
|
9
|
+
sqsDetails?: SQSDetails;
|
|
10
|
+
disableQueue?: boolean;
|
|
11
|
+
};
|
|
12
|
+
export type TaskQueue = {
|
|
13
|
+
key: string;
|
|
14
|
+
queueName: string;
|
|
15
|
+
config?: QueueConfig;
|
|
16
|
+
};
|
|
17
|
+
export type TaskFn = (messageBody: Record<string, any>) => Promise<void> | Promise<any>;
|
|
18
|
+
export type PreMessageHandlers = {
|
|
19
|
+
preSendMessageFn: (messageBody: Record<string, any>) => Record<string, any>;
|
|
20
|
+
preProcessMessageFn: (messageBody: Record<string, any>, taskFn: TaskFn) => Promise<void>;
|
|
21
|
+
};
|
|
22
|
+
export type TaskQueueOptions = {
|
|
23
|
+
globalConfig?: QueueConfig;
|
|
24
|
+
preMessageHandlers?: PreMessageHandlers;
|
|
25
|
+
visibilityTimeout?: number;
|
|
26
|
+
intervalForVisibilityExtender?: number;
|
|
27
|
+
queues: TaskQueue[];
|
|
28
|
+
};
|
|
29
|
+
export type TaskQueueAsyncOptions = {
|
|
30
|
+
imports?: any[];
|
|
31
|
+
useFactory: (...args: any[]) => Promise<TaskQueueOptions>;
|
|
32
|
+
inject?: any[];
|
|
33
|
+
};
|
|
34
|
+
export declare function campxPreMessageHandlers(sharedService: SharedService): PreMessageHandlers;
|
|
35
|
+
export declare class TaskQueueModule {
|
|
36
|
+
static forRoot(props: TaskQueueOptions): DynamicModule;
|
|
37
|
+
static forRootAsync(props: TaskQueueAsyncOptions): DynamicModule;
|
|
38
|
+
}
|
|
39
|
+
export {};
|
|
40
|
+
//# sourceMappingURL=task-queue.module.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"task-queue.module.d.ts","sourceRoot":"","sources":["../../src/task-queue/task-queue.module.ts"],"names":[],"m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EAAE,GAAG,EAAE,CAAC;IAChB,UAAU,EAAE,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,OAAO,CAAC,gBAAgB,CAAC,CAAC;IAC1D,MAAM,CAAC,EAAE,GAAG,EAAE,CAAC;CAChB,CAAC;AAMF,wBAAgB,uBAAuB,CAAC,aAAa,EAAE,aAAa,GAAG,kBAAkB,CAoCxF;AAED,qBAMa,eAAe;IAC1B,MAAM,CAAC,OAAO,CAAC,KAAK,EAAE,gBAAgB,GAAG,aAAa;IAiBtD,MAAM,CAAC,YAAY,CAAC,KAAK,EAAE,qBAAqB,GAAG,aAAa;CAiBjE"}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var TaskQueueModule_1;
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
exports.TaskQueueModule = exports.campxPreMessageHandlers = void 0;
|
|
11
|
+
const nestjs_discovery_1 = require("@golevelup/nestjs-discovery");
|
|
12
|
+
const common_1 = require("@nestjs/common");
|
|
13
|
+
const request_store_1 = require("../request-store");
|
|
14
|
+
const task_queue_manager_service_1 = require("./task-queue-manager.service");
|
|
15
|
+
const task_queue_constants_1 = require("./task-queue.constants");
|
|
16
|
+
const task_queue_service_1 = require("./task-queue.service");
|
|
17
|
+
function campxPreMessageHandlers(sharedService) {
|
|
18
|
+
return {
|
|
19
|
+
preSendMessageFn: (messageBody) => {
|
|
20
|
+
const body = {
|
|
21
|
+
tenantDetails: (0, request_store_1.getTenantDetailsIfExists)(),
|
|
22
|
+
institution: (0, request_store_1.getInstitutionOrFail)(),
|
|
23
|
+
userData: (0, request_store_1.getUserData)(),
|
|
24
|
+
evaluatorData: (0, request_store_1.getEvaluatorData)(),
|
|
25
|
+
leadData: (0, request_store_1.getLeadData)(),
|
|
26
|
+
messageBody: messageBody || {},
|
|
27
|
+
};
|
|
28
|
+
return body;
|
|
29
|
+
},
|
|
30
|
+
preProcessMessageFn: async (messageBody, taskFn) => {
|
|
31
|
+
const body = messageBody;
|
|
32
|
+
await (0, request_store_1.storeSession)({
|
|
33
|
+
session: async () => {
|
|
34
|
+
if (body.tenantDetails)
|
|
35
|
+
(0, request_store_1.setTenantDetails)(body.tenantDetails);
|
|
36
|
+
if (body.institution)
|
|
37
|
+
(0, request_store_1.setInstitution)(body.institution);
|
|
38
|
+
if (body.userData)
|
|
39
|
+
(0, request_store_1.setUserData)(body.userData);
|
|
40
|
+
if (body.evaluatorData)
|
|
41
|
+
(0, request_store_1.setEvaluatorData)(body.evaluatorData);
|
|
42
|
+
if (body.leadData)
|
|
43
|
+
(0, request_store_1.setLeadData)(body.leadData);
|
|
44
|
+
const tenantId = body?.tenantDetails?.id;
|
|
45
|
+
if (tenantId) {
|
|
46
|
+
const dataSource = await sharedService.getTenantRootConnection(tenantId);
|
|
47
|
+
(0, request_store_1.setTenantDataSource)(dataSource);
|
|
48
|
+
}
|
|
49
|
+
await taskFn(body.messageBody);
|
|
50
|
+
},
|
|
51
|
+
});
|
|
52
|
+
},
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
exports.campxPreMessageHandlers = campxPreMessageHandlers;
|
|
56
|
+
let TaskQueueModule = TaskQueueModule_1 = class TaskQueueModule {
|
|
57
|
+
static forRoot(props) {
|
|
58
|
+
return {
|
|
59
|
+
global: true,
|
|
60
|
+
module: TaskQueueModule_1,
|
|
61
|
+
imports: [nestjs_discovery_1.DiscoveryModule],
|
|
62
|
+
providers: [
|
|
63
|
+
{
|
|
64
|
+
provide: task_queue_constants_1.TASK_QUEUE_OPTIONS,
|
|
65
|
+
useValue: props,
|
|
66
|
+
},
|
|
67
|
+
task_queue_manager_service_1.TaskQueueManagerService,
|
|
68
|
+
task_queue_service_1.TaskQueueService,
|
|
69
|
+
],
|
|
70
|
+
exports: [task_queue_service_1.TaskQueueService],
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
static forRootAsync(props) {
|
|
74
|
+
return {
|
|
75
|
+
global: true,
|
|
76
|
+
module: TaskQueueModule_1,
|
|
77
|
+
imports: [nestjs_discovery_1.DiscoveryModule, ...(props.imports || [])],
|
|
78
|
+
providers: [
|
|
79
|
+
{
|
|
80
|
+
provide: task_queue_constants_1.TASK_QUEUE_OPTIONS,
|
|
81
|
+
useFactory: props.useFactory,
|
|
82
|
+
inject: props.inject,
|
|
83
|
+
},
|
|
84
|
+
task_queue_manager_service_1.TaskQueueManagerService,
|
|
85
|
+
task_queue_service_1.TaskQueueService,
|
|
86
|
+
],
|
|
87
|
+
exports: [task_queue_service_1.TaskQueueService],
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
exports.TaskQueueModule = TaskQueueModule;
|
|
92
|
+
exports.TaskQueueModule = TaskQueueModule = TaskQueueModule_1 = __decorate([
|
|
93
|
+
(0, common_1.Global)(),
|
|
94
|
+
(0, common_1.Module)({
|
|
95
|
+
imports: [nestjs_discovery_1.DiscoveryModule],
|
|
96
|
+
providers: [task_queue_manager_service_1.TaskQueueManagerService, task_queue_service_1.TaskQueueService],
|
|
97
|
+
exports: [task_queue_service_1.TaskQueueService],
|
|
98
|
+
})
|
|
99
|
+
], TaskQueueModule);
|
|
100
|
+
//# sourceMappingURL=task-queue.module.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"task-queue.module.js","sourceRoot":"","sources":["../../src/task-queue/task-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CAAC;QACtD,OAAO,EAAE,CAAC,qCAAgB,CAAC;KAC5B,CAAC;GACW,eAAe,CAmC3B"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { TaskQueueManagerService } from './task-queue-manager.service';
|
|
2
|
+
export declare class TaskQueueService {
|
|
3
|
+
private readonly manager;
|
|
4
|
+
constructor(manager: TaskQueueManagerService);
|
|
5
|
+
emit(eventName: string, messageBody: Record<string, any>): Promise<void>;
|
|
6
|
+
}
|
|
7
|
+
//# sourceMappingURL=task-queue.service.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"task-queue.service.d.ts","sourceRoot":"","sources":["../../src/task-queue/task-queue.service.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,uBAAuB,EAAE,MAAM,8BAA8B,CAAC;AAEvE,qBACa,gBAAgB;IACf,OAAO,CAAC,QAAQ,CAAC,OAAO;gBAAP,OAAO,EAAE,uBAAuB;IAEvD,IAAI,CAAC,SAAS,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC;CAG/D"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.TaskQueueService = void 0;
|
|
13
|
+
const common_1 = require("@nestjs/common");
|
|
14
|
+
const task_queue_manager_service_1 = require("./task-queue-manager.service");
|
|
15
|
+
let TaskQueueService = class TaskQueueService {
|
|
16
|
+
constructor(manager) {
|
|
17
|
+
this.manager = manager;
|
|
18
|
+
}
|
|
19
|
+
async emit(eventName, messageBody) {
|
|
20
|
+
return this.manager.emit(eventName, messageBody);
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
exports.TaskQueueService = TaskQueueService;
|
|
24
|
+
exports.TaskQueueService = TaskQueueService = __decorate([
|
|
25
|
+
(0, common_1.Injectable)(),
|
|
26
|
+
__metadata("design:paramtypes", [task_queue_manager_service_1.TaskQueueManagerService])
|
|
27
|
+
], TaskQueueService);
|
|
28
|
+
//# sourceMappingURL=task-queue.service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"task-queue.service.js","sourceRoot":"","sources":["../../src/task-queue/task-queue.service.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,2CAA4C;AAC5C,6EAAuE;AAGhE,IAAM,gBAAgB,GAAtB,MAAM,gBAAgB;IAC3B,YAA6B,OAAgC;QAAhC,YAAO,GAAP,OAAO,CAAyB;IAAG,CAAC;IAEjE,KAAK,CAAC,IAAI,CAAC,SAAiB,EAAE,WAAgC;QAC5D,OAAO,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,SAAS,EAAE,WAAW,CAAC,CAAC;IACnD,CAAC;CACF,CAAA;AANY,4CAAgB;2BAAhB,gBAAgB;IAD5B,IAAA,mBAAU,GAAE;qCAE2B,oDAAuB;GADlD,gBAAgB,CAM5B"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@campxdev/server-shared",
|
|
3
|
-
"version": "1.5.
|
|
3
|
+
"version": "1.5.32",
|
|
4
4
|
"description": "Campx server shared files",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"license": "MIT",
|
|
@@ -25,10 +25,10 @@
|
|
|
25
25
|
"@aws-sdk/client-cloudwatch-logs": "^3.511.0",
|
|
26
26
|
"@aws-sdk/client-s3": "^3.490.0",
|
|
27
27
|
"@aws-sdk/client-sqs": "^3.547.0",
|
|
28
|
+
"@golevelup/nestjs-discovery": "^4.0.1",
|
|
28
29
|
"@nestjs/common": "^10.3.0",
|
|
29
30
|
"@nestjs/config": "^3.1.1",
|
|
30
31
|
"@nestjs/core": "^10.3.0",
|
|
31
|
-
"@nestjs/event-emitter": "^2.0.0",
|
|
32
32
|
"@nestjs/microservices": "^10.3.0",
|
|
33
33
|
"@nestjs/mongoose": "10.0.2",
|
|
34
34
|
"@ssut/nestjs-sqs": "^2.2.0",
|
|
@@ -44,6 +44,7 @@
|
|
|
44
44
|
"mysql2": "^3.7.0",
|
|
45
45
|
"reflect-metadata": "^0.1.12",
|
|
46
46
|
"rxjs": "^7.8.1",
|
|
47
|
+
"sqs-consumer": "^10.3.0",
|
|
47
48
|
"typeorm": "^0.3.19",
|
|
48
49
|
"typeorm-naming-strategies": "^4.1.0",
|
|
49
50
|
"ulidx": "^2.2.1",
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { DynamicModule } from '@nestjs/common';
|
|
2
|
-
export declare abstract class EventQueueEmitter {
|
|
3
|
-
abstract emit(eventName: string, messageBody: Record<string, any>): Promise<void>;
|
|
4
|
-
}
|
|
5
|
-
export declare const OnQueueEvent: (eventName: string) => MethodDecorator;
|
|
6
|
-
export declare class EventQueueModule {
|
|
7
|
-
static forRoot(props: {
|
|
8
|
-
queueName: string;
|
|
9
|
-
envQueueKey?: string;
|
|
10
|
-
}): DynamicModule;
|
|
11
|
-
}
|
|
12
|
-
//# sourceMappingURL=event-queue.module.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"event-queue.module.d.ts","sourceRoot":"","sources":["../../src/event-queue/event-queue.module.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAgD,MAAM,gBAAgB,CAAC;AAO7F,8BAAsB,iBAAiB;IACrC,QAAQ,CAAC,IAAI,CAAC,SAAS,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;CAClF;AAED,eAAO,MAAM,YAAY,cAAe,MAAM,oBAE7C,CAAC;AAEF,qBAEa,gBAAgB;IAC3B,MAAM,CAAC,OAAO,CAAC,KAAK,EAAE;QAAE,SAAS,EAAE,MAAM,CAAC;QAAC,WAAW,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,aAAa;CAsDlF"}
|
|
@@ -1,113 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
-
};
|
|
8
|
-
var EventQueueModule_1;
|
|
9
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
-
exports.EventQueueModule = exports.OnQueueEvent = exports.EventQueueEmitter = void 0;
|
|
11
|
-
const client_sqs_1 = require("@aws-sdk/client-sqs");
|
|
12
|
-
const common_1 = require("@nestjs/common");
|
|
13
|
-
const config_1 = require("@nestjs/config");
|
|
14
|
-
const event_emitter_1 = require("@nestjs/event-emitter");
|
|
15
|
-
const nestjs_sqs_1 = require("@ssut/nestjs-sqs");
|
|
16
|
-
const shared_module_1 = require("../shared-module");
|
|
17
|
-
const event_queue_service_1 = require("./event-queue.service");
|
|
18
|
-
class EventQueueEmitter {
|
|
19
|
-
}
|
|
20
|
-
exports.EventQueueEmitter = EventQueueEmitter;
|
|
21
|
-
const OnQueueEvent = (eventName) => {
|
|
22
|
-
return (0, event_emitter_1.OnEvent)(eventName, { async: true, promisify: true });
|
|
23
|
-
};
|
|
24
|
-
exports.OnQueueEvent = OnQueueEvent;
|
|
25
|
-
let EventQueueModule = EventQueueModule_1 = class EventQueueModule {
|
|
26
|
-
static forRoot(props) {
|
|
27
|
-
let queueUrl = '';
|
|
28
|
-
let client;
|
|
29
|
-
return {
|
|
30
|
-
module: EventQueueModule_1,
|
|
31
|
-
imports: [
|
|
32
|
-
shared_module_1.SharedModule,
|
|
33
|
-
nestjs_sqs_1.SqsModule.registerAsync({
|
|
34
|
-
inject: [config_1.ConfigService],
|
|
35
|
-
useFactory: async (configService) => {
|
|
36
|
-
const result = await generateQueue({
|
|
37
|
-
configService,
|
|
38
|
-
queueName: props.queueName,
|
|
39
|
-
envQueueKey: props.envQueueKey,
|
|
40
|
-
});
|
|
41
|
-
queueUrl = result.queueUrl;
|
|
42
|
-
client = result.client;
|
|
43
|
-
props.queueName = result.queueName;
|
|
44
|
-
return {
|
|
45
|
-
consumers: configService.get('DISABLE_QUEUE') != true
|
|
46
|
-
? [
|
|
47
|
-
{
|
|
48
|
-
name: event_queue_service_1.EVENT_QUEUE_EMITTER_NAME,
|
|
49
|
-
queueUrl: queueUrl,
|
|
50
|
-
batchSize: 10,
|
|
51
|
-
region: configService.get('AWS_REGION'),
|
|
52
|
-
},
|
|
53
|
-
]
|
|
54
|
-
: [],
|
|
55
|
-
};
|
|
56
|
-
},
|
|
57
|
-
}),
|
|
58
|
-
],
|
|
59
|
-
providers: [
|
|
60
|
-
{
|
|
61
|
-
provide: EventQueueEmitter,
|
|
62
|
-
useFactory: (eventEmitter, sharedService) => {
|
|
63
|
-
return new event_queue_service_1.EventQueueConsumerService(props.queueName, queueUrl, client, eventEmitter, sharedService);
|
|
64
|
-
},
|
|
65
|
-
inject: [event_emitter_1.EventEmitter2, shared_module_1.SharedService],
|
|
66
|
-
},
|
|
67
|
-
],
|
|
68
|
-
exports: [EventQueueEmitter],
|
|
69
|
-
};
|
|
70
|
-
}
|
|
71
|
-
};
|
|
72
|
-
exports.EventQueueModule = EventQueueModule;
|
|
73
|
-
exports.EventQueueModule = EventQueueModule = EventQueueModule_1 = __decorate([
|
|
74
|
-
(0, common_1.Global)(),
|
|
75
|
-
(0, common_1.Module)({})
|
|
76
|
-
], EventQueueModule);
|
|
77
|
-
async function generateQueue(props) {
|
|
78
|
-
const { configService } = props;
|
|
79
|
-
let queueName = props.queueName;
|
|
80
|
-
if (props.envQueueKey && configService.get(props.envQueueKey)) {
|
|
81
|
-
queueName = configService.get(props.envQueueKey);
|
|
82
|
-
}
|
|
83
|
-
const accessKey = configService.get('AWS_ACCESS_KEY_ID');
|
|
84
|
-
const secretAccessKey = configService.get('AWS_SECRET_ACCESS_KEY');
|
|
85
|
-
const region = configService.get('AWS_REGION');
|
|
86
|
-
const sqsClient = new client_sqs_1.SQSClient({
|
|
87
|
-
region: region,
|
|
88
|
-
credentials: {
|
|
89
|
-
accessKeyId: accessKey,
|
|
90
|
-
secretAccessKey: secretAccessKey,
|
|
91
|
-
},
|
|
92
|
-
});
|
|
93
|
-
const command = new client_sqs_1.CreateQueueCommand({
|
|
94
|
-
QueueName: queueName,
|
|
95
|
-
Attributes: {
|
|
96
|
-
VisibilityTimeout: '30',
|
|
97
|
-
FifoQueue: queueName.endsWith('.fifo') ? 'true' : 'false',
|
|
98
|
-
},
|
|
99
|
-
});
|
|
100
|
-
try {
|
|
101
|
-
const result = await sqsClient.send(command);
|
|
102
|
-
return {
|
|
103
|
-
client: sqsClient,
|
|
104
|
-
queueName: queueName,
|
|
105
|
-
queueUrl: result.QueueUrl,
|
|
106
|
-
};
|
|
107
|
-
}
|
|
108
|
-
catch (err) {
|
|
109
|
-
console.error('Queue Creation field', err);
|
|
110
|
-
throw new common_1.UnprocessableEntityException('Unable to create queue');
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
//# sourceMappingURL=event-queue.module.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"event-queue.module.js","sourceRoot":"","sources":["../../src/event-queue/event-queue.module.ts"],"names":[],"mappings":";;;;;;;;;;AAAA,oDAAoE;AACpE,2CAA6F;AAC7F,2CAA+C;AAC/C,yDAA+D;AAC/D,iDAA6C;AAC7C,oDAA+D;AAC/D,+DAA4F;AAE5F,MAAsB,iBAAiB;CAEtC;AAFD,8CAEC;AAEM,MAAM,YAAY,GAAG,CAAC,SAAiB,EAAE,EAAE;IAChD,OAAO,IAAA,uBAAO,EAAC,SAAS,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;AAC9D,CAAC,CAAC;AAFW,QAAA,YAAY,gBAEvB;AAIK,IAAM,gBAAgB,wBAAtB,MAAM,gBAAgB;IAC3B,MAAM,CAAC,OAAO,CAAC,KAAkD;QAC/D,IAAI,QAAQ,GAAG,EAAE,CAAC;QAClB,IAAI,MAAiB,CAAC;QAEtB,OAAO;YACL,MAAM,EAAE,kBAAgB;YACxB,OAAO,EAAE;gBACP,4BAAY;gBACZ,sBAAS,CAAC,aAAa,CAAC;oBACtB,MAAM,EAAE,CAAC,sBAAa,CAAC;oBACvB,UAAU,EAAE,KAAK,EAAE,aAA4B,EAAE,EAAE;wBACjD,MAAM,MAAM,GAAG,MAAM,aAAa,CAAC;4BACjC,aAAa;4BACb,SAAS,EAAE,KAAK,CAAC,SAAS;4BAC1B,WAAW,EAAE,KAAK,CAAC,WAAW;yBAC/B,CAAC,CAAC;wBACH,QAAQ,GAAG,MAAM,CAAC,QAAQ,CAAC;wBAC3B,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC;wBACvB,KAAK,CAAC,SAAS,GAAG,MAAM,CAAC,SAAS,CAAC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AAuB,CAAC,CAAC;IACnE,MAAM,MAAM,GAAG,aAAa,CAAC,GAAG,CAAC,YAAY,CAAC,CAAC;IAE/C,MAAM,SAAS,GAAG,IAAI,sBAAS,CAAC;QAC9B,MAAM,EAAE,MAAM;QACd,WAAW,EAAE;YACX,WAAW,EAAE,SAAS;YACtB,eAAe,EAAE,eAAe;SACjC;KACF,CAAC,CAAC;IAEH,MAAM,OAAO,GAAG,IAAI,+BAAkB,CAAC;QACrC,SAAS,EAAE,SAAS;QACpB,UAAU,EAAE;YACV,iBAAiB,EAAE,IAAI;YACvB,SAAS,EAAE,SAAS,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO;SAC1D;KACF,CAAC,CAAC;IAEH,IAAI,CAAC;QACH,MAAM,MAAM,GAAG,MAAM,SAAS,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QAC7C,OAAO;YACL,MAAM,EAAE,SAAS;YACjB,SAAS,EAAE,SAAS;YACpB,QAAQ,EAAE,MAAM,CAAC,QAAQ;SAC1B,CAAC;IACJ,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,OAAO,CAAC,KAAK,CAAC,sBAAsB,EAAE,GAAG,CAAC,CAAC;QAC3C,MAAM,IAAI,qCAA4B,CAAC,wBAAwB,CAAC,CAAC;IACnE,CAAC;AACH,CAAC"}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { Message, SQSClient } from '@aws-sdk/client-sqs';
|
|
2
|
-
import { EventEmitter2 } from '@nestjs/event-emitter';
|
|
3
|
-
import { SharedService } from '../shared-module';
|
|
4
|
-
export declare const EVENT_QUEUE_EMITTER_NAME: string;
|
|
5
|
-
export declare class EventQueueConsumerService {
|
|
6
|
-
readonly queueName: string;
|
|
7
|
-
readonly queueUrl: string;
|
|
8
|
-
private readonly sqsClient;
|
|
9
|
-
private readonly eventEmitter;
|
|
10
|
-
private readonly sharedService;
|
|
11
|
-
constructor(queueName: string, queueUrl: string, sqsClient: SQSClient, eventEmitter: EventEmitter2, sharedService: SharedService);
|
|
12
|
-
emit(eventName: string, messageBody: Record<string, any>): Promise<void>;
|
|
13
|
-
processEvent(message: Message): Promise<void>;
|
|
14
|
-
onProcessingError(error: Error, message: Message): void;
|
|
15
|
-
}
|
|
16
|
-
//# sourceMappingURL=event-queue.service.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"event-queue.service.d.ts","sourceRoot":"","sources":["../../src/event-queue/event-queue.service.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,OAAO,EACP,SAAS,EAEV,MAAM,qBAAqB,CAAC;AAE7B,OAAO,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAkBtD,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAGjD,eAAO,MAAM,wBAAwB,QAAe,CAAC;AAOrD,qBAAa,yBAAyB;aAElB,SAAS,EAAE,MAAM;aACjB,QAAQ,EAAE,MAAM;IAChC,OAAO,CAAC,QAAQ,CAAC,SAAS;IAC1B,OAAO,CAAC,QAAQ,CAAC,YAAY;IAC7B,OAAO,CAAC,QAAQ,CAAC,aAAa;gBAJd,SAAS,EAAE,MAAM,EACjB,QAAQ,EAAE,MAAM,EACf,SAAS,EAAE,SAAS,EACpB,YAAY,EAAE,aAAa,EAC3B,aAAa,EAAE,aAAa;IAGzC,IAAI,CAAC,SAAS,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC;IA2BxD,YAAY,CAAC,OAAO,EAAE,OAAO;IAwD5B,iBAAiB,CAAC,KAAK,EAAE,KAAK,EAAE,OAAO,EAAE,OAAO;CAGxD"}
|
|
@@ -1,122 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
-
};
|
|
8
|
-
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
-
};
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.EventQueueConsumerService = exports.EVENT_QUEUE_EMITTER_NAME = void 0;
|
|
13
|
-
const client_sqs_1 = require("@aws-sdk/client-sqs");
|
|
14
|
-
const common_1 = require("@nestjs/common");
|
|
15
|
-
const nestjs_sqs_1 = require("@ssut/nestjs-sqs");
|
|
16
|
-
const request_store_1 = require("../request-store");
|
|
17
|
-
const utils_1 = require("../utils");
|
|
18
|
-
exports.EVENT_QUEUE_EMITTER_NAME = (0, utils_1.generateId)();
|
|
19
|
-
class EventQueueConsumerService {
|
|
20
|
-
constructor(queueName, queueUrl, sqsClient, eventEmitter, sharedService) {
|
|
21
|
-
this.queueName = queueName;
|
|
22
|
-
this.queueUrl = queueUrl;
|
|
23
|
-
this.sqsClient = sqsClient;
|
|
24
|
-
this.eventEmitter = eventEmitter;
|
|
25
|
-
this.sharedService = sharedService;
|
|
26
|
-
}
|
|
27
|
-
async emit(eventName, messageBody) {
|
|
28
|
-
const body = {
|
|
29
|
-
tenantDetails: (0, request_store_1.getTenantDetailsIfExists)(),
|
|
30
|
-
institution: (0, request_store_1.getInstitutionOrFail)(),
|
|
31
|
-
userData: (0, request_store_1.getUserData)(),
|
|
32
|
-
evaluatorData: (0, request_store_1.getEvaluatorData)(),
|
|
33
|
-
leadData: (0, request_store_1.getLeadData)(),
|
|
34
|
-
eventName: eventName,
|
|
35
|
-
messageBody: messageBody || {},
|
|
36
|
-
};
|
|
37
|
-
const command = new client_sqs_1.SendMessageCommand({
|
|
38
|
-
QueueUrl: this.queueUrl,
|
|
39
|
-
MessageBody: JSON.stringify(body),
|
|
40
|
-
MessageDeduplicationId: (0, utils_1.generateId)(),
|
|
41
|
-
MessageGroupId: (0, utils_1.generateId)(),
|
|
42
|
-
});
|
|
43
|
-
try {
|
|
44
|
-
await this.sqsClient.send(command);
|
|
45
|
-
}
|
|
46
|
-
catch (err) {
|
|
47
|
-
console.error('Error sending message to SQS', err);
|
|
48
|
-
throw new common_1.BadRequestException('Error sending to queue');
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
async processEvent(message) {
|
|
52
|
-
console.log('Received message:', message);
|
|
53
|
-
const timer = setInterval(async () => {
|
|
54
|
-
const changeMessageVisibilityCommand = new client_sqs_1.ChangeMessageVisibilityCommand({
|
|
55
|
-
QueueUrl: this.queueUrl,
|
|
56
|
-
ReceiptHandle: message.ReceiptHandle,
|
|
57
|
-
VisibilityTimeout: 40,
|
|
58
|
-
});
|
|
59
|
-
try {
|
|
60
|
-
await this.sqsClient.send(changeMessageVisibilityCommand);
|
|
61
|
-
console.log('Visibility timeout updated successfully');
|
|
62
|
-
}
|
|
63
|
-
catch (err) {
|
|
64
|
-
console.log('error updating Visibility timeout', err);
|
|
65
|
-
}
|
|
66
|
-
}, 1000 * 25);
|
|
67
|
-
let body = {};
|
|
68
|
-
try {
|
|
69
|
-
body = JSON.parse(message.Body);
|
|
70
|
-
}
|
|
71
|
-
catch (error) {
|
|
72
|
-
console.error('error', error);
|
|
73
|
-
}
|
|
74
|
-
try {
|
|
75
|
-
const messageBody = body;
|
|
76
|
-
if (!messageBody.eventName)
|
|
77
|
-
return;
|
|
78
|
-
await (0, request_store_1.storeSession)({
|
|
79
|
-
session: async () => {
|
|
80
|
-
if (messageBody.tenantDetails)
|
|
81
|
-
(0, request_store_1.setTenantDetails)(messageBody.tenantDetails);
|
|
82
|
-
if (messageBody.institution)
|
|
83
|
-
(0, request_store_1.setInstitution)(messageBody.institution);
|
|
84
|
-
if (messageBody.userData)
|
|
85
|
-
(0, request_store_1.setUserData)(messageBody.userData);
|
|
86
|
-
if (messageBody.evaluatorData)
|
|
87
|
-
(0, request_store_1.setEvaluatorData)(messageBody.evaluatorData);
|
|
88
|
-
if (messageBody.leadData)
|
|
89
|
-
(0, request_store_1.setLeadData)(messageBody.leadData);
|
|
90
|
-
if (messageBody.tenantDetails) {
|
|
91
|
-
const dataSource = await this.sharedService.getTenantRootConnection((0, request_store_1.getTenantDetails)().id);
|
|
92
|
-
(0, request_store_1.setTenantDataSource)(dataSource);
|
|
93
|
-
}
|
|
94
|
-
await this.eventEmitter.emitAsync(messageBody.eventName, messageBody.messageBody);
|
|
95
|
-
},
|
|
96
|
-
});
|
|
97
|
-
}
|
|
98
|
-
catch (error) {
|
|
99
|
-
console.error('error', error);
|
|
100
|
-
}
|
|
101
|
-
finally {
|
|
102
|
-
clearInterval(timer);
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
onProcessingError(error, message) {
|
|
106
|
-
console.log(`error ${error.message}`, message);
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
exports.EventQueueConsumerService = EventQueueConsumerService;
|
|
110
|
-
__decorate([
|
|
111
|
-
(0, nestjs_sqs_1.SqsMessageHandler)(exports.EVENT_QUEUE_EMITTER_NAME),
|
|
112
|
-
__metadata("design:type", Function),
|
|
113
|
-
__metadata("design:paramtypes", [Object]),
|
|
114
|
-
__metadata("design:returntype", Promise)
|
|
115
|
-
], EventQueueConsumerService.prototype, "processEvent", null);
|
|
116
|
-
__decorate([
|
|
117
|
-
(0, nestjs_sqs_1.SqsConsumerEventHandler)(exports.EVENT_QUEUE_EMITTER_NAME, 'processing_error'),
|
|
118
|
-
__metadata("design:type", Function),
|
|
119
|
-
__metadata("design:paramtypes", [Error, Object]),
|
|
120
|
-
__metadata("design:returntype", void 0)
|
|
121
|
-
], EventQueueConsumerService.prototype, "onProcessingError", null);
|
|
122
|
-
//# sourceMappingURL=event-queue.service.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"event-queue.service.js","sourceRoot":"","sources":["../../src/event-queue/event-queue.service.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,oDAK6B;AAC7B,2CAAqD;AAErD,iDAA8E;AAE9E,oDAc0B;AAE1B,oCAAsC;AAEzB,QAAA,wBAAwB,GAAG,IAAA,kBAAU,GAAE,CAAC;AAOrD,MAAa,yBAAyB;IACpC,YACkB,SAAiB,EACjB,QAAgB,EACf,SAAoB,EACpB,YAA2B,EAC3B,aAA4B;QAJ7B,cAAS,GAAT,SAAS,CAAQ;QACjB,aAAQ,GAAR,QAAQ,CAAQ;QACf,cAAS,GAAT,SAAS,CAAW;QACpB,iBAAY,GAAZ,YAAY,CAAe;QAC3B,kBAAa,GAAb,aAAa,CAAe;IAC5C,CAAC;IAEJ,KAAK,CAAC,IAAI,CAAC,SAAiB,EAAE,WAAgC;QAC5D,MAAM,IAAI,GAAgB;YACxB,aAAa,EAAE,IAAA,wCAAwB,GAAE;YACzC,WAAW,EAAE,IAAA,oCAAoB,GAAE;YACnC,QAAQ,EAAE,IAAA,2BAAW,GAAE;YACvB,aAAa,EAAE,IAAA,gCAAgB,GAAE;YACjC,QAAQ,EAAE,IAAA,2BAAW,GAAE;YACvB,SAAS,EAAE,SAAS;YACpB,WAAW,EAAE,WAAW,IAAI,EAAE;SAC/B,CAAC;QAEF,MAAM,OAAO,GAAG,IAAI,+BAAkB,CAAC;YACrC,QAAQ,EAAE,IAAI,CAAC,QAAQ;YACvB,WAAW,EAAE,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC;YACjC,sBAAsB,EAAE,IAAA,kBAAU,GAAE;YACpC,cAAc,EAAE,IAAA,kBAAU,GAAE;SAC7B,CAAC,CAAC;QAEH,IAAI,CAAC;YACH,MAAM,IAAI,CAAC,SAA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AAGM;IADN,IAAA,oCAAuB,EAAC,gCAAwB,EAAE,kBAAkB,CAAC;;qCACtC,KAAK;;kEAEpC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/event-queue/index.ts"],"names":[],"mappings":"AAAA,cAAc,sBAAsB,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/event-queue/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,uDAAqC"}
|