/** * @author Martin Karkowski * @email m.karkowski@zema.de * @create date 2020-10-12 17:38:15 * @modify date 2020-10-12 17:59:38 * @desc Defintion of a generic Module. */ import { externalEvent } from "./Interface.CommunicationInterface"; import { INopeObservable, pipe } from "./Interface.nopeObservebale"; export type IDescriptorSchemaBaseTypes = 'string' | 'number' | 'integer' | 'object' | 'array' | 'boolean' | 'null' | 'function'; export type IDescriptorSchemaTypes = IDescriptorSchemaBaseTypes | Array | { $ref: string } /** * Description of an Author * * @export * @interface IAuthor */ export interface IAuthor { surename: string; forename: string; mail: string; } /** * Description of a Version * * @export * @interface IVersion */ export interface IVersion { version: number; date: Date; } /** * Generic Descriptor of an Version. * * @export * @interface IDescriptor */ export interface IDescriptor { $ref?: string; $schema?: string; ///////////////////////////////////////////////// // Schema Metadata ///////////////////////////////////////////////// /** * This is important because it tells refs where * the root of the document is located */ $id?: string; /** * It is recommended that the meta-schema is * included in the root of any JSON Schema */ // $schema?: IJsonSchema; /** * Title of the schema */ title?: string; /** * Schema description */ description?: string; examples?: any /** * Default json for the object represented by */ default?: any; ///////////////////////////////////////////////// // Number Validation ///////////////////////////////////////////////// /** * The value must be a multiple of the number * (e.g. 10 is a multiple of 5) */ multipleOf?: number; maximum?: number; /** * If true maximum must be > value, >= otherwise */ exclusiveMaximum?: boolean; minimum?: number; /** * If true minimum must be < value, <= otherwise */ exclusiveMinimum?: boolean; ///////////////////////////////////////////////// // String Validation ///////////////////////////////////////////////// maxLength?: number; minLength?: number; /** * This is a regex string that the value must * conform to */ pattern?: string; ///////////////////////////////////////////////// // Array Validation ///////////////////////////////////////////////// additionalItems?: boolean | IDescriptor; items?: IDescriptor | IDescriptor[]; maxItems?: number; minItems?: number; uniqueItems?: boolean; ///////////////////////////////////////////////// // Object Validation ///////////////////////////////////////////////// maxProperties?: number; minProperties?: number; /** * Props that must be integrated */ required?: string[]; additionalProperties?: boolean | IDescriptor; /** * Holds simple JSON Schema definitions for * referencing from elsewhere. */ definitions?: { [key: string]: IDescriptor }; /** * The keys that can exist on the object with the * json schema that should validate their value */ properties?: { [property: string]: IDescriptor }; /** * The key of this object is a regex for which * properties the schema applies to */ patternProperties?: { [pattern: string]: IDescriptor }; /** * If the key is present as a property then the * string of properties must also be present. * If the value is a JSON Schema then it must * also be valid for the object if the key is * present. */ dependencies?: { [key: string]: IDescriptor | string[] }; ///////////////////////////////////////////////// // Generic ///////////////////////////////////////////////// /** * Enumerates the values that this schema can be * e.g. * * { * "type": "string", * "enum": ["red", "green", "blue"] * } */ enum?: any[]; /** * The basic type of this schema, can be one of * ['string' | 'number' | 'object' | 'array' | 'boolean' | 'null'] * or an array of the acceptable types */ type?: IDescriptorSchemaTypes ///////////////////////////////////////////////// // Combining Schemas ///////////////////////////////////////////////// allOf?: IDescriptor[]; anyOf?: IDescriptor[]; oneOf?: IDescriptor[]; /** * The entity being validated must not match this schema */ not?: IDescriptor; inputs?: Array<{ name: string, position: string, schema: IDescriptor }>; outputs?: Array<{ name: string, schema: IDescriptor }> } /** * Descriptor of an Property. * * @export * @interface IPropertyOptions * @template K */ export interface IPropertyOptions { mode: 'subscribe' | 'publish' | Array<'subscribe' | 'publish'>, schema: IDescriptor, topic: string | { subscribe?: string, publish?: string, }, pipe?: { pipe?: pipe, scope?: { [index: string]: any } }, preventSendingToRegistery?: boolean } /** * Options, used to register a Function. * * @export * @interface IFunctionOptions */ export interface IFunctionOptions { /** * Flag to enable unregistering the function after calling. * * @type {boolean} * @memberof IFunctionOptions */ deleteAfterCalling?: boolean; /** * Instead of generating a uuid an id could be provided * * @type {string} * @memberof IFunctionOptions */ id?: string; /** * Flag to enable / disable sending to registery * * @type {boolean} * @memberof IFunctionOptions */ preventSendingToRegistery?: boolean; /** * Schema of the Function. * * @type {IDescriptor} * @memberof IFunctionOptions */ schema: IDescriptor; } export interface IBaseModule { /** * Name of the Module. The name of the module must be written in lowercase. * * @type {string} * @memberof IBaseModule */ name: string; /** * A Description of the Module. This is used to describe roughly * what the module is capable of doing. Consider this as Module * a kind of Documentation. Based on the fact, that the module * will be offered in the Network, provide a meaning full documentation * * @type {string} * @memberof IBaseModule */ description: string; /** * The Author of the Module * * @type {IAuthor} * @memberof IBaseModule */ author: IAuthor; /** * Description of the provided Version of the Module. * * @type {IVersion} * @memberof IBaseModule */ version: IVersion; /** * Function used to register a Function * * @param {string} name Name of the Function * @param {(...args) => Promise} func The Function * @param {IFunctionOptions} options The Options used during subscription * @return {*} {Promise} * @memberof IBaseModule */ registerFunction(name: string, func: (...args) => Promise, options: IFunctionOptions): Promise; /** * Function used to unregister a Function * * @param {string} name Name of the Function. * @return {*} {Promise} * @memberof IBaseModule */ unregisterFunction(name: string): Promise; /** * Function to Register a Property. If called for an existing Property, the Data will be * updated. * * @template T * @template K * @template S * @template G * @param {string} name Name of the Property. * @param {INopeObservable} observable The Observable. * @param {IPropertyOptions} options The Options which are used during registering the Observable. * @return {*} {Promise} * @memberof IBaseModule */ registerProperty(name: string, observable: INopeObservable, options: IPropertyOptions): Promise; /** * Function used to unregister a Property * * @param {string} name Name of the Property. * @return {*} {Promise} * @memberof IBaseModule */ unregisterProperty(name: string): Promise; /** * Function to list the available Functions of the module. This will hold all available functions * (dynamic and static functions). * * @return {*} {Promise>} * @memberof IBaseModule */ listFunctions(): Promise Promise, options: IFunctionOptions }>> /** * Function used to get an List of all registered Properties. * * @return {*} {Promise>} * @memberof IBaseModule */ listProperties(): Promise> /** * Function used to initialze the Module. * * @return {*} {Promise} * @memberof IBaseModule */ init(): Promise; /** * Function used to Dispose the Module. * * @return {*} {Promise} * @memberof IBaseModule */ dispose(): Promise; }