@hastehaul/common 1.0.15 → 1.0.17

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.
@@ -1,6 +1,8 @@
1
1
  import { NatsConnection, ConsumerConfig, JsMsg } from "nats";
2
- import { DurableName, Subjects, Streams } from "../common/enums";
3
2
  import { MainSubjects, ValidateSubjectFormat } from "../common/enums/subjects/main-subjects";
3
+ import { Subjects } from '../common/enums/subjects';
4
+ import { DurableName } from '../common/enums/durable-names';
5
+ import { Streams } from '../common/enums/streams';
4
6
  /**
5
7
  * Interface representing an event published to NATS.
6
8
  */
@@ -1,6 +1,6 @@
1
1
  import { PubAck, NatsConnection } from "nats";
2
- import { Subjects } from "../common/enums";
3
2
  import { MainSubjects, ValidateSubjectFormat } from "../common/enums/subjects/main-subjects";
3
+ import { Subjects } from '../common/enums/subjects';
4
4
  /**
5
5
  * Interface representing an event to be published to NATS.
6
6
  */
@@ -1,6 +1,6 @@
1
1
  import { NatsConnection } from "nats";
2
- import { Streams } from "../common/enums";
3
2
  import { MainSubjects } from "../common/enums/subjects/main-subjects";
3
+ import { Streams } from '../common/enums/streams';
4
4
  /**
5
5
  * Interface representing an event to be used with NATS streams.
6
6
  */
