fastify-rabbitmq 0.0.1-alpha.1 → 0.0.1-alpha.2

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.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { Channel, ConfirmChannel } from "amqplib";
1
+ import { Channel, ConfirmChannel } from 'amqplib';
2
2
  import { ChannelWrapper } from 'amqp-connection-manager';
3
3
  import type { AmqpConnectionManager, AmqpConnectionManagerOptions, ConnectionUrl } from 'amqp-connection-manager';
4
4
  import { FastifyInstance } from 'fastify';
package/dist/index.js CHANGED
@@ -20,10 +20,10 @@ const decorateFastifyInstance = (fastify, options, connection) => {
20
20
  const { logLevel = 'silent', namespace = '' } = options;
21
21
  // override log level
22
22
  const logger = fastify.log.child({}, { level: logLevel });
23
- if (namespace != '') {
23
+ if (namespace !== '') {
24
24
  logger.debug('[fastify-rabbitmq] Namespace: %s', namespace);
25
25
  }
26
- if (namespace != '') {
26
+ if (namespace !== '') {
27
27
  if (typeof fastify.rabbitmq === 'undefined') {
28
28
  fastify.decorate('rabbitmq', connection);
29
29
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fastify-rabbitmq",
3
- "version": "0.0.1-alpha.1",
3
+ "version": "0.0.1-alpha.2",
4
4
  "description": "A Fastify RabbitMQ Plugin Developed in Pure TypeScript using the AMQPLIB",
5
5
  "type": "module",
6
6
  "types": "dist/index.d.ts",
@@ -10,6 +10,7 @@
10
10
  "build:watch": "tsc -w",
11
11
  "lint": "ts-standard",
12
12
  "lint:fix": "ts-standard --fix",
13
+ "test": "jest",
13
14
  "update": "npx npm-check-updates -u && npm install"
14
15
  },
15
16
  "repository": {
@@ -36,11 +37,16 @@
36
37
  },
37
38
  "devDependencies": {
38
39
  "@types/amqplib": "^0.10.1",
39
- "@types/node": "^20.4.9",
40
+ "@types/jest": "^29.5.3",
41
+ "@types/node": "^20.4.10",
40
42
  "fastify": "^4.21.0",
41
- "npm-check-updates": "^16.10.18",
43
+ "jest": "^29.6.2",
44
+ "npm-check-updates": "^16.11.1",
42
45
  "pre-commit": "^1.2.2",
46
+ "ts-jest": "^29.1.1",
47
+ "ts-node": "^10.9.1",
43
48
  "ts-standard": "^12.0.2",
49
+ "tsd": "^0.28.1",
44
50
  "typescript": "^5.1.6"
45
51
  },
46
52
  "pre-commit": []
@@ -1,8 +0,0 @@
1
- version: 2
2
- updates:
3
- - package-ecosystem: npm
4
- directory: "/"
5
- schedule:
6
- interval: daily
7
- time: "10:00"
8
- open-pull-requests-limit: 10
@@ -1,8 +0,0 @@
1
- version: '3.2'
2
- services:
3
- rabbitmq:
4
- image: rabbitmq:3-management-alpine
5
- container_name: 'rabbitmq'
6
- ports:
7
- - 5672:5672
8
- - 15672:15672
package/src/index.ts DELETED
@@ -1,116 +0,0 @@
1
- import {Channel, ConfirmChannel} from "amqplib";
2
- import amqp, { ChannelWrapper } from 'amqp-connection-manager'
3
- import type {
4
- AmqpConnectionManager,
5
- AmqpConnectionManagerOptions,
6
- ConnectionUrl
7
- } from 'amqp-connection-manager'
8
- import { FastifyInstance } from 'fastify'
9
- import fp from 'fastify-plugin'
10
-
11
- import FastifyRabbitMQOptions = fastifyRabbitMQ.FastifyRabbitMQOptions
12
- import FastifyRabbitMQObject = fastifyRabbitMQ.FastifyRabbitMQObject
13
-
14
- declare module 'fastify' {
15
-
16
- interface FastifyInstance {
17
- rabbitmq: FastifyRabbitMQObject & fastifyRabbitMQ.FastifyRabbitMQNestedObject
18
- }
19
-
20
- }
21
-
22
- declare namespace fastifyRabbitMQ {
23
-
24
- export interface FastifyRabbitMQObject extends AmqpConnectionManager {
25
- channel?: ChannelWrapper
26
- }
27
-
28
- export interface FastifyRabbitMQNestedObject {
29
- [namespace: string]: FastifyRabbitMQObject
30
- }
31
-
32
- export interface FastifyRabbitMQOptions extends AmqpConnectionManagerOptions {
33
- logLevel?: 'trace' | 'debug' | 'info' | 'warn' | 'error'
34
- namespace?: string
35
- urLs: ConnectionUrl | ConnectionUrl[] | undefined | null
36
- }
37
-
38
- }
39
-
40
- /**
41
- * decorateFastifyInstance
42
- * @since 0.0.1
43
- * @param fastify
44
- * @param options
45
- * @param connection
46
- */
47
- const decorateFastifyInstance = (fastify: FastifyInstance, options: FastifyRabbitMQOptions, connection: any): void => {
48
- const {
49
- logLevel = 'silent',
50
- namespace = ''
51
- } = options
52
-
53
- // override log level
54
- const logger = fastify.log.child({}, { level: logLevel })
55
-
56
- if (namespace != '') {
57
- logger.debug('[fastify-rabbitmq] Namespace: %s', namespace)
58
- }
59
-
60
- if (namespace != '') {
61
- if (typeof fastify.rabbitmq === 'undefined') {
62
- fastify.decorate('rabbitmq', connection)
63
- }
64
- if (fastify.rabbitmq[namespace] != null) {
65
- throw Error('[fastify-rabbitmq] Connection name already registered: ' + namespace)
66
- }
67
- logger.trace('[fastify-rabbitmq] Decorate Fastify with Namespace: %', namespace)
68
- fastify.rabbitmq[namespace] = connection
69
- } else {
70
- if (typeof fastify.rabbitmq !== 'undefined') {
71
- throw Error('[fastify-rabbitmq] Already registered')
72
- }
73
- }
74
-
75
- if (typeof fastify.rabbitmq === 'undefined') {
76
- logger.trace('[fastify-rabbitmq] Decorate Fastify')
77
- fastify.decorate('rabbitmq', connection)
78
- }
79
- }
80
-
81
- const fastifyRabbit = fp(async (fastify: FastifyInstance, options: FastifyRabbitMQOptions): Promise<void> => {
82
- const {
83
- logLevel = 'silent',
84
- urLs,
85
- heartbeatIntervalInSeconds,
86
- reconnectTimeInSeconds,
87
- findServers,
88
- connectionOptions
89
- } = options
90
-
91
- // override log level
92
- const logger = fastify.log.child({}, { level: logLevel })
93
-
94
- const connection = amqp.connect(urLs, {
95
- heartbeatIntervalInSeconds,
96
- reconnectTimeInSeconds,
97
- findServers,
98
- connectionOptions
99
- })
100
-
101
- connection.on('connect', function () {
102
- logger.debug('[fastify-rabbitmq] Connection to RabbitMQ Successful')
103
- })
104
-
105
- connection.on('disconnect', function () {
106
- logger.debug('[fastify-rabbitmq] Connection to RabbitMQ Disconnected')
107
- })
108
-
109
- /**
110
- * Decorate Fastify
111
- */
112
- decorateFastifyInstance(fastify, options, connection)
113
- })
114
-
115
- export { Channel, ConfirmChannel }
116
- export default fastifyRabbit
package/tsconfig.json DELETED
@@ -1,34 +0,0 @@
1
- {
2
- "files": [
3
- "src/index.ts"
4
- ],
5
- "compilerOptions": {
6
- "target": "es2015",
7
- "module": "es2015",
8
- "moduleResolution": "node",
9
- "declaration": true,
10
- "outDir": "./dist",
11
- "noEmit": false,
12
- "strict": true,
13
- "noImplicitAny": true,
14
- "strictNullChecks": true,
15
- "strictFunctionTypes": true,
16
- "strictBindCallApply": true,
17
- "strictPropertyInitialization": true,
18
- "noImplicitThis": true,
19
- "alwaysStrict": true,
20
- "noUnusedLocals": true,
21
- "noUnusedParameters": true,
22
- "noImplicitReturns": true,
23
- "noFallthroughCasesInSwitch": true,
24
- "noUncheckedIndexedAccess": true,
25
- "noImplicitOverride": true,
26
- "noPropertyAccessFromIndexSignature": true,
27
- "esModuleInterop": true,
28
- "forceConsistentCasingInFileNames": true,
29
- "skipLibCheck": true
30
- },
31
- "exclude": [
32
- "node_modules"
33
- ]
34
- }