UNPKG

@eclipse-emfcloud/modelserver-client

Version:

Typescript rest client to interact with an EMF.cloud modelserver

108 lines 5.95 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 { AddOperation, Operation, RemoveOperation, ReplaceOperation } from 'fast-json-patch'; import URI from 'urijs'; import { ModelServerObjectV2, ModelServerReferenceDescriptionV2 } from '../model/base-model'; import { AnyObject, TypeGuard } from './type-util'; /** * The definition of a Type. Used e.g. to indicate which type of object * should be created, for a Create operation. */ export interface TypeDefinition { $type: string; } /** * Create a ReplaceOperation, to change the value of a property of the specified object. * @param modeluri the uri of the model to edit * @param object the object to edit * @param feature the property to edit * @param value the value to set * @returns The Json Patch ReplaceOperation to set the property. */ export declare function replace<T>(modeluri: URI, object: ModelServerObjectV2, feature: string, value: T): ReplaceOperation<T>; /** * Create an AddOperation, to create a new object of the specified type, in the specified parent. * @param modeluri the uri of the model to edit * @param parent the parent in which the new element should be created * @param feature the property of the parent in which the new element should be added * @param $type the type of element to create * @param attributes the attributes to initialize for the new element * @returns The Json Patch AddOperation to create the element. */ export declare function create(modeluri: URI, parent: ModelServerObjectV2, feature: string, $type: string, attributes?: AnyObject): AddOperation<TypeDefinition>; /** * Create an AddOperation, to add an existing object of the specified type, in the specified parent. * @param modeluri the uri of the model to edit * @param parent the parent in which the element should be added * @param feature the property of the parent in which the element should be added * @param value the element to add * @returns The Json Patch AddOperation to add the element in the parent. */ export declare function add(modeluri: URI, parent: ModelServerObjectV2, feature: string, value: ModelServerObjectV2 | ModelServerReferenceDescriptionV2): AddOperation<ModelServerObjectV2>; /** * Create a RemoveOperation, to delete an object from the model. * @param modeluri the uri of the model to edit * @param object the object to remove from the model * @returns The Json Patch RemoveOperation to remove the element. */ export declare function deleteElement(modeluri: URI, object: ModelServerObjectV2): RemoveOperation; /** * Create a RemoveOperation, to remove a value from a list. * @param modeluri the uri of the model to edit * @param object the object from which a value will be removed * @param feature the property from which a value will be removed * @param index the index of the value to remove */ export declare function removeValueAt(modeluri: URI, object: ModelServerObjectV2, feature: string, index: number): RemoveOperation; /** * Create a RemoveOperation, to remove a value from a list. * @param modeluri the uri of the model to edit * @param object the object from which a value will be removed * @param feature the property from which a value will be removed * @param value the value to remove */ export declare function removeValue(modeluri: URI, object: ModelServerObjectV2, feature: string, value: AnyObject): RemoveOperation | undefined; /** * Create a RemoveOperation, to delete an object from the model. * @param modeluri the uri of the model to edit * @param objectToRemove the object to delete from the model */ export declare function removeObject(modeluri: URI, objectToRemove: ModelServerObjectV2): RemoveOperation; /** * Utility functions for working with JSON Patch operations. */ export declare namespace Operations { /** * Tests is the given object is a Json Patch {@link Operation} * @param object the object to test * @returns true if the object is an Operation, false otherwise. */ function isOperation(object: unknown): object is Operation; /** * Tests is the given object is a Json Patch (Which is an array of {@link Operation Operations}) * @param object the object to test * @returns true if the object is a Json Patch, false otherwise. */ function isPatch(object: unknown): object is Operation[]; /** Type guard testing whether an operation is an add operation, with a nested guard on the value type. */ function isAdd(op: Operation, typeGuard: 'string'): op is AddOperation<string>; function isAdd(op: Operation, typeGuard: 'number'): op is AddOperation<number>; function isAdd(op: Operation, typeGuard: 'boolean'): op is AddOperation<boolean>; function isAdd<T = unknown>(op: Operation, typeGuard: TypeGuard<T>): op is AddOperation<T>; /** Type guard testing whether an operation is a replace operation, with a nested guard on the value type. */ function isReplace(op: Operation, typeGuard: 'string'): op is ReplaceOperation<string>; function isReplace(op: Operation, typeGuard: 'number'): op is ReplaceOperation<number>; function isReplace(op: Operation, typeGuard: 'boolean'): op is ReplaceOperation<boolean>; function isReplace<T = unknown>(op: Operation, typeGuard: TypeGuard<T>): op is ReplaceOperation<T>; /** Type guard testing whether an operation is a remove operation. */ function isRemove(op: Operation): op is RemoveOperation; } //# sourceMappingURL=patch-utils.d.ts.map