package/build/index.d.ts CHANGED
@@ -1,5 +1,166 @@
1
- export * from "./connections-wrappers";
2
- export * from "./errors";
3
- export * from "./middlewares";
4
- export * from "./utils";
5
- export * from "./events";
1
+ /**
2
+ * Re-exports all the contents from the "redis-connection-wrapper" module.
3
+ *
4
+ * The "redis-connection-wrapper" module contains a class that wraps the Redis client connection and provides easy access to the Redis client instance.
5
+ * It also includes error handling and connection management features.
6
+ */
7
+ export * from "./connections-wrappers/redis-connection-wrapper";
8
+ /**
9
+ * Re-exports all the contents from the "socket-connection-wrapper" module.
10
+ *
11
+ * The "socket-connection-wrapper" module contains a class that wraps the Socket.IO server connection and provides easy access to the Socket.IO server instance.
12
+ * It includes error handling and connection management features for Socket.IO server connections.
13
+ */
14
+ export * from "./connections-wrappers/socket-connection-wrapper";
15
+ /**
16
+ * Re-exports all the contents from the "nats-wrapper" module.
17
+ *
18
+ * The "nats-wrapper" module contains a class that wraps the NATS (NATS Streaming Server) client connection and provides easy access to the NATS client instance.
19
+ * It includes error handling and connection management features for NATS client connections.
20
+ */
21
+ export * from "./connections-wrappers/nats-wrapper";
22
+ /**
23
+ * Re-exports the "BadRequestError" class from the "bad-request-error" file.
24
+ *
25
+ * The "BadRequestError" class represents a specific "Bad Request" error and is used to handle client requests with invalid or malformed data.
26
+ */
27
+ export * from "./errors/bad-request-error";
28
+ /**
29
+ * Re-exports the "CustomError" abstract class from the "custom-error" file.
30
+ *
31
+ * The "CustomError" abstract class serves as the foundation for creating specific error classes for different types of errors.
32
+ */
33
+ export * from "./errors/custom-error";
34
+ /**
35
+ * Re-exports the "DatabaseError" class from the "database-error" file.
36
+ *
37
+ * The "DatabaseError" class represents a specific error related to database operations or connectivity issues.
38
+ */
39
+ export * from "./errors/database-error";
40
+ /**
41
+ * Re-exports the "NotFoundError" class from the "not-found-error" file.
42
+ *
43
+ * The "NotFoundError" class represents a specific "Not Found" error and is used when a requested resource is not found.
44
+ */
45
+ export * from "./errors/not-found-error";
46
+ /**
47
+ * Re-exports the "SystemError" class from the "system-error" file.
48
+ *
49
+ * The "SystemError" class represents a specific "System Error" that can occur due to unexpected issues in the system.
50
+ */
51
+ export * from "./errors/system-error";
52
+ /**
53
+ * Re-exports the "currentUser" middleware from the "current-user" module.
54
+ *
55
+ * The "currentUser" middleware is used to extract and verify the current user's information from the request headers.
56
+ * It checks for a valid bearer token in the "Authorization" header, verifies the JWT token, and attaches the user payload to the request object for further processing in subsequent middleware or route handlers.
57
+ */
58
+ export * from "./middlewares/current-user";
59
+ /**
60
+ * Re-exports the "errorHandler" middleware from the "error-handler" module.
61
+ *
62
+ * The "errorHandler" middleware is a custom error-handling middleware used to handle and respond to errors that occur during request processing.
63
+ * It intercepts any uncaught errors in the application, such as custom errors or other exceptions, and sends appropriate error responses to the client.
64
+ * If the error is a custom error (e.g., BadRequestError, NotFoundError, DatabaseError, etc.), the middleware serializes the error and sends it with the corresponding status code and error messages.
65
+ * If the error is not a custom error, a generic error response is sent with a 500 status code and a default error message.
66
+ */
67
+ export * from "./middlewares/error-handler";
68
+ /**
69
+ *? Re-exports all the enums from the "enums" module.
70
+ *
71
+ * The "enums" module contains various enumerations used in the application.
72
+ * Enumerations are used to define named constant values, such as status codes, subject names, or stream names.
73
+ */
74
+ export * from "./utils/enums";
75
+ /**
76
+ *? Re-exports all the functions related to reading directories from the "read-dir" module.
77
+ *
78
+ * The "read-dir" module contains utility functions to read and access files and directories in the application.
79
+ * These functions are used for dynamic loading, configuration, and other file-related operations.
80
+ */
81
+ export * from "./utils/read-dir";
82
+ /**
83
+ *? Re-exports all the contents from the "base-producers" module.
84
+ *
85
+ * The "base-producers" module contains base classes and utilities for implementing job producers in the application.
86
+ * Job producers are responsible for generating and queuing jobs to be processed by job workers.
87
+ */
88
+ export * from "./utils/base_classes/jobs/base-producers";
89
+ /**
90
+ *? Re-exports all the contents from the "base-worker" module.
91
+ *
92
+ * The "base-worker" module contains base classes and utilities for implementing job workers in the application.
93
+ * Job workers are responsible for processing jobs generated by job producers and executing the required tasks.
94
+ */
95
+ export * from "./utils/base_classes/jobs/base-worker";
96
+ /**
97
+ *? Re-exports all the contents from the "base-namespace" module.
98
+ *
99
+ * The "base-namespace" module contains base classes and utilities for implementing custom namespaces in the application.
100
+ * Custom namespaces provide separate channels for communication between connected clients and the server, allowing for organized event handling within separate contexts.
101
+ */
102
+ export * from "./utils/base_classes/listeners/base-namespace";
103
+ /**
104
+ *? Re-exports the "BaseConsumer" class from the "base-consumer" file.
105
+ *
106
+ * The "BaseConsumer" class serves as a base class for implementing event consumers.
107
+ * It provides common functionality and methods that can be extended by specific consumer implementations.
108
+ */
109
+ export * from "./events/base/base-consumer";
110
+ /**
111
+ * Re-exports the "BasePublisher" class from the "base-publisher" file.
112
+ *
113
+ * The "BasePublisher" class serves as a base class for implementing event publishers.
114
+ * It provides common functionality and methods that can be extended by specific publisher implementations.
115
+ */
116
+ export * from "./events/base/base-publisher";
117
+ /**
118
+ * Re-exports the "BaseStream" class from the "base-stream" file.
119
+ *
120
+ * The "BaseStream" class serves as a base class for implementing event streams.
121
+ * It provides common functionality and methods that can be extended by specific stream implementations.
122
+ */
123
+ export * from "./events/base/base-stream";
124
+ /**
125
+ * Re-exports the "OrderCancelledEvent" class from the "order-cancelled-event" file.
126
+ *
127
+ * The "OrderCancelledEvent" class represents an event related to the cancellation of an order.
128
+ */
129
+ export * from "./events/common/interfaces/order-events-interfaces/order-cancelled-event";
130
+ /**
131
+ * Re-exports the "OrderCompletedEvent" class from the "order-completed-event" file.
132
+ *
133
+ * The "OrderCompletedEvent" class represents an event related to the completion of an order.
134
+ */
135
+ export * from "./events/common/interfaces/order-events-interfaces/order-completed-event";
136
+ /**
137
+ * Re-exports the "OrderRequestedEvent" class from the "order-requested-event" file.
138
+ *
139
+ * The "OrderRequestedEvent" class represents an event related to a request for an order.
140
+ */
141
+ export * from "./events/common/interfaces/order-events-interfaces/order-requested-event";
142
+ /**
143
+ * Re-exports all the interfaces related to streams from the "stream-interfaces" file.
144
+ *
145
+ * The "stream-interfaces" file contains interfaces for various streams used in the application.
146
+ * For example, "OrderStreamEvent" represents an event associated with the "Order" stream.
147
+ */
148
+ export * from "./events/common/interfaces/stream-interfaces/order-stream-interface";
149
+ /**
150
+ * Re-exports all the types related to durable names from the "durable-names" file.
151
+ *
152
+ * The types include enums and utility types used to define durable names for consumers of different event types.
153
+ */
154
+ export * from "./events/common/enums/durable-names";
155
+ /**
156
+ * Re-exports the type related to streams from the "streams" file.
157
+ *
158
+ * The "Streams" type alias represents a JetStream stream that can handle different event types.
159
+ */
160
+ export * from "./events/common/enums/streams";
161
+ /**
162
+ * Re-exports the type related to subjects from the "subjects" file.
163
+ *
164
+ * The "Subjects" type alias represents the subjects for different event types.
165
+ */
166
+ export * from "./events/common/enums/subjects";
package/build/index.js CHANGED
@@ -1,4 +1,5 @@
1
1
  "use strict";
