fastify-rabbitmq 3.1.0 → 3.3.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/lib/cjs/index.js +106 -68
- package/lib/esm/index.mjs +82 -0
- package/lib/types/index.d.ts +40 -7
- package/package.json +59 -54
- package/lib/cjs/decorate.js +0 -2
- package/lib/cjs/errors.js +0 -15
- package/lib/cjs/package.json +0 -3
- package/lib/cjs/types.js +0 -2
- package/lib/cjs/validation.js +0 -17
- package/lib/esm/decorate.d.ts +0 -13
- package/lib/esm/decorate.js +0 -1
- package/lib/esm/errors.d.ts +0 -14
- package/lib/esm/errors.js +0 -9
- package/lib/esm/index.d.ts +0 -26
- package/lib/esm/index.js +0 -57
- package/lib/esm/package.json +0 -3
- package/lib/esm/types.d.ts +0 -12
- package/lib/esm/types.js +0 -1
- package/lib/esm/validation.d.ts +0 -2
- package/lib/esm/validation.js +0 -13
- package/lib/types/decorate.d.ts +0 -13
- package/lib/types/errors.d.ts +0 -14
- package/lib/types/types.d.ts +0 -12
- package/lib/types/validation.d.ts +0 -2
package/lib/cjs/index.js
CHANGED
|
@@ -1,77 +1,115 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
for (
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
15
19
|
};
|
|
16
|
-
var
|
|
17
|
-
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// src/index.ts
|
|
31
|
+
var index_exports = {};
|
|
32
|
+
__export(index_exports, {
|
|
33
|
+
decorateFastifyInstance: () => decorateFastifyInstance,
|
|
34
|
+
default: () => index_default
|
|
35
|
+
});
|
|
36
|
+
module.exports = __toCommonJS(index_exports);
|
|
37
|
+
var import_fastify_plugin = __toESM(require("fastify-plugin"));
|
|
38
|
+
var import_rabbitmq_client = require("rabbitmq-client");
|
|
39
|
+
|
|
40
|
+
// src/errors.ts
|
|
41
|
+
var import_error = __toESM(require("@fastify/error"));
|
|
42
|
+
var errors = {
|
|
43
|
+
/** Error if there is an invalid option used during registration. */
|
|
44
|
+
FASTIFY_RABBIT_MQ_ERR_INVALID_OPTS: (0, import_error.default)(
|
|
45
|
+
"FASTIFY_RABBIT_MQ_ERR_INVALID_OPTS",
|
|
46
|
+
"Invalid options: %s"
|
|
47
|
+
),
|
|
48
|
+
/** Error if there is an setup error of the plugin itself. */
|
|
49
|
+
FASTIFY_RABBIT_MQ_ERR_SETUP_ERRORS: (0, import_error.default)(
|
|
50
|
+
"FASTIFY_RABBIT_MQ_ERR_SETUP_ERRORS",
|
|
51
|
+
"Setup error: %s"
|
|
52
|
+
),
|
|
53
|
+
/** If an invalid usage error was done, this error would pop up. */
|
|
54
|
+
FASTIFY_RABBIT_MQ_ERR_USAGE: (0, import_error.default)(
|
|
55
|
+
"FASTIFY_RABBIT_MQ_ERR_USAGE",
|
|
56
|
+
"Usage error: %s"
|
|
57
|
+
)
|
|
18
58
|
};
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
if (typeof namespace !== "undefined" && namespace !== "") {
|
|
30
|
-
fastify.log.debug("[fastify-rabbitmq] Namespace Attempt: %s", namespace);
|
|
59
|
+
|
|
60
|
+
// src/validation.ts
|
|
61
|
+
var validateOpts = async (options) => {
|
|
62
|
+
if (typeof options.connection === "undefined") {
|
|
63
|
+
throw new errors.FASTIFY_RABBIT_MQ_ERR_INVALID_OPTS(
|
|
64
|
+
"connection or findServers must be defined."
|
|
65
|
+
);
|
|
66
|
+
}
|
|
67
|
+
if (typeof options.connection !== "undefined") {
|
|
68
|
+
if (typeof options.connection !== "object") {
|
|
31
69
|
}
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
// src/index.ts
|
|
74
|
+
var decorateFastifyInstance = (fastify, options, connection) => {
|
|
75
|
+
const { namespace = "" } = options;
|
|
76
|
+
if (typeof namespace !== "undefined" && namespace !== "") {
|
|
77
|
+
fastify.log.debug("[fastify-rabbitmq] Namespace Attempt: %s", namespace);
|
|
78
|
+
}
|
|
79
|
+
if (typeof namespace !== "undefined" && namespace !== "") {
|
|
80
|
+
if (typeof fastify.rabbitmq === "undefined") {
|
|
81
|
+
fastify.decorate("rabbitmq", /* @__PURE__ */ Object.create(null));
|
|
41
82
|
}
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
83
|
+
if (typeof fastify.rabbitmq[namespace] !== "undefined") {
|
|
84
|
+
throw new errors.FASTIFY_RABBIT_MQ_ERR_SETUP_ERRORS(
|
|
85
|
+
`Already registered with namespace: ${namespace}`
|
|
86
|
+
);
|
|
46
87
|
}
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
88
|
+
fastify.log.trace(
|
|
89
|
+
"[fastify-rabbitmq] Decorate Fastify with Namespace: %",
|
|
90
|
+
namespace
|
|
91
|
+
);
|
|
92
|
+
fastify.rabbitmq[namespace] = connection;
|
|
93
|
+
} else {
|
|
94
|
+
if (typeof fastify.rabbitmq !== "undefined") {
|
|
95
|
+
throw new errors.FASTIFY_RABBIT_MQ_ERR_SETUP_ERRORS(
|
|
96
|
+
"Already registered."
|
|
97
|
+
);
|
|
50
98
|
}
|
|
99
|
+
}
|
|
100
|
+
if (typeof fastify.rabbitmq === "undefined") {
|
|
101
|
+
fastify.log.trace("[fastify-rabbitmq] Decorate Fastify");
|
|
102
|
+
fastify.decorate("rabbitmq", connection);
|
|
103
|
+
}
|
|
51
104
|
};
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
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);
|
|
105
|
+
var fastifyRabbit = (0, import_fastify_plugin.default)(async (fastify, opts) => {
|
|
106
|
+
await validateOpts(opts);
|
|
107
|
+
const { connection } = opts;
|
|
108
|
+
const c = new import_rabbitmq_client.Connection(connection);
|
|
109
|
+
decorateFastifyInstance(fastify, opts, c);
|
|
110
|
+
});
|
|
111
|
+
var index_default = fastifyRabbit;
|
|
112
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
113
|
+
0 && (module.exports = {
|
|
114
|
+
decorateFastifyInstance
|
|
76
115
|
});
|
|
77
|
-
exports.default = fastifyRabbit;
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
// src/index.ts
|
|
2
|
+
import fp from "fastify-plugin";
|
|
3
|
+
import {
|
|
4
|
+
Connection as RabbitMQConnection
|
|
5
|
+
} from "rabbitmq-client";
|
|
6
|
+
|
|
7
|
+
// src/errors.ts
|
|
8
|
+
import createError from "@fastify/error";
|
|
9
|
+
var errors = {
|
|
10
|
+
/** Error if there is an invalid option used during registration. */
|
|
11
|
+
FASTIFY_RABBIT_MQ_ERR_INVALID_OPTS: createError(
|
|
12
|
+
"FASTIFY_RABBIT_MQ_ERR_INVALID_OPTS",
|
|
13
|
+
"Invalid options: %s"
|
|
14
|
+
),
|
|
15
|
+
/** Error if there is an setup error of the plugin itself. */
|
|
16
|
+
FASTIFY_RABBIT_MQ_ERR_SETUP_ERRORS: createError(
|
|
17
|
+
"FASTIFY_RABBIT_MQ_ERR_SETUP_ERRORS",
|
|
18
|
+
"Setup error: %s"
|
|
19
|
+
),
|
|
20
|
+
/** If an invalid usage error was done, this error would pop up. */
|
|
21
|
+
FASTIFY_RABBIT_MQ_ERR_USAGE: createError(
|
|
22
|
+
"FASTIFY_RABBIT_MQ_ERR_USAGE",
|
|
23
|
+
"Usage error: %s"
|
|
24
|
+
)
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
// src/validation.ts
|
|
28
|
+
var validateOpts = async (options) => {
|
|
29
|
+
if (typeof options.connection === "undefined") {
|
|
30
|
+
throw new errors.FASTIFY_RABBIT_MQ_ERR_INVALID_OPTS(
|
|
31
|
+
"connection or findServers must be defined."
|
|
32
|
+
);
|
|
33
|
+
}
|
|
34
|
+
if (typeof options.connection !== "undefined") {
|
|
35
|
+
if (typeof options.connection !== "object") {
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
// src/index.ts
|
|
41
|
+
var decorateFastifyInstance = (fastify, options, connection) => {
|
|
42
|
+
const { namespace = "" } = options;
|
|
43
|
+
if (typeof namespace !== "undefined" && namespace !== "") {
|
|
44
|
+
fastify.log.debug("[fastify-rabbitmq] Namespace Attempt: %s", namespace);
|
|
45
|
+
}
|
|
46
|
+
if (typeof namespace !== "undefined" && namespace !== "") {
|
|
47
|
+
if (typeof fastify.rabbitmq === "undefined") {
|
|
48
|
+
fastify.decorate("rabbitmq", /* @__PURE__ */ Object.create(null));
|
|
49
|
+
}
|
|
50
|
+
if (typeof fastify.rabbitmq[namespace] !== "undefined") {
|
|
51
|
+
throw new errors.FASTIFY_RABBIT_MQ_ERR_SETUP_ERRORS(
|
|
52
|
+
`Already registered with namespace: ${namespace}`
|
|
53
|
+
);
|
|
54
|
+
}
|
|
55
|
+
fastify.log.trace(
|
|
56
|
+
"[fastify-rabbitmq] Decorate Fastify with Namespace: %",
|
|
57
|
+
namespace
|
|
58
|
+
);
|
|
59
|
+
fastify.rabbitmq[namespace] = connection;
|
|
60
|
+
} else {
|
|
61
|
+
if (typeof fastify.rabbitmq !== "undefined") {
|
|
62
|
+
throw new errors.FASTIFY_RABBIT_MQ_ERR_SETUP_ERRORS(
|
|
63
|
+
"Already registered."
|
|
64
|
+
);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
if (typeof fastify.rabbitmq === "undefined") {
|
|
68
|
+
fastify.log.trace("[fastify-rabbitmq] Decorate Fastify");
|
|
69
|
+
fastify.decorate("rabbitmq", connection);
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
var fastifyRabbit = fp(async (fastify, opts) => {
|
|
73
|
+
await validateOpts(opts);
|
|
74
|
+
const { connection } = opts;
|
|
75
|
+
const c = new RabbitMQConnection(connection);
|
|
76
|
+
decorateFastifyInstance(fastify, opts, c);
|
|
77
|
+
});
|
|
78
|
+
var index_default = fastifyRabbit;
|
|
79
|
+
export {
|
|
80
|
+
decorateFastifyInstance,
|
|
81
|
+
index_default as default
|
|
82
|
+
};
|
package/lib/types/index.d.ts
CHANGED
|
@@ -1,7 +1,40 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
export
|
|
1
|
+
import * as fastify from 'fastify';
|
|
2
|
+
import { FastifyInstance } from 'fastify';
|
|
3
|
+
import { ConnectionOptions, Connection } from 'rabbitmq-client';
|
|
4
|
+
export { ConnectionOptions } from 'rabbitmq-client';
|
|
5
|
+
|
|
6
|
+
interface FastifyRabbitMQOptions {
|
|
7
|
+
/**
|
|
8
|
+
* @since 1.0.0
|
|
9
|
+
* @remarks Connection String or object pointing to the RabbitMQ Broker Services
|
|
10
|
+
*/
|
|
11
|
+
connection: string | ConnectionOptions;
|
|
12
|
+
/**
|
|
13
|
+
* @since 1.0.0
|
|
14
|
+
* @remarks To set the custom nNamespace within this plugin instance. Used to register this plugin more than one time.
|
|
15
|
+
*/
|
|
16
|
+
namespace?: string;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
declare module "fastify" {
|
|
20
|
+
interface FastifyInstance {
|
|
21
|
+
/** Main Decorator for Fastify **/
|
|
22
|
+
rabbitmq: Connection & fastifyRabbitMQ.FastifyRabbitMQNO;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
declare namespace fastifyRabbitMQ {
|
|
26
|
+
interface FastifyRabbitMQNO {
|
|
27
|
+
[namespace: string]: Connection;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* How we talk with Fastify
|
|
33
|
+
* @since 1.0.0
|
|
34
|
+
* @param fastify
|
|
35
|
+
* @param options
|
|
36
|
+
* @param connection
|
|
37
|
+
*/
|
|
5
38
|
declare const decorateFastifyInstance: (fastify: FastifyInstance, options: FastifyRabbitMQOptions, connection: any) => void;
|
|
6
39
|
/**
|
|
7
40
|
* Main Function
|
|
@@ -21,6 +54,6 @@ declare const decorateFastifyInstance: (fastify: FastifyInstance, options: Fasti
|
|
|
21
54
|
* @see [https://cody-greene.github.io/node-rabbitmq-client/latest/index.html](https://cody-greene.github.io/node-rabbitmq-client/latest/index.html)
|
|
22
55
|
*
|
|
23
56
|
*/
|
|
24
|
-
declare const fastifyRabbit:
|
|
25
|
-
|
|
26
|
-
export { decorateFastifyInstance,
|
|
57
|
+
declare const fastifyRabbit: fastify.FastifyPluginCallback<FastifyRabbitMQOptions, fastify.RawServerDefault, fastify.FastifyTypeProviderDefault, fastify.FastifyBaseLogger>;
|
|
58
|
+
|
|
59
|
+
export { type FastifyRabbitMQOptions, decorateFastifyInstance, fastifyRabbit as default, fastifyRabbitMQ };
|
package/package.json
CHANGED
|
@@ -1,92 +1,97 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "fastify-rabbitmq",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.3.0",
|
|
4
4
|
"description": "A Fastify RabbitMQ Plugin Developed in Pure TypeScript.",
|
|
5
|
-
"
|
|
6
|
-
|
|
7
|
-
|
|
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
24
|
"types": "./lib/types/index.d.ts",
|
|
11
|
-
"import": "./lib/esm/index.
|
|
25
|
+
"import": "./lib/esm/index.mjs",
|
|
12
26
|
"require": "./lib/cjs/index.js",
|
|
13
27
|
"default": "./lib/cjs/index.js"
|
|
14
28
|
}
|
|
15
29
|
},
|
|
30
|
+
"main": "./lib/cjs/index.js",
|
|
31
|
+
"module": "./lib/esm/index.mjs",
|
|
32
|
+
"types": "./lib/types/index.d.ts",
|
|
16
33
|
"files": [
|
|
17
34
|
"lib/",
|
|
18
35
|
"README.md",
|
|
19
36
|
"LICENSE"
|
|
20
37
|
],
|
|
21
|
-
"engines": {
|
|
22
|
-
"node": ">=20.11.0"
|
|
23
|
-
},
|
|
24
38
|
"scripts": {
|
|
39
|
+
"build": "tsup",
|
|
40
|
+
"build:dev": "NODE_ENV=development tsup",
|
|
25
41
|
"clean": "rm -rf coverage docs lib temp",
|
|
26
|
-
"
|
|
27
|
-
"
|
|
28
|
-
"
|
|
29
|
-
"
|
|
30
|
-
"
|
|
31
|
-
"lint": "
|
|
32
|
-
"lint:fix": "npm run npm:lint && eslint --fix | snazzy",
|
|
42
|
+
"format:check": "prettier --check '**/*.{md,ts,json,mts}'",
|
|
43
|
+
"format:write": "prettier --write '**/*.{md,ts,json,mts}'",
|
|
44
|
+
"lint": "npm run lint:npm && eslint | snazzy && npm run format:check",
|
|
45
|
+
"lint:fix": "npm run lint:npm && eslint --fix | snazzy && npm run format:write",
|
|
46
|
+
"lint:npm": "npmPkgJsonLint .",
|
|
47
|
+
"lint:package": "npx sort-package-json",
|
|
33
48
|
"pack": "npm pack",
|
|
34
49
|
"prepublishOnly": "npm run clean && npm run build && npm run pack",
|
|
35
50
|
"test": "vitest run",
|
|
51
|
+
"test:coverage": "vitest --coverage",
|
|
36
52
|
"test:verbose": "vitest run --reporter verbose",
|
|
37
53
|
"test:watch": "vitest watch",
|
|
38
|
-
"test:coverage": "vitest --coverage",
|
|
39
54
|
"typedoc": "typedoc",
|
|
40
55
|
"typedoc:watch": "typedoc -watch",
|
|
41
56
|
"update": "npx npm-check-updates -u --enginesNode && npm run update:post-update",
|
|
42
57
|
"update:post-update": "npm install && npm run test"
|
|
43
58
|
},
|
|
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
|
-
},
|
|
60
|
-
"homepage": "https://github.com/Bugs5382/fastify-rabbitmq#readme",
|
|
61
59
|
"dependencies": {
|
|
62
|
-
"@fastify/error": "^4.
|
|
60
|
+
"@fastify/error": "^4.1.0",
|
|
63
61
|
"fastify-plugin": "^5.0.1",
|
|
64
|
-
"rabbitmq-client": "^5.0.
|
|
62
|
+
"rabbitmq-client": "^5.0.4"
|
|
65
63
|
},
|
|
66
64
|
"devDependencies": {
|
|
67
|
-
"@eslint/js": "^9.
|
|
68
|
-
"@
|
|
69
|
-
"@
|
|
70
|
-
"@types/node": "^22.
|
|
71
|
-
"@
|
|
72
|
-
"@typescript-eslint/
|
|
73
|
-
"@
|
|
74
|
-
"@vitest/
|
|
75
|
-
"
|
|
76
|
-
"eslint": "^
|
|
77
|
-
"eslint-
|
|
78
|
-
"eslint-plugin-
|
|
79
|
-
"fastify": "^5.
|
|
80
|
-
"npm-check-updates": "^
|
|
65
|
+
"@eslint/js": "^9.28.0",
|
|
66
|
+
"@ianvs/prettier-plugin-sort-imports": "^4.4.2",
|
|
67
|
+
"@shipgirl/typedoc-plugin-versions": "^0.3.1",
|
|
68
|
+
"@types/node": "^22.15.29",
|
|
69
|
+
"@typescript-eslint/eslint-plugin": "^8.33.0",
|
|
70
|
+
"@typescript-eslint/parser": "^8.33.0",
|
|
71
|
+
"@vitest/coverage-v8": "^3.1.4",
|
|
72
|
+
"@vitest/ui": "^3.1.4",
|
|
73
|
+
"eslint": "^9.28.0",
|
|
74
|
+
"eslint-config-prettier": "^10.1.5",
|
|
75
|
+
"eslint-plugin-prettier": "^5.4.1",
|
|
76
|
+
"eslint-plugin-sort-class-members": "^1.21.0",
|
|
77
|
+
"fastify": "^5.3.3",
|
|
78
|
+
"npm-check-updates": "^18.0.1",
|
|
81
79
|
"npm-package-json-lint": "^8.0.0",
|
|
80
|
+
"npm-package-json-lint-config-default": "^7.0.1",
|
|
82
81
|
"pre-commit": "^1.2.2",
|
|
82
|
+
"prettier-plugin-organize-imports": "^4.1.0",
|
|
83
83
|
"snazzy": "^9.0.0",
|
|
84
|
+
"sort-package-json": "^3.2.1",
|
|
84
85
|
"ts-node": "^10.9.2",
|
|
85
|
-
"tsd": "^0.
|
|
86
|
-
"
|
|
87
|
-
"
|
|
88
|
-
"typescript
|
|
89
|
-
"
|
|
86
|
+
"tsd": "^0.32.0",
|
|
87
|
+
"tsup": "^8.5.0",
|
|
88
|
+
"typedoc": "^0.28.5",
|
|
89
|
+
"typescript": "^5.8.3",
|
|
90
|
+
"typescript-eslint": "^8.33.0",
|
|
91
|
+
"vitest": "^3.1.4"
|
|
92
|
+
},
|
|
93
|
+
"engines": {
|
|
94
|
+
"node": ">=20.11.0"
|
|
90
95
|
},
|
|
91
96
|
"precommit": [
|
|
92
97
|
"test",
|
package/lib/cjs/decorate.js
DELETED
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/package.json
DELETED
package/lib/cjs/types.js
DELETED
package/lib/cjs/validation.js
DELETED
|
@@ -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;
|
package/lib/esm/decorate.d.ts
DELETED
|
@@ -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
|
-
}
|
package/lib/esm/decorate.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/lib/esm/errors.d.ts
DELETED
|
@@ -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.d.ts
DELETED
|
@@ -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 };
|
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 };
|
package/lib/esm/package.json
DELETED
package/lib/esm/types.d.ts
DELETED
|
@@ -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 {};
|
package/lib/esm/validation.d.ts
DELETED
package/lib/esm/validation.js
DELETED
|
@@ -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
|
-
};
|
package/lib/types/decorate.d.ts
DELETED
|
@@ -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
|
-
}
|
package/lib/types/errors.d.ts
DELETED
|
@@ -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/types/types.d.ts
DELETED
|
@@ -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
|
-
}
|