import { IThingTranslator } from "./IThingTranslator"; import { Logger } from "./Logger"; import { ThingSchema } from "./ThingSchema"; /** * Provides reflection-style access to thing properties and methods via translators. */ export declare class OpenT2T { private logger; constructor(logger?: Logger); /** * Loads a schema from a module. This is just a convenience wrapper * around require(). Throws if the module could not be loaded. * * @param {string} schemaModuleName Package-qualified name (or relative path) of * the schema module. The package-qualified name can be obtained from * PackageTranslatorInfo.schemas. * * @returns {Promise} The loaded thing schema. */ getSchemaAsync(schemaModuleName: string): Promise; /** * Loads a schema from a module. This is just a convenience wrapper * around require(). Throws if the module could not be loaded. * * @param {string} packageName Name (or relative path) of the package containing * the module. The name can be obtained from PackageInfo.name. * @param {string} schemaModuleName Simple name of the schema module. Can be * obtained from PackageInterfaceInfo.name. * @returns {Promise} The loaded thing schema. */ getSchemaAsync(packageName: string, schemaModuleName: string): Promise; /** * Loads a translator from a module. This is just a convenience wrapper * around require(). Throws if the module could not be loaded. * * @param {string} translatorModuleName Package-qualified name (or relative path) of * the translator module. * @param {*} properties Property bag to be passed to the translator constructor. * @returns {Promise} The loaded translator instance. */ createTranslatorAsync(translatorModuleName: string, properties: any): Promise; /** * Loads a translator from a module. This is just a convenience wrapper * around require(). Throws if the module could not be loaded. * * @param {string} packageName Name (or relative path) of the package containing * the module. The name can be obtained from PackageInfo.name. * @param {string} translatorModuleName Name of the translator module. Can be obtained * from PackageTranslatorInfo.name. * @param {*} properties Property bag to be passed to the translator constructor. * @returns {Promise} The loaded translator instance. */ createTranslatorAsync(packageName: string, translatorModuleName: string, properties: any): Promise; /** * Gets the value of a property on a thing, using a specified schema. * * @param {IThingTranslator} translator Thing translator instance * @param {(string | ThingSchema)} schemaName Name of the schema used * to access the device, or a ThingSchema object * @param {string} propertyName Name of the property to get * @returns {Promise} Value returned by the property getter; the value is * expected to conform to the JSON schema for the property value as specified * by the thing schema */ getPropertyAsync(translator: IThingTranslator, schemaName: string | ThingSchema, propertyName: string): Promise; /** * Sets the value of a property on a device, using a specified schema. * * @param {IThingTranslator} translator Thing translator instance * @param {(string | ThingSchema)} schemaName Name of the schema used * to access the device, or a ThingSchema object * @param {string} propertyName Name of the property to set * @param {*} value Value passed to the property setter; the value is * expected to conform to the JSON schema for the property value as specified * by the thing schema */ setPropertyAsync(translator: IThingTranslator, schemaName: string | ThingSchema, propertyName: string, value: any): Promise; /** * Adds a listener callback to a property that will be invoked if and when the * property sends notifications. * * @param {IThingTranslator} translator Thing translator instance * @param {(string | ThingSchema)} schemaName Name of the schema used * to access the device, or a ThingSchema object * @param {string} propertyName Name of the property to listen to * @param {(value: any) => void} callback Callback function that will be invoked * if and when the property sends notifications; the callback takes a single * parameter, which is expected to conform to the property value schema as * specified by the thing schema */ addPropertyListener(translator: IThingTranslator, schemaName: string | ThingSchema, propertyName: string, callback: (value: any) => void): void; /** * Removes a listener callback that was previously added to a property. * * @param {IThingTranslator} translator Thing translator instance * @param {(string | ThingSchema)} schemaName Name of the schema used * to access the device, or a ThingSchema object * @param {string} propertyName Name of the property that is being listened to * @param {(value: any) => void} callback Callback function that was previously * added as a listener to the same property on the same device */ removePropertyListener(translator: IThingTranslator, schemaName: string | ThingSchema, propertyName: string, callback: (value: any) => void): void; /** * Invokes a method on a device, using a specified schema. * * @param {IThingTranslator} translator Thing translator instance * @param {(string | ThingSchema)} schemaName Name of the schema used * to access the device, or a ThingSchema object * @param {string} methodName Name of the method to invoke * @param {any[]} args Arguments to pass to the method; the number and types of * arguments are expected to conform to the thing schema definition of the method * and the JSON schemas for each method argument in the schema. * @returns {Promise} Value returned by the method, or undefined if the * method has a void return type; the value is expected to conform to the * JSON schema for the method return value as specified by the thing schema */ invokeMethodAsync(translator: IThingTranslator, schemaName: string | ThingSchema, methodName: string, args: any[]): Promise; /** * Check for a `resolveSchema` method on the translator, and if found use it to request an object * that implements properties and methods for the requested schema. */ private getTranslatorForSchema(translator, schemaName); private validateMemberName(memberName); private capitalize(propertyName); private uncapitalize(propertyName); private throwError(eventName, startTime, error, data); }