UNPKG

@eclipse-glsp/client

Version:

A sprotty-based client for GLSP

89 lines 4.68 kB
/******************************************************************************** * Copyright (c) 2023-2024 EclipseSource and others. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0 which is available at * http://www.eclipse.org/legal/epl-2.0. * * This Source Code may also be made available under the following Secondary * Licenses when the conditions for such availability set forth in the Eclipse * Public License v. 2.0 are satisfied: GNU General Public License, version 2 * with the GNU Classpath Exception which is available at * https://www.gnu.org/software/classpath/license.html. * * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 ********************************************************************************/ import { Action, ActionMessage, Disposable, DisposableCollection, DisposeClientSessionParameters, GLSPClient, GModelRootSchema, ILogger, InitializeClientSessionParameters, InitializeResult, ModelSource } from '@eclipse-glsp/sprotty'; import { GLSPActionHandlerRegistry } from '../action-handler-registry'; import { IDiagramOptions } from './diagram-loader'; /** * A helper interface that allows the client to mark actions that have been received from the server. */ export interface ServerAction extends Action { __receivedFromServer: true; } export declare namespace ServerAction { function is(object: unknown): object is ServerAction; /** * Mark the given action as {@link ServerAction} by attaching the "__receivedFromServer" property * @param action The action that should be marked as server action */ function mark(action: Action): void; } /** * A helper interface that allows the client to mark actions that can be considered optional and should not throw an error if * no handler is available. */ export interface OptionalAction extends Action { __skipErrorIfNoHandler: true; } export declare namespace OptionalAction { function is(object: unknown): object is ServerAction; /** * Mark the given action as {@link OptionalAction} by attaching the "__skipErrorIfNoHandler" property * @param action The action that should be marked as optional action */ function mark<T extends Action>(action: T): T & OptionalAction; } /** * Central component for enabling the client-server action flow with the help of an underlying {@link GLSPClient}. * Handles & forwards actions that are intended for the GLSP server. In addition, it handles {@link ActionMessage}s received * from the server and dispatches the corresponding actions locally. * * Note that in sprotty a {@link ModelSource} is serving the model to the event cycle and * is used to commit the local (i.e. client-side) model back to the source. * However, in GLSP the update flow is reversed meaning that changes to the source model are applied * on the server side and then an update is sent to the client. */ export declare class GLSPModelSource extends ModelSource implements Disposable { protected logger: ILogger; protected options: IDiagramOptions; protected toDispose: DisposableCollection; clientId: string; protected _currentRoot: GModelRootSchema; protected registry: GLSPActionHandlerRegistry; protected glspClient?: GLSPClient; get diagramType(): string; get sourceUri(): string | undefined; /** * Configure forwarding of server-handled actions to the given {@link GLSPClient} and * handling of action received from the `GLSPClient` (i.e. server). It is expected that the * given GLSP client has already been initialized. * @param glspClient The GLSP to use. * @throws An error if the given `GLSPClient` has not been initialized yet or if the set of server handled * action kinds could not be derived from the initialize result */ configure(glspClient: GLSPClient): Promise<void>; protected createInitializeClientSessionParameters(_initializeResult: InitializeResult): InitializeClientSessionParameters; protected createDisposeClientSessionParameters(): DisposeClientSessionParameters; protected configureServeActions(initializeResult: InitializeResult): void; protected messageReceived(message: ActionMessage): void; initialize(registry: GLSPActionHandlerRegistry): void; handle(action: Action): void; protected forwardToServer(action: Action): void; protected shouldForwardToServer(action: Action): boolean; commitModel(newRoot: GModelRootSchema): GModelRootSchema; get model(): GModelRootSchema; dispose(): void; } //# sourceMappingURL=glsp-model-source.d.ts.map