fastify-rabbitmq 3.2.0 → 3.4.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/dist/index.mjs ADDED
@@ -0,0 +1,86 @@
1
+ import fp from "fastify-plugin";
2
+ import { AMQPChannelError, AMQPConnectionError, AMQPError, Connection, ConsumerStatus } from "rabbitmq-client";
3
+ import createError from "@fastify/error";
4
+ //#region src/errors.ts
5
+ const errors = {
6
+ /** Error if there is an invalid option used during registration. */
7
+ FASTIFY_RABBIT_MQ_ERR_INVALID_OPTS: createError("FASTIFY_RABBIT_MQ_ERR_INVALID_OPTS", "Invalid options: %s"),
8
+ /** Error if there is an setup error of the plugin itself. */
9
+ FASTIFY_RABBIT_MQ_ERR_SETUP_ERRORS: createError("FASTIFY_RABBIT_MQ_ERR_SETUP_ERRORS", "Setup error: %s"),
10
+ /** If an invalid usage error was done, this error would pop up. */
11
+ FASTIFY_RABBIT_MQ_ERR_USAGE: createError("FASTIFY_RABBIT_MQ_ERR_USAGE", "Usage error: %s")
12
+ };
13
+ //#endregion
14
+ //#region src/validation.ts
15
+ /**
16
+ * Validate Options
17
+ *
18
+ * The plugin validates only the *shape* of `connection` -- that it is a
19
+ * non-empty connection string or a `ConnectionOptions` object. Parsing the URL
20
+ * and validating the broker options (hosts, TLS, reconnect, etc.) is delegated
21
+ * to `rabbitmq-client`. The shape guard exists because `new Connection(...)`
22
+ * accepts garbage (a number, an array, `null`, `{}`) without throwing and then
23
+ * silently fails to connect at runtime; rejecting it here surfaces a clear
24
+ * registration-time error instead.
25
+ * @since 1.0.0
26
+ * @param options
27
+ */
28
+ const validateOpts = async (options) => {
29
+ const { connection } = options;
30
+ if (connection === void 0) throw new errors.FASTIFY_RABBIT_MQ_ERR_INVALID_OPTS("connection must be defined.");
31
+ if (typeof connection === "string") {
32
+ if (connection.length === 0) throw new errors.FASTIFY_RABBIT_MQ_ERR_INVALID_OPTS("connection string must not be empty.");
33
+ return;
34
+ }
35
+ if (!(typeof connection === "object" && connection !== null && !Array.isArray(connection))) throw new errors.FASTIFY_RABBIT_MQ_ERR_INVALID_OPTS("connection must be a connection string or a ConnectionOptions object.");
36
+ };
37
+ //#endregion
38
+ //#region src/index.ts
39
+ /**
40
+ * How we talk with Fastify
41
+ * @since 1.0.0
42
+ * @param fastify
43
+ * @param options
44
+ * @param connection
45
+ */
46
+ const decorateFastifyInstance = (fastify, options, connection) => {
47
+ const { namespace = "" } = options;
48
+ if (namespace !== void 0 && namespace !== "") fastify.log.debug("[fastify-rabbitmq] Namespace Attempt: %s", namespace);
49
+ if (namespace !== void 0 && namespace !== "") {
50
+ if (fastify.rabbitmq === void 0) fastify.decorate("rabbitmq", Object.create(null));
51
+ if (fastify.rabbitmq[namespace] !== void 0) throw new errors.FASTIFY_RABBIT_MQ_ERR_SETUP_ERRORS(`Already registered with namespace: ${namespace}`);
52
+ fastify.log.trace(`[fastify-rabbitmq] Decorate Fastify with Namespace: ${namespace}`);
53
+ fastify.rabbitmq[namespace] = connection;
54
+ } else if (fastify.rabbitmq !== void 0) throw new errors.FASTIFY_RABBIT_MQ_ERR_SETUP_ERRORS("Already registered.");
55
+ if (fastify.rabbitmq === void 0) {
56
+ fastify.log.trace("[fastify-rabbitmq] Decorate Fastify");
57
+ fastify.decorate("rabbitmq", connection);
58
+ }
59
+ };
60
+ /**
61
+ * Main Function
62
+ * @since 1.0.0
63
+ * @example
64
+ * This is the basics on how to use this plugin:
65
+ * ```js
66
+ * app.register(fastifyRabbit, {
67
+ * connection: 'amqp://guest:guest@localhost'
68
+ * })
69
+ * ```
70
+ * This will allow you to read from your Fastify "object" and
71
+ * use this plugin at the "rabbitmq" level. From there you can execute and maintain
72
+ * the RabbitMQ Connection using the 'rabbitmq-client' package, which is wrapping around
73
+ * this plugin to execute functions it provides.
74
+ *
75
+ * @see [https://cody-greene.github.io/node-rabbitmq-client/latest/index.html](https://cody-greene.github.io/node-rabbitmq-client/latest/index.html)
76
+ *
77
+ */
78
+ const fastifyRabbit = fp(async (fastify, opts) => {
79
+ await validateOpts(opts);
80
+ const { connection } = opts;
81
+ decorateFastifyInstance(fastify, opts, new Connection(connection));
82
+ });
83
+ //#endregion
84
+ export { AMQPChannelError, AMQPConnectionError, AMQPError, ConsumerStatus, decorateFastifyInstance, fastifyRabbit as default };
85
+
86
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.mjs","names":["RabbitMQConnection"],"sources":["../src/errors.ts","../src/validation.ts","../src/index.ts"],"sourcesContent":["/*\nMIT License\n\nCopyright (c) 2026 Shane Froebel\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.\n*/\nimport createError from \"@fastify/error\";\n\nexport const errors = {\n /** Error if there is an invalid option used during registration. */\n FASTIFY_RABBIT_MQ_ERR_INVALID_OPTS: createError(\n \"FASTIFY_RABBIT_MQ_ERR_INVALID_OPTS\",\n \"Invalid options: %s\",\n ),\n /** Error if there is an setup error of the plugin itself. */\n FASTIFY_RABBIT_MQ_ERR_SETUP_ERRORS: createError(\n \"FASTIFY_RABBIT_MQ_ERR_SETUP_ERRORS\",\n \"Setup error: %s\",\n ),\n /** If an invalid usage error was done, this error would pop up. */\n FASTIFY_RABBIT_MQ_ERR_USAGE: createError(\n \"FASTIFY_RABBIT_MQ_ERR_USAGE\",\n \"Usage error: %s\",\n ),\n};\n","/*\nMIT License\n\nCopyright (c) 2026 Shane Froebel\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.\n*/\nimport { FastifyRabbitMQOptions } from \"./decorate\";\nimport { errors } from \"./errors\";\n\n/**\n * Validate Options\n *\n * The plugin validates only the *shape* of `connection` -- that it is a\n * non-empty connection string or a `ConnectionOptions` object. Parsing the URL\n * and validating the broker options (hosts, TLS, reconnect, etc.) is delegated\n * to `rabbitmq-client`. The shape guard exists because `new Connection(...)`\n * accepts garbage (a number, an array, `null`, `{}`) without throwing and then\n * silently fails to connect at runtime; rejecting it here surfaces a clear\n * registration-time error instead.\n * @since 1.0.0\n * @param options\n */\nexport const validateOpts = async (\n options: FastifyRabbitMQOptions,\n): Promise<void> => {\n const { connection } = options;\n\n // Mandatory\n if (connection === undefined) {\n throw new errors.FASTIFY_RABBIT_MQ_ERR_INVALID_OPTS(\n \"connection must be defined.\",\n );\n }\n\n if (typeof connection === \"string\") {\n if (connection.length === 0) {\n throw new errors.FASTIFY_RABBIT_MQ_ERR_INVALID_OPTS(\n \"connection string must not be empty.\",\n );\n }\n return;\n }\n\n const isConnectionOptions =\n typeof connection === \"object\" &&\n connection !== null &&\n !Array.isArray(connection);\n\n if (!isConnectionOptions) {\n throw new errors.FASTIFY_RABBIT_MQ_ERR_INVALID_OPTS(\n \"connection must be a connection string or a ConnectionOptions object.\",\n );\n }\n};\n","/*\nMIT License\n\nCopyright (c) 2026 Shane Froebel\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.\n*/\nimport { FastifyInstance } from \"fastify\";\nimport fp from \"fastify-plugin\";\nimport { Connection as RabbitMQConnection } from \"rabbitmq-client\";\n\nimport { FastifyRabbitMQOptions } from \"./decorate\";\nimport { errors } from \"./errors\";\nimport { validateOpts } from \"./validation\";\nexport { type FastifyRabbitMQOptions } from \"./decorate\";\n\n/**\n * How we talk with Fastify\n * @since 1.0.0\n * @param fastify\n * @param options\n * @param connection\n */\nconst decorateFastifyInstance = (\n fastify: FastifyInstance,\n options: FastifyRabbitMQOptions,\n connection: any,\n): void => {\n const { namespace = \"\" } = options;\n\n if (namespace !== undefined && namespace !== \"\") {\n fastify.log.debug(\"[fastify-rabbitmq] Namespace Attempt: %s\", namespace);\n }\n if (namespace !== undefined && namespace !== \"\") {\n if (fastify.rabbitmq === undefined) {\n fastify.decorate(\"rabbitmq\", Object.create(null));\n }\n\n if (fastify.rabbitmq[namespace] !== undefined) {\n throw new errors.FASTIFY_RABBIT_MQ_ERR_SETUP_ERRORS(\n `Already registered with namespace: ${namespace}`,\n );\n }\n\n fastify.log.trace(\n `[fastify-rabbitmq] Decorate Fastify with Namespace: ${namespace}`,\n );\n fastify.rabbitmq[namespace] = connection;\n } else {\n if (fastify.rabbitmq !== undefined) {\n throw new errors.FASTIFY_RABBIT_MQ_ERR_SETUP_ERRORS(\n \"Already registered.\",\n );\n }\n }\n\n if (fastify.rabbitmq === undefined) {\n fastify.log.trace(\"[fastify-rabbitmq] Decorate Fastify\");\n fastify.decorate(\"rabbitmq\", connection);\n }\n};\n\n/**\n * Main Function\n * @since 1.0.0\n * @example\n * This is the basics on how to use this plugin:\n * ```js\n * app.register(fastifyRabbit, {\n * connection: 'amqp://guest:guest@localhost'\n * })\n * ```\n * This will allow you to read from your Fastify \"object\" and\n * use this plugin at the \"rabbitmq\" level. From there you can execute and maintain\n * the RabbitMQ Connection using the 'rabbitmq-client' package, which is wrapping around\n * this plugin to execute functions it provides.\n *\n * @see [https://cody-greene.github.io/node-rabbitmq-client/latest/index.html](https://cody-greene.github.io/node-rabbitmq-client/latest/index.html)\n *\n */\nconst fastifyRabbit = fp<FastifyRabbitMQOptions>(async (fastify, opts) => {\n await validateOpts(opts);\n\n const { connection } = opts;\n\n const c = new RabbitMQConnection(connection);\n\n decorateFastifyInstance(fastify, opts, c);\n});\n\nexport default fastifyRabbit;\n\nexport { decorateFastifyInstance };\n\nexport * from \"./types\";\n\n// Re-export the rabbitmq-client surface so consumers import from this package\n// instead of reaching for the wrapped client. These are the exact types the\n// app.rabbitmq decorator hands back, so they stay correct without owning a\n// parallel definition.\nexport type {\n AsyncMessage,\n Channel,\n Connection,\n ConnectionOptions,\n Consumer,\n ConsumerHandler,\n ConsumerProps,\n Envelope,\n HeaderFields,\n MessageBody,\n Publisher,\n PublisherProps,\n ReturnedMessage,\n RPCClient,\n RPCProps,\n SyncMessage,\n} from \"rabbitmq-client\";\nexport {\n AMQPChannelError,\n AMQPConnectionError,\n AMQPError,\n ConsumerStatus,\n} from \"rabbitmq-client\";\n"],"mappings":";;;;AAwBA,MAAa,SAAS;;CAEpB,oCAAoC,YAClC,sCACA,qBACF;;CAEA,oCAAoC,YAClC,sCACA,iBACF;;CAEA,6BAA6B,YAC3B,+BACA,iBACF;AACF;;;;;;;;;;;;;;;;ACFA,MAAa,eAAe,OAC1B,YACkB;CAClB,MAAM,EAAE,eAAe;CAGvB,IAAI,eAAe,KAAA,GACjB,MAAM,IAAI,OAAO,mCACf,6BACF;CAGF,IAAI,OAAO,eAAe,UAAU;EAClC,IAAI,WAAW,WAAW,GACxB,MAAM,IAAI,OAAO,mCACf,sCACF;EAEF;CACF;CAOA,IAAI,EAJF,OAAO,eAAe,YACtB,eAAe,QACf,CAAC,MAAM,QAAQ,UAAU,IAGzB,MAAM,IAAI,OAAO,mCACf,uEACF;AAEJ;;;;;;;;;;AC/BA,MAAM,2BACJ,SACA,SACA,eACS;CACT,MAAM,EAAE,YAAY,OAAO;CAE3B,IAAI,cAAc,KAAA,KAAa,cAAc,IAC3C,QAAQ,IAAI,MAAM,4CAA4C,SAAS;CAEzE,IAAI,cAAc,KAAA,KAAa,cAAc,IAAI;EAC/C,IAAI,QAAQ,aAAa,KAAA,GACvB,QAAQ,SAAS,YAAY,OAAO,OAAO,IAAI,CAAC;EAGlD,IAAI,QAAQ,SAAS,eAAe,KAAA,GAClC,MAAM,IAAI,OAAO,mCACf,sCAAsC,WACxC;EAGF,QAAQ,IAAI,MACV,uDAAuD,WACzD;EACA,QAAQ,SAAS,aAAa;CAChC,OACE,IAAI,QAAQ,aAAa,KAAA,GACvB,MAAM,IAAI,OAAO,mCACf,qBACF;CAIJ,IAAI,QAAQ,aAAa,KAAA,GAAW;EAClC,QAAQ,IAAI,MAAM,qCAAqC;EACvD,QAAQ,SAAS,YAAY,UAAU;CACzC;AACF;;;;;;;;;;;;;;;;;;;AAoBA,MAAM,gBAAgB,GAA2B,OAAO,SAAS,SAAS;CACxE,MAAM,aAAa,IAAI;CAEvB,MAAM,EAAE,eAAe;CAIvB,wBAAwB,SAAS,MAAM,IAFzBA,WAAmB,UAEM,CAAC;AAC1C,CAAC"}
@@ -2,7 +2,7 @@ import { Connection as RabbitMQConnection } from "rabbitmq-client";
2
2
  declare module "fastify" {
3
3
  interface FastifyInstance {
4
4
  /** Main Decorator for Fastify **/
5
- rabbitmq: RabbitMQConnection & fastifyRabbitMQ.FastifyRabbitMQNO;
5
+ rabbitmq: fastifyRabbitMQ.FastifyRabbitMQNO & RabbitMQConnection;
6
6
  }
7
7
  }
