import { Backend, KDocumentContent, Plugin } from "kuzzle"; import { AbstractEngine, ConfigManager, EngineContent } from "kuzzle-plugin-commons"; import { AssetModelContent, DeviceModelContent, GroupModelContent, MeasureModelContent } from "../model"; import { DeviceManagerPlugin } from "./DeviceManagerPlugin"; import { DeviceManagerConfiguration } from "./types/DeviceManagerConfiguration"; import { InternalCollection } from "./types/InternalCollection"; import { ConflictChunk } from "../model/ModelsConflicts"; export type TwinType = "asset" | "device"; export type TwinModelContent = AssetModelContent | DeviceModelContent; export interface EngineDocument extends KDocumentContent { type: "engine-device-manager"; engine: { group: string; index: string; name: string; }; } export type AskEngineList = { name: "ask:device-manager:engine:list"; payload: { group?: string; }; result: EngineContent[]; }; export type AskEngineUpdateAll = { name: "ask:device-manager:engine:updateAll"; payload: void; result: void; }; export type AskEngineUpdateConflict = { name: "ask:device-manager:engine:doesUpdateConflict"; payload: { twin?: { type: TwinType; models: TwinModelContent[]; }; measuresModels?: MeasureModelContent[]; groupModels?: GroupModelContent[]; }; result: ConflictChunk[]; }; export declare class DeviceManagerEngine extends AbstractEngine { config: DeviceManagerConfiguration; get app(): Backend; constructor(plugin: Plugin, adminConfigManager: ConfigManager, engineConfigManager: ConfigManager); /** * Return conflicts between the new and already present twin models * * @param twinType The target twin type * @param twinModels The already present twin models * @param additionalModels The new or updated twin models * @param measureModels The already present measures models * * @throws If a measure type declared in the twin does not exists * @returns An array of conflict chunk */ private doesTwinUpdateConflicts; /** * Return conflicts between the new and already present group models * * @param groupModels The already present group models * @param additionalGroups The new or updated group models * @returns An array of ConflictChunk */ private doesGroupsUpdateConflicts; /** * Return conflicts between the new and already present measure models * * @param measuresModels The already present measure models * @param additionalMeasures The new or updated measure models * @returns An array of ConflictChunk */ private doesMeasuresUpdateConflicts; updateEngines(): Promise; /** * Search and return every engines in use * * @returns An array of the available engines */ getEngines(): Promise; updateMeasuresSchema(): Promise; onCreate(index: string, group?: string): Promise<{ collections: any[]; }>; onUpdate(index: string, group?: string): Promise<{ collections: any[]; }>; onDelete(index: string): Promise<{ collections: InternalCollection[]; }>; /** * Generate assets mappings and create the assets collection in the engine * * @param engineId The target engine Id * @param engineGroup The engine group * * @throws If it failed during the assets collection creation */ createAssetsCollection(engineId: string, engineGroup: string): Promise; /** * Generate assets mappings and create the assets history collection in the engine * * @param engineId The target engine Id * @param engineGroup The engine group * * @throws If it failed during the assets history collection creation */ createAssetsHistoryCollection(engineId: string, engineGroup: string): Promise; /** * Create the assets groups collection with the assets groups mappings in the engine * * @param engineId The target engine Id * @param engineGroup The engine group * * @throws If it failed during the assets groups collection creation */ createAssetsGroupsCollection(engineId: string): Promise; /** * Generate devices mappings and create the devices collection in the engine * * @param engineId The target engine Id * @param engineGroup The engine group * * @throws If it failed during the devices collection creation */ createDevicesCollection(engineId: string): Promise; /** * Generate measures mappings and create the measures collection in the engine * * @param engineId The target engine Id * @param engineGroup The engine group * * @throws If it failed during the measures collection creation */ createMeasuresCollection(engineId: string, engineGroup: string): Promise; /** * Create a collection with custom mappings in an engine * * @param engineIndex The target engine * @param collection The collection name * @param mappings The collection mappings * * @throws If it failed to create the collection */ private tryCreateCollection; /** * Generate ES mappings from twin models and theirs associated measures, all fetched from the database * * @param digitalTwinType The target twin type * @param engineGroup The twin engine group * @returns The complete ES mappings produces by merging all the target type twins */ private getDigitalTwinMappingsFromDB; /** * Generate ES mappings from twin models and theirs associated measures * * @param digitalTwinType The target twin type * @param models The twin models * @param measureModels The associated measures * @returns The complete ES mappings produces by merging all the target type twins */ private getDigitalTwinMappings; /** * Generate ES mappings from measures and theirs associated assets, all fetched via the database * * @param engineGroup The target engine group * @returns The complete ES mappings produced by merging models mappings */ private getMeasuresMappingsFromDB; /** * Generate ES mappings from measures and theirs associated assets * * @param models The measures models * @param assetsMappings The assets complete mappings * @returns The complete ES mappings produced by merging models mappings */ private getMeasuresMappings; getAssetGroupsMappingFromDB(): Promise; /** * Retrieve a certain type of models associated to an engine * * @param engineId The target engine Id * @param type The desired model type * @param engineGroup The target engine group * @returns An array of the generic type provided */ private getModels; /** * Detach all devices of an index in the admin index * * @param engineId The target engine Id * @returns {any} */ private detachDevicesFromAdminIndex; }