@seidor-cloud-produtos/orbit-backend-lib 2.0.97 → 2.0.98
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/clean-arch/application/consistency-event-dispatcher/consistency-event-dispatcher.d.ts +8 -0
- package/dist/clean-arch/application/consistency-event-dispatcher/consistency-event-dispatcher.js +16 -0
- package/dist/clean-arch/domain/entities/entity.d.ts +1 -0
- package/dist/clean-arch/domain/entities/entity.js +3 -0
- package/dist/clean-arch/domain/entities/watched-list.d.ts +1 -1
- package/dist/clean-arch/domain/events/consistency-event.d.ts +9 -0
- package/dist/clean-arch/domain/events/consistency-event.js +15 -0
- package/dist/clean-arch/infra/consistency-event-dispatcher/amqp-consistency-event-dispatcher.d.ts +7 -0
- package/dist/clean-arch/infra/consistency-event-dispatcher/amqp-consistency-event-dispatcher.js +15 -0
- package/dist/clean-arch/infra/consistency-event-dispatcher/in-memory-consistency-event-dispatcher.d.ts +8 -0
- package/dist/clean-arch/infra/consistency-event-dispatcher/in-memory-consistency-event-dispatcher.js +15 -0
- package/dist/clean-arch/infra/queue/rabbitmq/amqp-lib.d.ts +2 -10
- package/dist/clean-arch/infra/queue/rabbitmq/amqp-lib.js +13 -5
- package/package.json +1 -1
package/dist/clean-arch/application/consistency-event-dispatcher/consistency-event-dispatcher.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { AuthorizerHeaders } from '../../infra/http/handle-authorizer-headers';
|
|
2
|
+
import { Entity } from '../../domain/entities/entity';
|
|
3
|
+
import ConsistencyEvent from '../../domain/events/consistency-event';
|
|
4
|
+
export declare abstract class ConsistencyEventDispatcher {
|
|
5
|
+
dispatch(entity: Entity<any>, authorizerHeaders: AuthorizerHeaders, eventName: string): Promise<void>;
|
|
6
|
+
dispatchBatch(entities: Entity<any>[], authorizerHeaders: AuthorizerHeaders, eventName: string): Promise<void>;
|
|
7
|
+
abstract publish(event: ConsistencyEvent): Promise<void>;
|
|
8
|
+
}
|
package/dist/clean-arch/application/consistency-event-dispatcher/consistency-event-dispatcher.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ConsistencyEventDispatcher = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const consistency_event_1 = tslib_1.__importDefault(require("../../domain/events/consistency-event"));
|
|
6
|
+
class ConsistencyEventDispatcher {
|
|
7
|
+
async dispatch(entity, authorizerHeaders, eventName) {
|
|
8
|
+
const event = new consistency_event_1.default(entity, authorizerHeaders, eventName);
|
|
9
|
+
await this.publish(event);
|
|
10
|
+
}
|
|
11
|
+
async dispatchBatch(entities, authorizerHeaders, eventName) {
|
|
12
|
+
const events = entities.map(entity => new consistency_event_1.default(entity, authorizerHeaders, eventName));
|
|
13
|
+
await Promise.all(events.map(event => this.publish(event)));
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
exports.ConsistencyEventDispatcher = ConsistencyEventDispatcher;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { AuthorizerHeaders } from '../../infra/http/handle-authorizer-headers';
|
|
2
|
+
import { Entity } from '../entities/entity';
|
|
3
|
+
import DomainEvent from './domain-event';
|
|
4
|
+
export default class ConsistencyEvent implements DomainEvent {
|
|
5
|
+
readonly eventDate: Date;
|
|
6
|
+
readonly name: string;
|
|
7
|
+
readonly input: Record<string, unknown>;
|
|
8
|
+
constructor(entity: Entity<any>, authorizerHeaders: AuthorizerHeaders, eventName: string);
|
|
9
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
class ConsistencyEvent {
|
|
4
|
+
eventDate = new Date();
|
|
5
|
+
name;
|
|
6
|
+
input;
|
|
7
|
+
constructor(entity, authorizerHeaders, eventName) {
|
|
8
|
+
this.name = eventName;
|
|
9
|
+
this.input = {
|
|
10
|
+
origin: authorizerHeaders,
|
|
11
|
+
payload: entity.toEventDispatchObject(),
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
exports.default = ConsistencyEvent;
|
package/dist/clean-arch/infra/consistency-event-dispatcher/amqp-consistency-event-dispatcher.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { ConsistencyEventDispatcher } from '../../application/consistency-event-dispatcher/consistency-event-dispatcher';
|
|
2
|
+
import ConsistencyEvent from '../../domain/events/consistency-event';
|
|
3
|
+
export declare class InMemoryConsistencyEventDispatcher extends ConsistencyEventDispatcher {
|
|
4
|
+
protected events: ConsistencyEvent[];
|
|
5
|
+
constructor(events?: ConsistencyEvent[]);
|
|
6
|
+
publish(event: ConsistencyEvent): Promise<void>;
|
|
7
|
+
}
|
package/dist/clean-arch/infra/consistency-event-dispatcher/amqp-consistency-event-dispatcher.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.InMemoryConsistencyEventDispatcher = void 0;
|
|
4
|
+
const consistency_event_dispatcher_1 = require("../../application/consistency-event-dispatcher/consistency-event-dispatcher");
|
|
5
|
+
class InMemoryConsistencyEventDispatcher extends consistency_event_dispatcher_1.ConsistencyEventDispatcher {
|
|
6
|
+
events;
|
|
7
|
+
constructor(events = []) {
|
|
8
|
+
super();
|
|
9
|
+
this.events = events;
|
|
10
|
+
}
|
|
11
|
+
async publish(event) {
|
|
12
|
+
this.events.push(event);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
exports.InMemoryConsistencyEventDispatcher = InMemoryConsistencyEventDispatcher;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { ConsistencyEventDispatcher } from '../../application/consistency-event-dispatcher/consistency-event-dispatcher';
|
|
2
|
+
import AmqpQueue from '../queue/rabbitmq/amqp-lib';
|
|
3
|
+
import ConsistencyEvent from '../../domain/events/consistency-event';
|
|
4
|
+
export declare class AmqpConsistencyEventDispatcher extends ConsistencyEventDispatcher {
|
|
5
|
+
protected amqp: AmqpQueue;
|
|
6
|
+
constructor(amqp: AmqpQueue);
|
|
7
|
+
publish(event: ConsistencyEvent): Promise<void>;
|
|
8
|
+
}
|
package/dist/clean-arch/infra/consistency-event-dispatcher/in-memory-consistency-event-dispatcher.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AmqpConsistencyEventDispatcher = void 0;
|
|
4
|
+
const consistency_event_dispatcher_1 = require("../../application/consistency-event-dispatcher/consistency-event-dispatcher");
|
|
5
|
+
class AmqpConsistencyEventDispatcher extends consistency_event_dispatcher_1.ConsistencyEventDispatcher {
|
|
6
|
+
amqp;
|
|
7
|
+
constructor(amqp) {
|
|
8
|
+
super();
|
|
9
|
+
this.amqp = amqp;
|
|
10
|
+
}
|
|
11
|
+
async publish(event) {
|
|
12
|
+
await this.amqp.publish(event.name, event, { storeMessageOnError: false });
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
exports.AmqpConsistencyEventDispatcher = AmqpConsistencyEventDispatcher;
|
|
@@ -4,24 +4,16 @@ import QueueConnection from '../../../application/queue/queue-connection';
|
|
|
4
4
|
import DomainEvent from '../../../domain/events/domain-event';
|
|
5
5
|
import { AmqpQueueGetResult } from './types';
|
|
6
6
|
import { Logger } from '../../../application/logger';
|
|
7
|
-
interface SocketOptions {
|
|
8
|
-
retry?: {
|
|
9
|
-
maxCount: number;
|
|
10
|
-
intervalMs: number;
|
|
11
|
-
};
|
|
12
|
-
timeoutSeconds?: number;
|
|
13
|
-
}
|
|
14
7
|
/**
|
|
15
8
|
* Opções de socket/conexão para o AMQP.
|
|
16
9
|
*/
|
|
17
10
|
interface SocketOptions {
|
|
18
|
-
/**
|
|
19
|
-
* Política simples de retry para a conexão inicial.
|
|
20
|
-
*/
|
|
21
11
|
retry?: {
|
|
22
12
|
maxCount: number;
|
|
23
13
|
intervalMs: number;
|
|
24
14
|
};
|
|
15
|
+
timeoutSeconds?: number;
|
|
16
|
+
maxStoredMessagesOnError?: number;
|
|
25
17
|
}
|
|
26
18
|
/**
|
|
27
19
|
* Implementação de fila baseada em AMQP (RabbitMQ) usando `amqplib`.
|
|
@@ -32,7 +32,10 @@ class AmqpQueue {
|
|
|
32
32
|
* Define (ou atualiza) as opções de conexão.
|
|
33
33
|
*/
|
|
34
34
|
setSocketOptions(socketOptions) {
|
|
35
|
-
this.socketOptions =
|
|
35
|
+
this.socketOptions = {
|
|
36
|
+
...(socketOptions || {}),
|
|
37
|
+
maxStoredMessagesOnError: 500,
|
|
38
|
+
};
|
|
36
39
|
return this;
|
|
37
40
|
}
|
|
38
41
|
/**
|
|
@@ -194,15 +197,20 @@ class AmqpQueue {
|
|
|
194
197
|
return result;
|
|
195
198
|
}
|
|
196
199
|
catch (err) {
|
|
200
|
+
this.logger.info({
|
|
201
|
+
message: `⛔ Error to publish messages to: ${domainEvent.name}.`,
|
|
202
|
+
error: err,
|
|
203
|
+
});
|
|
204
|
+
if (buildedConfigs.storeMessageOnError === false ||
|
|
205
|
+
(this.socketOptions?.maxStoredMessagesOnError || 0) <
|
|
206
|
+
this.messagesInMemory.length) {
|
|
207
|
+
return;
|
|
208
|
+
}
|
|
197
209
|
this.messagesInMemory.push({
|
|
198
210
|
exchangeName,
|
|
199
211
|
domainEvent,
|
|
200
212
|
configs: buildedConfigs,
|
|
201
213
|
});
|
|
202
|
-
this.logger.info({
|
|
203
|
-
message: `⛔ Error to publish messages to: ${domainEvent.name}. Publish in memory!`,
|
|
204
|
-
error: err,
|
|
205
|
-
});
|
|
206
214
|
}
|
|
207
215
|
}
|
|
208
216
|
async publishToServer(exchangeName, domainEvent, buildedConfigs) {
|