8
8
  export declare namespace fastifyRabbitMQ {
@@ -10,3 +10,4 @@ export declare namespace fastifyRabbitMQ {
10
10
  [namespace: string]: RabbitMQConnection;
11
11
  }
12
12
  }
13
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAsBA,OAAO,EAAE,UAAU,IAAI,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AAEnE,OAAO,QAAQ,SAAS,CAAC;IACvB,UAAiB,eAAe;QAC9B,kCAAkC;QAClC,QAAQ,EAAE,eAAe,CAAC,iBAAiB,GAAG,kBAAkB,CAAC;KAClE;CACF;AAGD,MAAM,CAAC,OAAO,WAAW,eAAe,CAAC;IACvC,UAAiB,iBAAiB;QAChC,CAAC,SAAS,EAAE,MAAM,GAAG,kBAAkB,CAAC;KACzC;CACF"}
@@ -0,0 +1,16 @@
1
+ import { FastifyRabbitMQOptions } from "./decorate";
2
+ /**
3
+ * Validate Options
4
+ *
5
+ * The plugin validates only the *shape* of `connection` -- that it is a
6
+ * non-empty connection string or a `ConnectionOptions` object. Parsing the URL
7
+ * and validating the broker options (hosts, TLS, reconnect, etc.) is delegated
8
+ * to `rabbitmq-client`. The shape guard exists because `new Connection(...)`
9
+ * accepts garbage (a number, an array, `null`, `{}`) without throwing and then
10
+ * silently fails to connect at runtime; rejecting it here surfaces a clear
11
+ * registration-time error instead.
12
+ * @since 1.0.0
13
+ * @param options
14
+ */
15
+ export declare const validateOpts: (options: FastifyRabbitMQOptions) => Promise<void>;
16
+ //# sourceMappingURL=validation.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validation.d.ts","sourceRoot":"","sources":["../src/validation.ts"],"names":[],"mappings":"AAsBA,OAAO,EAAE,sBAAsB,EAAE,MAAM,YAAY,CAAC;AAGpD;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,YAAY,GACvB,SAAS,sBAAsB,KAC9B,OAAO,CAAC,IAAI,CA6Bd,CAAC"}
package/package.json CHANGED
@@ -1,92 +1,98 @@
1
1
  {
2
2
  "name": "fastify-rabbitmq",
3
- "version": "3.2.0",
3
+ "version": "3.4.0",
4
4
  "description": "A Fastify RabbitMQ Plugin Developed in Pure TypeScript.",
5
- "module": "./lib/esm/index.js",
6
- "main": "./lib/cjs/index.js",
7
- "types": "./lib/types/index.d.ts",
5
+ "keywords": [
6
+ "rabbitmq-client",
7
+ "typescript",
8
+ "rabbitmq",
9
+ "fastify",
10
+ "fastify-plugin"
11
+ ],
12
+ "homepage": "https://github.com/Bugs5382/fastify-rabbitmq#readme",
13
+ "bugs": {
14
+ "url": "https://github.com/Bugs5382/fastify-rabbitmq/issues"
15
+ },
16
+ "repository": {
17
+ "type": "git",
18
+ "url": "git+https://github.com/Bugs5382/fastify-rabbitmq.git"
19
+ },
20
+ "license": "MIT",
21
+ "author": "Shane Froebel",
8
22
  "exports": {
9
23
  ".": {
10
- "types": "./lib/types/index.d.ts",
11
- "import": "./lib/esm/index.js",
12
- "require": "./lib/cjs/index.js",
13
- "default": "./lib/cjs/index.js"
24
+ "import": {
25
+ "types": "./dist/index.d.ts",
26
+ "default": "./dist/index.mjs"
27
+ },
28
+ "require": {
29
+ "types": "./dist/index.d.ts",
30
+ "default": "./dist/index.cjs"
31
+ }
14
32
  }
15
33
  },
34
+ "main": "./dist/index.cjs",
35
+ "module": "./dist/index.mjs",
36
+ "types": "./dist/index.d.ts",
16
37
  "files": [
17
- "lib/",
38
+ "dist",
18
39
  "README.md",
19
- "LICENSE"
40
+ "LICENSE",
41
+ "CHANGELOG.md"
20
42
  ],
21
- "engines": {
22
- "node": ">=20.11.0"
23
- },
24
43
  "scripts": {
25
- "clean": "rm -rf coverage docs lib temp",
26
- "build": "tsc -p src/tsconfig.esm.json && tsc -p src/tsconfig.cjs.json && tsc -p src/tsconfig.types.json && ./bin/build-types.sh",
27
- "build:watch": "tsc -p src/tsconfig.esm.json -w",
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",
44
+ "build": "tsdown && tsc --emitDeclarationOnly",
45
+ "clean": "rm -rf coverage docs dist temp",
46
+ "lint": "eslint .",
47
+ "lint:fix": "eslint . --fix",
48
+ "lint:npm": "npmPkgJsonLint .",
49
+ "lint:package": "npx sort-package-json",
33
50
  "pack": "npm pack",
34
- "prepublishOnly": "npm run clean && npm run build && npm run pack",
51
+ "prepublishOnly": "npm run clean && npm run build",
35
52
  "test": "vitest run",
53
+ "test:coverage": "vitest --coverage",
36
54
  "test:verbose": "vitest run --reporter verbose",
37
55
  "test:watch": "vitest watch",
38
- "test:coverage": "vitest --coverage",
39
56
  "typedoc": "typedoc",
40
57
  "typedoc:watch": "typedoc -watch",
41
58
  "update": "npx npm-check-updates -u --enginesNode && npm run update:post-update",
42
- "update:post-update": "npm install && npm run test"
43
- },
44
- "repository": {
45
- "type": "git",
46
- "url": "git+https://github.com/Bugs5382/fastify-rabbitmq.git"
47
- },
48
- "keywords": [
49
- "rabbitmq-client",
50
- "typescript",
51
- "rabbitmq",
52
- "fastify",
53
- "fastify-plugin"
54
- ],
55
- "author": "Shane Froebel",
56
- "license": "MIT",
57
- "bugs": {
58
- "url": "https://github.com/Bugs5382/fastify-rabbitmq/issues"
59
+ "update:post-update": "npm install && npm run test",
60
+ "build:watch": "tsdown --watch",
61
+ "typecheck": "tsc --noEmit"
59
62
  },
60
- "homepage": "https://github.com/Bugs5382/fastify-rabbitmq#readme",
61
63
  "dependencies": {
62
- "@fastify/error": "^4.1.0",
63
- "fastify-plugin": "^5.0.1",
64
- "rabbitmq-client": "^5.0.2"
64
+ "@fastify/error": "^4.2.0",
65
+ "fastify-plugin": "^5.1.0",
66
+ "rabbitmq-client": "^5.0.8"
65
67
  },
66
68
  "devDependencies": {
67
- "@eslint/js": "^9.23.0",
68
- "@shipgirl/typedoc-plugin-versions": "^0.3.0",
69
- "@types/node": "^22.13.13",
70
- "@types/tcp-port-used": "^1.0.4",
71
- "@typescript-eslint/eslint-plugin": "^8.28.0",
72
- "@typescript-eslint/parser": "^8.28.0",
73
- "@vitest/coverage-v8": "^3.0.9",
74
- "@vitest/ui": "^3.0.9",
75
- "eslint": "^9.23.0",
76
- "eslint-config-prettier": "^10.1.1",
77
- "eslint-plugin-prettier": "^5.2.4",
78
- "fastify": "^5.2.1",
79
- "npm-check-updates": "^17.1.16",
69
+ "@eslint/js": "^9.28.0",
70
+ "@shipgirl/typedoc-plugin-versions": "^0.3.1",
71
+ "@types/node": "^22.15.29",
72
+ "@typescript-eslint/eslint-plugin": "^8.33.0",
73
+ "@typescript-eslint/parser": "^8.33.0",
74
+ "@vitest/coverage-v8": "^3.1.4",
75
+ "@vitest/ui": "^3.1.4",
76
+ "eslint": "^9.28.0",
77
+ "eslint-plugin-sort-class-members": "^1.21.0",
78
+ "fastify": "^5.3.3",
79
+ "npm-check-updates": "^18.0.1",
80
80
  "npm-package-json-lint": "^8.0.0",
81
81
  "npm-package-json-lint-config-default": "^7.0.1",
82
82
  "pre-commit": "^1.2.2",
83
83
  "snazzy": "^9.0.0",
84
+ "sort-package-json": "^3.2.1",
84
85
  "ts-node": "^10.9.2",
85
- "tsd": "^0.31.2",
86
- "typedoc": "^0.28.1",
87
- "typescript": "^5.8.2",
88
- "typescript-eslint": "^8.28.0",
89
- "vitest": "^3.0.9"
86
+ "tsd": "^0.32.0",
87
+ "typedoc": "^0.28.5",
88
+ "typescript": "^5.8.3",
89
+ "typescript-eslint": "^8.33.0",
90
+ "vitest": "^3.1.4",
91
+ "@the-rabbit-hole/eslint-config": "^0.4.0",
92
+ "tsdown": "^0.22.2"
93
+ },
94
+ "engines": {
95
+ "node": ">=20.15.0"
90
96
  },
91
97
  "precommit": [
92
98
  "test",
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
package/lib/cjs/errors.js DELETED
@@ -1,15 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.errors = void 0;
7
- const error_1 = __importDefault(require("@fastify/error"));
8
- exports.errors = {
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"),
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"),
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"),
15
- };
package/lib/cjs/index.js DELETED
@@ -1,77 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- var __importDefault = (this && this.__importDefault) || function (mod) {
17
- return (mod && mod.__esModule) ? mod : { "default": mod };
18
- };
19
- Object.defineProperty(exports, "__esModule", { value: true });
20
- exports.decorateFastifyInstance = void 0;
21
- const fastify_plugin_1 = __importDefault(require("fastify-plugin"));
22
- const rabbitmq_client_1 = require("rabbitmq-client");
23
- const errors_js_1 = require("./errors.js");
24
- const validation_js_1 = require("./validation.js");
25
- __exportStar(require("./types.js"), exports);
26
- /* eslint-disable @typescript-eslint/no-explicit-any */
27
- const decorateFastifyInstance = (fastify, options, connection) => {
28
- const { namespace = "" } = options;
29
- if (typeof namespace !== "undefined" && namespace !== "") {
30
- fastify.log.debug("[fastify-rabbitmq] Namespace Attempt: %s", namespace);
31
- }
32
- if (typeof namespace !== "undefined" && namespace !== "") {
33
- if (typeof fastify.rabbitmq === "undefined") {
34
- fastify.decorate("rabbitmq", Object.create(null));
35
- }
36
- if (typeof fastify.rabbitmq[namespace] !== "undefined") {
37
- throw new errors_js_1.errors.FASTIFY_RABBIT_MQ_ERR_SETUP_ERRORS(`Already registered with namespace: ${namespace}`);
38
- }
39
- fastify.log.trace("[fastify-rabbitmq] Decorate Fastify with Namespace: %", namespace);
40
- fastify.rabbitmq[namespace] = connection;
41
- }
42
- else {
43
- if (typeof fastify.rabbitmq !== "undefined") {
44
- throw new errors_js_1.errors.FASTIFY_RABBIT_MQ_ERR_SETUP_ERRORS("Already registered.");
45
- }
46
- }
47
- if (typeof fastify.rabbitmq === "undefined") {
48
- fastify.log.trace("[fastify-rabbitmq] Decorate Fastify");
49
- fastify.decorate("rabbitmq", connection);
50
- }
51
- };
52
- exports.decorateFastifyInstance = decorateFastifyInstance;
53
- /**
54
- * Main Function
55
- * @since 1.0.0
56
- * @example
57
- * This is the basics on how to use this plugin:
58
- * ```js
59
- * app.register(fastifyRabbit, {
60
- * connection: 'amqp://guest:guest@localhost'
61
- * })
62
- * ```
63
- * This will allow you to read from your Fastify "object" and
64
- * use this plugin at the "rabbitmq" level. From there you can execute and maintain
65
- * the RabbitMQ Connection using the 'rabbitmq-client' package, which is wrapping around
66
- * this plugin to execute functions it provides.
67
- *
68
- * @see [https://cody-greene.github.io/node-rabbitmq-client/latest/index.html](https://cody-greene.github.io/node-rabbitmq-client/latest/index.html)
69
- *
70
- */
71
- const fastifyRabbit = (0, fastify_plugin_1.default)(async (fastify, opts) => {
72
- await (0, validation_js_1.validateOpts)(opts);
73
- const { connection } = opts;
74
- const c = new rabbitmq_client_1.Connection(connection);
75
- decorateFastifyInstance(fastify, opts, c);
76
- });
77
- exports.default = fastifyRabbit;
@@ -1,3 +0,0 @@
1
- {
2
- "type": "commonjs"
3
- }
package/lib/cjs/types.js DELETED
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,17 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.validateOpts = void 0;
4
- const errors_js_1 = require("./errors.js");
5
- const validateOpts = async (options) => {
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.");
9
- }
10
- // Mandatory
11
- if (typeof options.connection !== "undefined") {
12
- if (typeof options.connection !== "object") {
13
- // we need to do some sort of check here to make sure RabbitMQOptions is "valid"
14
- }
15
- }
16
- };
17
- exports.validateOpts = validateOpts;
@@ -1 +0,0 @@
1
- export {};
@@ -1,14 +0,0 @@
1
- export declare const errors: {
2
- /** Error if there is an invalid option used during registration. */
3
- FASTIFY_RABBIT_MQ_ERR_INVALID_OPTS: import("@fastify/error").FastifyErrorConstructor<{
4
- code: "FASTIFY_RABBIT_MQ_ERR_INVALID_OPTS";
5
- }, [any?, any?, any?]>;
6
- /** Error if there is an setup error of the plugin itself. */
7
- FASTIFY_RABBIT_MQ_ERR_SETUP_ERRORS: import("@fastify/error").FastifyErrorConstructor<{
8
- code: "FASTIFY_RABBIT_MQ_ERR_SETUP_ERRORS";
9
- }, [any?, any?, any?]>;
10
- /** If an invalid usage error was done, this error would pop up. */
11
- FASTIFY_RABBIT_MQ_ERR_USAGE: import("@fastify/error").FastifyErrorConstructor<{
12
- code: "FASTIFY_RABBIT_MQ_ERR_USAGE";
13
- }, [any?, any?, any?]>;
14
- };
package/lib/esm/errors.js DELETED
@@ -1,9 +0,0 @@
1
- import createError from "@fastify/error";
2
- export const errors = {
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"),
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"),
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"),
9
- };
package/lib/esm/index.js DELETED
@@ -1,57 +0,0 @@
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 */
7
- const decorateFastifyInstance = (fastify, options, connection) => {
8
- const { namespace = "" } = options;
9
- if (typeof namespace !== "undefined" && namespace !== "") {
10
- fastify.log.debug("[fastify-rabbitmq] Namespace Attempt: %s", namespace);
11
- }
12
- if (typeof namespace !== "undefined" && namespace !== "") {
13
- if (typeof fastify.rabbitmq === "undefined") {
14
- fastify.decorate("rabbitmq", Object.create(null));
15
- }
16
- if (typeof fastify.rabbitmq[namespace] !== "undefined") {
17
- throw new errors.FASTIFY_RABBIT_MQ_ERR_SETUP_ERRORS(`Already registered with namespace: ${namespace}`);
18
- }
19
- fastify.log.trace("[fastify-rabbitmq] Decorate Fastify with Namespace: %", namespace);
20
- fastify.rabbitmq[namespace] = connection;
21
- }
22
- else {
23
- if (typeof fastify.rabbitmq !== "undefined") {
24
- throw new errors.FASTIFY_RABBIT_MQ_ERR_SETUP_ERRORS("Already registered.");
25
- }
26
- }
27
- if (typeof fastify.rabbitmq === "undefined") {
28
- fastify.log.trace("[fastify-rabbitmq] Decorate Fastify");
29
- fastify.decorate("rabbitmq", connection);
30
- }
31
- };
32
- /**
33
- * Main Function
34
- * @since 1.0.0
35
- * @example
36
- * This is the basics on how to use this plugin:
37
- * ```js
38
- * app.register(fastifyRabbit, {
39
- * connection: 'amqp://guest:guest@localhost'
40
- * })
41
- * ```
42
- * This will allow you to read from your Fastify "object" and
43
- * use this plugin at the "rabbitmq" level. From there you can execute and maintain
44
- * the RabbitMQ Connection using the 'rabbitmq-client' package, which is wrapping around
45
- * this plugin to execute functions it provides.
46
- *
47
- * @see [https://cody-greene.github.io/node-rabbitmq-client/latest/index.html](https://cody-greene.github.io/node-rabbitmq-client/latest/index.html)
48
- *
49
- */
50
- const fastifyRabbit = fp(async (fastify, opts) => {
51
- await validateOpts(opts);
52
- const { connection } = opts;
53
- const c = new RabbitMQConnection(connection);
54
- decorateFastifyInstance(fastify, opts, c);
55
- });
56
- export default fastifyRabbit;
57
- export { decorateFastifyInstance };
@@ -1,3 +0,0 @@
1
- {
2
- "type": "module"
3
- }
@@ -1,12 +0,0 @@
1
- import { Connection as RabbitMQConnection } from "rabbitmq-client";
2
- declare module "fastify" {
3
- interface FastifyInstance {
4
- /** Main Decorator for Fastify **/
5
- rabbitmq: RabbitMQConnection & fastifyRabbitMQ.FastifyRabbitMQNO;
6
- }
7
- }
8
- export declare namespace fastifyRabbitMQ {
9
- interface FastifyRabbitMQNO {
10
- [namespace: string]: RabbitMQConnection;
11
- }
12
- }
package/lib/esm/types.js DELETED
@@ -1 +0,0 @@
1
- export {};
@@ -1,2 +0,0 @@
1
- import { FastifyRabbitMQOptions } from "./decorate.js";
2
- export declare const validateOpts: (options: FastifyRabbitMQOptions) => Promise<void>;
@@ -1,13 +0,0 @@
1
- import { errors } from "./errors.js";
2
- export const validateOpts = async (options) => {
3
- // Mandatory
4
- if (typeof options.connection === "undefined") {
5
- throw new errors.FASTIFY_RABBIT_MQ_ERR_INVALID_OPTS("connection or findServers must be defined.");
6
- }
7
- // Mandatory
8
- if (typeof options.connection !== "undefined") {
9
- if (typeof options.connection !== "object") {
10
- // we need to do some sort of check here to make sure RabbitMQOptions is "valid"
11
- }
12
- }
13
- };
@@ -1,13 +0,0 @@
1
- import { ConnectionOptions } from "rabbitmq-client";
2
- export interface FastifyRabbitMQOptions {
3
- /**
4
- * @since 1.0.0
5
- * @remarks Connection String or object pointing to the RabbitMQ Broker Services
6
- */
7
- connection: string | ConnectionOptions;
8
- /**
9
- * @since 1.0.0
10
- * @remarks To set the custom nNamespace within this plugin instance. Used to register this plugin more than one time.
11
- */
12
- namespace?: string;
13
- }
@@ -1,26 +0,0 @@
1
- import { FastifyInstance } from "fastify";
2
- import { ConnectionOptions } from "rabbitmq-client";
3
- import { FastifyRabbitMQOptions } from "./decorate.js";
4
- export * from "./types.js";
5
- declare const decorateFastifyInstance: (fastify: FastifyInstance, options: FastifyRabbitMQOptions, connection: any) => void;
6
- /**
7
- * Main Function
8
- * @since 1.0.0
9
- * @example
10
- * This is the basics on how to use this plugin:
11
- * ```js
12
- * app.register(fastifyRabbit, {
13
- * connection: 'amqp://guest:guest@localhost'
14
- * })
15
- * ```
16
- * This will allow you to read from your Fastify "object" and
17
- * use this plugin at the "rabbitmq" level. From there you can execute and maintain
18
- * the RabbitMQ Connection using the 'rabbitmq-client' package, which is wrapping around
19
- * this plugin to execute functions it provides.
20
- *
21
- * @see [https://cody-greene.github.io/node-rabbitmq-client/latest/index.html](https://cody-greene.github.io/node-rabbitmq-client/latest/index.html)
22
- *
23
- */
24
- declare const fastifyRabbit: import("fastify").FastifyPluginCallback<FastifyRabbitMQOptions, import("fastify").RawServerDefault, import("fastify").FastifyTypeProviderDefault, import("fastify").FastifyBaseLogger>;
25
- export default fastifyRabbit;
26
- export { decorateFastifyInstance, FastifyRabbitMQOptions, ConnectionOptions };
@@ -1,2 +0,0 @@
1
- import { FastifyRabbitMQOptions } from "./decorate.js";
2
- export declare const validateOpts: (options: FastifyRabbitMQOptions) => Promise<void>;