@social-mail/social-mail-web-server 1.7.237 → 1.7.239

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@social-mail/social-mail-web-server",
3
- "version": "1.7.237",
3
+ "version": "1.7.239",
4
4
  "description": "## Phase 1",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -4,7 +4,7 @@ import PgEvents from "./PgEvents.js";
4
4
  import { globalEnv } from "../../../common/globalEnv.js";
5
5
 
6
6
  export interface IMessageChannel<T = string> {
7
- on(fx: (name: string, data: T) => any);
7
+ on(fx: (data: T) => any);
8
8
  notify(data: T);
9
9
  }
10
10
 
@@ -27,18 +27,18 @@ export default class MessagingService extends ServiceObject {
27
27
  }
28
28
 
29
29
  notify(messageName: string, data: any): any {
30
- return this.pgEvents.emit(messageName, JSON.stringify(data ?? ""));
30
+ return this.pgEvents.emit(messageName, data);
31
31
  }
32
32
 
33
33
  listen(messageName: string, fx: (name: string, data: any) => any): any {
34
34
  return this.pgEvents.listen(messageName, (msg, data) => {
35
- return fx(msg, JSON.parse(data));
35
+ return fx(msg, data);
36
36
  });
37
37
  }
38
38
 
39
39
  private segment(messageName: string): IMessageChannel<any> {
40
40
  return {
41
- on: (fx) => this.listen(messageName, (data) => fx(messageName, data)?.catch?.(console.error)),
41
+ on: (fx) => this.listen(messageName, (data) => fx(data)?.catch?.(console.error)),
42
42
  notify: (data) => this.notify(messageName, data)?.catch?.(console.error),
43
43
  };
44
44
  }
@@ -35,11 +35,12 @@ export default class PgEvents {
35
35
  c.on("notification", async ({ channel, payload}) => {
36
36
  try {
37
37
  console.log(`Notification received ${channel}`);
38
+ payload = JSON.parse(payload);
38
39
  const fx = this.handlers.get(channel);
39
40
  if (fx) {
40
41
  for (const { original, handler } of fx) {
41
42
  try {
42
- const p = handler(original as any, JSON.parse(payload));
43
+ const p = handler(original as any, payload);
43
44
  if (p?.then) {
44
45
  p.catch(console.error);
45
46
  }