UNPKG

@eclipse-ditto/ditto-javascript-client-dom

Version:

DOM implementation of Eclipse Ditto JavaScript API to be used in browsers.

77 lines 3.24 kB
/*! * Copyright (c) 2019 Contributors to the Eclipse Foundation * * See the NOTICE file(s) distributed with this work for additional * information regarding copyright ownership. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License 2.0 which is available at * http://www.eclipse.org/legal/epl-2.0 * * SPDX-License-Identifier: EPL-2.0 */ /** * Model to represent an Entity in Ditto. */ export declare abstract class EntityModel { /** * Turns an object into an array of the type A. It contains one Entity for every key of the original object * * @typeParam A - The type of array to return * @param o - The object to parse. * @param parser - A method to parse instances of the desired Entity. * @returns The array of Entities. */ static objectToArray<T extends EntityWithId>(o: Object, parser: (obj: Object, key: string) => T): T[]; /** * Builds an object representation out of the provided content. * * @param content - The content of the object representation. * @returns The object containing all elements of the content that aren't undefined. */ protected static buildObject(content: Map<string, any>): object; toJson(): string; equals(toCompare: EntityModel): boolean; /** * Turns the Entity into an object. * * @returns The object representation of the Entity. */ abstract toObject(): Object | undefined; } /** * Entity with an 'id' field */ export declare abstract class EntityWithId extends EntityModel { abstract id: string; equals(toCompare: EntityWithId): boolean; } /** * Abstract entity model class that consists of entities of the same type but with unknown property keys. */ export declare abstract class IndexedEntityModel<EntryType extends EntityModel> implements Record<string, EntryType> { [key: string]: EntryType; static toJson<T extends EntityModel>(entity: IndexedEntityModel<T>): string; static equals<T extends EntityModel>(a: IndexedEntityModel<T>, b: IndexedEntityModel<T>): boolean; /** * Map the object to an indexed object with types. Iterates all keys and maps all values with {@code mapValue}. * * @param objectToMap - the object to map. * @param mapValue - how to get the value from an objects value. * @param mapKey - how to get the key from an objects key. */ static fromPlainObject<T extends EntityModel>(objectToMap: Object | undefined, mapValue: (value: any, key: string) => T, mapKey?: (key: string, value: any) => string): IndexedEntityModel<T>; /** * Removes all type information from the indexed type. * @param objectToMap - the object to map. * @param removeType - function that is called to remove the type of the objects values. */ static toPlainObject<T extends EntityModel>(objectToMap: IndexedEntityModel<T>, removeType: (typedObject: T) => any): any; /** * Turns the Entity into an object. * * @returns The object representation of the Entity. */ static toObject<T extends EntityModel>(entityModel: IndexedEntityModel<T> | undefined): Object | undefined; } //# sourceMappingURL=model.d.ts.map