@mqueue/multicast
Advanced tools
+6
-10
| { | ||
| "name": "@mqueue/multicast", | ||
| "version": "1.0.0-next-20250728071929", | ||
| "version": "1.0.0", | ||
| "type": "module", | ||
@@ -11,3 +11,3 @@ "description": "MQueue adapter for multi-backend publishing and subscribing", | ||
| "engines": { | ||
| "node": ">=18" | ||
| "node": ">=20" | ||
| }, | ||
@@ -26,6 +26,2 @@ "files": [ | ||
| "default": "./dist/index.js" | ||
| }, | ||
| "require": { | ||
| "types": "./dist/index.d.cts", | ||
| "default": "./dist/index.cjs" | ||
| } | ||
@@ -45,3 +41,3 @@ } | ||
| "peerDependencies": { | ||
| "@mqueue/queue": "0.1.0-next-20250728071929" | ||
| "@mqueue/queue": "1.0.0" | ||
| }, | ||
@@ -54,7 +50,7 @@ "devDependencies": { | ||
| "typescript": "^5.8.3", | ||
| "@mqueue/queue": "0.1.0-next-20250728071929", | ||
| "@mqueue/null": "1.0.0-next-20250728071929" | ||
| "@mqueue/queue": "1.0.0", | ||
| "@mqueue/null": "1.0.0" | ||
| }, | ||
| "scripts": { | ||
| "build": "tsup src/index.ts --no-config --dts --format esm,cjs --cjsInterop --minify --sourcemap --splitting --treeshake", | ||
| "build": "tsup src/index.ts --no-config --dts --format esm --cjsInterop --minify --sourcemap --splitting --treeshake", | ||
| "typecheck": "tsc --noEmit", | ||
@@ -61,0 +57,0 @@ "test": "node --import tsx --test --test-reporter=spec tests/**/*.test.ts tests/*.test.ts", |
+21
-0
@@ -39,2 +39,11 @@ # Mulitcast Strategy for MQueue | ||
| ); | ||
| // Start listening to the queue | ||
| await incomingQueue.consume(async (payload) => { | ||
| const topicOrQueueName = payload.transport.name; | ||
| const headers = payload.message.headers; | ||
| const data = await payload.message.json(); | ||
| await payload.accept(); // or await payload.reject(); | ||
| // ... | ||
| }); | ||
| ``` | ||
@@ -45,2 +54,5 @@ | ||
| ```ts | ||
| import MQueue from "@mqueue/queue"; // or require("@mqueue/queue"); | ||
| import { MulticastQueue } from "@mqueue/multicast"; // or require("@mqueue/multicast"); | ||
| // Select one random adapter (for example) | ||
@@ -71,2 +83,11 @@ const filter = (adapters) => [adapters[randomInt(adapters.length)]]; | ||
| ); | ||
| // Start listening to the queue | ||
| await incomingQueue.consume(async (payload) => { | ||
| const topicOrQueueName = payload.transport.name; | ||
| const headers = payload.message.headers; | ||
| const data = await payload.message.json(); | ||
| await payload.accept(); // or await payload.reject(); | ||
| // ... | ||
| }); | ||
| ``` | ||
@@ -73,0 +94,0 @@ |
| 'use strict';var u=class{constructor(e,t={}){this._adapters=e;this._filter=t.filter??(s=>s);}type="multicast";_filter;async healthcheck(){await Promise.all(this._adapters.map(e=>e.healthcheck()));}async consume(e){await Promise.all(this._filter(this._adapters).map(t=>t.consume(e)));}async close(){await Promise.all(this._adapters.map(e=>e.close()));}};var i=class{constructor(e,t={}){this._adapters=e;this._filter=t.filter??(s=>s);}type="multicast";_filter;async healthcheck(){await Promise.all(this._adapters.map(e=>e.healthcheck()));}async sendMessage(e){await Promise.all(this._filter(this._adapters,e).map(t=>t.sendMessage(e)));}async close(){await Promise.all(this._adapters.map(e=>e.close()));}};var a=class{constructor(){}static Outgoing=i;static Incoming=u};exports.MulticastIncomingQueue=u;exports.MulticastOutgoingQueue=i;exports.MulticastQueue=a;//# sourceMappingURL=index.cjs.map | ||
| //# sourceMappingURL=index.cjs.map |
| {"version":3,"sources":["../src/MulticastIncomingQueue.ts","../src/MulticastOutgoingQueue.ts","../src/MulticastQueue.ts"],"names":["MulticastIncomingQueue","_adapters","options","adapters","adapter","callback","MulticastOutgoingQueue","message","MulticastQueue"],"mappings":"aAeA,IAAqBA,EAArB,KAGA,CAKE,WACYC,CAAAA,CAAAA,CACVC,EAA4C,EAAC,CAC7C,CAFU,IAAA,CAAA,SAAA,CAAAD,EAGV,IAAK,CAAA,OAAA,CAAUC,EAAQ,MAAYC,GAAAA,CAAAA,EAAaA,GAClD,CATO,IAAA,CAAO,WAEJ,CAAA,OAAA,CASV,MAAa,WAAc,EAAA,CACzB,M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AAWF,CACzB,CAAA,OAAc,SAAWN,CAC3B","file":"index.cjs","sourcesContent":["import {\n IncomingQueueAdapter,\n IncomingQueueMessageAdapterListener,\n} from \"@mqueue/queue\";\n\ntype MulticastIncomingQueueFilter<\n T extends [IncomingQueueAdapter, ...IncomingQueueAdapter[]],\n> = (adapters: T) => IncomingQueueAdapter[];\n\nexport interface MulticastIncomingQueueOptions<\n T extends [IncomingQueueAdapter, ...IncomingQueueAdapter[]],\n> {\n filter?: MulticastIncomingQueueFilter<T>;\n}\n\nexport default class MulticastIncomingQueue<\n T extends [IncomingQueueAdapter, ...IncomingQueueAdapter[]],\n> implements IncomingQueueAdapter\n{\n public type = \"multicast\";\n\n protected _filter: MulticastIncomingQueueFilter<T>;\n\n constructor(\n protected _adapters: T,\n options: MulticastIncomingQueueOptions<T> = {},\n ) {\n this._filter = options.filter ?? ((adapters) => adapters);\n }\n\n public async healthcheck() {\n await Promise.all(this._adapters.map((adapter) => adapter.healthcheck()));\n }\n\n public async consume(\n callback: IncomingQueueMessageAdapterListener,\n ): Promise<void> {\n await Promise.all(\n this._filter(this._adapters).map((adapter) => adapter.consume(callback)),\n );\n }\n\n public async close() {\n await Promise.all(this._adapters.map((adapter) => adapter.close()));\n }\n}\n","import { OutgoingQueueAdapter, QueueMessage } from \"@mqueue/queue\";\n\ntype MulticastOutgoingQueueFilter<\n T extends [OutgoingQueueAdapter, ...OutgoingQueueAdapter[]],\n> = (adapters: T, message: QueueMessage) => OutgoingQueueAdapter[];\n\nexport interface MulticastOutgoingQueueOptions<\n T extends [OutgoingQueueAdapter, ...OutgoingQueueAdapter[]],\n> {\n filter?: MulticastOutgoingQueueFilter<T>;\n}\n\nexport default class MulticastOutgoingQueue<\n T extends [OutgoingQueueAdapter, ...OutgoingQueueAdapter[]],\n> implements OutgoingQueueAdapter\n{\n public type = \"multicast\";\n\n protected _filter: MulticastOutgoingQueueFilter<T>;\n\n constructor(\n protected _adapters: T,\n options: MulticastOutgoingQueueOptions<T> = {},\n ) {\n this._filter = options.filter ?? ((adapters) => adapters);\n }\n\n public async healthcheck() {\n await Promise.all(this._adapters.map((adapter) => adapter.healthcheck()));\n }\n\n public async sendMessage(message: QueueMessage): Promise<void> {\n await Promise.all(\n this._filter(this._adapters, message).map((adapter) =>\n adapter.sendMessage(message),\n ),\n );\n }\n\n public async close() {\n await Promise.all(this._adapters.map((adapter) => adapter.close()));\n }\n}\n","import MulticastIncomingQueue from \"./MulticastIncomingQueue.js\";\nimport MulticastOutgoingQueue from \"./MulticastOutgoingQueue.js\";\n\nexport default class MulticastQueue {\n private constructor() {}\n\n public static Outgoing = MulticastOutgoingQueue;\n public static Incoming = MulticastIncomingQueue;\n}\n"]} |
| import { IncomingQueueAdapter, IncomingQueueMessageAdapterListener, OutgoingQueueAdapter, QueueMessage } from '@mqueue/queue'; | ||
| type MulticastIncomingQueueFilter<T extends [IncomingQueueAdapter, ...IncomingQueueAdapter[]]> = (adapters: T) => IncomingQueueAdapter[]; | ||
| interface MulticastIncomingQueueOptions<T extends [IncomingQueueAdapter, ...IncomingQueueAdapter[]]> { | ||
| filter?: MulticastIncomingQueueFilter<T>; | ||
| } | ||
| declare class MulticastIncomingQueue<T extends [IncomingQueueAdapter, ...IncomingQueueAdapter[]]> implements IncomingQueueAdapter { | ||
| protected _adapters: T; | ||
| type: string; | ||
| protected _filter: MulticastIncomingQueueFilter<T>; | ||
| constructor(_adapters: T, options?: MulticastIncomingQueueOptions<T>); | ||
| healthcheck(): Promise<void>; | ||
| consume(callback: IncomingQueueMessageAdapterListener): Promise<void>; | ||
| close(): Promise<void>; | ||
| } | ||
| type MulticastOutgoingQueueFilter<T extends [OutgoingQueueAdapter, ...OutgoingQueueAdapter[]]> = (adapters: T, message: QueueMessage) => OutgoingQueueAdapter[]; | ||
| interface MulticastOutgoingQueueOptions<T extends [OutgoingQueueAdapter, ...OutgoingQueueAdapter[]]> { | ||
| filter?: MulticastOutgoingQueueFilter<T>; | ||
| } | ||
| declare class MulticastOutgoingQueue<T extends [OutgoingQueueAdapter, ...OutgoingQueueAdapter[]]> implements OutgoingQueueAdapter { | ||
| protected _adapters: T; | ||
| type: string; | ||
| protected _filter: MulticastOutgoingQueueFilter<T>; | ||
| constructor(_adapters: T, options?: MulticastOutgoingQueueOptions<T>); | ||
| healthcheck(): Promise<void>; | ||
| sendMessage(message: QueueMessage): Promise<void>; | ||
| close(): Promise<void>; | ||
| } | ||
| declare class MulticastQueue { | ||
| private constructor(); | ||
| static Outgoing: typeof MulticastOutgoingQueue; | ||
| static Incoming: typeof MulticastIncomingQueue; | ||
| } | ||
| export { MulticastIncomingQueue, MulticastOutgoingQueue, MulticastQueue }; |
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
2
-50%95
28.38%12349
-35.14%6
-33.33%37
-9.76%