@skillstew/common 1.0.16 → 1.0.18

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.
@@ -5,13 +5,13 @@ const AppError_1 = require("./AppError");
5
5
  const MessageQueueErrorCodes_1 = require("./codes/MessageQueueErrorCodes");
6
6
  class InvalidEventPayloadError extends AppError_1.InfrastructureError {
7
7
  constructor(eventName, errorString) {
8
- super(MessageQueueErrorCodes_1.MessageQueueErrorCodes.INVALID_EVENT_PAYLOAD + `for ${eventName}`, "INVALID_EVENT_PAYLOAD", { zodErrorString: errorString });
8
+ super(MessageQueueErrorCodes_1.MessageQueueErrorCodes.INVALID_EVENT_PAYLOAD + ` for ${eventName}`, "INVALID_EVENT_PAYLOAD", { zodErrorString: errorString });
9
9
  }
10
10
  toJSON() {
11
11
  return {
12
12
  message: this.message,
13
13
  code: this.code,
14
- error: this.context.zodErrorStrings,
14
+ error: this.context.zodErrorString,
15
15
  };
16
16
  }
17
17
  }
@@ -1,6 +1,7 @@
1
1
  import { Channel } from "amqplib";
2
2
  import { EventName } from "./EventMap";
3
3
  import { AppEvent } from "./AppEvent";
4
+ type EventHandler<T extends EventName> = (event: AppEvent<T>) => Promise<HandlerResult>;
4
5
  export declare class Consumer {
5
6
  private _channel;
6
7
  private _exchange;
@@ -9,7 +10,7 @@ export declare class Consumer {
9
10
  constructor();
10
11
  init: (channel: Channel, exchange: string, serviceName: string, interestedEvents: (string | EventName)[]) => Promise<void>;
11
12
  private handleEvent;
12
- registerHandler: <T extends EventName>(eventName: T, handler: (event: AppEvent<T>) => Promise<HandlerResult>) => void;
13
+ registerHandler: <T extends EventName>(eventName: T, handler: EventHandler<T>) => void;
13
14
  }
14
15
  interface HandlerResult {
15
16
  success: boolean;
package/build/index.d.ts CHANGED
@@ -11,3 +11,6 @@ export * from "./types/UserRoles";
11
11
  export * from "./constants/HttpStatus";
12
12
  export * from "./events/AppEvent";
13
13
  export * from "./events/schemas/userEventsSchema";
14
+ export * from "./events/CreateEvent";
15
+ export * from "./events/Consumer";
16
+ export * from "./events/Producer";
package/build/index.js CHANGED
@@ -33,3 +33,6 @@ __exportStar(require("./constants/HttpStatus"), exports);
33
33
  // Events
34
34
  __exportStar(require("./events/AppEvent"), exports);
35
35
  __exportStar(require("./events/schemas/userEventsSchema"), exports);
36
+ __exportStar(require("./events/CreateEvent"), exports);
37
+ __exportStar(require("./events/Consumer"), exports);
38
+ __exportStar(require("./events/Producer"), exports);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@skillstew/common",
3
- "version": "1.0.16",
3
+ "version": "1.0.18",
4
4
  "main": "./build/index.js",
5
5
  "types": "./build/index.d.ts",
6
6
  "scripts": {
package/publish.sh CHANGED
@@ -21,9 +21,7 @@ read COMMIT_MESSAGE
21
21
  git commit -m "[common] $COMMIT_MESSAGE"
22
22
 
23
23
  # Step 5: Push to GitHub
24
- echo "Enter remote branch to push to:"
25
- read REMOTE_BRANCH
26
- git push -u origin "$REMOTE_BRANCH"
24
+ git push
27
25
 
28
26
  # Step 6: Publish to npm
29
27
  npm publish
@@ -5,7 +5,7 @@ import { MessageQueueErrorCodes } from "./codes/MessageQueueErrorCodes";
5
5
  export class InvalidEventPayloadError extends InfrastructureError {
6
6
  constructor(eventName: EventName, errorString: string) {
7
7
  super(
8
- MessageQueueErrorCodes.INVALID_EVENT_PAYLOAD + `for ${eventName}`,
8
+ MessageQueueErrorCodes.INVALID_EVENT_PAYLOAD + ` for ${eventName}`,
9
9
  "INVALID_EVENT_PAYLOAD",
10
10
  { zodErrorString: errorString },
11
11
  );
@@ -14,7 +14,7 @@ export class InvalidEventPayloadError extends InfrastructureError {
14
14
  return {
15
15
  message: this.message,
16
16
  code: this.code,
17
- error: this.context!.zodErrorStrings,
17
+ error: this.context!.zodErrorString,
18
18
  };
19
19
  }
20
20
  }
@@ -8,13 +8,15 @@ import {
8
8
  } from "../errors/MessageQueueErrors";
9
9
  import z from "zod";
10
10
 
11
+ type EventHandler<T extends EventName> = (event: AppEvent<T>) => Promise<HandlerResult>;
12
+
11
13
  export class Consumer {
12
14
  private _channel!: Channel;
13
15
  private _exchange!: string;
14
16
  private _initialized: boolean = false;
15
17
  private _handlers = new Map<
16
18
  EventName,
17
- (event: any) => Promise<HandlerResult>
19
+ EventHandler<EventName>
18
20
  >();
19
21
  constructor() {}
20
22
 
@@ -93,12 +95,12 @@ export class Consumer {
93
95
 
94
96
  registerHandler = <T extends EventName>(
95
97
  eventName: T,
96
- handler: (event: AppEvent<T>) => Promise<HandlerResult>,
98
+ handler: EventHandler<T>,
97
99
  ) => {
98
100
  if (!this._initialized) {
99
101
  throw new ConsumerUsedBeforeInitializationError();
100
102
  }
101
- this._handlers.set(eventName, handler);
103
+ this._handlers.set(eventName, handler as EventHandler<EventName>);
102
104
  };
103
105
  }
104
106
 
package/src/index.ts CHANGED
@@ -22,3 +22,6 @@ export * from "./constants/HttpStatus";
22
22
  // Events
23
23
  export * from "./events/AppEvent";
24
24
  export * from "./events/schemas/userEventsSchema";
25
+ export * from "./events/CreateEvent";
26
+ export * from "./events/Consumer";
27
+ export * from "./events/Producer";