@eclipse-emfcloud/modelserver-client
Version:
Typescript rest client to interact with an EMF.cloud modelserver
135 lines • 5.62 kB
TypeScript
/********************************************************************************
* Copyright (c) 2021-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 URI from 'urijs';
import { Format } from '../model-server-client-api-v2';
import { Model } from '../model-server-message';
/**
* The built-in 'object' & 'Object' types are currently hard to use
* an should be avoided. It's recommended to use Record instead to describe the
* type meaning of "any object";
*/
export type AnyObject = Record<PropertyKey, unknown>;
export declare namespace AnyObject {
/**
* Type guard to check wether a given object is of type {@link AnyObject}.
* @param object The object to check.
* @returns The given object as {@link AnyObject} or `false`.
*/
function is(object: unknown): object is AnyObject;
}
/**
* Type that describes a type guard function for a specific type.
* Takes any object as input and verifies wether the object is of the given concrete type.
* @typeParam T the concrete type
*/
export type TypeGuard<T> = (object: unknown) => object is T;
/**
* Validates whether the given object as a property of type `string` with the given key.
* @param object The object that should be validated
* @param propertyKey The key of the property
* @returns `true` if the object has property with matching key of type `string`
*/
export declare function isString(object: AnyObject, propertyKey: string): boolean;
/**
* Validates whether the given object as a property of type `boolean` with the given key.
* @param object The object that should be validated
* @param propertyKey The key of the property
* @returns `true` if the object has property with matching key of type `boolean`
*/
export declare function isBoolean(object: AnyObject, propertyKey: string): boolean;
/**
* Validates whether the given object as a property of type `number` with the given key.
* @param object The object that should be validated
* @param propertyKey The key of the property
* @returns `true` if the object has property with matching key of type `number`
*/
export declare function isNumber(object: AnyObject, propertyKey: string): boolean;
/**
* Validates whether the given object as a property of type `object` with the given key.
* @param object The object that should be validated
* @param propertyKey The key of the property
* @returns `true` if the object has property of type {@link AnyObject}
*/
export declare function isObject(object: AnyObject, propertyKey: string): boolean;
/**
* Validates whether the given object as a property of type `Array` with the given key.
* @param object The object that should be validated
* @param propertyKey The key of the property
* @returns `true` if the object has property with matching key of type `Array`
*/
export declare function isArray(object: AnyObject, propertyKey: string): boolean;
/**
* Maps the given object to `string`.
* @param object The object to map
* @returns The object as `string`
*/
export declare function asString(object: unknown): string;
/**
* Maps the given object to a `string` array.
* @param object The object to map
* @returns The object as `string` array
* @throws {@link Error} if the given object is not an array
*/
export declare function asStringArray(object: unknown): string[];
/**
* Checks wether the given object is a defined object of type `object`.
* @param object The object to check
* @returns The correctly typed object
* @throws {@link Error} if the given object is not defined or of type 'object'.
*/
export declare function asObject(object: unknown): AnyObject;
/**
* Maps the given object to a concrete Type `T`.
* @param object The object to map
* @param guard The type guard function to test the given object against
* @returns The object as type `T`
* @throws {@link Error} if the given object fails the type guard check
*/
export declare function asType<T>(object: unknown, guard: TypeGuard<T>): T;
export declare function asModelArray(object: unknown): Model[];
/**
* Validates whether the given object is a (deferred) instance of an URI object.
* @param object The object that should be validated
* @returns `true` if the object is an instance of URI
*/
export declare function isURI(object: unknown): object is URI;
/**
* Maps the given object to an `URI` object.
* @param obj The object to map
* @returns The object as `URI`
*/
export declare function asURI(obj: unknown): URI;
/**
* Maps the given object to a `string` array.
* @param object The object to map
* @returns The object as `URI` array
* @throws {@link Error} if the given object is not an array
*/
export declare function asURIArray(object: unknown): URI[];
/** Protocol of a message encoder. */
export type Encoder<T = unknown> = (object: string | AnyObject) => T | string;
/**
* Obtain a message encoder for the request body.
*
* @param format the encoding format
* @returns the request body encoder format
*/
export declare function encodeRequestBody(format: Format): Encoder<{
data: any;
}>;
/**
* Obtain a message encoder.
*
* @param format the encoding format
* @returns the encoder
*/
export declare function encode(format: Format): Encoder;
//# sourceMappingURL=type-util.d.ts.map