UNPKG

@eclipse-emfcloud/modelserver-client

Version:

Typescript rest client to interact with an EMF.cloud modelserver

102 lines 5.01 kB
import WebSocket from 'isomorphic-ws'; import URI from 'urijs'; import { CloseNotification, DirtyStateNotification, ErrorNotification, FullUpdateNotification, IncrementalUpdateNotification, IncrementalUpdateNotificationV2, ModelServerNotification, UnknownNotification, ValidationNotification } from './model-server-notification'; /** * A `SubscriptionListener` is used to react to subscription notifications received by the model server. * When a subscription is started the model server client attaches the listener to the websocket which handles the * notifications for the subscribed model. */ export interface SubscriptionListener { onOpen(modeluri: URI, event: WebSocket.Event): void; onClose(modeluri: URI, event: WebSocket.CloseEvent): void; onError(modeluri: URI, event: WebSocket.ErrorEvent): void; onMessage(modeluri: URI, event: WebSocket.MessageEvent): void; } /** * A `ModelServerNotificationListener` can be used to treat & handle messages received via {@link SubscriptionListener.onMessage} by * as */ export interface ModelServerNotificationListener { /** * Can be implemented to react to a subscription opened notifications. * @param notification The notification providing the url of the model whose subscription channel has been opened. */ onOpen?(notification: ModelServerNotification): void; /** * Can be implemented to react to a {@link CloseNotification}s. * @param notification The close notification. */ onClose?(notification: CloseNotification): void; /** * Can be implemented to react to {@link ErrorNotification}s. * @param notification The error notification. */ onError?(notification: ErrorNotification): void; /** * Can be implemented to react to `success` notifications. * @param notification The notification providing the url of the model which caused the success notification. */ onSuccess?(notification: ModelServerNotification): void; /** * Can be implemented to react to {@link DirtyStateNotification}s. * @param notification The dirty state notification. */ onDirtyStateChanged?(notification: DirtyStateNotification): void; /** * Can be implemented to react to {@link IncrementalUpdateNotification}s. * @param notification The incremental update notification. */ onIncrementalUpdate?(notification: IncrementalUpdateNotification): void; /** * Can be implemented to react to {@link FullUpdateNotification}s. * @param notification The full update notification. */ onFullUpdate?(notification: FullUpdateNotification): void; /** * Can be implemented to react to {@link ValidationNotification}s. * @param notification The validation result notification. */ onValidation?(notification: ValidationNotification): void; /** * Can be implemented to react to unknown subscription notifications. (e.g. custom notifications) * @param notification The unknown notification. */ onUnknown?(notification: UnknownNotification): void; } /** * Default implementation of {@link SubscriptionListener} that maps received websocket events to the * corresponding {@link ModelServerNotification} and delegates them to the * {@link ModelServerNotificationListener} implementation passed via constructor. */ export declare class NotificationSubscriptionListener implements SubscriptionListener { protected notificationListener: ModelServerNotificationListener; constructor(notificationListener?: ModelServerNotificationListener); onOpen(modeluri: URI, _event: WebSocket.Event): void; onClose(modeluri: URI, event: WebSocket.CloseEvent): void; onError(modeluri: URI, event: WebSocket.ErrorEvent): void; onMessage(modeluri: URI, event: WebSocket.MessageEvent): void; } /** * Default implementation of {@link SubscriptionListener} that maps received websocket events to the * corresponding {@link ModelServerNotification} and delegates them to the * {@link ModelServerNotificationListenerV2} implementation passed via constructor. * * This class supports the V2 Client API. */ export declare class NotificationSubscriptionListenerV2 extends NotificationSubscriptionListener { protected notificationListener: ModelServerNotificationListenerV2; constructor(notificationListener?: ModelServerNotificationListenerV2); onMessage(modeluri: URI, event: WebSocket.MessageEvent): void; } /** * A {@link ModelServerNotificationListener} for V2 Client API. Uses JsonPatch for incremental * update notifications, instead of CommandExecutionResults. */ export interface ModelServerNotificationListenerV2 extends ModelServerNotificationListener { /** * Can be implemented to react to {@link IncrementalUpdateNotificationV2}s. * @param notification The incremental update notification. */ onIncrementalUpdateV2?(notification: IncrementalUpdateNotificationV2): void; } //# sourceMappingURL=subscription-listener.d.ts.map