fastify-rabbitmq 3.0.0 → 3.1.0

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 CHANGED
@@ -26,46 +26,46 @@ npm install fastify-rabbitmq
26
26
  ## Basic Usage
27
27
 
28
28
  Register this as a plugin.
29
- Make sure it is loaded before any ***routes*** are loaded.
29
+ Make sure it is loaded before any **_routes_** are loaded.
30
30
 
31
31
  ### Quick Setup on the Server Side
32
32
 
33
33
  ```typescript
34
34
  export default fp<FastifyRabbitMQOptions>((fastify, options, done) => {
35
-
36
- void fastify.register(fastifyRabbit, {
37
- connection: `amqp://guest:guest@localhost`
38
- })
39
-
40
- void fastify.ready().then(async () => {
41
-
42
- const consumer = fastify.rabbitmq.createConsumer({
43
- queue: 'foo',
44
- queueOptions: {durable: true}
45
- }, async (msg: any) => {
46
- console.log(msg) // ==> bar
47
- })
48
-
49
- })
50
-
35
+ void fastify.register(fastifyRabbit, {
36
+ connection: `amqp://guest:guest@localhost`,
37
+ });
38
+
39
+ void fastify.ready().then(async () => {
40
+ const consumer = fastify.rabbitmq.createConsumer(
41
+ {
42
+ queue: "foo",
43
+ queueOptions: { durable: true },
44
+ },
45
+ async (msg: any) => {
46
+ console.log(msg); // ==> bar
47
+ },
48
+ );
49
+ });
51
50
  });
52
51
  ```
52
+
53
53
  ### Quick Setup on the Client Side
54
54
 
55
- Within any "endpoint" function, or if you have access to ```fastify.rabbitmq``` you can then call:
55
+ Within any "endpoint" function, or if you have access to `fastify.rabbitmq` you can then call:
56
56
 
57
57
  ```js
58
- fastify.get('/rabbitmq', async (request, reply) => {
59
- let pub = request.rabbitmq.createPublisher({
60
- confirm: true,
61
- maxAttempts: 1
62
- })
63
-
64
- await pub.send('foo', "bar") // ==> sent to foo queue
65
- })
58
+ fastify.get("/rabbitmq", async (request, reply) => {
59
+ let pub = request.rabbitmq.createPublisher({
60
+ confirm: true,
61
+ maxAttempts: 1,
62
+ });
63
+
64
+ await pub.send("foo", "bar"); // ==> sent to foo queue
65
+ });
66
66
  ```
67
67
 
68
- Sending the string ```bar``` to the queue called ```foo```.
68
+ Sending the string `bar` to the queue called `foo`.
69
69
 
70
70
  ## Full Documentation
71
71
 
@@ -73,10 +73,10 @@ Sending the string ```bar``` to the queue called ```foo```.
73
73
 
74
74
  ```typescript
75
75
  export interface FastifyRabbitMQOptions {
76
- /** Connection String or object pointing to the RabbitMQ Broker Services */
77
- connection: string | ConnectionOptions
78
- /** To set the custom nNamespace within this plugin instance. Used to register this plugin more than one time. */
79
- namespace?: string
76
+ /** Connection String or object pointing to the RabbitMQ Broker Services */
77
+ connection: string | ConnectionOptions;
78
+ /** To set the custom nNamespace within this plugin instance. Used to register this plugin more than one time. */
79
+ namespace?: string;
80
80
  }
