@telperion/messenger 7.7.1 → 7.7.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/message-host.cjs CHANGED
@@ -23,7 +23,14 @@ class MessageHost {
23
23
  .pipe((0, operators_1.filter)(({ path: messagePath }) => path === messagePath))
24
24
  .subscribe(({ body, id }) => {
25
25
  for (const listener of listeners) {
26
- listener.call(this, body).pipe((0, operators_1.takeUntil)(this[selectors_1.TERMINATE_MESSAGE$].pipe((0, operators_1.filter)(terminatedMessageId => terminatedMessageId === id)))).subscribe({
26
+ let result$ = listener.call(this, body);
27
+ if (result$ instanceof Promise) {
28
+ result$ = (0, rxjs_1.from)(result$);
29
+ }
30
+ else if (!(result$ instanceof rxjs_1.Observable)) {
31
+ result$ = (0, rxjs_1.of)(result$);
32
+ }
33
+ result$.pipe((0, operators_1.takeUntil)(this[selectors_1.TERMINATE_MESSAGE$].pipe((0, operators_1.filter)(terminatedMessageId => terminatedMessageId === id)))).subscribe({
27
34
  next: result => {
28
35
  this[selectors_1.RESPONSE]({ completed: false, id, body: result });
29
36
  },
package/message-host.js CHANGED
@@ -1,4 +1,4 @@
1
- import { Subject } from 'rxjs';
1
+ import { from, Observable, of, Subject } from 'rxjs';
2
2
  import { filter, takeUntil } from 'rxjs/operators';
3
3
  import { LISTEN, MESSAGE_LISTENERS, RESPONSE, TERMINATE_MESSAGE$ } from './selectors';
4
4
  /**
@@ -20,7 +20,14 @@ export class MessageHost {
20
20
  .pipe(filter(({ path: messagePath }) => path === messagePath))
21
21
  .subscribe(({ body, id }) => {
22
22
  for (const listener of listeners) {
23
- listener.call(this, body).pipe(takeUntil(this[TERMINATE_MESSAGE$].pipe(filter(terminatedMessageId => terminatedMessageId === id)))).subscribe({
23
+ let result$ = listener.call(this, body);
24
+ if (result$ instanceof Promise) {
25
+ result$ = from(result$);
26
+ }
27
+ else if (!(result$ instanceof Observable)) {
28
+ result$ = of(result$);
29
+ }
30
+ result$.pipe(takeUntil(this[TERMINATE_MESSAGE$].pipe(filter(terminatedMessageId => terminatedMessageId === id)))).subscribe({
24
31
  next: result => {
25
32
  this[RESPONSE]({ completed: false, id, body: result });
26
33
  },
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../libs/messenger/src/message-host.ts"],"names":[],"mappings":"AAAA,OAAO,EAAc,OAAO,EAAE,MAAM,MAAM,CAAC;AAC3C,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAKnD,OAAO,EAAE,MAAM,EAAE,iBAAiB,EAAE,QAAQ,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAEtF;;GAEG;AACH,MAAM,OAAgB,WAAW;IAC/B;;;;OAIG;IACgB,CAAC,kBAAkB,CAAC,GAAG,IAAI,OAAO,EAAU,CAAC;IAEhE;;OAEG;IACgB,CAAC,MAAM,CAAC,GAAG,CAAC,SAA8B,EAAQ,EAAE;QACrE,KAAK,MAAM,CAAC,IAAI,EAAE,SAAS,CAAC,IAAI,IAAI,CAAC,aAAa,EAAE,EAAE,CAAC;YACrD,SAAS;iBACN,IAAI,CAAC,MAAM,CAAC,CAAC,EAAE,IAAI,EAAE,WAAW,EAAE,EAAE,EAAE,CAAC,IAAI,KAAK,WAAW,CAAC,CAAC;iBAC7D,SAAS,CAAC,CAAC,EAAE,IAAI,EAAE,EAAE,EAAE,EAAE,EAAE;gBAC1B,KAAK,MAAM,QAAQ,IAAI,SAAS,EAAE,CAAC;oBAChC,QAAQ,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAqB,CAAC,IAAI,CACjD,SAAS,CAAC,IAAI,CAAC,kBAAkB,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,mBAAmB,CAAC,EAAE,CAAC,mBAAmB,KAAK,EAAE,CAAC,CAAC,CAAC,CACpG,CAAC,SAAS,CAAC;wBACV,IAAI,EAAE,MAAM,CAAC,EAAE;4BACb,IAAI,CAAC,QAAQ,CAAC,CAAC,EAAE,SAAS,EAAE,KAAK,EAAE,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC,CAAC;wBACzD,CAAC;wBACD,KAAK,EAAE,KAAK,CAAC,EAAE;4BACb,IAAI,CAAC,QAAQ,CAAC,CAAC,EAAE,SAAS,EAAE,IAAI,EAAE,EAAE,EAAE,KAAK,EAAE,CAAC,CAAC;wBACjD,CAAC;wBACD,QAAQ,EAAE,GAAG,EAAE;4BACb,IAAI,CAAC,QAAQ,CAAC,CAAC,EAAE,SAAS,EAAE,IAAI,EAAE,EAAE,EAAE,CAAC,CAAC;wBAC1C,CAAC;qBACF,CAAC,CAAC;gBACL,CAAC;YACH,CAAC,CAAC,CAAC;QACP,CAAC;IACH,CAAC,CAAC;IASF;;OAEG;IACH,aAAa;QACX,MAAM,GAAG,GAAoB,IAAI,GAAG,EAAE,CAAC;QACvC,IAAI,YAAY,GAAI,IAAY,CAAC,WAAW,GAAG,EAAE,CAAC,CAAC;QAEnD,OAAO,YAAY,CAAC,WAAW,KAAK,MAAM,EAAE,CAAC;YAC3C,IAAI,OAAO,CAAC,OAAO,CAAC,YAAY,CAAC,WAAW,CAAC,CAAC,QAAQ,CAAC,iBAAiB,CAAC,EAAE,CAAC;gBAC1E,KAAK,MAAM,CAAC,GAAG,EAAE,QAAQ,CAAC,IAAI,YAAY,CAAC,WAAW,CAAC,iBAAiB,CAAoB,EAAE,CAAC;oBAC7F,GAAG,CAAC,GAAG,CAAC,GAAG,EAAE,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC,EAAE,GAAG,QAAQ,CAAC,CAAC,CAAC;gBACvD,CAAC;YACH,CAAC;YAED,YAAY,GAAG,YAAY,CAAC,SAAS,CAAC;QACxC,CAAC;QAED,OAAO,GAAG,CAAC;IACb,CAAC;CACF","file":"message-host.js","sourcesContent":["import { Observable, Subject } from 'rxjs';\nimport { filter, takeUntil } from 'rxjs/operators';\n\nimport { ListenerStorage } from './listener-storage.type';\nimport { SuccessfulMessageResponse } from './message-response.type';\nimport { Message } from './message.interface';\nimport { LISTEN, MESSAGE_LISTENERS, RESPONSE, TERMINATE_MESSAGE$ } from './selectors';\n\n/**\n * Message Host\n */\nexport abstract class MessageHost {\n /**\n * Message Terminator Subject\n *\n * Use `next(messageId)` method to terminate a message connection\n */\n protected readonly [TERMINATE_MESSAGE$] = new Subject<string>();\n\n /**\n * Run this method to start listening the requests\n */\n protected readonly [LISTEN] = (messages$: Observable<Message>): void => {\n for (const [path, listeners] of this.#getListeners()) {\n messages$\n .pipe(filter(({ path: messagePath }) => path === messagePath))\n .subscribe(({ body, id }) => {\n for (const listener of listeners) {\n (listener.call(this, body) as Observable<any>).pipe(\n takeUntil(this[TERMINATE_MESSAGE$].pipe(filter(terminatedMessageId => terminatedMessageId === id))),\n ).subscribe({\n next: result => {\n this[RESPONSE]({ completed: false, id, body: result });\n },\n error: error => {\n this[RESPONSE]({ completed: true, id, error });\n },\n complete: () => {\n this[RESPONSE]({ completed: true, id });\n }\n });\n }\n });\n }\n };\n\n /**\n * Build a reponse method to send the responses to the requests by using the communication methods of the platform\n *\n * @param message Incoming response message\n */\n protected abstract [RESPONSE]<T = any>(message: SuccessfulMessageResponse<T>): void;\n\n /**\n * All inherited listeners\n */\n #getListeners(): ListenerStorage {\n const map: ListenerStorage = new Map();\n let currentProto = (this as any)['__proto__' + ''];\n\n while (currentProto.constructor !== Object) {\n if (Reflect.ownKeys(currentProto.constructor).includes(MESSAGE_LISTENERS)) {\n for (const [key, handlers] of currentProto.constructor[MESSAGE_LISTENERS] as ListenerStorage) {\n map.set(key, [...(map.get(key) || []), ...handlers]);\n }\n }\n\n currentProto = currentProto.__proto__;\n }\n\n return map;\n }\n}\n"]}
1
+ {"version":3,"sources":["../../../../../libs/messenger/src/message-host.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,UAAU,EAAE,EAAE,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AACrD,OA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AC,CAAC,EAAE,SAAS,EAAE,KAAK,EAAE,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC,CAAC;wBACzD,CAAC;wBACD,KAAK,EAAE,KAAK,CAAC,EAAE;4BACb,IAAI,CAAC,QAAQ,CAAC,CAAC,EAAE,SAAS,EAAE,IAAI,EAAE,EAAE,EAAE,KAAK,EAAE,CAAC,CAAC;wBACjD,CAAC;wBACD,QAAQ,EAAE,GAAG,EAAE;4BACb,IAAI,CAAC,QAAQ,CAAC,CAAC,EAAE,SAAS,EAAE,IAAI,EAAE,EAAE,EAAE,CAAC,CAAC;wBAC1C,CAAC;qBACF,CAAC,CAAC;gBACL,CAAC;YACH,CAAC,CAAC,CAAC;QACP,CAAC;IACH,CAAC,CAAC;IASF;;OAEG;IACH,aAAa;QACX,MAAM,GAAG,GAAoB,IAAI,GAAG,EAAE,CAAC;QACvC,IAAI,YAAY,GAAI,IAAY,CAAC,WAAW,GAAG,EAAE,CAAC,CAAC;QAEnD,OAAO,YAAY,CAAC,WAAW,KAAK,MAAM,EAAE,CAAC;YAC3C,IAAI,OAAO,CAAC,OAAO,CAAC,YAAY,CAAC,WAAW,CAAC,CAAC,QAAQ,CAAC,iBAAiB,CAAC,EAAE,CAAC;gBAC1E,KAAK,MAAM,CAAC,GAAG,EAAE,QAAQ,CAAC,IAAI,YAAY,CAAC,WAAW,CAAC,iBAAiB,CAAoB,EAAE,CAAC;oBAC7F,GAAG,CAAC,GAAG,CAAC,GAAG,EAAE,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC,EAAE,GAAG,QAAQ,CAAC,CAAC,CAAC;gBACvD,CAAC;YACH,CAAC;YAED,YAAY,GAAG,YAAY,CAAC,SAAS,CAAC;QACxC,CAAC;QAED,OAAO,GAAG,CAAC;IACb,CAAC;CACF","file":"message-host.js","sourcesContent":["import { from, Observable, of, Subject } from 'rxjs';\nimport { filter, takeUntil } from 'rxjs/operators';\n\nimport { ListenerStorage } from './listener-storage.type';\nimport { SuccessfulMessageResponse } from './message-response.type';\nimport { Message } from './message.interface';\nimport { LISTEN, MESSAGE_LISTENERS, RESPONSE, TERMINATE_MESSAGE$ } from './selectors';\n\n/**\n * Message Host\n */\nexport abstract class MessageHost {\n /**\n * Message Terminator Subject\n *\n * Use `next(messageId)` method to terminate a message connection\n */\n protected readonly [TERMINATE_MESSAGE$] = new Subject<string>();\n\n /**\n * Run this method to start listening the requests\n */\n protected readonly [LISTEN] = (messages$: Observable<Message>): void => {\n for (const [path, listeners] of this.#getListeners()) {\n messages$\n .pipe(filter(({ path: messagePath }) => path === messagePath))\n .subscribe(({ body, id }) => {\n for (const listener of listeners) {\n let result$: Observable<any> = listener.call(this, body);\n\n if (result$ instanceof Promise) {\n result$ = from(result$);\n } else if (!(result$ instanceof Observable)) {\n result$ = of(result$);\n }\n\n result$.pipe(\n takeUntil(this[TERMINATE_MESSAGE$].pipe(filter(terminatedMessageId => terminatedMessageId === id))),\n ).subscribe({\n next: result => {\n this[RESPONSE]({ completed: false, id, body: result });\n },\n error: error => {\n this[RESPONSE]({ completed: true, id, error });\n },\n complete: () => {\n this[RESPONSE]({ completed: true, id });\n }\n });\n }\n });\n }\n };\n\n /**\n * Build a reponse method to send the responses to the requests by using the communication methods of the platform\n *\n * @param message Incoming response message\n */\n protected abstract [RESPONSE]<T = any>(message: SuccessfulMessageResponse<T>): void;\n\n /**\n * All inherited listeners\n */\n #getListeners(): ListenerStorage {\n const map: ListenerStorage = new Map();\n let currentProto = (this as any)['__proto__' + ''];\n\n while (currentProto.constructor !== Object) {\n if (Reflect.ownKeys(currentProto.constructor).includes(MESSAGE_LISTENERS)) {\n for (const [key, handlers] of currentProto.constructor[MESSAGE_LISTENERS] as ListenerStorage) {\n map.set(key, [...(map.get(key) || []), ...handlers]);\n }\n }\n\n currentProto = currentProto.__proto__;\n }\n\n return map;\n }\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@telperion/messenger",
3
- "version": "7.7.1",
3
+ "version": "7.7.2",
4
4
  "description": "Javascript messaging library",
5
5
  "keywords": [
6
6
  "javascript",