2
+ //* Import and re-export multiple modules related to connection wrappers.
2
3
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
4
  if (k2 === undefined) k2 = k;
4
5
  var desc = Object.getOwnPropertyDescriptor(m, k);
@@ -14,8 +15,177 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
15
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
16
  };
16
17
  Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./connections-wrappers"), exports);
18
- __exportStar(require("./errors"), exports);
19
- __exportStar(require("./middlewares"), exports);
20
- __exportStar(require("./utils"), exports);
21
- __exportStar(require("./events"), exports);
18
+ /**
19
+ * Re-exports all the contents from the "redis-connection-wrapper" module.
20
+ *
21
+ * The "redis-connection-wrapper" module contains a class that wraps the Redis client connection and provides easy access to the Redis client instance.
22
+ * It also includes error handling and connection management features.
23
+ */
24
+ __exportStar(require("./connections-wrappers/redis-connection-wrapper"), exports);
25
+ /**
26
+ * Re-exports all the contents from the "socket-connection-wrapper" module.
27
+ *
28
+ * The "socket-connection-wrapper" module contains a class that wraps the Socket.IO server connection and provides easy access to the Socket.IO server instance.
29
+ * It includes error handling and connection management features for Socket.IO server connections.
30
+ */
31
+ __exportStar(require("./connections-wrappers/socket-connection-wrapper"), exports);
32
+ /**
33
+ * Re-exports all the contents from the "nats-wrapper" module.
34
+ *
35
+ * The "nats-wrapper" module contains a class that wraps the NATS (NATS Streaming Server) client connection and provides easy access to the NATS client instance.
36
+ * It includes error handling and connection management features for NATS client connections.
37
+ */
38
+ __exportStar(require("./connections-wrappers/nats-wrapper"), exports);
39
+ //* Import and re-export custom error classes for easier access.
40
+ /**
41
+ * Re-exports the "BadRequestError" class from the "bad-request-error" file.
42
+ *
43
+ * The "BadRequestError" class represents a specific "Bad Request" error and is used to handle client requests with invalid or malformed data.
44
+ */
45
+ __exportStar(require("./errors/bad-request-error"), exports);
46
+ /**
47
+ * Re-exports the "CustomError" abstract class from the "custom-error" file.
48
+ *
49
+ * The "CustomError" abstract class serves as the foundation for creating specific error classes for different types of errors.
50
+ */
51
+ __exportStar(require("./errors/custom-error"), exports);
52
+ /**
53
+ * Re-exports the "DatabaseError" class from the "database-error" file.
54
+ *
55
+ * The "DatabaseError" class represents a specific error related to database operations or connectivity issues.
56
+ */
57
+ __exportStar(require("./errors/database-error"), exports);
58
+ /**
59
+ * Re-exports the "NotFoundError" class from the "not-found-error" file.
60
+ *
61
+ * The "NotFoundError" class represents a specific "Not Found" error and is used when a requested resource is not found.
62
+ */
63
+ __exportStar(require("./errors/not-found-error"), exports);
64
+ /**
65
+ * Re-exports the "SystemError" class from the "system-error" file.
66
+ *
67
+ * The "SystemError" class represents a specific "System Error" that can occur due to unexpected issues in the system.
68
+ */
69
+ __exportStar(require("./errors/system-error"), exports);
70
+ //* Import and re-export multiple middleware modules.
71
+ /**
72
+ * Re-exports the "currentUser" middleware from the "current-user" module.
73
+ *
74
+ * The "currentUser" middleware is used to extract and verify the current user's information from the request headers.
75
+ * It checks for a valid bearer token in the "Authorization" header, verifies the JWT token, and attaches the user payload to the request object for further processing in subsequent middleware or route handlers.
76
+ */
77
+ __exportStar(require("./middlewares/current-user"), exports);
78
+ /**
79
+ * Re-exports the "errorHandler" middleware from the "error-handler" module.
80
+ *
81
+ * The "errorHandler" middleware is a custom error-handling middleware used to handle and respond to errors that occur during request processing.
82
+ * It intercepts any uncaught errors in the application, such as custom errors or other exceptions, and sends appropriate error responses to the client.
83
+ * If the error is a custom error (e.g., BadRequestError, NotFoundError, DatabaseError, etc.), the middleware serializes the error and sends it with the corresponding status code and error messages.
84
+ * If the error is not a custom error, a generic error response is sent with a 500 status code and a default error message.
85
+ */
86
+ __exportStar(require("./middlewares/error-handler"), exports);
87
+ //* Import and re-export multiple modules for enums, base classes, and read-dir functionality.
88
+ /**
89
+ *? Re-exports all the enums from the "enums" module.
90
+ *
91
+ * The "enums" module contains various enumerations used in the application.
92
+ * Enumerations are used to define named constant values, such as status codes, subject names, or stream names.
93
+ */
94
+ __exportStar(require("./utils/enums"), exports);
95
+ /**
96
+ *? Re-exports all the functions related to reading directories from the "read-dir" module.
97
+ *
98
+ * The "read-dir" module contains utility functions to read and access files and directories in the application.
99
+ * These functions are used for dynamic loading, configuration, and other file-related operations.
100
+ */
101
+ __exportStar(require("./utils/read-dir"), exports);
102
+ /**
103
+ *? Re-exports all the contents from the "base-producers" module.
104
+ *
105
+ * The "base-producers" module contains base classes and utilities for implementing job producers in the application.
106
+ * Job producers are responsible for generating and queuing jobs to be processed by job workers.
107
+ */
108
+ __exportStar(require("./utils/base_classes/jobs/base-producers"), exports);
109
+ /**
110
+ *? Re-exports all the contents from the "base-worker" module.
111
+ *
112
+ * The "base-worker" module contains base classes and utilities for implementing job workers in the application.
113
+ * Job workers are responsible for processing jobs generated by job producers and executing the required tasks.
114
+ */
115
+ __exportStar(require("./utils/base_classes/jobs/base-worker"), exports);
116
+ /**
117
+ *? Re-exports all the contents from the "base-namespace" module.
118
+ *
119
+ * The "base-namespace" module contains base classes and utilities for implementing custom namespaces in the application.
120
+ * Custom namespaces provide separate channels for communication between connected clients and the server, allowing for organized event handling within separate contexts.
121
+ */
122
+ __exportStar(require("./utils/base_classes/listeners/base-namespace"), exports);
123
+ //* Import and re-export base classes for consumers, publishers, and streams.
124
+ /**
125
+ *? Re-exports the "BaseConsumer" class from the "base-consumer" file.
126
+ *
127
+ * The "BaseConsumer" class serves as a base class for implementing event consumers.
128
+ * It provides common functionality and methods that can be extended by specific consumer implementations.
129
+ */
130
+ __exportStar(require("./events/base/base-consumer"), exports);
131
+ /**
132
+ * Re-exports the "BasePublisher" class from the "base-publisher" file.
133
+ *
134
+ * The "BasePublisher" class serves as a base class for implementing event publishers.
135
+ * It provides common functionality and methods that can be extended by specific publisher implementations.
136
+ */
137
+ __exportStar(require("./events/base/base-publisher"), exports);
138
+ /**
139
+ * Re-exports the "BaseStream" class from the "base-stream" file.
140
+ *
141
+ * The "BaseStream" class serves as a base class for implementing event streams.
142
+ * It provides common functionality and methods that can be extended by specific stream implementations.
143
+ */
144
+ __exportStar(require("./events/base/base-stream"), exports);
145
+ //* Import and re-export multiple interfaces related to different events and streams.
146
+ /**
147
+ * Re-exports the "OrderCancelledEvent" class from the "order-cancelled-event" file.
148
+ *
149
+ * The "OrderCancelledEvent" class represents an event related to the cancellation of an order.
150
+ */
151
+ __exportStar(require("./events/common/interfaces/order-events-interfaces/order-cancelled-event"), exports);
152
+ /**
153
+ * Re-exports the "OrderCompletedEvent" class from the "order-completed-event" file.
154
+ *
155
+ * The "OrderCompletedEvent" class represents an event related to the completion of an order.
156
+ */
157
+ __exportStar(require("./events/common/interfaces/order-events-interfaces/order-completed-event"), exports);
158
+ /**
159
+ * Re-exports the "OrderRequestedEvent" class from the "order-requested-event" file.
160
+ *
161
+ * The "OrderRequestedEvent" class represents an event related to a request for an order.
162
+ */
163
+ __exportStar(require("./events/common/interfaces/order-events-interfaces/order-requested-event"), exports);
164
+ //! Interfaces related to payment events are currently commented out using '//'.
165
+ // export * from "./payment-event-interfaces";
166
+ /**
167
+ * Re-exports all the interfaces related to streams from the "stream-interfaces" file.
168
+ *
169
+ * The "stream-interfaces" file contains interfaces for various streams used in the application.
170
+ * For example, "OrderStreamEvent" represents an event associated with the "Order" stream.
171
+ */
172
+ __exportStar(require("./events/common/interfaces/stream-interfaces/order-stream-interface"), exports);
173
+ //* Import and re-export types from other files in events enums for easier access.
174
+ /**
175
+ * Re-exports all the types related to durable names from the "durable-names" file.
176
+ *
177
+ * The types include enums and utility types used to define durable names for consumers of different event types.
178
+ */
179
+ __exportStar(require("./events/common/enums/durable-names"), exports);
180
+ /**
181
+ * Re-exports the type related to streams from the "streams" file.
182
+ *
183
+ * The "Streams" type alias represents a JetStream stream that can handle different event types.
184
+ */
185
+ __exportStar(require("./events/common/enums/streams"), exports);
186
+ /**
187
+ * Re-exports the type related to subjects from the "subjects" file.
188
+ *
189
+ * The "Subjects" type alias represents the subjects for different event types.
190
+ */
191
+ __exportStar(require("./events/common/enums/subjects"), exports);
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.AbstractJobQueue = void 0;
4
4
  const bullmq_1 = require("bullmq");
