@warlock.js/herald 4.0.174 → 4.1.1
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/README.md +36 -33
- package/cjs/index.cjs +1355 -0
- package/cjs/index.cjs.map +1 -0
- package/esm/communicators/broker-registry.d.mts +157 -0
- package/esm/communicators/broker-registry.d.mts.map +1 -0
- package/esm/communicators/broker-registry.mjs +204 -0
- package/esm/communicators/broker-registry.mjs.map +1 -0
- package/esm/communicators/broker.d.mts +104 -0
- package/esm/communicators/broker.d.mts.map +1 -0
- package/esm/communicators/broker.mjs +104 -0
- package/esm/communicators/broker.mjs.map +1 -0
- package/esm/communicators/index.d.mts +2 -0
- package/esm/communicators/index.mjs +4 -0
- package/esm/contracts/broker-driver.contract.d.mts +200 -0
- package/esm/contracts/broker-driver.contract.d.mts.map +1 -0
- package/esm/contracts/channel.contract.d.mts +197 -0
- package/esm/contracts/channel.contract.d.mts.map +1 -0
- package/esm/contracts/index.d.mts +2 -0
- package/esm/decorators/consumable.d.mts +17 -0
- package/esm/decorators/consumable.d.mts.map +1 -0
- package/esm/decorators/consumable.mjs +36 -0
- package/esm/decorators/consumable.mjs.map +1 -0
- package/esm/decorators/index.d.mts +1 -0
- package/esm/decorators/index.mjs +3 -0
- package/esm/drivers/index.d.mts +2 -0
- package/esm/drivers/index.mjs +5 -0
- package/esm/drivers/rabbitmq/index.d.mts +2 -0
- package/esm/drivers/rabbitmq/index.mjs +4 -0
- package/esm/drivers/rabbitmq/rabbitmq-channel.d.mts +85 -0
- package/esm/drivers/rabbitmq/rabbitmq-channel.d.mts.map +1 -0
- package/esm/drivers/rabbitmq/rabbitmq-channel.mjs +352 -0
- package/esm/drivers/rabbitmq/rabbitmq-channel.mjs.map +1 -0
- package/esm/drivers/rabbitmq/rabbitmq-driver.d.mts +130 -0
- package/esm/drivers/rabbitmq/rabbitmq-driver.d.mts.map +1 -0
- package/esm/drivers/rabbitmq/rabbitmq-driver.mjs +291 -0
- package/esm/drivers/rabbitmq/rabbitmq-driver.mjs.map +1 -0
- package/esm/index.d.mts +20 -0
- package/esm/index.mjs +16 -0
- package/esm/message-managers/event-consumer.d.mts +61 -0
- package/esm/message-managers/event-consumer.d.mts.map +1 -0
- package/esm/message-managers/event-consumer.mjs +63 -0
- package/esm/message-managers/event-consumer.mjs.map +1 -0
- package/esm/message-managers/event-message.d.mts +87 -0
- package/esm/message-managers/event-message.d.mts.map +1 -0
- package/esm/message-managers/event-message.mjs +68 -0
- package/esm/message-managers/event-message.mjs.map +1 -0
- package/esm/message-managers/index.d.mts +3 -0
- package/esm/message-managers/index.mjs +4 -0
- package/esm/message-managers/prepare-consumer-subscription.mjs +42 -0
- package/esm/message-managers/prepare-consumer-subscription.mjs.map +1 -0
- package/esm/message-managers/types.d.mts +23 -0
- package/esm/message-managers/types.d.mts.map +1 -0
- package/esm/types/channel.types.d.mts +23 -0
- package/esm/types/channel.types.d.mts.map +1 -0
- package/esm/types/connection.types.d.mts +67 -0
- package/esm/types/connection.types.d.mts.map +1 -0
- package/esm/types/driver.types.d.mts +13 -0
- package/esm/types/driver.types.d.mts.map +1 -0
- package/esm/types/index.d.mts +7 -0
- package/esm/types/message.types.d.mts +37 -0
- package/esm/types/message.types.d.mts.map +1 -0
- package/esm/types/publish.types.d.mts +16 -0
- package/esm/types/publish.types.d.mts.map +1 -0
- package/esm/types/registry.types.d.mts +8 -0
- package/esm/types/registry.types.d.mts.map +1 -0
- package/esm/types/subscribe.types.d.mts +21 -0
- package/esm/types/subscribe.types.d.mts.map +1 -0
- package/esm/use-case-broadcast.d.mts +41 -0
- package/esm/use-case-broadcast.d.mts.map +1 -0
- package/esm/use-case-broadcast.mjs +30 -0
- package/esm/use-case-broadcast.mjs.map +1 -0
- package/esm/utils/{connect-to-broker.d.ts → connect-to-broker.d.mts} +15 -10
- package/esm/utils/connect-to-broker.d.mts.map +1 -0
- package/esm/utils/connect-to-broker.mjs +168 -0
- package/esm/utils/connect-to-broker.mjs.map +1 -0
- package/esm/utils/index.d.mts +1 -0
- package/esm/utils/index.mjs +3 -0
- package/llms-full.txt +581 -0
- package/llms.txt +12 -0
- package/package.json +46 -46
- package/skills/README.md +21 -0
- package/skills/consume-message/SKILL.md +217 -0
- package/skills/herald-basics/SKILL.md +96 -0
- package/skills/publish-message/SKILL.md +172 -0
- package/skills/request-and-respond/SKILL.md +74 -0
- package/cjs/communicators/broker-registry.d.ts +0 -155
- package/cjs/communicators/broker-registry.d.ts.map +0 -1
- package/cjs/communicators/broker-registry.js +0 -206
- package/cjs/communicators/broker-registry.js.map +0 -1
- package/cjs/communicators/broker.d.ts +0 -100
- package/cjs/communicators/broker.d.ts.map +0 -1
- package/cjs/communicators/broker.js +0 -105
- package/cjs/communicators/broker.js.map +0 -1
- package/cjs/communicators/index.d.ts +0 -3
- package/cjs/communicators/index.d.ts.map +0 -1
- package/cjs/contracts/broker-driver.contract.d.ts +0 -196
- package/cjs/contracts/broker-driver.contract.d.ts.map +0 -1
- package/cjs/contracts/channel.contract.d.ts +0 -191
- package/cjs/contracts/channel.contract.d.ts.map +0 -1
- package/cjs/contracts/index.d.ts +0 -3
- package/cjs/contracts/index.d.ts.map +0 -1
- package/cjs/decorators/consumable.d.ts +0 -13
- package/cjs/decorators/consumable.d.ts.map +0 -1
- package/cjs/decorators/consumable.js +0 -33
- package/cjs/decorators/consumable.js.map +0 -1
- package/cjs/decorators/index.d.ts +0 -2
- package/cjs/decorators/index.d.ts.map +0 -1
- package/cjs/drivers/index.d.ts +0 -2
- package/cjs/drivers/index.d.ts.map +0 -1
- package/cjs/drivers/rabbitmq/index.d.ts +0 -3
- package/cjs/drivers/rabbitmq/index.d.ts.map +0 -1
- package/cjs/drivers/rabbitmq/rabbitmq-channel.d.ts +0 -79
- package/cjs/drivers/rabbitmq/rabbitmq-channel.d.ts.map +0 -1
- package/cjs/drivers/rabbitmq/rabbitmq-channel.js +0 -414
- package/cjs/drivers/rabbitmq/rabbitmq-channel.js.map +0 -1
- package/cjs/drivers/rabbitmq/rabbitmq-driver.d.ts +0 -124
- package/cjs/drivers/rabbitmq/rabbitmq-driver.d.ts.map +0 -1
- package/cjs/drivers/rabbitmq/rabbitmq-driver.js +0 -347
- package/cjs/drivers/rabbitmq/rabbitmq-driver.js.map +0 -1
- package/cjs/index.d.ts +0 -47
- package/cjs/index.d.ts.map +0 -1
- package/cjs/index.js +0 -1
- package/cjs/index.js.map +0 -1
- package/cjs/message-managers/event-consumer.d.ts +0 -64
- package/cjs/message-managers/event-consumer.d.ts.map +0 -1
- package/cjs/message-managers/event-consumer.js +0 -71
- package/cjs/message-managers/event-consumer.js.map +0 -1
- package/cjs/message-managers/event-message.d.ts +0 -90
- package/cjs/message-managers/event-message.d.ts.map +0 -1
- package/cjs/message-managers/event-message.js +0 -84
- package/cjs/message-managers/event-message.js.map +0 -1
- package/cjs/message-managers/index.d.ts +0 -4
- package/cjs/message-managers/index.d.ts.map +0 -1
- package/cjs/message-managers/prepare-consumer-subscription.d.ts +0 -4
- package/cjs/message-managers/prepare-consumer-subscription.d.ts.map +0 -1
- package/cjs/message-managers/prepare-consumer-subscription.js +0 -40
- package/cjs/message-managers/prepare-consumer-subscription.js.map +0 -1
- package/cjs/message-managers/types.d.ts +0 -20
- package/cjs/message-managers/types.d.ts.map +0 -1
- package/cjs/types/channel.types.d.ts +0 -19
- package/cjs/types/channel.types.d.ts.map +0 -1
- package/cjs/types/connection.types.d.ts +0 -65
- package/cjs/types/connection.types.d.ts.map +0 -1
- package/cjs/types/driver.types.d.ts +0 -10
- package/cjs/types/driver.types.d.ts.map +0 -1
- package/cjs/types/index.d.ts +0 -8
- package/cjs/types/index.d.ts.map +0 -1
- package/cjs/types/message.types.d.ts +0 -34
- package/cjs/types/message.types.d.ts.map +0 -1
- package/cjs/types/publish.types.d.ts +0 -13
- package/cjs/types/publish.types.d.ts.map +0 -1
- package/cjs/types/registry.types.d.ts +0 -4
- package/cjs/types/registry.types.d.ts.map +0 -1
- package/cjs/types/subscribe.types.d.ts +0 -18
- package/cjs/types/subscribe.types.d.ts.map +0 -1
- package/cjs/utils/connect-to-broker.d.ts +0 -131
- package/cjs/utils/connect-to-broker.d.ts.map +0 -1
- package/cjs/utils/connect-to-broker.js +0 -171
- package/cjs/utils/connect-to-broker.js.map +0 -1
- package/cjs/utils/index.d.ts +0 -2
- package/cjs/utils/index.d.ts.map +0 -1
- package/esm/communicators/broker-registry.d.ts +0 -155
- package/esm/communicators/broker-registry.d.ts.map +0 -1
- package/esm/communicators/broker-registry.js +0 -206
- package/esm/communicators/broker-registry.js.map +0 -1
- package/esm/communicators/broker.d.ts +0 -100
- package/esm/communicators/broker.d.ts.map +0 -1
- package/esm/communicators/broker.js +0 -105
- package/esm/communicators/broker.js.map +0 -1
- package/esm/communicators/index.d.ts +0 -3
- package/esm/communicators/index.d.ts.map +0 -1
- package/esm/contracts/broker-driver.contract.d.ts +0 -196
- package/esm/contracts/broker-driver.contract.d.ts.map +0 -1
- package/esm/contracts/channel.contract.d.ts +0 -191
- package/esm/contracts/channel.contract.d.ts.map +0 -1
- package/esm/contracts/index.d.ts +0 -3
- package/esm/contracts/index.d.ts.map +0 -1
- package/esm/decorators/consumable.d.ts +0 -13
- package/esm/decorators/consumable.d.ts.map +0 -1
- package/esm/decorators/consumable.js +0 -33
- package/esm/decorators/consumable.js.map +0 -1
- package/esm/decorators/index.d.ts +0 -2
- package/esm/decorators/index.d.ts.map +0 -1
- package/esm/drivers/index.d.ts +0 -2
- package/esm/drivers/index.d.ts.map +0 -1
- package/esm/drivers/rabbitmq/index.d.ts +0 -3
- package/esm/drivers/rabbitmq/index.d.ts.map +0 -1
- package/esm/drivers/rabbitmq/rabbitmq-channel.d.ts +0 -79
- package/esm/drivers/rabbitmq/rabbitmq-channel.d.ts.map +0 -1
- package/esm/drivers/rabbitmq/rabbitmq-channel.js +0 -414
- package/esm/drivers/rabbitmq/rabbitmq-channel.js.map +0 -1
- package/esm/drivers/rabbitmq/rabbitmq-driver.d.ts +0 -124
- package/esm/drivers/rabbitmq/rabbitmq-driver.d.ts.map +0 -1
- package/esm/drivers/rabbitmq/rabbitmq-driver.js +0 -347
- package/esm/drivers/rabbitmq/rabbitmq-driver.js.map +0 -1
- package/esm/index.d.ts +0 -47
- package/esm/index.d.ts.map +0 -1
- package/esm/index.js +0 -1
- package/esm/index.js.map +0 -1
- package/esm/message-managers/event-consumer.d.ts +0 -64
- package/esm/message-managers/event-consumer.d.ts.map +0 -1
- package/esm/message-managers/event-consumer.js +0 -71
- package/esm/message-managers/event-consumer.js.map +0 -1
- package/esm/message-managers/event-message.d.ts +0 -90
- package/esm/message-managers/event-message.d.ts.map +0 -1
- package/esm/message-managers/event-message.js +0 -84
- package/esm/message-managers/event-message.js.map +0 -1
- package/esm/message-managers/index.d.ts +0 -4
- package/esm/message-managers/index.d.ts.map +0 -1
- package/esm/message-managers/prepare-consumer-subscription.d.ts +0 -4
- package/esm/message-managers/prepare-consumer-subscription.d.ts.map +0 -1
- package/esm/message-managers/prepare-consumer-subscription.js +0 -40
- package/esm/message-managers/prepare-consumer-subscription.js.map +0 -1
- package/esm/message-managers/types.d.ts +0 -20
- package/esm/message-managers/types.d.ts.map +0 -1
- package/esm/types/channel.types.d.ts +0 -19
- package/esm/types/channel.types.d.ts.map +0 -1
- package/esm/types/connection.types.d.ts +0 -65
- package/esm/types/connection.types.d.ts.map +0 -1
- package/esm/types/driver.types.d.ts +0 -10
- package/esm/types/driver.types.d.ts.map +0 -1
- package/esm/types/index.d.ts +0 -8
- package/esm/types/index.d.ts.map +0 -1
- package/esm/types/message.types.d.ts +0 -34
- package/esm/types/message.types.d.ts.map +0 -1
- package/esm/types/publish.types.d.ts +0 -13
- package/esm/types/publish.types.d.ts.map +0 -1
- package/esm/types/registry.types.d.ts +0 -4
- package/esm/types/registry.types.d.ts.map +0 -1
- package/esm/types/subscribe.types.d.ts +0 -18
- package/esm/types/subscribe.types.d.ts.map +0 -1
- package/esm/utils/connect-to-broker.d.ts.map +0 -1
- package/esm/utils/connect-to-broker.js +0 -171
- package/esm/utils/connect-to-broker.js.map +0 -1
- package/esm/utils/index.d.ts +0 -2
- package/esm/utils/index.d.ts.map +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"event-message.mjs","names":[],"sources":["../../../../../../@warlock.js/herald/src/message-managers/event-message.ts"],"sourcesContent":["/**\n * This class is used to be part of the Herald Event Message Manager.\n * It should be used to trigger events to Either RabbitMQ or Kafka through Herald\n *\n * It's highly recommended using it instead of declaring manual channel namd and publishing data\n */\nimport { GenericObject } from \"@mongez/reinforcements\";\nimport { type ObjectValidator } from \"@warlock.js/seal\";\nimport { randomUUID } from \"crypto\";\n\nexport abstract class EventMessage<TPayload = Record<string, any>> {\n /**\n * Event Name\n */\n public abstract eventName: string;\n\n /**\n * Event version\n */\n public version?: number;\n\n /**\n * Additional metadata (if any)\n */\n public metadata?: Record<string, any>;\n\n /**\n * Event Message id\n */\n public messageId?: string;\n\n /**\n * Schema of payload that will be used to determine whether this event should be published\n */\n public schema?: ObjectValidator;\n\n /**\n * Data that will be sent with the event (Payload)\n */\n public toJSON(): TPayload {\n if (!this.data) {\n throw new Error(`no Data is defined for Event: ${this.eventName}`);\n }\n\n return this.data as TPayload;\n }\n\n public constructor(protected data?: TPayload) {}\n\n /**\n * Serialize the event to be ready for publishing.\n * Delegates payload resolution to toJSON() — override toJSON() to customize.\n *\n * @throws Error if toJSON() throws (e.g. no data provided)\n */\n public serialize() {\n const payload = this.toJSON();\n\n return {\n payload,\n metadata: this.metadata,\n messageId: this.messageId ?? randomUUID(),\n eventName: this.eventName,\n version: this.version,\n occurredAt: new Date(),\n __through: \"EventMessage\",\n };\n }\n}\n\ntype EventOptions<T> = {\n /**\n * Shapen the data that will be used\n */\n toJSON?: (data: T) => GenericObject;\n /**\n * Validation schema\n */\n schema?: ObjectValidator;\n};\n\n/**\n * Represents an EventMessage class constructor.\n *\n * @template TIncoming - The type of data accepted by the constructor\n * @template TOutgoing - The type of data returned by toJSON() (defaults to TIncoming)\n */\ntype EventMessageClass<TIncoming = Record<string, any>, TOutgoing = TIncoming> = new (\n data?: TIncoming,\n) => EventMessage<TOutgoing>;\n\n/**\n * A shorthand to define an event without declaring an entire class.\n *\n * This factory function creates an EventMessage subclass that transforms\n * input data (IncomingData) into a different output format (OutgoingData).\n *\n * @template IncomingData - The type of data passed to the constructor\n * @template OutgoingData - The type of data returned by toJSON()\n *\n * @example\n * ```typescript\n * const UserCreatedEvent = defineEvent<User, { id: number; name: string }>(\n * \"user.created\",\n * { toJSON: (user) => user.only([\"id\", \"name\"]) }\n * );\n *\n * publishEvent(new UserCreatedEvent(user));\n * ```\n */\nexport function defineEvent<IncomingData = unknown, OutgoingData = unknown>(\n eventName: string,\n options: EventOptions<IncomingData> = {},\n): EventMessageClass<IncomingData, OutgoingData> {\n // We need to use `any` here to bridge the IncomingData -> OutgoingData transformation\n // The class accepts IncomingData in constructor but outputs OutgoingData via toJSON()\n return class AnnouncedEvent extends EventMessage<OutgoingData> {\n public eventName = eventName;\n public schema = options.schema;\n\n public constructor(data?: IncomingData) {\n super(data as any);\n }\n\n public toJSON(): OutgoingData {\n if (!options.toJSON) return this.data as OutgoingData;\n\n return options.toJSON(this.data as IncomingData) as OutgoingData;\n }\n };\n}\n"],"mappings":";;;AAUA,IAAsB,eAAtB,MAAmE;;;;CA6BjE,AAAO,SAAmB;EACxB,IAAI,CAAC,KAAK,MACR,MAAM,IAAI,MAAM,iCAAiC,KAAK,WAAW;EAGnE,OAAO,KAAK;CACd;CAEA,AAAO,YAAY,AAAU,MAAiB;EAAjB;CAAkB;;;;;;;CAQ/C,AAAO,YAAY;EAGjB,OAAO;GACL,SAHc,KAAK,OAGb;GACN,UAAU,KAAK;GACf,WAAW,KAAK,aAAa,WAAW;GACxC,WAAW,KAAK;GAChB,SAAS,KAAK;GACd,4BAAY,IAAI,KAAK;GACrB,WAAW;EACb;CACF;AACF;;;;;;;;;;;;;;;;;;;;AA0CA,SAAgB,YACd,WACA,UAAsC,CAAC,GACQ;CAG/C,OAAO,MAAM,uBAAuB,aAA2B;EAI7D,AAAO,YAAY,MAAqB;GACtC,MAAM,IAAW;oBAJA;iBACH,QAAQ;EAIxB;EAEA,AAAO,SAAuB;GAC5B,IAAI,CAAC,QAAQ,QAAQ,OAAO,KAAK;GAEjC,OAAO,QAAQ,OAAO,KAAK,IAAoB;EACjD;CACF;AACF"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
//#region ../../@warlock.js/herald/src/message-managers/prepare-consumer-subscription.ts
|
|
2
|
+
function prepareConsumerSubscription(Consumer, onError) {
|
|
3
|
+
const callback = async (message, ctx) => {
|
|
4
|
+
const envelope = message.payload;
|
|
5
|
+
let eventPayload = envelope.payload;
|
|
6
|
+
if (envelope.version) {
|
|
7
|
+
if (!Consumer.isAcceptedVersion(Number(envelope.version))) {
|
|
8
|
+
ctx.ack();
|
|
9
|
+
return;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
const consumer = new Consumer();
|
|
13
|
+
if (consumer.schema) {
|
|
14
|
+
const result = await consumer.validate(eventPayload);
|
|
15
|
+
if (!result || result.isValid === false) {
|
|
16
|
+
ctx.nack();
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
eventPayload = result.data;
|
|
20
|
+
}
|
|
21
|
+
try {
|
|
22
|
+
await consumer.handle(eventPayload, {
|
|
23
|
+
payload: eventPayload,
|
|
24
|
+
eventName: Consumer.eventName,
|
|
25
|
+
messageId: message.metadata.messageId,
|
|
26
|
+
occurredAt: envelope.occurredAt ? new Date(envelope.occurredAt) : void 0,
|
|
27
|
+
metadata: envelope.metadata,
|
|
28
|
+
version: envelope.version,
|
|
29
|
+
message
|
|
30
|
+
});
|
|
31
|
+
ctx.ack();
|
|
32
|
+
} catch (error) {
|
|
33
|
+
ctx.nack(true);
|
|
34
|
+
if (onError) onError(error, Consumer.eventName);
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
return callback;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
//#endregion
|
|
41
|
+
export { prepareConsumerSubscription };
|
|
42
|
+
//# sourceMappingURL=prepare-consumer-subscription.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prepare-consumer-subscription.mjs","names":[],"sources":["../../../../../../@warlock.js/herald/src/message-managers/prepare-consumer-subscription.ts"],"sourcesContent":["import type { MessageHandler } from \"./../types\";\nimport { EventConsumerClass } from \"./types\";\n\nexport function prepareConsumerSubscription(\n Consumer: EventConsumerClass,\n onError?: (error: unknown, consumerName: string) => void,\n) {\n const callback: MessageHandler<any> = async (message, ctx) => {\n const envelope = message.payload;\n let eventPayload = envelope.payload;\n\n if (envelope.version) {\n if (!Consumer.isAcceptedVersion(Number(envelope.version))) {\n ctx.ack(); // Acknowledge but don't process\n return;\n }\n }\n\n const consumer = new Consumer();\n\n if (consumer.schema) {\n const result = await consumer.validate(eventPayload);\n if (!result || result.isValid === false) {\n ctx.nack();\n return;\n }\n\n eventPayload = result.data;\n }\n try {\n await consumer.handle(eventPayload, {\n payload: eventPayload,\n eventName: Consumer.eventName,\n messageId: message.metadata.messageId!,\n occurredAt: envelope.occurredAt ? new Date(envelope.occurredAt) : undefined,\n metadata: envelope.metadata,\n version: envelope.version,\n message,\n });\n ctx.ack(); // Auto-ack on success?\n } catch (error) {\n ctx.nack(true); // Requeue on failure\n if (onError) {\n onError(error, Consumer.eventName);\n }\n }\n };\n\n return callback;\n}\n"],"mappings":";AAGA,SAAgB,4BACd,UACA,SACA;CACA,MAAM,WAAgC,OAAO,SAAS,QAAQ;EAC5D,MAAM,WAAW,QAAQ;EACzB,IAAI,eAAe,SAAS;EAE5B,IAAI,SAAS,SACX;OAAI,CAAC,SAAS,kBAAkB,OAAO,SAAS,OAAO,CAAC,GAAG;IACzD,IAAI,IAAI;IACR;GACF;;EAGF,MAAM,WAAW,IAAI,SAAS;EAE9B,IAAI,SAAS,QAAQ;GACnB,MAAM,SAAS,MAAM,SAAS,SAAS,YAAY;GACnD,IAAI,CAAC,UAAU,OAAO,YAAY,OAAO;IACvC,IAAI,KAAK;IACT;GACF;GAEA,eAAe,OAAO;EACxB;EACA,IAAI;GACF,MAAM,SAAS,OAAO,cAAc;IAClC,SAAS;IACT,WAAW,SAAS;IACpB,WAAW,QAAQ,SAAS;IAC5B,YAAY,SAAS,aAAa,IAAI,KAAK,SAAS,UAAU,IAAI;IAClE,UAAU,SAAS;IACnB,SAAS,SAAS;IAClB;GACF,CAAC;GACD,IAAI,IAAI;EACV,SAAS,OAAO;GACd,IAAI,KAAK,IAAI;GACb,IAAI,SACF,QAAQ,OAAO,SAAS,SAAS;EAErC;CACF;CAEA,OAAO;AACT"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { Message } from "../types/message.types.mjs";
|
|
2
|
+
import { EventConsumer } from "./event-consumer.mjs";
|
|
3
|
+
//#region ../../@warlock.js/herald/src/message-managers/types.d.ts
|
|
4
|
+
type ConsumedEventMessage = {
|
|
5
|
+
version?: number;
|
|
6
|
+
occurredAt?: Date;
|
|
7
|
+
metadata?: Record<string, any>;
|
|
8
|
+
messageId: string;
|
|
9
|
+
eventName: string;
|
|
10
|
+
payload: Record<string, any>;
|
|
11
|
+
message: Message<any>;
|
|
12
|
+
};
|
|
13
|
+
type EventConsumerClass<P = Record<string, any>> = {
|
|
14
|
+
new (): EventConsumer<P>;
|
|
15
|
+
eventName: string;
|
|
16
|
+
consumerId: string;
|
|
17
|
+
minVersion?: number;
|
|
18
|
+
maxVersion?: number;
|
|
19
|
+
isAcceptedVersion(version: number): boolean;
|
|
20
|
+
};
|
|
21
|
+
//#endregion
|
|
22
|
+
export { ConsumedEventMessage, EventConsumerClass };
|
|
23
|
+
//# sourceMappingURL=types.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.mts","names":[],"sources":["../../../../../../@warlock.js/herald/src/message-managers/types.ts"],"mappings":";;;KAGY,oBAAA;EACV,OAAA;EACA,UAAA,GAAa,IAAA;EACb,QAAA,GAAW,MAAA;EACX,SAAA;EACA,SAAA;EACA,OAAA,EAAS,MAAA;EACT,OAAA,EAAS,OAAA;AAAA;AAAA,KAGC,kBAAA,KAAuB,MAAA;EAAA,QACzB,aAAA,CAAc,CAAA;EACtB,SAAA;EACA,UAAA;EACA,UAAA;EACA,UAAA;EACA,iBAAA,CAAkB,OAAA;AAAA"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { DeadLetterOptions } from "./subscribe.types.mjs";
|
|
2
|
+
import { BaseValidator } from "@warlock.js/seal";
|
|
3
|
+
|
|
4
|
+
//#region ../../@warlock.js/herald/src/types/channel.types.d.ts
|
|
5
|
+
type ChannelOptions<TPayload = unknown> = {
|
|
6
|
+
type?: "queue" | "topic" | "fanout";
|
|
7
|
+
durable?: boolean;
|
|
8
|
+
autoDelete?: boolean;
|
|
9
|
+
exclusive?: boolean;
|
|
10
|
+
deadLetter?: DeadLetterOptions;
|
|
11
|
+
maxMessageSize?: number;
|
|
12
|
+
messageTtl?: number;
|
|
13
|
+
maxLength?: number;
|
|
14
|
+
schema?: BaseValidator;
|
|
15
|
+
};
|
|
16
|
+
type ChannelStats = {
|
|
17
|
+
messageCount: number;
|
|
18
|
+
consumerCount: number;
|
|
19
|
+
name: string;
|
|
20
|
+
};
|
|
21
|
+
//#endregion
|
|
22
|
+
export { ChannelOptions, ChannelStats };
|
|
23
|
+
//# sourceMappingURL=channel.types.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"channel.types.d.mts","names":[],"sources":["../../../../../../@warlock.js/herald/src/types/channel.types.ts"],"mappings":";;;;KAGY,cAAA;EACV,IAAA;EACA,OAAA;EACA,UAAA;EACA,SAAA;EACA,UAAA,GAAa,iBAAA;EACb,cAAA;EACA,UAAA;EACA,SAAA;EACA,MAAA,GAAS,aAAa;AAAA;AAAA,KAGZ,YAAA;EACV,YAAA;EACA,aAAA;EACA,IAAA;AAAA"}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
//#region ../../@warlock.js/herald/src/types/connection.types.d.ts
|
|
2
|
+
type BaseConnectionOptions = {
|
|
3
|
+
name?: string;
|
|
4
|
+
isDefault?: boolean;
|
|
5
|
+
};
|
|
6
|
+
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
|
+
type RabbitMQClientOptions = {
|
|
18
|
+
frameMax?: number;
|
|
19
|
+
channelMax?: number;
|
|
20
|
+
locale?: string;
|
|
21
|
+
socket?: RabbitMQSocketOptions;
|
|
22
|
+
};
|
|
23
|
+
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
|
+
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
|
+
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
|
+
type ConnectionOptions = RabbitMQConnectionOptions | KafkaConnectionOptions;
|
|
64
|
+
type BrokerConfigurations<TClientOptions = any> = RabbitMQConnectionOptions<TClientOptions extends RabbitMQClientOptions ? TClientOptions : RabbitMQClientOptions> | KafkaConnectionOptions<TClientOptions extends KafkaClientOptions ? TClientOptions : KafkaClientOptions>;
|
|
65
|
+
//#endregion
|
|
66
|
+
export { BaseConnectionOptions, BrokerConfigurations, ConnectionOptions, KafkaClientOptions, KafkaConnectionOptions, RabbitMQClientOptions, RabbitMQConnectionOptions, RabbitMQSocketOptions };
|
|
67
|
+
//# sourceMappingURL=connection.types.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"connection.types.d.mts","names":[],"sources":["../../../../../../@warlock.js/herald/src/types/connection.types.ts"],"mappings":";KAAY,qBAAA;EACV,IAAA;EACA,SAAS;AAAA;AAAA,KAGC,qBAAA;EACV,SAAA;EACA,OAAA;EACA,OAAA;EACA,EAAA,YAAc,MAAA,GAAS,KAAA,UAAe,MAAA;EACtC,IAAA,YAAgB,MAAA;EAChB,GAAA,YAAe,MAAA;EACf,UAAA;EACA,UAAA;EACA,kBAAA;AAAA;AAAA,KAGU,qBAAA;EACV,QAAA;EACA,UAAA;EACA,MAAA;EACA,MAAA,GAAS,qBAAqB;AAAA;AAAA,KAGpB,yBAAA,wBACa,qBAAA,GAAwB,qBAAA,IAC7C,qBAAA;EACF,MAAA;EACA,IAAA;EACA,IAAA;EACA,QAAA;EACA,QAAA;EACA,KAAA;EACA,GAAA;EACA,SAAA;EACA,iBAAA;EACA,SAAA;EACA,cAAA;EACA,QAAA;EACA,aAAA,GAAgB,cAAA;AAAA;AAAA,KAGN,kBAAA;EACV,KAAA;IACE,gBAAA;IACA,OAAA;IACA,YAAA;IACA,MAAA;IACA,UAAA;EAAA;EAEF,QAAA;EACA,UAAA;AAAA;AAAA,KAGU,sBAAA,wBAA8C,kBAAA,GAAqB,kBAAA,IAC7E,qBAAA;EACE,MAAA;EACA,OAAA;EACA,QAAA;EACA,iBAAA;EACA,cAAA;EACA,GAAA;EACA,IAAA;IACE,SAAA;IACA,QAAA;IACA,QAAA;EAAA;EAEF,aAAA,GAAgB,cAAA;AAAA;AAAA,KAGR,iBAAA,GAAoB,yBAAA,GAA4B,sBAAsB;AAAA,KAEtE,oBAAA,yBACR,yBAAA,CACE,cAAA,SAAuB,qBAAA,GAAwB,cAAA,GAAiB,qBAAA,IAElE,sBAAA,CACE,cAAA,SAAuB,kBAAA,GAAqB,cAAA,GAAiB,kBAAA"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
//#region ../../@warlock.js/herald/src/types/driver.types.d.ts
|
|
2
|
+
type BrokerDriverType = "rabbitmq" | "kafka" | "redis-streams" | "sqs";
|
|
3
|
+
type BrokerEvent = "connected" | "disconnected" | "error" | "reconnecting";
|
|
4
|
+
type BrokerEventListener = (...args: unknown[]) => void;
|
|
5
|
+
type HealthCheckResult = {
|
|
6
|
+
healthy: boolean;
|
|
7
|
+
latency?: number;
|
|
8
|
+
error?: string;
|
|
9
|
+
details?: Record<string, unknown>;
|
|
10
|
+
};
|
|
11
|
+
//#endregion
|
|
12
|
+
export { BrokerDriverType, BrokerEvent, BrokerEventListener, HealthCheckResult };
|
|
13
|
+
//# sourceMappingURL=driver.types.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"driver.types.d.mts","names":[],"sources":["../../../../../../@warlock.js/herald/src/types/driver.types.ts"],"mappings":";KAAY,gBAAA;AAAA,KAEA,WAAA;AAAA,KAEA,mBAAA,OAA0B,IAAI;AAAA,KAE9B,iBAAA;EACV,OAAA;EACA,OAAA;EACA,KAAA;EACA,OAAA,GAAU,MAAM;AAAA"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { DeadLetterOptions, RetryOptions, SubscribeOptions } from "./subscribe.types.mjs";
|
|
2
|
+
import { ChannelOptions, ChannelStats } from "./channel.types.mjs";
|
|
3
|
+
import { BaseConnectionOptions, BrokerConfigurations, ConnectionOptions, KafkaClientOptions, KafkaConnectionOptions, RabbitMQClientOptions, RabbitMQConnectionOptions, RabbitMQSocketOptions } from "./connection.types.mjs";
|
|
4
|
+
import { BrokerDriverType, BrokerEvent, BrokerEventListener, HealthCheckResult } from "./driver.types.mjs";
|
|
5
|
+
import { Message, MessageContext, MessageHandler, MessageMetadata, ResponseHandler, Subscription } from "./message.types.mjs";
|
|
6
|
+
import { PublishOptions, RequestOptions } from "./publish.types.mjs";
|
|
7
|
+
import { BrokerRegistryEvent, BrokerRegistryListener } from "./registry.types.mjs";
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
//#region ../../@warlock.js/herald/src/types/message.types.d.ts
|
|
2
|
+
type MessageMetadata = {
|
|
3
|
+
messageId: string;
|
|
4
|
+
correlationId?: string;
|
|
5
|
+
replyTo?: string;
|
|
6
|
+
priority?: number;
|
|
7
|
+
timestamp: Date;
|
|
8
|
+
headers?: Record<string, string>;
|
|
9
|
+
retryCount?: number;
|
|
10
|
+
originalChannel?: string;
|
|
11
|
+
};
|
|
12
|
+
type Message<TPayload = unknown> = {
|
|
13
|
+
readonly metadata: MessageMetadata;
|
|
14
|
+
readonly payload: TPayload;
|
|
15
|
+
readonly raw?: unknown;
|
|
16
|
+
};
|
|
17
|
+
type MessageContext = {
|
|
18
|
+
ack(): Promise<void>;
|
|
19
|
+
nack(requeue?: boolean): Promise<void>;
|
|
20
|
+
reject(): Promise<void>;
|
|
21
|
+
reply<T>(payload: T): Promise<void>;
|
|
22
|
+
retry(delay?: number): Promise<void>;
|
|
23
|
+
};
|
|
24
|
+
type Subscription = {
|
|
25
|
+
readonly id: string;
|
|
26
|
+
readonly channel: string;
|
|
27
|
+
readonly consumerTag?: string;
|
|
28
|
+
unsubscribe(): Promise<void>;
|
|
29
|
+
pause(): Promise<void>;
|
|
30
|
+
resume(): Promise<void>;
|
|
31
|
+
isActive(): boolean;
|
|
32
|
+
};
|
|
33
|
+
type MessageHandler<TPayload = unknown> = (message: Message<TPayload>, ctx: MessageContext) => Promise<void> | void;
|
|
34
|
+
type ResponseHandler<TPayload = unknown, TResponse = unknown> = (message: Message<TPayload>, ctx: MessageContext) => Promise<TResponse> | TResponse;
|
|
35
|
+
//#endregion
|
|
36
|
+
export { Message, MessageContext, MessageHandler, MessageMetadata, ResponseHandler, Subscription };
|
|
37
|
+
//# sourceMappingURL=message.types.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"message.types.d.mts","names":[],"sources":["../../../../../../@warlock.js/herald/src/types/message.types.ts"],"mappings":";KAAY,eAAA;EACV,SAAA;EACA,aAAA;EACA,OAAA;EACA,QAAA;EACA,SAAA,EAAW,IAAA;EACX,OAAA,GAAU,MAAM;EAChB,UAAA;EACA,eAAA;AAAA;AAAA,KAGU,OAAA;EAAA,SACD,QAAA,EAAU,eAAA;EAAA,SACV,OAAA,EAAS,QAAQ;EAAA,SACjB,GAAA;AAAA;AAAA,KAGC,cAAA;EACV,GAAA,IAAO,OAAA;EACP,IAAA,CAAK,OAAA,aAAoB,OAAA;EACzB,MAAA,IAAU,OAAA;EACV,KAAA,IAAS,OAAA,EAAS,CAAA,GAAI,OAAA;EACtB,KAAA,CAAM,KAAA,YAAiB,OAAA;AAAA;AAAA,KAGb,YAAA;EAAA,SACD,EAAA;EAAA,SACA,OAAA;EAAA,SACA,WAAA;EACT,WAAA,IAAe,OAAA;EACf,KAAA,IAAS,OAAA;EACT,MAAA,IAAU,OAAA;EACV,QAAA;AAAA;AAAA,KAGU,cAAA,wBACV,OAAA,EAAS,OAAA,CAAQ,QAAA,GACjB,GAAA,EAAK,cAAA,KACF,OAAA;AAAA,KAEO,eAAA,6CACV,OAAA,EAAS,OAAA,CAAQ,QAAA,GACjB,GAAA,EAAK,cAAA,KACF,OAAA,CAAQ,SAAA,IAAa,SAAA"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
//#region ../../@warlock.js/herald/src/types/publish.types.d.ts
|
|
2
|
+
type PublishOptions = {
|
|
3
|
+
priority?: number;
|
|
4
|
+
ttl?: number;
|
|
5
|
+
delay?: number;
|
|
6
|
+
headers?: Record<string, string>;
|
|
7
|
+
persistent?: boolean;
|
|
8
|
+
correlationId?: string;
|
|
9
|
+
expiration?: number;
|
|
10
|
+
};
|
|
11
|
+
type RequestOptions = PublishOptions & {
|
|
12
|
+
timeout?: number;
|
|
13
|
+
};
|
|
14
|
+
//#endregion
|
|
15
|
+
export { PublishOptions, RequestOptions };
|
|
16
|
+
//# sourceMappingURL=publish.types.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"publish.types.d.mts","names":[],"sources":["../../../../../../@warlock.js/herald/src/types/publish.types.ts"],"mappings":";KAAY,cAAA;EACV,QAAA;EACA,GAAA;EACA,KAAA;EACA,OAAA,GAAU,MAAM;EAChB,UAAA;EACA,aAAA;EACA,UAAA;AAAA;AAAA,KAGU,cAAA,GAAiB,cAAc;EACzC,OAAO;AAAA"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Broker } from "../communicators/broker.mjs";
|
|
2
|
+
|
|
3
|
+
//#region ../../@warlock.js/herald/src/types/registry.types.d.ts
|
|
4
|
+
type BrokerRegistryEvent = "registered" | "default-registered" | "connected" | "disconnected";
|
|
5
|
+
type BrokerRegistryListener = (broker: Broker) => void;
|
|
6
|
+
//#endregion
|
|
7
|
+
export { BrokerRegistryEvent, BrokerRegistryListener };
|
|
8
|
+
//# sourceMappingURL=registry.types.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"registry.types.d.mts","names":[],"sources":["../../../../../../@warlock.js/herald/src/types/registry.types.ts"],"mappings":";;;KAEY,mBAAA;AAAA,KAMA,sBAAA,IAA0B,MAAc,EAAN,MAAM"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
//#region ../../@warlock.js/herald/src/types/subscribe.types.d.ts
|
|
2
|
+
type RetryOptions = {
|
|
3
|
+
maxRetries: number;
|
|
4
|
+
delay: number | ((attempt: number) => number);
|
|
5
|
+
};
|
|
6
|
+
type DeadLetterOptions = {
|
|
7
|
+
channel: string;
|
|
8
|
+
preserveOriginal?: boolean;
|
|
9
|
+
};
|
|
10
|
+
type SubscribeOptions = {
|
|
11
|
+
consumerId?: string;
|
|
12
|
+
group?: string;
|
|
13
|
+
prefetch?: number;
|
|
14
|
+
autoAck?: boolean;
|
|
15
|
+
retry?: RetryOptions;
|
|
16
|
+
deadLetter?: DeadLetterOptions;
|
|
17
|
+
exclusive?: boolean;
|
|
18
|
+
};
|
|
19
|
+
//#endregion
|
|
20
|
+
export { DeadLetterOptions, RetryOptions, SubscribeOptions };
|
|
21
|
+
//# sourceMappingURL=subscribe.types.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"subscribe.types.d.mts","names":[],"sources":["../../../../../../@warlock.js/herald/src/types/subscribe.types.ts"],"mappings":";KAAY,YAAA;EACV,UAAA;EACA,KAAA,aAAkB,OAAA;AAAA;AAAA,KAGR,iBAAA;EACV,OAAA;EACA,gBAAgB;AAAA;AAAA,KAGN,gBAAA;EACV,UAAA;EACA,KAAA;EACA,QAAA;EACA,OAAA;EACA,KAAA,GAAQ,YAAA;EACR,UAAA,GAAa,iBAAiB;EAC9B,SAAA;AAAA"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
//#region ../../@warlock.js/herald/src/use-case-broadcast.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Minimal mirror of `@warlock.js/core`'s `UseCaseBroadcastEvent`.
|
|
4
|
+
*
|
|
5
|
+
* Kept local on purpose: this adapter is **structurally typed** so `@warlock.js/herald`
|
|
6
|
+
* takes no dependency on `@warlock.js/core`. The shape only needs the fields the
|
|
7
|
+
* adapter reads (`event` for the channel, `payload` for the body).
|
|
8
|
+
*/
|
|
9
|
+
type UseCaseBroadcastEvent = {
|
|
10
|
+
useCase: string;
|
|
11
|
+
event: string;
|
|
12
|
+
id: string;
|
|
13
|
+
at: Date;
|
|
14
|
+
payload: unknown;
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* Channel adapter that publishes use-case broadcast events onto a herald broker.
|
|
18
|
+
*
|
|
19
|
+
* Register it in the use-cases config so successful use cases fan out to the bus:
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* // src/config/use-cases.ts
|
|
23
|
+
* import { heraldBroadcast } from "@warlock.js/herald";
|
|
24
|
+
*
|
|
25
|
+
* export default {
|
|
26
|
+
* broadcast: {
|
|
27
|
+
* enabled: true,
|
|
28
|
+
* channels: [heraldBroadcast({ broker: "default" })],
|
|
29
|
+
* },
|
|
30
|
+
* } satisfies UseCaseConfigurations;
|
|
31
|
+
*
|
|
32
|
+
* @param options - Optional broker name (defaults to the default broker)
|
|
33
|
+
*/
|
|
34
|
+
declare function heraldBroadcast(options?: {
|
|
35
|
+
broker?: string;
|
|
36
|
+
}): {
|
|
37
|
+
broadcast(event: UseCaseBroadcastEvent): Promise<void>;
|
|
38
|
+
};
|
|
39
|
+
//#endregion
|
|
40
|
+
export { UseCaseBroadcastEvent, heraldBroadcast };
|
|
41
|
+
//# sourceMappingURL=use-case-broadcast.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-case-broadcast.d.mts","names":[],"sources":["../../../../../@warlock.js/herald/src/use-case-broadcast.ts"],"mappings":";;AASA;;;;;;KAAY,qBAAA;EACV,OAAA;EACA,KAAA;EACA,EAAA;EACA,EAAA,EAAI,IAAI;EACR,OAAA;AAAA;;;;;;;;;;;AAuBwD;;;;;;;;iBAF1C,eAAA,CAAgB,OAAA;EAAY,MAAA;AAAA;mBAEjB,qBAAA,GAAwB,OAAO;AAAA"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { herald } from "./utils/connect-to-broker.mjs";
|
|
2
|
+
|
|
3
|
+
//#region ../../@warlock.js/herald/src/use-case-broadcast.ts
|
|
4
|
+
/**
|
|
5
|
+
* Channel adapter that publishes use-case broadcast events onto a herald broker.
|
|
6
|
+
*
|
|
7
|
+
* Register it in the use-cases config so successful use cases fan out to the bus:
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* // src/config/use-cases.ts
|
|
11
|
+
* import { heraldBroadcast } from "@warlock.js/herald";
|
|
12
|
+
*
|
|
13
|
+
* export default {
|
|
14
|
+
* broadcast: {
|
|
15
|
+
* enabled: true,
|
|
16
|
+
* channels: [heraldBroadcast({ broker: "default" })],
|
|
17
|
+
* },
|
|
18
|
+
* } satisfies UseCaseConfigurations;
|
|
19
|
+
*
|
|
20
|
+
* @param options - Optional broker name (defaults to the default broker)
|
|
21
|
+
*/
|
|
22
|
+
function heraldBroadcast(options) {
|
|
23
|
+
return { async broadcast(event) {
|
|
24
|
+
await herald(options?.broker).channel(event.event).publish(event.payload);
|
|
25
|
+
} };
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
//#endregion
|
|
29
|
+
export { heraldBroadcast };
|
|
30
|
+
//# sourceMappingURL=use-case-broadcast.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-case-broadcast.mjs","names":[],"sources":["../../../../../@warlock.js/herald/src/use-case-broadcast.ts"],"sourcesContent":["import { herald } from \"./utils/connect-to-broker\";\n\n/**\n * Minimal mirror of `@warlock.js/core`'s `UseCaseBroadcastEvent`.\n *\n * Kept local on purpose: this adapter is **structurally typed** so `@warlock.js/herald`\n * takes no dependency on `@warlock.js/core`. The shape only needs the fields the\n * adapter reads (`event` for the channel, `payload` for the body).\n */\nexport type UseCaseBroadcastEvent = {\n useCase: string;\n event: string;\n id: string;\n at: Date;\n payload: unknown;\n};\n\n/**\n * Channel adapter that publishes use-case broadcast events onto a herald broker.\n *\n * Register it in the use-cases config so successful use cases fan out to the bus:\n *\n * @example\n * // src/config/use-cases.ts\n * import { heraldBroadcast } from \"@warlock.js/herald\";\n *\n * export default {\n * broadcast: {\n * enabled: true,\n * channels: [heraldBroadcast({ broker: \"default\" })],\n * },\n * } satisfies UseCaseConfigurations;\n *\n * @param options - Optional broker name (defaults to the default broker)\n */\nexport function heraldBroadcast(options?: { broker?: string }) {\n return {\n async broadcast(event: UseCaseBroadcastEvent): Promise<void> {\n await herald(options?.broker).channel(event.event).publish(event.payload);\n },\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAmCA,SAAgB,gBAAgB,SAA+B;CAC7D,OAAO,EACL,MAAM,UAAU,OAA6C;EAC3D,MAAM,OAAO,SAAS,MAAM,EAAE,QAAQ,MAAM,KAAK,EAAE,QAAQ,MAAM,OAAO;CAC1E,EACF;AACF"}
|
|
@@ -1,7 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
4
|
-
import
|
|
1
|
+
import { ChannelOptions } from "../types/channel.types.mjs";
|
|
2
|
+
import { ConnectionOptions } from "../types/connection.types.mjs";
|
|
3
|
+
import { ChannelContract } from "../contracts/channel.contract.mjs";
|
|
4
|
+
import { EventMessage } from "../message-managers/event-message.mjs";
|
|
5
|
+
import { EventConsumerClass } from "../message-managers/types.mjs";
|
|
6
|
+
import { Broker } from "../communicators/broker.mjs";
|
|
7
|
+
//#region ../../@warlock.js/herald/src/utils/connect-to-broker.d.ts
|
|
5
8
|
/**
|
|
6
9
|
* Connect to a message broker and register it.
|
|
7
10
|
*
|
|
@@ -55,7 +58,7 @@ import type { ChannelOptions, ConnectionOptions } from "../types";
|
|
|
55
58
|
* herald("analytics").channel("events").publish({ ... });
|
|
56
59
|
* ```
|
|
57
60
|
*/
|
|
58
|
-
|
|
61
|
+
declare function connectToBroker(options: ConnectionOptions): Promise<Broker>;
|
|
59
62
|
/**
|
|
60
63
|
* Get a broker by name or the default one.
|
|
61
64
|
*
|
|
@@ -84,7 +87,7 @@ export declare function connectToBroker(options: ConnectionOptions): Promise<Bro
|
|
|
84
87
|
* });
|
|
85
88
|
* ```
|
|
86
89
|
*/
|
|
87
|
-
|
|
90
|
+
declare function herald(name?: string): Broker;
|
|
88
91
|
/**
|
|
89
92
|
* Get channel instance for the given name from default broker.
|
|
90
93
|
*
|
|
@@ -101,7 +104,7 @@ export declare function herald(name?: string): Broker;
|
|
|
101
104
|
* await channel.publish({ userId: 1 });
|
|
102
105
|
* ```
|
|
103
106
|
*/
|
|
104
|
-
|
|
107
|
+
declare function heraldChannel<TPayload = unknown>(name: string, options?: ChannelOptions<TPayload>): ChannelContract<TPayload>;
|
|
105
108
|
/**
|
|
106
109
|
* Publish an EventMessage to the default broker.
|
|
107
110
|
*
|
|
@@ -114,7 +117,7 @@ export declare function heraldChannel<TPayload = unknown>(name: string, options?
|
|
|
114
117
|
* await publishEvent(new UserUpdatedEvent({ id: 1, name: "John Doe" }));
|
|
115
118
|
* ```
|
|
116
119
|
*/
|
|
117
|
-
|
|
120
|
+
declare function publishEvent<TPayload = Record<string, any>>(event: EventMessage<TPayload>): Promise<void>;
|
|
118
121
|
/**
|
|
119
122
|
* Subscribe an EventConsumer class to the default broker.
|
|
120
123
|
*
|
|
@@ -127,5 +130,7 @@ export declare function publishEvent<TPayload = Record<string, any>>(event: Even
|
|
|
127
130
|
* await subscribeConsumer(UserUpdatedConsumer);
|
|
128
131
|
* ```
|
|
129
132
|
*/
|
|
130
|
-
|
|
131
|
-
//#
|
|
133
|
+
declare function subscribeConsumer<TPayload = Record<string, any>>(Consumer: EventConsumerClass<TPayload>): Promise<() => void>;
|
|
134
|
+
//#endregion
|
|
135
|
+
export { connectToBroker, herald, heraldChannel, publishEvent, subscribeConsumer };
|
|
136
|
+
//# sourceMappingURL=connect-to-broker.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"connect-to-broker.d.mts","names":[],"sources":["../../../../../../@warlock.js/herald/src/utils/connect-to-broker.ts"],"mappings":";;;;;;;;;;;;;;;AA0DA;;;;;;;;;;;;;AAAiF;AA6EjF;;;;AAA6C;AAoB7C;;;;;;;;;;;;;;;;;AAG2B;AAgB3B;;;;;;;;iBApHsB,eAAA,CAAgB,OAAA,EAAS,iBAAA,GAAoB,OAAA,CAAQ,MAAA;;;;;;;;AAoHqB;AAgBhG;;;;;;;;;;;;;;;;AACwC;;;;iBAxDxB,MAAA,CAAO,IAAA,YAAgB,MAAM;;;;;;;;;;;;;;;;;iBAoB7B,aAAA,oBAAA,CACd,IAAA,UACA,OAAA,GAAU,cAAA,CAAe,QAAA,IACxB,eAAA,CAAgB,QAAA;;;;;;;;;;;;;iBAgBG,YAAA,YAAwB,MAAA,cAAA,CAAqB,KAAA,EAAO,YAAA,CAAa,QAAA,IAAS,OAAA;;;;;;;;;;;;;iBAgB1E,iBAAA,YAA6B,MAAA,cAAA,CACjD,QAAA,EAAU,kBAAA,CAAmB,QAAA,IAAS,OAAA"}
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
import { brokerRegistry } from "../communicators/broker-registry.mjs";
|
|
2
|
+
import "../communicators/index.mjs";
|
|
3
|
+
|
|
4
|
+
//#region ../../@warlock.js/herald/src/utils/connect-to-broker.ts
|
|
5
|
+
/**
|
|
6
|
+
* Connect to a message broker and register it.
|
|
7
|
+
*
|
|
8
|
+
* This is a high-level utility function that simplifies connection setup
|
|
9
|
+
* for most projects. It handles driver instantiation, connection,
|
|
10
|
+
* broker creation, and automatic registration.
|
|
11
|
+
*
|
|
12
|
+
* **Supported Drivers:**
|
|
13
|
+
* - `rabbitmq` (default) - RabbitMQ/AMQP driver
|
|
14
|
+
* - `kafka` - Apache Kafka driver (coming soon)
|
|
15
|
+
*
|
|
16
|
+
* @param options - Connection configuration options
|
|
17
|
+
* @returns A connected and registered Broker instance
|
|
18
|
+
* @throws {Error} If connection fails or driver is not implemented
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```typescript
|
|
22
|
+
* // RabbitMQ connection
|
|
23
|
+
* const broker = await connectToBroker({
|
|
24
|
+
* driver: "rabbitmq",
|
|
25
|
+
* host: "localhost",
|
|
26
|
+
* port: 5672,
|
|
27
|
+
* username: "guest",
|
|
28
|
+
* password: "guest",
|
|
29
|
+
* });
|
|
30
|
+
*
|
|
31
|
+
* // Use the broker
|
|
32
|
+
* await broker.channel("user.created").publish({ userId: 1 });
|
|
33
|
+
* ```
|
|
34
|
+
*
|
|
35
|
+
* @example
|
|
36
|
+
* ```typescript
|
|
37
|
+
* // Multiple brokers
|
|
38
|
+
* await connectToBroker({
|
|
39
|
+
* driver: "rabbitmq",
|
|
40
|
+
* name: "notifications",
|
|
41
|
+
* isDefault: true,
|
|
42
|
+
* host: process.env.RABBITMQ_HOST,
|
|
43
|
+
* });
|
|
44
|
+
*
|
|
45
|
+
* await connectToBroker({
|
|
46
|
+
* driver: "rabbitmq",
|
|
47
|
+
* name: "analytics",
|
|
48
|
+
* host: process.env.ANALYTICS_RABBITMQ_HOST,
|
|
49
|
+
* });
|
|
50
|
+
*
|
|
51
|
+
* // Use default broker
|
|
52
|
+
* herald().channel("notifications").publish({ ... });
|
|
53
|
+
*
|
|
54
|
+
* // Use specific broker
|
|
55
|
+
* herald("analytics").channel("events").publish({ ... });
|
|
56
|
+
* ```
|
|
57
|
+
*/
|
|
58
|
+
async function connectToBroker(options) {
|
|
59
|
+
const driverType = options.driver ?? "rabbitmq";
|
|
60
|
+
const brokerName = options.name ?? "default";
|
|
61
|
+
const isDefault = options.isDefault ?? true;
|
|
62
|
+
let driver;
|
|
63
|
+
switch (driverType) {
|
|
64
|
+
case "rabbitmq": {
|
|
65
|
+
const rabbitOptions = options;
|
|
66
|
+
const { RabbitMQDriver } = await import("../drivers/rabbitmq/rabbitmq-driver.mjs");
|
|
67
|
+
driver = new RabbitMQDriver(rabbitOptions);
|
|
68
|
+
break;
|
|
69
|
+
}
|
|
70
|
+
case "kafka": throw new Error("Kafka driver is not yet implemented. Coming soon! For now, please use RabbitMQ.");
|
|
71
|
+
default: throw new Error(`Unknown driver: "${driverType}". Supported drivers: rabbitmq, kafka`);
|
|
72
|
+
}
|
|
73
|
+
const broker = brokerRegistry.register({
|
|
74
|
+
name: brokerName,
|
|
75
|
+
driver,
|
|
76
|
+
isDefault
|
|
77
|
+
});
|
|
78
|
+
try {
|
|
79
|
+
await driver.connect();
|
|
80
|
+
} catch (error) {
|
|
81
|
+
throw new Error(`Failed to connect to ${driverType}: ${error instanceof Error ? error.message : String(error)}`);
|
|
82
|
+
}
|
|
83
|
+
return broker;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Get a broker by name or the default one.
|
|
87
|
+
*
|
|
88
|
+
* This is the main entry point for using brokers in your application.
|
|
89
|
+
* Named after the package — `herald()` carries your messages!
|
|
90
|
+
*
|
|
91
|
+
* @param name - Optional broker name (uses default if not provided)
|
|
92
|
+
* @returns Broker instance
|
|
93
|
+
* @throws MissingBrokerError if broker not found
|
|
94
|
+
*
|
|
95
|
+
* @example
|
|
96
|
+
* // Get default broker
|
|
97
|
+
* const channel = herald().channel("user.created");
|
|
98
|
+
* await channel.publish({ userId: 1 });
|
|
99
|
+
*
|
|
100
|
+
* // Get specific broker
|
|
101
|
+
* const analyticsChannel = herald("analytics").channel("events");
|
|
102
|
+
* await analyticsChannel.publish({ event: "page_view" });
|
|
103
|
+
*
|
|
104
|
+
* // Subscribe to messages
|
|
105
|
+
* herald()
|
|
106
|
+
* .channel<UserPayload>("user.created")
|
|
107
|
+
* .subscribe(async (message, ctx) => {
|
|
108
|
+
* console.log("User created:", message.payload);
|
|
109
|
+
* await ctx.ack();
|
|
110
|
+
* });
|
|
111
|
+
* ```
|
|
112
|
+
*/
|
|
113
|
+
function herald(name) {
|
|
114
|
+
return brokerRegistry.get(name);
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Get channel instance for the given name from default broker.
|
|
118
|
+
*
|
|
119
|
+
* Shorthand for `herald().channel(name, options)`.
|
|
120
|
+
*
|
|
121
|
+
* @param name - Channel name
|
|
122
|
+
* @param options - Optional channel options
|
|
123
|
+
* @returns Channel instance
|
|
124
|
+
* @throws MissingBrokerError if broker not found
|
|
125
|
+
*
|
|
126
|
+
* @example
|
|
127
|
+
* ```typescript
|
|
128
|
+
* const channel = heraldChannel("user.created");
|
|
129
|
+
* await channel.publish({ userId: 1 });
|
|
130
|
+
* ```
|
|
131
|
+
*/
|
|
132
|
+
function heraldChannel(name, options) {
|
|
133
|
+
return herald().channel(name, options);
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Publish an EventMessage to the default broker.
|
|
137
|
+
*
|
|
138
|
+
* @param event - Event message to publish
|
|
139
|
+
* @returns Promise that resolves when the event is published
|
|
140
|
+
* @throws Error if the broker is not connected
|
|
141
|
+
*
|
|
142
|
+
* @example
|
|
143
|
+
* ```typescript
|
|
144
|
+
* await publishEvent(new UserUpdatedEvent({ id: 1, name: "John Doe" }));
|
|
145
|
+
* ```
|
|
146
|
+
*/
|
|
147
|
+
async function publishEvent(event) {
|
|
148
|
+
return herald().publish(event);
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* Subscribe an EventConsumer class to the default broker.
|
|
152
|
+
*
|
|
153
|
+
* @param Consumer - Event consumer class
|
|
154
|
+
* @returns Unsubscribe function
|
|
155
|
+
* @throws MissingBrokerError if broker not found
|
|
156
|
+
*
|
|
157
|
+
* @example
|
|
158
|
+
* ```typescript
|
|
159
|
+
* await subscribeConsumer(UserUpdatedConsumer);
|
|
160
|
+
* ```
|
|
161
|
+
*/
|
|
162
|
+
async function subscribeConsumer(Consumer) {
|
|
163
|
+
return herald().subscribe(Consumer);
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
//#endregion
|
|
167
|
+
export { connectToBroker, herald, heraldChannel, publishEvent, subscribeConsumer };
|
|
168
|
+
//# sourceMappingURL=connect-to-broker.mjs.map
|