@warlock.js/herald 4.0.166 → 4.0.171
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/cjs/communicators/broker-registry.d.ts +155 -0
- package/cjs/communicators/broker-registry.d.ts.map +1 -0
- package/cjs/communicators/broker-registry.js +206 -0
- package/cjs/communicators/broker-registry.js.map +1 -0
- package/{esm/communicators/communicator.d.ts → cjs/communicators/broker.d.ts} +20 -20
- package/cjs/communicators/broker.d.ts.map +1 -0
- package/cjs/communicators/{communicator.js → broker.js} +12 -12
- package/cjs/communicators/broker.js.map +1 -0
- package/cjs/communicators/index.d.ts +2 -2
- package/cjs/communicators/index.d.ts.map +1 -1
- package/{esm/contracts/communicator-driver.contract.d.ts → cjs/contracts/broker-driver.contract.d.ts} +8 -8
- package/cjs/contracts/broker-driver.contract.d.ts.map +1 -0
- package/cjs/contracts/channel.contract.d.ts +6 -1
- package/cjs/contracts/channel.contract.d.ts.map +1 -1
- package/cjs/contracts/index.d.ts +1 -1
- package/cjs/contracts/index.d.ts.map +1 -1
- package/cjs/decorators/consumable.d.ts +2 -2
- package/cjs/decorators/consumable.d.ts.map +1 -1
- package/cjs/decorators/consumable.js +12 -12
- package/cjs/decorators/consumable.js.map +1 -1
- package/cjs/drivers/rabbitmq/rabbitmq-channel.d.ts +2 -1
- package/cjs/drivers/rabbitmq/rabbitmq-channel.d.ts.map +1 -1
- package/cjs/drivers/rabbitmq/rabbitmq-channel.js +4 -2
- package/cjs/drivers/rabbitmq/rabbitmq-channel.js.map +1 -1
- package/cjs/drivers/rabbitmq/rabbitmq-driver.d.ts +10 -8
- package/cjs/drivers/rabbitmq/rabbitmq-driver.d.ts.map +1 -1
- package/cjs/drivers/rabbitmq/rabbitmq-driver.js +11 -10
- package/cjs/drivers/rabbitmq/rabbitmq-driver.js.map +1 -1
- package/cjs/index.d.ts +7 -7
- package/cjs/index.d.ts.map +1 -1
- package/cjs/index.js +1 -1
- package/cjs/message-managers/event-consumer.d.ts +2 -1
- package/cjs/message-managers/event-consumer.d.ts.map +1 -1
- package/cjs/message-managers/event-consumer.js +7 -1
- package/cjs/message-managers/event-consumer.js.map +1 -1
- package/cjs/message-managers/event-message.d.ts +7 -4
- package/cjs/message-managers/event-message.d.ts.map +1 -1
- package/cjs/message-managers/event-message.js +8 -8
- package/cjs/message-managers/event-message.js.map +1 -1
- package/cjs/message-managers/prepare-consumer-subscription.d.ts +1 -1
- package/cjs/message-managers/prepare-consumer-subscription.d.ts.map +1 -1
- package/cjs/message-managers/prepare-consumer-subscription.js +4 -3
- package/cjs/message-managers/prepare-consumer-subscription.js.map +1 -1
- package/cjs/types/channel.types.d.ts +19 -0
- package/cjs/types/channel.types.d.ts.map +1 -0
- package/cjs/types/connection.types.d.ts +65 -0
- package/cjs/types/connection.types.d.ts.map +1 -0
- package/cjs/types/driver.types.d.ts +10 -0
- package/cjs/types/driver.types.d.ts.map +1 -0
- package/cjs/types/index.d.ts +8 -0
- package/cjs/types/index.d.ts.map +1 -0
- package/cjs/types/message.types.d.ts +34 -0
- package/cjs/types/message.types.d.ts.map +1 -0
- package/cjs/types/publish.types.d.ts +13 -0
- package/cjs/types/publish.types.d.ts.map +1 -0
- package/cjs/types/registry.types.d.ts +4 -0
- package/cjs/types/registry.types.d.ts.map +1 -0
- package/cjs/types/subscribe.types.d.ts +18 -0
- package/cjs/types/subscribe.types.d.ts.map +1 -0
- package/{esm/utils/connect-to-communicator.d.ts → cjs/utils/connect-to-broker.d.ts} +43 -41
- package/cjs/utils/connect-to-broker.d.ts.map +1 -0
- package/cjs/utils/{connect-to-communicator.js → connect-to-broker.js} +52 -50
- package/cjs/utils/connect-to-broker.js.map +1 -0
- package/cjs/utils/index.d.ts +1 -1
- package/cjs/utils/index.d.ts.map +1 -1
- package/esm/communicators/broker-registry.d.ts +155 -0
- package/esm/communicators/broker-registry.d.ts.map +1 -0
- package/esm/communicators/broker-registry.js +206 -0
- package/esm/communicators/broker-registry.js.map +1 -0
- package/{cjs/communicators/communicator.d.ts → esm/communicators/broker.d.ts} +20 -20
- package/esm/communicators/broker.d.ts.map +1 -0
- package/esm/communicators/{communicator.js → broker.js} +12 -12
- package/esm/communicators/broker.js.map +1 -0
- package/esm/communicators/index.d.ts +2 -2
- package/esm/communicators/index.d.ts.map +1 -1
- package/{cjs/contracts/communicator-driver.contract.d.ts → esm/contracts/broker-driver.contract.d.ts} +8 -8
- package/esm/contracts/broker-driver.contract.d.ts.map +1 -0
- package/esm/contracts/channel.contract.d.ts +6 -1
- package/esm/contracts/channel.contract.d.ts.map +1 -1
- package/esm/contracts/index.d.ts +1 -1
- package/esm/contracts/index.d.ts.map +1 -1
- package/esm/decorators/consumable.d.ts +2 -2
- package/esm/decorators/consumable.d.ts.map +1 -1
- package/esm/decorators/consumable.js +12 -12
- package/esm/decorators/consumable.js.map +1 -1
- package/esm/drivers/rabbitmq/rabbitmq-channel.d.ts +2 -1
- package/esm/drivers/rabbitmq/rabbitmq-channel.d.ts.map +1 -1
- package/esm/drivers/rabbitmq/rabbitmq-channel.js +4 -2
- package/esm/drivers/rabbitmq/rabbitmq-channel.js.map +1 -1
- package/esm/drivers/rabbitmq/rabbitmq-driver.d.ts +10 -8
- package/esm/drivers/rabbitmq/rabbitmq-driver.d.ts.map +1 -1
- package/esm/drivers/rabbitmq/rabbitmq-driver.js +11 -10
- package/esm/drivers/rabbitmq/rabbitmq-driver.js.map +1 -1
- package/esm/index.d.ts +7 -7
- package/esm/index.d.ts.map +1 -1
- package/esm/index.js +1 -1
- package/esm/message-managers/event-consumer.d.ts +2 -1
- package/esm/message-managers/event-consumer.d.ts.map +1 -1
- package/esm/message-managers/event-consumer.js +7 -1
- package/esm/message-managers/event-consumer.js.map +1 -1
- package/esm/message-managers/event-message.d.ts +7 -4
- package/esm/message-managers/event-message.d.ts.map +1 -1
- package/esm/message-managers/event-message.js +8 -8
- package/esm/message-managers/event-message.js.map +1 -1
- package/esm/message-managers/prepare-consumer-subscription.d.ts +1 -1
- package/esm/message-managers/prepare-consumer-subscription.d.ts.map +1 -1
- package/esm/message-managers/prepare-consumer-subscription.js +4 -3
- package/esm/message-managers/prepare-consumer-subscription.js.map +1 -1
- package/esm/types/channel.types.d.ts +19 -0
- package/esm/types/channel.types.d.ts.map +1 -0
- package/esm/types/connection.types.d.ts +65 -0
- package/esm/types/connection.types.d.ts.map +1 -0
- package/esm/types/driver.types.d.ts +10 -0
- package/esm/types/driver.types.d.ts.map +1 -0
- package/esm/types/index.d.ts +8 -0
- package/esm/types/index.d.ts.map +1 -0
- package/esm/types/message.types.d.ts +34 -0
- package/esm/types/message.types.d.ts.map +1 -0
- package/esm/types/publish.types.d.ts +13 -0
- package/esm/types/publish.types.d.ts.map +1 -0
- package/esm/types/registry.types.d.ts +4 -0
- package/esm/types/registry.types.d.ts.map +1 -0
- package/esm/types/subscribe.types.d.ts +18 -0
- package/esm/types/subscribe.types.d.ts.map +1 -0
- package/{cjs/utils/connect-to-communicator.d.ts → esm/utils/connect-to-broker.d.ts} +43 -41
- package/esm/utils/connect-to-broker.d.ts.map +1 -0
- package/esm/utils/{connect-to-communicator.js → connect-to-broker.js} +52 -50
- package/esm/utils/connect-to-broker.js.map +1 -0
- package/esm/utils/index.d.ts +1 -1
- package/esm/utils/index.d.ts.map +1 -1
- package/package.json +3 -3
- package/cjs/communicators/communicator-registry.d.ts +0 -155
- package/cjs/communicators/communicator-registry.d.ts.map +0 -1
- package/cjs/communicators/communicator-registry.js +0 -206
- package/cjs/communicators/communicator-registry.js.map +0 -1
- package/cjs/communicators/communicator.d.ts.map +0 -1
- package/cjs/communicators/communicator.js.map +0 -1
- package/cjs/contracts/communicator-driver.contract.d.ts.map +0 -1
- package/cjs/types.d.ts +0 -399
- package/cjs/types.d.ts.map +0 -1
- package/cjs/utils/connect-to-communicator.d.ts.map +0 -1
- package/cjs/utils/connect-to-communicator.js.map +0 -1
- package/esm/communicators/communicator-registry.d.ts +0 -155
- package/esm/communicators/communicator-registry.d.ts.map +0 -1
- package/esm/communicators/communicator-registry.js +0 -206
- package/esm/communicators/communicator-registry.js.map +0 -1
- package/esm/communicators/communicator.d.ts.map +0 -1
- package/esm/communicators/communicator.js.map +0 -1
- package/esm/contracts/communicator-driver.contract.d.ts.map +0 -1
- package/esm/types.d.ts +0 -399
- package/esm/types.d.ts.map +0 -1
- package/esm/utils/connect-to-communicator.d.ts.map +0 -1
- package/esm/utils/connect-to-communicator.js.map +0 -1
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
export type BaseConnectionOptions = {
|
|
3
|
+
name?: string;
|
|
4
|
+
isDefault?: boolean;
|
|
5
|
+
};
|
|
6
|
+
export type RabbitMQSocketOptions = {
|
|
7
|
+
keepAlive?: boolean | number;
|
|
8
|
+
noDelay?: boolean;
|
|
9
|
+
timeout?: number;
|
|
10
|
+
ca?: string | Buffer | Array<string | Buffer>;
|
|
11
|
+
cert?: string | Buffer;
|
|
12
|
+
key?: string | Buffer;
|
|
13
|
+
passphrase?: string;
|
|
14
|
+
servername?: string;
|
|
15
|
+
rejectUnauthorized?: boolean;
|
|
16
|
+
};
|
|
17
|
+
export type RabbitMQClientOptions = {
|
|
18
|
+
frameMax?: number;
|
|
19
|
+
channelMax?: number;
|
|
20
|
+
locale?: string;
|
|
21
|
+
socket?: RabbitMQSocketOptions;
|
|
22
|
+
};
|
|
23
|
+
export type RabbitMQConnectionOptions<TClientOptions extends RabbitMQClientOptions = RabbitMQClientOptions> = BaseConnectionOptions & {
|
|
24
|
+
driver: "rabbitmq";
|
|
25
|
+
host?: string;
|
|
26
|
+
port?: number;
|
|
27
|
+
username?: string;
|
|
28
|
+
password?: string;
|
|
29
|
+
vhost?: string;
|
|
30
|
+
uri?: string;
|
|
31
|
+
heartbeat?: number;
|
|
32
|
+
connectionTimeout?: number;
|
|
33
|
+
reconnect?: boolean;
|
|
34
|
+
reconnectDelay?: number;
|
|
35
|
+
prefetch?: number;
|
|
36
|
+
clientOptions?: TClientOptions;
|
|
37
|
+
};
|
|
38
|
+
export type KafkaClientOptions = {
|
|
39
|
+
retry?: {
|
|
40
|
+
initialRetryTime?: number;
|
|
41
|
+
retries?: number;
|
|
42
|
+
maxRetryTime?: number;
|
|
43
|
+
factor?: number;
|
|
44
|
+
multiplier?: number;
|
|
45
|
+
};
|
|
46
|
+
logLevel?: number;
|
|
47
|
+
logCreator?: any;
|
|
48
|
+
};
|
|
49
|
+
export type KafkaConnectionOptions<TClientOptions extends KafkaClientOptions = KafkaClientOptions> = BaseConnectionOptions & {
|
|
50
|
+
driver: "kafka";
|
|
51
|
+
brokers: string[];
|
|
52
|
+
clientId?: string;
|
|
53
|
+
connectionTimeout?: number;
|
|
54
|
+
requestTimeout?: number;
|
|
55
|
+
ssl?: boolean | object;
|
|
56
|
+
sasl?: {
|
|
57
|
+
mechanism: "plain" | "scram-sha-256" | "scram-sha-512";
|
|
58
|
+
username: string;
|
|
59
|
+
password: string;
|
|
60
|
+
};
|
|
61
|
+
clientOptions?: TClientOptions;
|
|
62
|
+
};
|
|
63
|
+
export type ConnectionOptions = RabbitMQConnectionOptions | KafkaConnectionOptions;
|
|
64
|
+
export type BrokerConfigurations<TClientOptions = any> = RabbitMQConnectionOptions<TClientOptions extends RabbitMQClientOptions ? TClientOptions : RabbitMQClientOptions> | KafkaConnectionOptions<TClientOptions extends KafkaClientOptions ? TClientOptions : KafkaClientOptions>;
|
|
65
|
+
//# sourceMappingURL=connection.types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"connection.types.d.ts","sourceRoot":"","sources":["../../src/types/connection.types.ts"],"names":[],"mappings":";AAAA,MAAM,MAAM,qBAAqB,GAAG;IAClC,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,SAAS,CAAC,EAAE,OAAO,CAAC;CACrB,CAAC;AAEF,MAAM,MAAM,qBAAqB,GAAG;IAClC,SAAS,CAAC,EAAE,OAAO,GAAG,MAAM,CAAC;IAC7B,OAAO,CAAC,EAAE,OA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AAE,MAAM,CAAC;QACjB,YAAY,CAAC,EAAE,MAAM,CAAC;QACtB,MAAM,CAAC,EAAE,MAAM,CAAC;QAChB,UAAU,CAAC,EAAE,MAAM,CAAC;KACrB,CAAC;IACF,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,UAAU,CAAC,EAAE,GAAG,CAAC;CAClB,CAAC;AAEF,MAAM,MAAM,sBAAsB,CAAC,cAAc,SAAS,kBAAkB,GAAG,kBAAkB,IAC/F,qBAAqB,GAAG;IACtB,MAAM,EAAE,OAAO,CAAC;IAChB,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,GAAG,CAAC,EAAE,OAAO,GAAG,MAAM,CAAC;IACvB,IAAI,CAAC,EAAE;QACL,SAAS,EAAE,OAAO,GAAG,eAAe,GAAG,eAAe,CAAC;QACvD,QAAQ,EAAE,MAAM,CAAC;QACjB,QAAQ,EAAE,MAAM,CAAC;KAClB,CAAC;IACF,aAAa,CAAC,EAAE,cAAc,CAAC;CAChC,CAAC;AAEJ,MAAM,MAAM,iBAAiB,GAAG,yBAAyB,GAAG,sBAAsB,CAAC;AAEnF,MAAM,MAAM,oBAAoB,CAAC,cAAc,GAAG,GAAG,IACjD,yBAAyB,CACvB,cAAc,SAAS,qBAAqB,GAAG,cAAc,GAAG,qBAAqB,CACtF,GACD,sBAAsB,CACpB,cAAc,SAAS,kBAAkB,GAAG,cAAc,GAAG,kBAAkB,CAChF,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export type BrokerDriverType = "rabbitmq" | "kafka" | "redis-streams" | "sqs";
|
|
2
|
+
export type BrokerEvent = "connected" | "disconnected" | "error" | "reconnecting";
|
|
3
|
+
export type BrokerEventListener = (...args: unknown[]) => void;
|
|
4
|
+
export type HealthCheckResult = {
|
|
5
|
+
healthy: boolean;
|
|
6
|
+
latency?: number;
|
|
7
|
+
error?: string;
|
|
8
|
+
details?: Record<string, unknown>;
|
|
9
|
+
};
|
|
10
|
+
//# sourceMappingURL=driver.types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"driver.types.d.ts","sourceRoot":"","sources":["../../src/types/driver.types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,gBAAgB,GAAG,UAAU,GAAG,OAAO,GAAG,eAAe,GAAG,KAAK,CAAC;AAE9E,MAAM,MAAM,WAAW,GAAG,WAAW,GAAG,cAAc,GAAG,OAAO,GAAG,cAAc,CAAC;AAElF,MAAM,MAAM,mBAAmB,GAAG,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,IAAI,CAAC;AAE/D,MAAM,MAAM,iBAAiB,GAAG;IAC9B,OAAO,EAAE,OAAO,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACnC,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export * from "./channel.types";
|
|
2
|
+
export * from "./connection.types";
|
|
3
|
+
export * from "./driver.types";
|
|
4
|
+
export * from "./message.types";
|
|
5
|
+
export * from "./publish.types";
|
|
6
|
+
export * from "./registry.types";
|
|
7
|
+
export * from "./subscribe.types";
|
|
8
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC;AAChC,cAAc,oBAAoB,CAAC;AACnC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,iBAAiB,CAAC;AAChC,cAAc,iBAAiB,CAAC;AAChC,cAAc,kBAAkB,CAAC;AACjC,cAAc,mBAAmB,CAAC"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
export type MessageMetadata = {
|
|
2
|
+
messageId: string;
|
|
3
|
+
correlationId?: string;
|
|
4
|
+
replyTo?: string;
|
|
5
|
+
priority?: number;
|
|
6
|
+
timestamp: Date;
|
|
7
|
+
headers?: Record<string, string>;
|
|
8
|
+
retryCount?: number;
|
|
9
|
+
originalChannel?: string;
|
|
10
|
+
};
|
|
11
|
+
export type Message<TPayload = unknown> = {
|
|
12
|
+
readonly metadata: MessageMetadata;
|
|
13
|
+
readonly payload: TPayload;
|
|
14
|
+
readonly raw?: unknown;
|
|
15
|
+
};
|
|
16
|
+
export type MessageContext = {
|
|
17
|
+
ack(): Promise<void>;
|
|
18
|
+
nack(requeue?: boolean): Promise<void>;
|
|
19
|
+
reject(): Promise<void>;
|
|
20
|
+
reply<T>(payload: T): Promise<void>;
|
|
21
|
+
retry(delay?: number): Promise<void>;
|
|
22
|
+
};
|
|
23
|
+
export type Subscription = {
|
|
24
|
+
readonly id: string;
|
|
25
|
+
readonly channel: string;
|
|
26
|
+
readonly consumerTag?: string;
|
|
27
|
+
unsubscribe(): Promise<void>;
|
|
28
|
+
pause(): Promise<void>;
|
|
29
|
+
resume(): Promise<void>;
|
|
30
|
+
isActive(): boolean;
|
|
31
|
+
};
|
|
32
|
+
export type MessageHandler<TPayload = unknown> = (message: Message<TPayload>, ctx: MessageContext) => Promise<void> | void;
|
|
33
|
+
export type ResponseHandler<TPayload = unknown, TResponse = unknown> = (message: Message<TPayload>, ctx: MessageContext) => Promise<TResponse> | TResponse;
|
|
34
|
+
//# sourceMappingURL=message.types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"message.types.d.ts","sourceRoot":"","sources":["../../src/types/message.types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,eAAe,GAAG;IAC5B,SAAS,EAAE,MAAM,CAAC;IAClB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,OAAO,CAAC,EAAE,MAAM,CA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O,EAAE,OAAO,CAAC,QAAQ,CAAC,EAC1B,GAAG,EAAE,cAAc,KAChB,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC;AAE1B,MAAM,MAAM,eAAe,CAAC,QAAQ,GAAG,OAAO,EAAE,SAAS,GAAG,OAAO,IAAI,CACrE,OAAO,EAAE,OAAO,CAAC,QAAQ,CAAC,EAC1B,GAAG,EAAE,cAAc,KAChB,OAAO,CAAC,SAAS,CAAC,GAAG,SAAS,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export type PublishOptions = {
|
|
2
|
+
priority?: number;
|
|
3
|
+
ttl?: number;
|
|
4
|
+
delay?: number;
|
|
5
|
+
headers?: Record<string, string>;
|
|
6
|
+
persistent?: boolean;
|
|
7
|
+
correlationId?: string;
|
|
8
|
+
expiration?: number;
|
|
9
|
+
};
|
|
10
|
+
export type RequestOptions = PublishOptions & {
|
|
11
|
+
timeout?: number;
|
|
12
|
+
};
|
|
13
|
+
//# sourceMappingURL=publish.types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"publish.types.d.ts","sourceRoot":"","sources":["../../src/types/publish.types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,cAAc,GAAG;IAC3B,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACjC,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB,CAAC;AAEF,MAAM,MAAM,cAAc,GAAG,cAAc,GAAG;IAC5C,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"registry.types.d.ts","sourceRoot":"","sources":["../../src/types/registry.types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAC;AAEtD,MAAM,MAAM,mBAAmB,GAC3B,YAAY,GACZ,oBAAoB,GACpB,WAAW,GACX,cAAc,CAAC;AAEnB,MAAM,MAAM,sBAAsB,GAAG,CAAC,MAAM,EAAE,MAAM,KAAK,IAAI,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export type RetryOptions = {
|
|
2
|
+
maxRetries: number;
|
|
3
|
+
delay: number | ((attempt: number) => number);
|
|
4
|
+
};
|
|
5
|
+
export type DeadLetterOptions = {
|
|
6
|
+
channel: string;
|
|
7
|
+
preserveOriginal?: boolean;
|
|
8
|
+
};
|
|
9
|
+
export type SubscribeOptions = {
|
|
10
|
+
consumerId?: string;
|
|
11
|
+
group?: string;
|
|
12
|
+
prefetch?: number;
|
|
13
|
+
autoAck?: boolean;
|
|
14
|
+
retry?: RetryOptions;
|
|
15
|
+
deadLetter?: DeadLetterOptions;
|
|
16
|
+
exclusive?: boolean;
|
|
17
|
+
};
|
|
18
|
+
//# sourceMappingURL=subscribe.types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"subscribe.types.d.ts","sourceRoot":"","sources":["../../src/types/subscribe.types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,YAAY,GAAG;IACzB,UAAU,EAAE,MAAM,CAAC;IACnB,KAAK,EAAE,MAAM,GAAG,CAAC,CAAC,OAAO,EAAE,MAAM,KAAK,MAAM,CAAC,CAAC;CAC/C,CAAC;AAEF,MAAM,MAAM,iBAAiB,GAAG;IAC9B,OAAO,EAAE,MAAM,CAAC;IAChB,gBAAgB,CAAC,EAAE,OAAO,CAAC;CAC5B,CAAC;AAEF,MAAM,MAAM,gBAAgB,GAAG;IAC7B,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,KAAK,CAAC,EAAE,YAAY,CAAC;IACrB,UAAU,CAAC,EAAE,iBAAiB,CAAC;IAC/B,SAAS,CAAC,EAAE,OAAO,CAAC;CACrB,CAAC"}
|
|
@@ -1,26 +1,26 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Broker } from "../communicators";
|
|
2
2
|
import type { ChannelContract } from "../contracts";
|
|
3
3
|
import { EventConsumerClass, EventMessage } from "../message-managers";
|
|
4
4
|
import type { ChannelOptions, ConnectionOptions } from "../types";
|
|
5
5
|
/**
|
|
6
|
-
* Connect to a message broker and register
|
|
6
|
+
* Connect to a message broker and register it.
|
|
7
7
|
*
|
|
8
8
|
* This is a high-level utility function that simplifies connection setup
|
|
9
9
|
* for most projects. It handles driver instantiation, connection,
|
|
10
|
-
*
|
|
10
|
+
* broker creation, and automatic registration.
|
|
11
11
|
*
|
|
12
12
|
* **Supported Drivers:**
|
|
13
13
|
* - `rabbitmq` (default) - RabbitMQ/AMQP driver
|
|
14
14
|
* - `kafka` - Apache Kafka driver (coming soon)
|
|
15
15
|
*
|
|
16
16
|
* @param options - Connection configuration options
|
|
17
|
-
* @returns A connected and registered
|
|
17
|
+
* @returns A connected and registered Broker instance
|
|
18
18
|
* @throws {Error} If connection fails or driver is not implemented
|
|
19
19
|
*
|
|
20
20
|
* @example
|
|
21
21
|
* ```typescript
|
|
22
22
|
* // RabbitMQ connection
|
|
23
|
-
* const
|
|
23
|
+
* const broker = await connectToBroker({
|
|
24
24
|
* driver: "rabbitmq",
|
|
25
25
|
* host: "localhost",
|
|
26
26
|
* port: 5672,
|
|
@@ -28,55 +28,55 @@ import type { ChannelOptions, ConnectionOptions } from "../types";
|
|
|
28
28
|
* password: "guest",
|
|
29
29
|
* });
|
|
30
30
|
*
|
|
31
|
-
* // Use the
|
|
32
|
-
* await
|
|
31
|
+
* // Use the broker
|
|
32
|
+
* await broker.channel("user.created").publish({ userId: 1 });
|
|
33
33
|
* ```
|
|
34
34
|
*
|
|
35
35
|
* @example
|
|
36
36
|
* ```typescript
|
|
37
|
-
* // Multiple
|
|
38
|
-
* await
|
|
37
|
+
* // Multiple brokers
|
|
38
|
+
* await connectToBroker({
|
|
39
39
|
* driver: "rabbitmq",
|
|
40
40
|
* name: "notifications",
|
|
41
41
|
* isDefault: true,
|
|
42
42
|
* host: process.env.RABBITMQ_HOST,
|
|
43
43
|
* });
|
|
44
44
|
*
|
|
45
|
-
* await
|
|
45
|
+
* await connectToBroker({
|
|
46
46
|
* driver: "rabbitmq",
|
|
47
47
|
* name: "analytics",
|
|
48
48
|
* host: process.env.ANALYTICS_RABBITMQ_HOST,
|
|
49
49
|
* });
|
|
50
50
|
*
|
|
51
|
-
* // Use default
|
|
52
|
-
*
|
|
51
|
+
* // Use default broker
|
|
52
|
+
* herald().channel("notifications").publish({ ... });
|
|
53
53
|
*
|
|
54
|
-
* // Use specific
|
|
55
|
-
*
|
|
54
|
+
* // Use specific broker
|
|
55
|
+
* herald("analytics").channel("events").publish({ ... });
|
|
56
56
|
* ```
|
|
57
57
|
*/
|
|
58
|
-
export declare function
|
|
58
|
+
export declare function connectToBroker(options: ConnectionOptions): Promise<Broker>;
|
|
59
59
|
/**
|
|
60
|
-
* Get a
|
|
60
|
+
* Get a broker by name or the default one.
|
|
61
61
|
*
|
|
62
|
-
* This is the main entry point for using
|
|
62
|
+
* This is the main entry point for using brokers in your application.
|
|
63
|
+
* Named after the package — `herald()` carries your messages!
|
|
63
64
|
*
|
|
64
|
-
* @param name - Optional
|
|
65
|
-
* @returns
|
|
66
|
-
* @throws
|
|
65
|
+
* @param name - Optional broker name (uses default if not provided)
|
|
66
|
+
* @returns Broker instance
|
|
67
|
+
* @throws MissingBrokerError if broker not found
|
|
67
68
|
*
|
|
68
69
|
* @example
|
|
69
|
-
*
|
|
70
|
-
*
|
|
71
|
-
* const channel = communicators().channel("user.created");
|
|
70
|
+
* // Get default broker
|
|
71
|
+
* const channel = herald().channel("user.created");
|
|
72
72
|
* await channel.publish({ userId: 1 });
|
|
73
73
|
*
|
|
74
|
-
* // Get specific
|
|
75
|
-
* const analyticsChannel =
|
|
74
|
+
* // Get specific broker
|
|
75
|
+
* const analyticsChannel = herald("analytics").channel("events");
|
|
76
76
|
* await analyticsChannel.publish({ event: "page_view" });
|
|
77
77
|
*
|
|
78
78
|
* // Subscribe to messages
|
|
79
|
-
*
|
|
79
|
+
* herald()
|
|
80
80
|
* .channel<UserPayload>("user.created")
|
|
81
81
|
* .subscribe(async (message, ctx) => {
|
|
82
82
|
* console.log("User created:", message.payload);
|
|
@@ -84,25 +84,30 @@ export declare function connectToCommunicator(options: ConnectionOptions): Promi
|
|
|
84
84
|
* });
|
|
85
85
|
* ```
|
|
86
86
|
*/
|
|
87
|
-
export declare function
|
|
87
|
+
export declare function herald(name?: string): Broker;
|
|
88
88
|
/**
|
|
89
|
-
* Get channel instance for the given name from default
|
|
89
|
+
* Get channel instance for the given name from default broker.
|
|
90
|
+
*
|
|
91
|
+
* Shorthand for `herald().channel(name, options)`.
|
|
92
|
+
*
|
|
90
93
|
* @param name - Channel name
|
|
94
|
+
* @param options - Optional channel options
|
|
91
95
|
* @returns Channel instance
|
|
92
|
-
* @throws
|
|
96
|
+
* @throws MissingBrokerError if broker not found
|
|
93
97
|
*
|
|
94
98
|
* @example
|
|
95
99
|
* ```typescript
|
|
96
|
-
* const channel =
|
|
100
|
+
* const channel = heraldChannel("user.created");
|
|
97
101
|
* await channel.publish({ userId: 1 });
|
|
98
102
|
* ```
|
|
99
103
|
*/
|
|
100
|
-
export declare function
|
|
104
|
+
export declare function heraldChannel<TPayload = unknown>(name: string, options?: ChannelOptions<TPayload>): ChannelContract<TPayload>;
|
|
101
105
|
/**
|
|
102
|
-
* Publish the
|
|
106
|
+
* Publish an EventMessage to the default broker.
|
|
107
|
+
*
|
|
103
108
|
* @param event - Event message to publish
|
|
104
109
|
* @returns Promise that resolves when the event is published
|
|
105
|
-
* @throws Error if the
|
|
110
|
+
* @throws Error if the broker is not connected
|
|
106
111
|
*
|
|
107
112
|
* @example
|
|
108
113
|
* ```typescript
|
|
@@ -111,19 +116,16 @@ export declare function communicatorChannel<TPayload = unknown>(name: string, op
|
|
|
111
116
|
*/
|
|
112
117
|
export declare function publishEvent<TPayload = Record<string, any>>(event: EventMessage<TPayload>): Promise<void>;
|
|
113
118
|
/**
|
|
114
|
-
* Subscribe
|
|
119
|
+
* Subscribe an EventConsumer class to the default broker.
|
|
120
|
+
*
|
|
115
121
|
* @param Consumer - Event consumer class
|
|
116
|
-
* @returns
|
|
117
|
-
* @throws
|
|
122
|
+
* @returns Unsubscribe function
|
|
123
|
+
* @throws MissingBrokerError if broker not found
|
|
118
124
|
*
|
|
119
125
|
* @example
|
|
120
126
|
* ```typescript
|
|
121
127
|
* await subscribeConsumer(UserUpdatedConsumer);
|
|
122
|
-
* });
|
|
123
|
-
*
|
|
124
|
-
* // Unsubscribe
|
|
125
|
-
* await unsubscribeConsumer(UserUpdatedConsumer);
|
|
126
128
|
* ```
|
|
127
129
|
*/
|
|
128
130
|
export declare function subscribeConsumer<TPayload = Record<string, any>>(Consumer: EventConsumerClass<TPayload>): Promise<() => void>;
|
|
129
|
-
//# sourceMappingURL=connect-to-
|
|
131
|
+
//# sourceMappingURL=connect-to-broker.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"connect-to-broker.d.ts","sourceRoot":"","sources":["../../src/utils/connect-to-broker.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAkB,MAAM,kBAAkB,CAAC;AAC1D,OAAO,KAAK,EAAwB,eAAe,EAAE,MAAM,cAAc,CAAC;AAC1E,OAAO,EAAE,kBAAkB,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACvE,OAAO,KAAK,EAAE,cAAc,EAAE,iBAAiB,EAA6B,MAAM,UAAU,CAAC;AAE7F;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoDG;AACH,wBAAsB,eAAe,CAAC,OAAO,EAAE,iBAAiB,GAAG,OAAO,CAAC,MAAM,CAAC,CA+CjF;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,wBAAgB,MAAM,CAAC,IAAI,CAAC,EAAE,MAAM,GAAG,MAAM,CAE5C;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,aAAa,CAAC,QAAQ,GAAG,OAAO,EAC9C,IAAI,EAAE,MAAM,EACZ,OAAO,CAAC,EAAE,cAAc,CAAC,QAAQ,CAAC,GACjC,eAAe,CAAC,QAAQ,CAAC,CAE3B;AAED;;;;;;;;;;;GAWG;AACH,wBAAsB,YAAY,CAAC,QAAQ,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE,KAAK,EAAE,YAAY,CAAC,QAAQ,CAAC,iBAE/F;AAED;;;;;;;;;;;GAWG;AACH,wBAAsB,iBAAiB,CAAC,QAAQ,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EACpE,QAAQ,EAAE,kBAAkB,CAAC,QAAQ,CAAC,uBAGvC"}
|
|
@@ -1,22 +1,22 @@
|
|
|
1
|
-
import {
|
|
2
|
-
* Connect to a message broker and register
|
|
1
|
+
import {brokerRegistry}from'../communicators/broker-registry.js';/**
|
|
2
|
+
* Connect to a message broker and register it.
|
|
3
3
|
*
|
|
4
4
|
* This is a high-level utility function that simplifies connection setup
|
|
5
5
|
* for most projects. It handles driver instantiation, connection,
|
|
6
|
-
*
|
|
6
|
+
* broker creation, and automatic registration.
|
|
7
7
|
*
|
|
8
8
|
* **Supported Drivers:**
|
|
9
9
|
* - `rabbitmq` (default) - RabbitMQ/AMQP driver
|
|
10
10
|
* - `kafka` - Apache Kafka driver (coming soon)
|
|
11
11
|
*
|
|
12
12
|
* @param options - Connection configuration options
|
|
13
|
-
* @returns A connected and registered
|
|
13
|
+
* @returns A connected and registered Broker instance
|
|
14
14
|
* @throws {Error} If connection fails or driver is not implemented
|
|
15
15
|
*
|
|
16
16
|
* @example
|
|
17
17
|
* ```typescript
|
|
18
18
|
* // RabbitMQ connection
|
|
19
|
-
* const
|
|
19
|
+
* const broker = await connectToBroker({
|
|
20
20
|
* driver: "rabbitmq",
|
|
21
21
|
* host: "localhost",
|
|
22
22
|
* port: 5672,
|
|
@@ -24,37 +24,37 @@ import {communicatorRegistry}from'../communicators/communicator-registry.js';/**
|
|
|
24
24
|
* password: "guest",
|
|
25
25
|
* });
|
|
26
26
|
*
|
|
27
|
-
* // Use the
|
|
28
|
-
* await
|
|
27
|
+
* // Use the broker
|
|
28
|
+
* await broker.channel("user.created").publish({ userId: 1 });
|
|
29
29
|
* ```
|
|
30
30
|
*
|
|
31
31
|
* @example
|
|
32
32
|
* ```typescript
|
|
33
|
-
* // Multiple
|
|
34
|
-
* await
|
|
33
|
+
* // Multiple brokers
|
|
34
|
+
* await connectToBroker({
|
|
35
35
|
* driver: "rabbitmq",
|
|
36
36
|
* name: "notifications",
|
|
37
37
|
* isDefault: true,
|
|
38
38
|
* host: process.env.RABBITMQ_HOST,
|
|
39
39
|
* });
|
|
40
40
|
*
|
|
41
|
-
* await
|
|
41
|
+
* await connectToBroker({
|
|
42
42
|
* driver: "rabbitmq",
|
|
43
43
|
* name: "analytics",
|
|
44
44
|
* host: process.env.ANALYTICS_RABBITMQ_HOST,
|
|
45
45
|
* });
|
|
46
46
|
*
|
|
47
|
-
* // Use default
|
|
48
|
-
*
|
|
47
|
+
* // Use default broker
|
|
48
|
+
* herald().channel("notifications").publish({ ... });
|
|
49
49
|
*
|
|
50
|
-
* // Use specific
|
|
51
|
-
*
|
|
50
|
+
* // Use specific broker
|
|
51
|
+
* herald("analytics").channel("events").publish({ ... });
|
|
52
52
|
* ```
|
|
53
53
|
*/
|
|
54
|
-
async function
|
|
54
|
+
async function connectToBroker(options) {
|
|
55
55
|
// Default values
|
|
56
56
|
const driverType = options.driver ?? "rabbitmq";
|
|
57
|
-
const
|
|
57
|
+
const brokerName = options.name ?? "default";
|
|
58
58
|
const isDefault = options.isDefault ?? true;
|
|
59
59
|
// Create driver based on type
|
|
60
60
|
let driver;
|
|
@@ -74,9 +74,9 @@ async function connectToCommunicator(options) {
|
|
|
74
74
|
default:
|
|
75
75
|
throw new Error(`Unknown driver: "${driverType}". Supported drivers: rabbitmq, kafka`);
|
|
76
76
|
}
|
|
77
|
-
// Create
|
|
78
|
-
const
|
|
79
|
-
name:
|
|
77
|
+
// Create broker
|
|
78
|
+
const broker = brokerRegistry.register({
|
|
79
|
+
name: brokerName,
|
|
80
80
|
driver,
|
|
81
81
|
isDefault,
|
|
82
82
|
});
|
|
@@ -87,29 +87,29 @@ async function connectToCommunicator(options) {
|
|
|
87
87
|
catch (error) {
|
|
88
88
|
throw new Error(`Failed to connect to ${driverType}: ${error instanceof Error ? error.message : String(error)}`);
|
|
89
89
|
}
|
|
90
|
-
return
|
|
90
|
+
return broker;
|
|
91
91
|
}
|
|
92
92
|
/**
|
|
93
|
-
* Get a
|
|
93
|
+
* Get a broker by name or the default one.
|
|
94
94
|
*
|
|
95
|
-
* This is the main entry point for using
|
|
95
|
+
* This is the main entry point for using brokers in your application.
|
|
96
|
+
* Named after the package — `herald()` carries your messages!
|
|
96
97
|
*
|
|
97
|
-
* @param name - Optional
|
|
98
|
-
* @returns
|
|
99
|
-
* @throws
|
|
98
|
+
* @param name - Optional broker name (uses default if not provided)
|
|
99
|
+
* @returns Broker instance
|
|
100
|
+
* @throws MissingBrokerError if broker not found
|
|
100
101
|
*
|
|
101
102
|
* @example
|
|
102
|
-
*
|
|
103
|
-
*
|
|
104
|
-
* const channel = communicators().channel("user.created");
|
|
103
|
+
* // Get default broker
|
|
104
|
+
* const channel = herald().channel("user.created");
|
|
105
105
|
* await channel.publish({ userId: 1 });
|
|
106
106
|
*
|
|
107
|
-
* // Get specific
|
|
108
|
-
* const analyticsChannel =
|
|
107
|
+
* // Get specific broker
|
|
108
|
+
* const analyticsChannel = herald("analytics").channel("events");
|
|
109
109
|
* await analyticsChannel.publish({ event: "page_view" });
|
|
110
110
|
*
|
|
111
111
|
* // Subscribe to messages
|
|
112
|
-
*
|
|
112
|
+
* herald()
|
|
113
113
|
* .channel<UserPayload>("user.created")
|
|
114
114
|
* .subscribe(async (message, ctx) => {
|
|
115
115
|
* console.log("User created:", message.payload);
|
|
@@ -117,29 +117,34 @@ async function connectToCommunicator(options) {
|
|
|
117
117
|
* });
|
|
118
118
|
* ```
|
|
119
119
|
*/
|
|
120
|
-
function
|
|
121
|
-
return
|
|
120
|
+
function herald(name) {
|
|
121
|
+
return brokerRegistry.get(name);
|
|
122
122
|
}
|
|
123
123
|
/**
|
|
124
|
-
* Get channel instance for the given name from default
|
|
124
|
+
* Get channel instance for the given name from default broker.
|
|
125
|
+
*
|
|
126
|
+
* Shorthand for `herald().channel(name, options)`.
|
|
127
|
+
*
|
|
125
128
|
* @param name - Channel name
|
|
129
|
+
* @param options - Optional channel options
|
|
126
130
|
* @returns Channel instance
|
|
127
|
-
* @throws
|
|
131
|
+
* @throws MissingBrokerError if broker not found
|
|
128
132
|
*
|
|
129
133
|
* @example
|
|
130
134
|
* ```typescript
|
|
131
|
-
* const channel =
|
|
135
|
+
* const channel = heraldChannel("user.created");
|
|
132
136
|
* await channel.publish({ userId: 1 });
|
|
133
137
|
* ```
|
|
134
138
|
*/
|
|
135
|
-
function
|
|
136
|
-
return
|
|
139
|
+
function heraldChannel(name, options) {
|
|
140
|
+
return herald().channel(name, options);
|
|
137
141
|
}
|
|
138
142
|
/**
|
|
139
|
-
* Publish the
|
|
143
|
+
* Publish an EventMessage to the default broker.
|
|
144
|
+
*
|
|
140
145
|
* @param event - Event message to publish
|
|
141
146
|
* @returns Promise that resolves when the event is published
|
|
142
|
-
* @throws Error if the
|
|
147
|
+
* @throws Error if the broker is not connected
|
|
143
148
|
*
|
|
144
149
|
* @example
|
|
145
150
|
* ```typescript
|
|
@@ -147,23 +152,20 @@ function communicatorChannel(name, options) {
|
|
|
147
152
|
* ```
|
|
148
153
|
*/
|
|
149
154
|
async function publishEvent(event) {
|
|
150
|
-
return
|
|
155
|
+
return herald().publish(event);
|
|
151
156
|
}
|
|
152
157
|
/**
|
|
153
|
-
* Subscribe
|
|
158
|
+
* Subscribe an EventConsumer class to the default broker.
|
|
159
|
+
*
|
|
154
160
|
* @param Consumer - Event consumer class
|
|
155
|
-
* @returns
|
|
156
|
-
* @throws
|
|
161
|
+
* @returns Unsubscribe function
|
|
162
|
+
* @throws MissingBrokerError if broker not found
|
|
157
163
|
*
|
|
158
164
|
* @example
|
|
159
165
|
* ```typescript
|
|
160
166
|
* await subscribeConsumer(UserUpdatedConsumer);
|
|
161
|
-
* });
|
|
162
|
-
*
|
|
163
|
-
* // Unsubscribe
|
|
164
|
-
* await unsubscribeConsumer(UserUpdatedConsumer);
|
|
165
167
|
* ```
|
|
166
168
|
*/
|
|
167
169
|
async function subscribeConsumer(Consumer) {
|
|
168
|
-
return
|
|
169
|
-
}export{
|
|
170
|
+
return herald().subscribe(Consumer);
|
|
171
|
+
}export{connectToBroker,herald,heraldChannel,publishEvent,subscribeConsumer};//# sourceMappingURL=connect-to-broker.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"connect-to-broker.js","sources":["../../src/utils/connect-to-broker.ts"],"sourcesContent":[null],"names":[],"mappings":"iEAKA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoDG;AACI,eAAe,eAAe,CAAC,OAA0B,EAAA;;AAE9D,IAAA,MAAM,UAAU,GAAG,OAAO,CAAC,MAAM,IAAI,UAAU,CAAC;AAChD,IAAA,MAAM,UAAU,GAAG,OAAO,CAAC,IAAI,IAAI,SAAS,CAAC;AAC7C,IAAA,MAAM,SAAS,GAAG,OAAO,CAAC,SAAS,IAAI,IAAI,CAAC;;AAG5C,IAAA,IAAI,MAA4B,CAAC;AAEjC,IAAA,QAAQ,UAAU;Q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9F,IAAA,OAAO,MAAM,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;AACjC,CAAC;AAED;;;;;;;;;;;AAWG;AACI,eAAe,iBAAiB,CACrC,QAAsC,EAAA;AAEtC,IAAA,OAAO,MAAM,EAAE,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC;AACtC"}
|
package/esm/utils/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export * from "./connect-to-
|
|
1
|
+
export * from "./connect-to-broker";
|
|
2
2
|
//# sourceMappingURL=index.d.ts.map
|
package/esm/utils/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@warlock.js/herald",
|
|
3
|
-
"version": "4.0.
|
|
3
|
+
"version": "4.0.171",
|
|
4
4
|
"description": "Message bus/communicators for RabbitMQ, Kafka, and more",
|
|
5
5
|
"main": "./cjs/index.js",
|
|
6
6
|
"dependencies": {
|
|
7
7
|
"@mongez/copper": "^1.0.1",
|
|
8
8
|
"@mongez/events": "^2.1.0",
|
|
9
9
|
"@mongez/reinforcements": "^2.3.17",
|
|
10
|
-
"@warlock.js/logger": "4.0.
|
|
11
|
-
"@warlock.js/seal": "4.0.
|
|
10
|
+
"@warlock.js/logger": "4.0.171",
|
|
11
|
+
"@warlock.js/seal": "4.0.171"
|
|
12
12
|
},
|
|
13
13
|
"scripts": {
|
|
14
14
|
"update": "npx ncu -u",
|