5
- const connections_wrappers_1 = require("../../../connections-wrappers");
5
+ const redis_connection_wrapper_1 = require("../../../connections-wrappers/redis-connection-wrapper");
6
6
  /**
7
7
  * Abstract class representing a Job Queue.
8
8
  */
@@ -14,7 +14,7 @@ class AbstractJobQueue {
14
14
  */
15
15
  constructor(queueName) {
16
16
  // Initialize the job queue with the provided name and a Redis connection from the redisWrapper.
17
- this.que = new bullmq_1.Queue(queueName, { connection: connections_wrappers_1.redisWrapper.client });
17
+ this.que = new bullmq_1.Queue(queueName, { connection: redis_connection_wrapper_1.redisWrapper.client });
18
18
  }
19
19
  }
20
20
  exports.AbstractJobQueue = AbstractJobQueue;
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.AbstractWorker = void 0;
4
4
  const bullmq_1 = require("bullmq");
5
- const connections_wrappers_1 = require("../../../connections-wrappers");
5
+ const redis_connection_wrapper_1 = require("../../../connections-wrappers/redis-connection-wrapper");
6
6
  /**
7
7
  * Abstract class representing a worker for processing jobs from a Job Queue.
8
8
  */
@@ -15,7 +15,7 @@ class AbstractWorker {
15
15
  constructor(queueName) {
16
16
  // Create a worker instance with the provided queueName and bind the 'process' method to this worker.
17
17
  this.worker = new bullmq_1.Worker(queueName, this.process.bind(this), {
18
- connection: connections_wrappers_1.redisWrapper.client,
18
+ connection: redis_connection_wrapper_1.redisWrapper.client,
19
19
  autorun: false,
20
20
  });
21
21
  // Handle errors that may occur during job processing.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hastehaul/common",
3
- "version": "1.0.15",
3
+ "version": "1.0.17",
4
4
  "description": "",
5
5
  "main": "./build/index.js",
6
6
  "types": "./build/index.d.ts",