UNPKG

@eclipse-emfcloud/modelserver-client

Version:

Typescript rest client to interact with an EMF.cloud modelserver

159 lines 7.52 kB
/******************************************************************************** * Copyright (c) 2022 STMicroelectronics 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 * https://www.eclipse.org/legal/epl-2.0, or the MIT License which is * available at https://opensource.org/licenses/MIT. * * SPDX-License-Identifier: EPL-2.0 OR MIT *******************************************************************************/ import { Operation } from 'fast-json-patch'; import URI from 'urijs'; import { ModelServerElement } from './model/base-model'; import { ModelServerCommand } from './model/command-model'; import { Diagnostic } from './model/diagnostic'; import { ServerConfiguration, SubscriptionOptions } from './model-server-client-api-v1'; import { Model, ModelServerMessage } from './model-server-message'; import { SubscriptionListener } from './subscription-listener'; import { AnyObject, TypeGuard } from './utils/type-util'; /** * Message Format for Json Models (V1). */ export declare const FORMAT_JSON_V1 = "json"; /** * Message Format for Json Models (V2). */ export declare const FORMAT_JSON_V2 = "json-v2"; /** * Message Format for XMI Models. */ export declare const FORMAT_XMI = "xmi"; /** JSON formats supported by the V2 client API. */ export type JsonFormat = 'json' | 'json-v2'; /** Message formats supported by the V2 client API. */ export type Format = string; /** * Additional subscription options supported by API v2 model subscriptions. */ export interface SubscriptionOptionsV2 extends SubscriptionOptions { /** * The scheme to use in the `path` property of {@link Operation}s in the * JSON Patches reported by API V2 queries. Supported values (case insensitive) * include `'jsonPointer'` (the default for standard JSON Patches) and * `'uriFragments'` (for a custom EMF-specific scheme based on the URI * fragments of `EObject`s) . */ paths?: string; } /** * A union type that represents all Patches or Commands supported by the model server: * - Operation * - Operation[] (Json Patch) * - ModelPatch * - ModelPatch[] * - ModelServerCommand */ export type PatchOrCommand = Operation | Operation[] | ModelPatch | ModelPatch[] | ModelServerCommand; /** * Basic client API to interact with a model server that conforms to the Modelserver API Version 2. */ export interface ModelServerClientApiV2 { /** * The `initialize` method should be executed before any other requests to the model server. * The given base url should point to the location of the model server API entry point. * (e.g. `http://localhost:8081/api/v2/`). Once the initialization is completed the client is expected * to be ready and should be able to handle REST requests to & responses from the model server. * Any requests to the model server before the client has been initialized are expected to fail (i.e. throw an error) * @param baseUrl Url pointing to the API entry point * @param defaultFormat Optional fallback format that should used when a request method is invoked and no explicit format argument * has been passed. The default-default is `'json-v2'` */ initialize(baseUrl: URI, defaultFormat?: Format): void | Promise<void>; /** * Retrieves all available models of the current workspace. */ getAll(): Promise<Model[]>; getAll<M>(typeGuard: TypeGuard<M>): Promise<Model<M>[]>; getAll(format: Format): Promise<Model<string>[]>; get(modeluri: URI, format?: Format): Promise<AnyObject>; get<M>(modeluri: URI, typeGuard: TypeGuard<M>, format?: Format): Promise<M>; getModelUris(): Promise<URI[]>; getElementById(modeluri: URI, elementid: string, format?: Format): Promise<AnyObject>; getElementById<M>(modeluri: URI, elementid: string, typeGuard: TypeGuard<M>, format?: Format): Promise<M>; getElementByName(modeluri: URI, elementname: string, format?: Format): Promise<AnyObject>; getElementByName<M>(modeluri: URI, elementname: string, typeGuard: TypeGuard<M>, format?: Format): Promise<M>; delete(modeluri: URI): Promise<boolean>; close(modeluri: URI): Promise<boolean>; create(modeluri: URI, model: AnyObject | string, format?: Format): Promise<AnyObject>; create<M>(modeluri: URI, model: AnyObject | string, typeGuard: TypeGuard<M>, format?: Format): Promise<M>; update(modeluri: URI, model: AnyObject | string, format?: Format): Promise<AnyObject>; update<M>(modeluri: URI, model: AnyObject | string, typeGuard: TypeGuard<M>, format?: Format): Promise<M>; save(modeluri: URI): Promise<boolean>; saveAll(): Promise<boolean>; validate(modeluri: URI): Promise<Diagnostic>; getValidationConstraints(modeluri: URI): Promise<string>; getTypeSchema(modeluri: URI): Promise<string>; getUiSchema(schemaname: string): Promise<string>; configureServer(configuration: ServerConfiguration): Promise<boolean>; ping(): Promise<boolean>; edit(modeluri: URI, patchOrCommand: PatchOrCommand, format?: Format): Promise<ModelUpdateResult>; undo(modeluri: URI): Promise<ModelUpdateResult>; redo(modeluri: URI): Promise<ModelUpdateResult>; subscribe(modeluri: URI, listener: SubscriptionListener, options?: SubscriptionOptionsV2): SubscriptionListener; send(modeluri: URI, message: ModelServerMessage): void; unsubscribe(modeluri: URI): void; } export declare namespace ModelServerClientApiV2 { const API_ENDPOINT = "api/v2"; } /** * A patch affecting a specific model. */ export interface ModelPatch { /** * The uri of the patched model. */ modelUri: string; /** * The patch describing the changes applied to the model. */ patch: Operation[]; } /** * Result sent to client after requesting a model update. */ export interface ModelUpdateResult { /** * True if the edit request was successful, false otherwise. */ success: boolean; /** * A function to update the model. Only present if the edit request was successful. * The function can be applied to the original model (before edition) and will return * the new model (after edition). * * @param oldModel the model to patch * @param copy by default, the patch will be directly applied to the oldModel, modifying * it in-place. If copy is true, the patch will be applied on a copy of the model, leaving * the original model unchanged. * @param modeluri the uri of the model to patch. This can be used when the model is split in multiple * resources, to identify the patch to apply. The modeluri should correspond to the oldModel object. * It can be omitted when patching the main model (or in single-model cases). * @return the patched model. */ patchModel?(oldModel: ModelServerElement, copy?: boolean, modeluri?: URI): ModelServerElement; /** * The Json Patch describing the changes that were applied to the model. Only present if * the edit request was successful. */ patch?: Operation[]; /** * The list of Json Patches describing the changes that were applied to the models. Only present if * the edit request was successful. * * The list contains one entry per modified model. Unmodified models will not contain any entry. */ allPatches?: ModelPatch[]; } //# sourceMappingURL=model-server-client-api-v2.d.ts.map