Options
All
  • Public
  • Public/Protected
  • All
Menu

Package muster-message-transport

Muster Message Transport

Introduction

Utilities for transporting messages between Muster instances

Usage

import {
  Message,
  messageTransportMiddleware,
  messageListenerDecorator
} from '@dws/muster-message-transport';

// ...

Install

With npm installed, run

$ npm install @dws/muster-message-transport

License

MIT

Index

Type aliases

DisposeListener

DisposeListener: function

Type declaration

    • (): void
    • Returns void

MessageCallback

MessageCallback: function

Type declaration

    • Parameters

      Returns void

SubscriptionsMap

SubscriptionsMap: Map<string, function>

Variables

Const DEFAULT_SANITIZER

DEFAULT_SANITIZER: sanitize = sanitize

Const DEFAULT_SANITIZER

DEFAULT_SANITIZER: sanitize = sanitize

Const MessageTransportMiddlewareNodeType

MessageTransportMiddlewareNodeType: StatefulNodeType<"message-transport-middleware", MessageTransportMiddlewareNodeProperties, MessageTransportMiddlewareState, MessageTransportMiddlewareData> = createNodeType<'message-transport-middleware',MessageTransportMiddlewareNodeProperties,MessageTransportMiddlewareState,MessageTransportMiddlewareData>('message-transport-middleware', {shape: {listen: types.func,send: types.func,sanitize: types.optional(types.func),},state: {result: types.objectOf(graphTypes.nodeDefinition),},getInitialState() {return {result: {},};},operations: {request: {run(node: MessageTransportMiddlewareNode,operation: RequestOperation,dependencies: never,contextDependencies: never,state: MessageTransportMiddlewareState,): NodeDefinition {return state.result[operation.id] || pending();},onSubscribe(this: NodeExecutionContext<MessageTransportMiddlewareState, MessageTransportMiddlewareData>,node: MessageTransportMiddlewareNode,operation: RequestOperation,): void {const { listen, send, sanitize = DEFAULT_SANITIZER } = node.definition.properties;const requestId = operation.id;const callback = (message: Message<any>) => {// Check the type of messageif (!message ||(typeof message === 'object' && message.name !== SubscriptionResultMessageName)) {return;}const subscriptionResultMessage = message as SubscriptionResultMessage;// Make sure the response is for the correct requestif (subscriptionResultMessage.requestId !== requestId) return;const response = deserialize(getMusterNodeTypesMap(),getMusterOperationTypesMap(),subscriptionResultMessage.response,);this.setState((state) => ({...state,result: {...state.result,[requestId]: response,},}));};this.setData((data) => ({...data,subscriptions: {...data.subscriptions,[requestId]: listen(callback),},}));const serializedQuery = sanitize(operation.properties.query);send(subscribe(requestId, serializedQuery));},onUnsubscribe(this: NodeExecutionContext<MessageTransportMiddlewareState, MessageTransportMiddlewareData>,node: MessageTransportMiddlewareNode,operation: RequestOperation,): void {const { send } = node.definition.properties;const requestId = operation.id;this.setData((data) => {const unsubscribeListener = data.subscriptions[requestId];unsubscribeListener && unsubscribeListener();return {...data,subscriptions: omit(data.subscriptions, requestId),};});this.setState((state) => ({...state,result: omit(state.result, requestId),}));send(unsubscribe(requestId));},},},})

Const SubscribeMessageName

SubscribeMessageName: "muster-message-transport-subscribe" = "muster-message-transport-subscribe"

Const SubscriptionResultMessageName

SubscriptionResultMessageName: "muster-message-transport-subscription-result" = "muster-message-transport-subscription-result"

Const UnsubscribeMessageName

UnsubscribeMessageName: "muster-message-transport-unsubscribe" = "muster-message-transport-unsubscribe"

Functions

messageListenerDecorator

messageTransportMiddleware

safelyDeserializeNode

subscribe

subscribe

subscriptionResult

unsubscribe

unsubscribe