kuzzle-device-manager-types 2.4.0-beta.16 → 2.4.0-beta.18

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -14,6 +14,10 @@ export declare class AssetService extends BaseService {
14
14
  * Update an asset metadata
15
15
  */
16
16
  update(engineId: string, assetId: string, metadata: Metadata, request: KuzzleRequest): Promise<KDocument<AssetContent>>;
17
+ /**
18
+ * Replace an asset metadata
19
+ */
20
+ replaceMetadata(engineId: string, assetId: string, metadata: Metadata, request: KuzzleRequest): Promise<KDocument<AssetContent>>;
17
21
  /**
18
22
  * Update or Create an asset metadata
19
23
  */
@@ -1,7 +1,7 @@
1
1
  import { ControllerDefinition, KuzzleRequest } from "kuzzle";
2
2
  import { DeviceManagerPlugin } from "../plugin";
3
3
  import { AssetService } from "./AssetService";
4
- import { ApiAssetCreateResult, ApiAssetUpsertResult, ApiAssetDeleteResult, ApiAssetGetMeasuresResult, ApiAssetGetResult, ApiAssetSearchResult, ApiAssetUpdateResult, ApiAssetMigrateTenantResult } from "./types/AssetApi";
4
+ import { ApiAssetCreateResult, ApiAssetUpsertResult, ApiAssetDeleteResult, ApiAssetGetMeasuresResult, ApiAssetGetResult, ApiAssetSearchResult, ApiAssetUpdateResult, ApiAssetMigrateTenantResult, ApiAssetMetadataReplaceResult } from "./types/AssetApi";
5
5
  export declare class AssetsController {
6
6
  private plugin;
7
7
  private assetService;
@@ -12,6 +12,7 @@ export declare class AssetsController {
12
12
  get(request: KuzzleRequest): Promise<ApiAssetGetResult>;
13
13
  upsert(request: KuzzleRequest): Promise<ApiAssetUpsertResult>;
14
14
  update(request: KuzzleRequest): Promise<ApiAssetUpdateResult>;
15
+ replaceMetadata(request: KuzzleRequest): Promise<ApiAssetMetadataReplaceResult>;
15
16
  create(request: KuzzleRequest): Promise<ApiAssetCreateResult>;
16
17
  delete(request: KuzzleRequest): Promise<ApiAssetDeleteResult>;
17
18
  search(request: KuzzleRequest): Promise<ApiAssetSearchResult>;
@@ -20,6 +20,15 @@ export interface ApiAssetUpdateRequest extends AssetsControllerRequest {
20
20
  };
21
21
  }
22
22
  export type ApiAssetUpdateResult = KDocument<AssetContent>;
23
+ export interface ApiAssetMetadataReplaceRequest extends AssetsControllerRequest {
24
+ action: "replaceMetadata";
25
+ _id: string;
26
+ refresh?: string;
27
+ body: {
28
+ metadata: Metadata;
29
+ };
30
+ }
31
+ export type ApiAssetMetadataReplaceResult = KDocument<AssetContent>;
23
32
  export interface ApiAssetUpsertRequest extends AssetsControllerRequest {
24
33
  action: "upsert";
25
34
  _id: string;
@@ -19,6 +19,17 @@ export type NamedMeasures = Array<{
19
19
  */
20
20
  export declare abstract class Decoder {
21
21
  private _http?;
22
+ /**
23
+ * Internal logger.
24
+ */
25
+ log: {
26
+ debug: (message: any) => void;
27
+ error: (message: any) => void;
28
+ info: (message: any) => void;
29
+ silly: (message: any) => void;
30
+ verbose: (message: any) => void;
31
+ warn: (message: any) => void;
32
+ };
22
33
  /**
23
34
  * Device model name.
24
35
  *
@@ -1,15 +1,40 @@
1
1
  import { JSONObject } from "kuzzle-sdk";
2
+ interface MeasureLocales {
3
+ [localeString: string]: {
4
+ friendlyName: string;
5
+ unit?: string;
6
+ };
7
+ }
8
+ export interface MeasureValuesDetails {
9
+ [valueName: string]: MeasureLocales;
10
+ }
2
11
  /**
3
12
  * Represents a measure definition registered by the Device Manager
4
13
  *
5
14
  * @example
6
- * {
7
- * valuesMappings: { temperature: { type: 'float' } },
8
- * }
15
+ *{
16
+ * valuesMappings: { temperature: { type: "float" } },
17
+ * valuesDetails: {
18
+ * temperature: {
19
+ * en: {
20
+ * friendlyName: "Temperature",
21
+ * unit: "°C",
22
+ * },
23
+ * fr: {
24
+ * friendlyName: "Température",
25
+ * unit: "°C",
26
+ * },
27
+ * },
28
+ * },
29
+ *}
9
30
  */
10
31
  export interface MeasureDefinition {
11
32
  /**
12
33
  * Mappings for the measurement values in order to index the fields
13
34
  */
14
35
  valuesMappings: JSONObject;
36
+ valuesDetails?: {
37
+ [valueName: string]: MeasureLocales;
38
+ };
15
39
  }
40
+ export {};
@@ -0,0 +1,7 @@
1
+ import { JSONObject, KuzzleError } from "kuzzle";
2
+ export declare class MappingsConflictsError extends KuzzleError {
3
+ private conflicts;
4
+ constructor(message: string, conflicts: JSONObject, id?: string, code?: number);
5
+ get name(): string;
6
+ toJSON(): JSONObject;
7
+ }
@@ -2,13 +2,15 @@ import { JSONObject, KDocument } from "kuzzle-sdk";
2
2
  import { DeviceManagerPlugin } from "../plugin";
3
3
  import { BaseService } from "../shared";
4
4
  import { AssetModelContent, DeviceModelContent, MeasureModelContent, MetadataDetails, MetadataGroups, MetadataMappings } from "./types/ModelContent";
5
+ import { MeasureValuesDetails } from "../measure";
5
6
  export declare class ModelService extends BaseService {
6
7
  constructor(plugin: DeviceManagerPlugin);
7
8
  registerAskEvents(): void;
9
+ private checkModelsConflicts;
8
10
  writeAsset(engineGroup: string, model: string, metadataMappings: MetadataMappings, defaultMetadata: JSONObject, metadataDetails: MetadataDetails, metadataGroups: MetadataGroups, measures: AssetModelContent["asset"]["measures"]): Promise<KDocument<AssetModelContent>>;
9
11
  private checkDefaultValues;
10
12
  writeDevice(model: string, metadataMappings: MetadataMappings, defaultMetadata: JSONObject, metadataDetails: MetadataDetails, metadataGroups: MetadataGroups, measures: DeviceModelContent["device"]["measures"]): Promise<KDocument<DeviceModelContent>>;
11
- writeMeasure(type: string, valuesMappings: JSONObject): Promise<KDocument<MeasureModelContent>>;
13
+ writeMeasure(type: string, valuesMappings: JSONObject, valuesDetails?: MeasureValuesDetails): Promise<KDocument<MeasureModelContent>>;
12
14
  deleteAsset(_id: string): Promise<void>;
13
15
  deleteDevice(_id: string): Promise<void>;
14
16
  deleteMeasure(_id: string): Promise<void>;
@@ -0,0 +1,30 @@
1
+ import { TwinModelContent, TwinType } from "../plugin";
2
+ import { MeasureModelContent } from "./exports";
3
+ export type ConflictChunk = {
4
+ sourceModel: string;
5
+ newModel: string;
6
+ modelType: string;
7
+ conflicts: MappingsConflict[];
8
+ };
9
+ export type MappingsConflict = {
10
+ path: string;
11
+ currentType: string | undefined;
12
+ newType: string | undefined;
13
+ };
14
+ /**
15
+ * Return every conflicts between the mappings of twins and a new twin model
16
+ *
17
+ * @param twinType The target twin type
18
+ * @param models The already present twin models
19
+ * @param additional The new asset
20
+ * @returns An array of ConflictChunk between current twins and the new twin
21
+ */
22
+ export declare function getTwinConflicts<TDigitalTwin extends TwinModelContent>(twinType: TwinType, models: TDigitalTwin[], additional: TDigitalTwin): ConflictChunk[];
23
+ /**
24
+ * Return every conflicts between the mappings of measure models and a new measure model
25
+ *
26
+ * @param measures The already present measure models
27
+ * @param additional The new measure
28
+ * @returns An array of ConflictChunk between current measures and the new measure
29
+ */
30
+ export declare function getMeasureConflicts(measures: MeasureModelContent[], additional: MeasureModelContent): ConflictChunk[];
@@ -1,5 +1,6 @@
1
1
  import { JSONObject, KDocument } from "kuzzle-sdk";
2
2
  import { AssetModelContent, DeviceModelContent, MeasureModelContent, MetadataDetails, MetadataGroups, MetadataMappings } from "./ModelContent";
3
+ import { MeasureValuesDetails } from "../../measure/types/MeasureDefinition";
3
4
  interface ModelsControllerRequest {
4
5
  controller: "device-manager/models";
5
6
  }
@@ -49,6 +50,7 @@ export interface ApiModelWriteMeasureRequest extends ModelsControllerRequest {
49
50
  body: {
50
51
  type: string;
51
52
  valuesMappings: JSONObject;
53
+ valuesDetails?: MeasureValuesDetails;
52
54
  };
53
55
  }
54
56
  export type ApiModelWriteMeasureResult = KDocument<MeasureModelContent>;
@@ -9,14 +9,17 @@ export interface MeasureModelContent extends KDocumentContent {
9
9
  }
10
10
  interface MetadataProperty {
11
11
  type: string;
12
+ strategy?: string;
13
+ format?: string;
12
14
  }
13
- export interface MetadataMappings {
14
- [key: string]: MetadataProperty | {
15
- properties: {
16
- [key: string]: MetadataProperty;
17
- };
15
+ interface MetadataObject {
16
+ properties: {
17
+ [key: string]: MetadataProperty | MetadataObject;
18
18
  };
19
19
  }
20
+ export interface MetadataMappings {
21
+ [key: string]: MetadataProperty | MetadataObject;
22
+ }
20
23
  interface LocaleDetails {
21
24
  friendlyName: string;
22
25
  description: string;
@@ -1,8 +1,20 @@
1
- import { Backend, Plugin } from "kuzzle";
1
+ import { Backend, KDocumentContent, Plugin } from "kuzzle";
2
2
  import { AbstractEngine, ConfigManager, EngineContent } from "kuzzle-plugin-commons";
3
+ import { AssetModelContent, DeviceModelContent, MeasureModelContent } from "../model";
3
4
  import { DeviceManagerPlugin } from "./DeviceManagerPlugin";
4
5
  import { DeviceManagerConfiguration } from "./types/DeviceManagerConfiguration";
5
6
  import { InternalCollection } from "./types/InternalCollection";
7
+ import { ConflictChunk } from "../model/ModelsConflicts";
8
+ export type TwinType = "asset" | "device";
9
+ export type TwinModelContent = AssetModelContent | DeviceModelContent;
10
+ export interface EngineDocument extends KDocumentContent {
11
+ type: "engine-device-manager";
12
+ engine: {
13
+ group: string;
14
+ index: string;
15
+ name: string;
16
+ };
17
+ }
6
18
  export type AskEngineList = {
7
19
  name: "ask:device-manager:engine:list";
8
20
  payload: {
@@ -15,11 +27,48 @@ export type AskEngineUpdateAll = {
15
27
  payload: void;
16
28
  result: void;
17
29
  };
30
+ export type AskEngineUpdateConflict = {
31
+ name: "ask:device-manager:engine:doesUpdateConflict";
32
+ payload: {
33
+ twin?: {
34
+ type: TwinType;
35
+ models: TwinModelContent[];
36
+ };
37
+ measuresModels?: MeasureModelContent[];
38
+ };
39
+ result: ConflictChunk[];
40
+ };
18
41
  export declare class DeviceManagerEngine extends AbstractEngine<DeviceManagerPlugin> {
19
42
  config: DeviceManagerConfiguration;
20
43
  get app(): Backend;
21
44
  constructor(plugin: Plugin, adminConfigManager: ConfigManager, engineConfigManager: ConfigManager);
45
+ /**
46
+ * Return conflicts between the new and already present twin models
47
+ *
48
+ * @param twinType The target twin type
49
+ * @param twinModels The already present twin models
50
+ * @param additionalModels The new or updated twin models
51
+ * @param measureModels The already present measures models
52
+ *
53
+ * @throws If a measure type declared in the twin does not exists
54
+ * @returns An array of conflict chunk
55
+ */
56
+ private doesTwinUpdateConflicts;
57
+ /**
58
+ * Return conflicts between the new and already present measure models
59
+ *
60
+ * @param measuresModels The already present measure models
61
+ * @param additionalMeasures The new or updated measure models
62
+ * @returns An array of ConflictChunk
63
+ */
64
+ private doesMeasuresUpdateConflicts;
22
65
  updateEngines(): Promise<void>;
66
+ /**
67
+ * Search and return every engines in use
68
+ *
69
+ * @returns An array of the available engines
70
+ */
71
+ getEngines(): Promise<EngineDocument[]>;
23
72
  onCreate(index: string, group?: string): Promise<{
24
73
  collections: any[];
25
74
  }>;
@@ -29,12 +78,100 @@ export declare class DeviceManagerEngine extends AbstractEngine<DeviceManagerPlu
29
78
  onDelete(index: string): Promise<{
30
79
  collections: InternalCollection[];
31
80
  }>;
81
+ /**
82
+ * Generate assets mappings and create the assets collection in the engine
83
+ *
84
+ * @param engineId The target engine Id
85
+ * @param engineGroup The engine group
86
+ *
87
+ * @throws If it failed during the assets collection creation
88
+ */
32
89
  createAssetsCollection(engineId: string, engineGroup: string): Promise<InternalCollection>;
90
+ /**
91
+ * Generate assets mappings and create the assets history collection in the engine
92
+ *
93
+ * @param engineId The target engine Id
94
+ * @param engineGroup The engine group
95
+ *
96
+ * @throws If it failed during the assets history collection creation
97
+ */
33
98
  createAssetsHistoryCollection(engineId: string, engineGroup: string): Promise<InternalCollection>;
99
+ /**
100
+ * Create the assets groups collection with the assets groups mappings in the engine
101
+ *
102
+ * @param engineId The target engine Id
103
+ * @param engineGroup The engine group
104
+ *
105
+ * @throws If it failed during the assets groups collection creation
106
+ */
34
107
  createAssetsGroupsCollection(engineId: string): Promise<InternalCollection>;
35
- private getDigitalTwinMappings;
108
+ /**
109
+ * Generate devices mappings and create the devices collection in the engine
110
+ *
111
+ * @param engineId The target engine Id
112
+ * @param engineGroup The engine group
113
+ *
114
+ * @throws If it failed during the devices collection creation
115
+ */
36
116
  createDevicesCollection(engineId: string): Promise<InternalCollection>;
117
+ /**
118
+ * Generate measures mappings and create the measures collection in the engine
119
+ *
120
+ * @param engineId The target engine Id
121
+ * @param engineGroup The engine group
122
+ *
123
+ * @throws If it failed during the measures collection creation
124
+ */
37
125
  createMeasuresCollection(engineId: string, engineGroup: string): Promise<InternalCollection>;
126
+ /**
127
+ * Create a collection with custom mappings in an engine
128
+ *
129
+ * @param engineIndex The target engine
130
+ * @param collection The collection name
131
+ * @param mappings The collection mappings
132
+ *
133
+ * @throws If it failed to create the collection
134
+ */
135
+ private tryCreateCollection;
136
+ /**
137
+ * Generate ES mappings from twin models and theirs associated measures, all fetched from the database
138
+ *
139
+ * @param digitalTwinType The target twin type
140
+ * @param engineGroup The twin engine group
141
+ * @returns The complete ES mappings produces by merging all the target type twins
142
+ */
143
+ private getDigitalTwinMappingsFromDB;
144
+ /**
145
+ * Generate ES mappings from twin models and theirs associated measures
146
+ *
147
+ * @param digitalTwinType The target twin type
148
+ * @param models The twin models
149
+ * @param measureModels The associated measures
150
+ * @returns The complete ES mappings produces by merging all the target type twins
151
+ */
152
+ private getDigitalTwinMappings;
153
+ /**
154
+ * Generate ES mappings from measures and theirs associated assets, all fetched via the database
155
+ *
156
+ * @param engineGroup The target engine group
157
+ * @returns The complete ES mappings produced by merging models mappings
158
+ */
159
+ private getMeasuresMappingsFromDB;
160
+ /**
161
+ * Generate ES mappings from measures and theirs associated assets
162
+ *
163
+ * @param models The measures models
164
+ * @param assetsMappings The assets complete mappings
165
+ * @returns The complete ES mappings produced by merging models mappings
166
+ */
38
167
  private getMeasuresMappings;
168
+ /**
169
+ * Retrieve a certain type of models associated to an engine
170
+ *
171
+ * @param engineId The target engine Id
172
+ * @param type The desired model type
173
+ * @param engineGroup The target engine group
174
+ * @returns An array of the generic type provided
175
+ */
39
176
  private getModels;
40
177
  }
@@ -20,6 +20,7 @@ export interface Column {
20
20
  header: string;
21
21
  path: string;
22
22
  isMeasure?: boolean;
23
+ isIsoDate?: boolean;
23
24
  }
24
25
  export declare abstract class AbstractExporter<P extends ExportParams = ExportParams> {
25
26
  protected plugin: DeviceManagerPlugin;
@@ -11,6 +11,7 @@ export declare class DummyTempPositionDecoder extends Decoder {
11
11
  readonly name: "position";
12
12
  readonly type: "position";
13
13
  }];
14
+ constructor();
14
15
  validate(payload: JSONObject): Promise<boolean>;
15
16
  decode(decodedPayload: DecodedPayload<DummyTempPositionDecoder>, payload: JSONObject): Promise<DecodedPayload<DummyTempPositionDecoder>>;
16
17
  }
package/package.json CHANGED
@@ -1,17 +1,18 @@
1
1
  {
2
2
  "name": "kuzzle-device-manager-types",
3
- "version": "2.4.0-beta.16",
3
+ "version": "2.4.0-beta.18",
4
4
  "description": "Shared types for Kuzzle Device Manager",
5
5
  "author": "The Kuzzle Team (support@kuzzle.io)",
6
6
  "main": "index.js",
7
7
  "types": "dist/index.d.ts",
8
8
  "repository": {
9
9
  "type": "git",
10
- "url": "git+https://github.com/kuzzleio/kuzzle-plugin-device-manager.git"
10
+ "url": "git+https://github.com/kuzzleio/kuzzle-plugin-device-manager.git",
11
+ "directory": "types"
11
12
  },
12
13
  "scripts": {
13
14
  "prepack": "npm run build",
14
- "build": "./copy-types.sh && node scripts/copy-version.js"
15
+ "build": "./copy-types.sh"
15
16
  },
16
17
  "license": "Apache-2.0",
17
18
  "files": [