81
81
  ```
82
82
 
@@ -85,14 +85,13 @@ export interface FastifyRabbitMQOptions {
85
85
  ##### `connection`
86
86
 
87
87
  Connection String or object pointing to the RabbitMQ Broker Services.
88
- This can be an object of ```ConnectionOptions``` from the ```rabbitmq-client``` plugin options.
88
+ This can be an object of `ConnectionOptions` from the `node-rabbitmq-client` plugin options.
89
89
 
90
90
  ##### `namespace`
91
91
 
92
92
  If you need more than one "connection" to a different set and/or array of RabbitMQ servers,
93
93
  either on network or cloud, each registration of the plugin needs it to be in its own namespace.
94
- If not provided, your application will fail to load.
95
-
94
+ If the name space is duplicated, it will fail to load.
96
95
 
97
96
  ## Acknowledgements
98
97
 
package/lib/cjs/errors.js CHANGED
@@ -7,9 +7,9 @@ exports.errors = void 0;
7
7
  const error_1 = __importDefault(require("@fastify/error"));
8
8
  exports.errors = {
9
9
  /** Error if there is an invalid option used during registration. */
10
- FASTIFY_RABBIT_MQ_ERR_INVALID_OPTS: (0, error_1.default)('FASTIFY_RABBIT_MQ_ERR_INVALID_OPTS', 'Invalid options: %s'),
10
+ FASTIFY_RABBIT_MQ_ERR_INVALID_OPTS: (0, error_1.default)("FASTIFY_RABBIT_MQ_ERR_INVALID_OPTS", "Invalid options: %s"),
11
11
  /** Error if there is an setup error of the plugin itself. */
12
- FASTIFY_RABBIT_MQ_ERR_SETUP_ERRORS: (0, error_1.default)('FASTIFY_RABBIT_MQ_ERR_SETUP_ERRORS', 'Setup error: %s'),
12
+ FASTIFY_RABBIT_MQ_ERR_SETUP_ERRORS: (0, error_1.default)("FASTIFY_RABBIT_MQ_ERR_SETUP_ERRORS", "Setup error: %s"),
13
13
  /** If an invalid usage error was done, this error would pop up. */
14
- FASTIFY_RABBIT_MQ_ERR_USAGE: (0, error_1.default)('FASTIFY_RABBIT_MQ_ERR_USAGE', 'Usage error: %s')
14
+ FASTIFY_RABBIT_MQ_ERR_USAGE: (0, error_1.default)("FASTIFY_RABBIT_MQ_ERR_USAGE", "Usage error: %s"),
15
15
  };
package/lib/cjs/index.js CHANGED
@@ -23,29 +23,30 @@ const rabbitmq_client_1 = require("rabbitmq-client");
23
23
  const errors_js_1 = require("./errors.js");
24
24
  const validation_js_1 = require("./validation.js");
25
25
  __exportStar(require("./types.js"), exports);
26
+ /* eslint-disable @typescript-eslint/no-explicit-any */
26
27
  const decorateFastifyInstance = (fastify, options, connection) => {
27
- const { namespace = '' } = options;
28
- if (typeof namespace !== 'undefined' && namespace !== '') {
29
- fastify.log.debug('[fastify-rabbitmq] Namespace Attempt: %s', namespace);
28
+ const { namespace = "" } = options;
29
+ if (typeof namespace !== "undefined" && namespace !== "") {
30
+ fastify.log.debug("[fastify-rabbitmq] Namespace Attempt: %s", namespace);
30
31
  }
31
- if (typeof namespace !== 'undefined' && namespace !== '') {
32
- if (typeof fastify.rabbitmq === 'undefined') {
33
- fastify.decorate('rabbitmq', Object.create(null));
32
+ if (typeof namespace !== "undefined" && namespace !== "") {
33
+ if (typeof fastify.rabbitmq === "undefined") {
34
+ fastify.decorate("rabbitmq", Object.create(null));
34
35
  }
35
- if (typeof fastify.rabbitmq[namespace] !== 'undefined') {
36
+ if (typeof fastify.rabbitmq[namespace] !== "undefined") {
36
37
  throw new errors_js_1.errors.FASTIFY_RABBIT_MQ_ERR_SETUP_ERRORS(`Already registered with namespace: ${namespace}`);
37
38
  }
38
- fastify.log.trace('[fastify-rabbitmq] Decorate Fastify with Namespace: %', namespace);
39
+ fastify.log.trace("[fastify-rabbitmq] Decorate Fastify with Namespace: %", namespace);
39
40
  fastify.rabbitmq[namespace] = connection;
40
41
  }
41
42
  else {
42
- if (typeof fastify.rabbitmq !== 'undefined') {
43
- throw new errors_js_1.errors.FASTIFY_RABBIT_MQ_ERR_SETUP_ERRORS('Already registered.');
43
+ if (typeof fastify.rabbitmq !== "undefined") {
44
+ throw new errors_js_1.errors.FASTIFY_RABBIT_MQ_ERR_SETUP_ERRORS("Already registered.");
44
45
  }
45
46
  }
46
- if (typeof fastify.rabbitmq === 'undefined') {
47
- fastify.log.trace('[fastify-rabbitmq] Decorate Fastify');
48
- fastify.decorate('rabbitmq', connection);
47
+ if (typeof fastify.rabbitmq === "undefined") {
48
+ fastify.log.trace("[fastify-rabbitmq] Decorate Fastify");
49
+ fastify.decorate("rabbitmq", connection);
49
50
  }
50
51
  };
51
52
  exports.decorateFastifyInstance = decorateFastifyInstance;
@@ -4,12 +4,12 @@ exports.validateOpts = void 0;
4
4
  const errors_js_1 = require("./errors.js");
5
5
  const validateOpts = async (options) => {
6
6
  // Mandatory
7
- if (typeof options.connection === 'undefined') {
8
- throw new errors_js_1.errors.FASTIFY_RABBIT_MQ_ERR_INVALID_OPTS('connection or findServers must be defined.');
7
+ if (typeof options.connection === "undefined") {
8
+ throw new errors_js_1.errors.FASTIFY_RABBIT_MQ_ERR_INVALID_OPTS("connection or findServers must be defined.");
9
9
  }
10
10
  // Mandatory
11
- if (typeof options.connection !== 'undefined') {
12
- if (typeof options.connection !== 'object') {
11
+ if (typeof options.connection !== "undefined") {
12
+ if (typeof options.connection !== "object") {
13
13
  // we need to do some sort of check here to make sure RabbitMQOptions is "valid"
14
14
  }
15
15
  }
@@ -1,13 +1,13 @@
1
- import { ConnectionOptions } from 'rabbitmq-client';
1
+ import { ConnectionOptions } from "rabbitmq-client";
2
2
  export interface FastifyRabbitMQOptions {
3
3
  /**
4
4
  * @since 1.0.0
5
- * @description Connection String or object pointing to the RabbitMQ Broker Services
5
+ * @remarks Connection String or object pointing to the RabbitMQ Broker Services
6
6
  */
7
7
  connection: string | ConnectionOptions;
8
8
  /**
9
9
  * @since 1.0.0
10
- * @description To set the custom nNamespace within this plugin instance. Used to register this plugin more than one time.
10
+ * @remarks To set the custom nNamespace within this plugin instance. Used to register this plugin more than one time.
11
11
  */
12
12
  namespace?: string;
13
13
  }
package/lib/esm/errors.js CHANGED
@@ -1,9 +1,9 @@
1
- import createError from '@fastify/error';
1
+ import createError from "@fastify/error";
2
2
  export const errors = {
3
3
  /** Error if there is an invalid option used during registration. */
4
- FASTIFY_RABBIT_MQ_ERR_INVALID_OPTS: createError('FASTIFY_RABBIT_MQ_ERR_INVALID_OPTS', 'Invalid options: %s'),
4
+ FASTIFY_RABBIT_MQ_ERR_INVALID_OPTS: createError("FASTIFY_RABBIT_MQ_ERR_INVALID_OPTS", "Invalid options: %s"),
5
5
  /** Error if there is an setup error of the plugin itself. */
6
- FASTIFY_RABBIT_MQ_ERR_SETUP_ERRORS: createError('FASTIFY_RABBIT_MQ_ERR_SETUP_ERRORS', 'Setup error: %s'),
6
+ FASTIFY_RABBIT_MQ_ERR_SETUP_ERRORS: createError("FASTIFY_RABBIT_MQ_ERR_SETUP_ERRORS", "Setup error: %s"),
7
7
  /** If an invalid usage error was done, this error would pop up. */
8
- FASTIFY_RABBIT_MQ_ERR_USAGE: createError('FASTIFY_RABBIT_MQ_ERR_USAGE', 'Usage error: %s')
8
+ FASTIFY_RABBIT_MQ_ERR_USAGE: createError("FASTIFY_RABBIT_MQ_ERR_USAGE", "Usage error: %s"),
9
9
  };
@@ -1,7 +1,7 @@
1
- import { FastifyInstance } from 'fastify';
2
- import { ConnectionOptions } from 'rabbitmq-client';
3
- import { FastifyRabbitMQOptions } from './decorate.js';
4
- export * from './types.js';
1
+ import { FastifyInstance } from "fastify";
2
+ import { ConnectionOptions } from "rabbitmq-client";
3
+ import { FastifyRabbitMQOptions } from "./decorate.js";
4
+ export * from "./types.js";
5
5
  declare const decorateFastifyInstance: (fastify: FastifyInstance, options: FastifyRabbitMQOptions, connection: any) => void;
6
6
  /**
7
7
  * Main Function
package/lib/esm/index.js CHANGED
@@ -1,31 +1,32 @@
1
- import fp from 'fastify-plugin';
2
- import { Connection as RabbitMQConnection } from 'rabbitmq-client';
3
- import { errors } from './errors.js';
4
- import { validateOpts } from './validation.js';
5
- export * from './types.js';
1
+ import fp from "fastify-plugin";
2
+ import { Connection as RabbitMQConnection, } from "rabbitmq-client";
3
+ import { errors } from "./errors.js";
4
+ import { validateOpts } from "./validation.js";
5
+ export * from "./types.js";
6
+ /* eslint-disable @typescript-eslint/no-explicit-any */
6
7
  const decorateFastifyInstance = (fastify, options, connection) => {
7
- const { namespace = '' } = options;
8
- if (typeof namespace !== 'undefined' && namespace !== '') {
9
- fastify.log.debug('[fastify-rabbitmq] Namespace Attempt: %s', namespace);
8
+ const { namespace = "" } = options;
9
+ if (typeof namespace !== "undefined" && namespace !== "") {
10
+ fastify.log.debug("[fastify-rabbitmq] Namespace Attempt: %s", namespace);
10
11
  }
11
- if (typeof namespace !== 'undefined' && namespace !== '') {
12
- if (typeof fastify.rabbitmq === 'undefined') {
13
- fastify.decorate('rabbitmq', Object.create(null));
12
+ if (typeof namespace !== "undefined" && namespace !== "") {
13
+ if (typeof fastify.rabbitmq === "undefined") {
14
+ fastify.decorate("rabbitmq", Object.create(null));
14
15
  }
15
- if (typeof fastify.rabbitmq[namespace] !== 'undefined') {
16
+ if (typeof fastify.rabbitmq[namespace] !== "undefined") {
16
17
  throw new errors.FASTIFY_RABBIT_MQ_ERR_SETUP_ERRORS(`Already registered with namespace: ${namespace}`);
17
18
  }
18
- fastify.log.trace('[fastify-rabbitmq] Decorate Fastify with Namespace: %', namespace);
19
+ fastify.log.trace("[fastify-rabbitmq] Decorate Fastify with Namespace: %", namespace);
19
20
  fastify.rabbitmq[namespace] = connection;
20
21
  }
21
22
  else {
22
- if (typeof fastify.rabbitmq !== 'undefined') {
23
- throw new errors.FASTIFY_RABBIT_MQ_ERR_SETUP_ERRORS('Already registered.');
23
+ if (typeof fastify.rabbitmq !== "undefined") {
24
+ throw new errors.FASTIFY_RABBIT_MQ_ERR_SETUP_ERRORS("Already registered.");
24
25
  }
25
26
  }
26
- if (typeof fastify.rabbitmq === 'undefined') {
27
- fastify.log.trace('[fastify-rabbitmq] Decorate Fastify');
28
- fastify.decorate('rabbitmq', connection);
27
+ if (typeof fastify.rabbitmq === "undefined") {
28
+ fastify.log.trace("[fastify-rabbitmq] Decorate Fastify");
29
+ fastify.decorate("rabbitmq", connection);
29
30
  }
30
31
  };
31
32
  /**
@@ -1,5 +1,5 @@
1
- import { Connection as RabbitMQConnection } from 'rabbitmq-client';
2
- declare module 'fastify' {
1
+ import { Connection as RabbitMQConnection } from "rabbitmq-client";
2
+ declare module "fastify" {
3
3
  interface FastifyInstance {
4
4
  /** Main Decorator for Fastify **/
5
5
  rabbitmq: RabbitMQConnection & fastifyRabbitMQ.FastifyRabbitMQNO;
@@ -1,2 +1,2 @@
1
- import { FastifyRabbitMQOptions } from './decorate.js';
1
+ import { FastifyRabbitMQOptions } from "./decorate.js";
2
2
  export declare const validateOpts: (options: FastifyRabbitMQOptions) => Promise<void>;
@@ -1,12 +1,12 @@
1
- import { errors } from './errors.js';
1
+ import { errors } from "./errors.js";
2
2
  export const validateOpts = async (options) => {
3
3
  // Mandatory
4
- if (typeof options.connection === 'undefined') {
5
- throw new errors.FASTIFY_RABBIT_MQ_ERR_INVALID_OPTS('connection or findServers must be defined.');
4
+ if (typeof options.connection === "undefined") {
5
+ throw new errors.FASTIFY_RABBIT_MQ_ERR_INVALID_OPTS("connection or findServers must be defined.");
6
6
  }
7
7
  // Mandatory
8
- if (typeof options.connection !== 'undefined') {
9
- if (typeof options.connection !== 'object') {
8
+ if (typeof options.connection !== "undefined") {
9
+ if (typeof options.connection !== "object") {
10
10
  // we need to do some sort of check here to make sure RabbitMQOptions is "valid"
11
11
  }
12
12
  }
@@ -1,13 +1,13 @@
1
- import { ConnectionOptions } from 'rabbitmq-client';
1
+ import { ConnectionOptions } from "rabbitmq-client";
2
2
  export interface FastifyRabbitMQOptions {
3
3
  /**
4
4
  * @since 1.0.0
5
- * @description Connection String or object pointing to the RabbitMQ Broker Services
5
+ * @remarks Connection String or object pointing to the RabbitMQ Broker Services
6
6
  */
7
7
  connection: string | ConnectionOptions;
8
8
  /**
9
9
  * @since 1.0.0
10
- * @description To set the custom nNamespace within this plugin instance. Used to register this plugin more than one time.
10
+ * @remarks To set the custom nNamespace within this plugin instance. Used to register this plugin more than one time.
11
11
  */
12
12
  namespace?: string;
13
13
  }
@@ -1,7 +1,7 @@
1
- import { FastifyInstance } from 'fastify';
2
- import { ConnectionOptions } from 'rabbitmq-client';
3
- import { FastifyRabbitMQOptions } from './decorate.js';
4
- export * from './types.js';
1
+ import { FastifyInstance } from "fastify";
2
+ import { ConnectionOptions } from "rabbitmq-client";
3
+ import { FastifyRabbitMQOptions } from "./decorate.js";
4
+ export * from "./types.js";
5
5
  declare const decorateFastifyInstance: (fastify: FastifyInstance, options: FastifyRabbitMQOptions, connection: any) => void;
6
6
  /**
7
7
  * Main Function
@@ -1,5 +1,5 @@
1
- import { Connection as RabbitMQConnection } from 'rabbitmq-client';
2
- declare module 'fastify' {
1
+ import { Connection as RabbitMQConnection } from "rabbitmq-client";
2
+ declare module "fastify" {
3
3
  interface FastifyInstance {
4
4
  /** Main Decorator for Fastify **/
5
5
  rabbitmq: RabbitMQConnection & fastifyRabbitMQ.FastifyRabbitMQNO;
@@ -1,2 +1,2 @@
1
- import { FastifyRabbitMQOptions } from './decorate.js';
1
+ import { FastifyRabbitMQOptions } from "./decorate.js";
2
2
  export declare const validateOpts: (options: FastifyRabbitMQOptions) => Promise<void>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fastify-rabbitmq",
3
- "version": "3.0.0",
3
+ "version": "3.1.0",
4
4
  "description": "A Fastify RabbitMQ Plugin Developed in Pure TypeScript.",
5
5
  "module": "./lib/esm/index.js",
6
6
  "main": "./lib/cjs/index.js",
@@ -14,18 +14,22 @@
14
14
  }
15
15
  },
16
16
  "files": [
17
- "lib/"
17
+ "lib/",
18
+ "README.md",
19
+ "LICENSE"
18
20
  ],
19
21
  "engines": {
20
22
  "node": ">=20.11.0"
21
23
  },
22
24
  "scripts": {
23
- "clean": "rm -rf lib docs coverage",
25
+ "clean": "rm -rf coverage docs lib temp",
24
26
  "build": "tsc -p src/tsconfig.esm.json && tsc -p src/tsconfig.cjs.json && tsc -p src/tsconfig.types.json && ./bin/build-types.sh",
25
27
  "build:watch": "tsc -p src/tsconfig.esm.json -w",
26
- "npmPkgJsonLint": "npmPkgJsonLint .",
27
- "lint": "npmPkgJsonLint . && ts-standard -p src/tsconfig.esm.json | snazzy",
28
- "lint:fix": "npmPkgJsonLint . && ts-standard -p src/tsconfig.esm.json --fix | snazzy",
28
+ "build:watch:cjs": "tsc -p src/tsconfig.cjs.json -w",
29
+ "npm:lint": "npmPkgJsonLint .",
30
+ "format": "prettier --write 'README.md' 'src/**/*.ts' '__tests__/**/*.ts'",
31
+ "lint": "npm run npm:lint && eslint | snazzy",
32
+ "lint:fix": "npm run npm:lint && eslint --fix | snazzy",
29
33
  "pack": "npm pack",
30
34
  "prepublishOnly": "npm run clean && npm run build && npm run pack",
31
35
  "test": "vitest run",
@@ -34,8 +38,6 @@
34
38
  "test:coverage": "vitest --coverage",
35
39
  "typedoc": "typedoc",
36
40
  "typedoc:watch": "typedoc -watch",
37
- "semantic-release": "semantic-release",
38
- "semantic-release:dry-run": "semantic-release --dry-run",
39
41
  "update": "npx npm-check-updates -u --enginesNode && npm run update:post-update",
40
42
  "update:post-update": "npm install && npm run test"
41
43
  },
@@ -59,29 +61,32 @@
59
61
  "dependencies": {
60
62
  "@fastify/error": "^4.0.0",
61
63
  "fastify-plugin": "^5.0.1",
62
- "rabbitmq-client": "^5.0.0"
64
+ "rabbitmq-client": "^5.0.1"
63
65
  },
64
66
  "devDependencies": {
65
- "@semantic-release/changelog": "^6.0.3",
66
- "@semantic-release/git": "^10.0.1",
67
- "@the-rabbit-hole/semantic-release-config": "^1.5.0",
68
- "@types/node": "^22.8.5",
69
- "@types/randomstring": "^1.3.0",
70
- "@typescript-eslint/parser": "^8.12.2",
71
- "@vitest/coverage-v8": "^2.1.4",
72
- "@vitest/ui": "^2.1.4",
73
- "fastify": "^5.0.0",
74
- "npm-check-updates": "^17.1.9",
67
+ "@eslint/js": "^9.15.0",
68
+ "@shipgirl/typedoc-plugin-versions": "^0.2.8",
69
+ "@types/eslint__js": "^8.42.3",
70
+ "@types/node": "^22.9.0",
71
+ "@types/tcp-port-used": "^1.0.4",
72
+ "@typescript-eslint/eslint-plugin": "^8.14.0",
73
+ "@typescript-eslint/parser": "^8.14.0",
74
+ "@vitest/coverage-v8": "^2.1.5",
75
+ "@vitest/ui": "^2.1.5",
76
+ "eslint": "^9.14.0",
77
+ "eslint-config-prettier": "^9.1.0",
78
+ "eslint-plugin-prettier": "^5.2.1",
79
+ "fastify": "^5.1.0",
80
+ "npm-check-updates": "^17.1.11",
75
81
  "npm-package-json-lint": "^8.0.0",
76
82
  "pre-commit": "^1.2.2",
77
- "semantic-release": "^24.2.0",
78
83
  "snazzy": "^9.0.0",
79
84
  "ts-node": "^10.9.2",
80
- "ts-standard": "^12.0.2",
81
85
  "tsd": "^0.31.2",
82
- "typedoc": "^0.26.10",
86
+ "typedoc": "^0.26.11",
83
87
  "typescript": "^5.6.3",
84
- "vitest": "^2.1.4"
88
+ "typescript-eslint": "^8.14.0",
89
+ "vitest": "^2.1.5"
85
90
  },
86
91
  "precommit": [
87
92
  "test",