kuzzle-device-manager 2.0.0-rc27 → 2.0.0-rc28

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.
@@ -121,7 +121,6 @@ class DeviceManagerPlugin extends kuzzle_1.Plugin {
121
121
  async init(config, context) {
122
122
  this.config = lodash_1.default.merge({}, this.config, config);
123
123
  this.context = context;
124
- this.assetCategoryService = new asset_category_1.AssetCategoryService(this);
125
124
  /* eslint-disable sort-keys */
126
125
  this.pipes = {
127
126
  "device-manager/asset:before*": this.pipeCheckEngine.bind(this),
@@ -129,32 +128,6 @@ class DeviceManagerPlugin extends kuzzle_1.Plugin {
129
128
  "device-manager/device:beforeSearch": this.pipeCheckEngine.bind(this),
130
129
  "device-manager/device:beforeUpdate": this.pipeCheckEngine.bind(this),
131
130
  "generic:document:beforeWrite": [],
132
- "generic:document:afterGet": async (documents, request) => {
133
- if ((request.input.args.collection === "assets" ||
134
- request.input.args.collection === "devices") &&
135
- request.input.args.options?.prettify) {
136
- for (const document of documents) {
137
- if (document._source?.metadata) {
138
- document._source.metadata =
139
- this.assetCategoryService.formatMetadataForGet(document._source.metadata);
140
- }
141
- }
142
- }
143
- return documents;
144
- },
145
- "generic:document:beforeUpdate": async (documents, request) => {
146
- if ((request.input.args.collection === "assets" ||
147
- request.input.args.collection === "devices") &&
148
- request.input.args.options?.prettify) {
149
- for (const document of documents) {
150
- if (document._source?.metadata) {
151
- document._source.metadata =
152
- this.assetCategoryService.formatMetadataForES(document._source.metadata);
153
- }
154
- }
155
- }
156
- return documents;
157
- },
158
131
  };
159
132
  /* eslint-enable sort-keys */
160
133
  this.adminConfigManager = new kuzzle_plugin_commons_1.ConfigManager(this, {
@@ -177,6 +150,7 @@ class DeviceManagerPlugin extends kuzzle_1.Plugin {
177
150
  mappings: this.config.engineCollections.config.mappings,
178
151
  settings: this.config.engineCollections.config.settings,
179
152
  });
153
+ this.assetCategoryService = new asset_category_1.AssetCategoryService(this);
180
154
  this.batchController = new kuzzle_1.BatchController(this.sdk, {
181
155
  interval: this.config.batchInterval,
182
156
  });
@@ -187,7 +161,7 @@ class DeviceManagerPlugin extends kuzzle_1.Plugin {
187
161
  this.deviceManagerEngine = new engine_1.DeviceManagerEngine(this, this.assetsRegister, this.devicesRegister, this.measuresRegister, this.adminConfigManager, this.engineConfigManager);
188
162
  this.decodersRegister.init(this.context);
189
163
  this.assetController = new asset_1.AssetController(this, this.assetService, this.deviceService, this.assetCategoryService, this.measuresService);
190
- this.deviceController = new device_1.DeviceController(this, this.deviceService, this.assetCategoryService);
164
+ this.deviceController = new device_1.DeviceController(this, this.deviceService);
191
165
  this.decodersController = new measure_1.DecoderController(this, this.decodersRegister);
192
166
  this.engineController = new kuzzle_plugin_commons_1.EngineController("device-manager", this, this.deviceManagerEngine);
193
167
  this.assetCategoryController = new asset_category_1.AssetCategoryController(this, this.assetCategoryService);
@@ -2,7 +2,6 @@ import { JSONObject, KDocument, Plugin } from "kuzzle";
2
2
  import { BaseAssetContent } from "./../asset";
3
3
  import { MetadataContent } from "./../metadata";
4
4
  import { AssetCategoryContent, FormattedMetadata, FormattedValue } from "./types/AssetCategoryContent";
5
- import { EsDeviceContent } from "../device";
6
5
  export declare class AssetCategoryService {
7
6
  private config;
8
7
  private context;
@@ -21,7 +20,7 @@ export declare class AssetCategoryService {
21
20
  * edit the document to format metadata
22
21
  * @param document
23
22
  */
24
- formatDocumentMetadata(document: KDocument<BaseAssetContent | EsDeviceContent>): KDocument<BaseAssetContent | EsDeviceContent>;
23
+ formatDocumentMetadata(document: KDocument<BaseAssetContent>): KDocument<BaseAssetContent>;
25
24
  formatMetadataForGet(assetMetadata: FormattedMetadata[]): JSONObject;
26
25
  getValue(value: FormattedValue, format?: boolean): string | number | boolean | JSONObject;
27
26
  }
@@ -9,7 +9,7 @@ class Device {
9
9
  constructor(content, _id) {
10
10
  this._id = _id || Device.id(content.model, content.reference);
11
11
  this._source = {
12
- metadata: [],
12
+ metadata: {},
13
13
  ...content,
14
14
  };
15
15
  if (!Array.isArray(this._source.measures)) {
@@ -2,17 +2,12 @@ import { CRUDController } from "kuzzle-plugin-commons";
2
2
  import { KuzzleRequest } from "kuzzle";
3
3
  import { DeviceManagerPlugin } from "./../../DeviceManagerPlugin";
4
4
  import { DeviceManagerConfiguration } from "./../engine";
5
- import { AssetCategoryService } from "../asset-category";
6
5
  import { DeviceService } from "./DeviceService";
7
6
  import { Device } from "./Device";
8
- import { EsDeviceContent } from "./types/DeviceContent";
9
7
  export declare class DeviceController extends CRUDController {
10
8
  protected config: DeviceManagerConfiguration;
11
9
  private deviceService;
12
- private assetCategoryService;
13
- protected get sdk(): import("kuzzle").EmbeddedSDK;
14
- constructor(plugin: DeviceManagerPlugin, deviceService: DeviceService, assetCategoryService: AssetCategoryService);
15
- get(request: KuzzleRequest): Promise<EsDeviceContent>;
10
+ constructor(plugin: DeviceManagerPlugin, deviceService: DeviceService);
16
11
  /**
17
12
  * Create and provision a new device
18
13
  */
@@ -10,9 +10,8 @@ const kuzzle_1 = require("kuzzle");
10
10
  const lodash_1 = __importDefault(require("lodash"));
11
11
  const Device_1 = require("./Device");
12
12
  class DeviceController extends kuzzle_plugin_commons_1.CRUDController {
13
- constructor(plugin, deviceService, assetCategoryService) {
13
+ constructor(plugin, deviceService) {
14
14
  super(plugin, "devices");
15
- this.assetCategoryService = assetCategoryService;
16
15
  this.deviceService = deviceService;
17
16
  /* eslint-disable sort-keys */
18
17
  this.definition = {
@@ -32,12 +31,6 @@ class DeviceController extends kuzzle_plugin_commons_1.CRUDController {
32
31
  { path: "device-manager/devices/:_id/_detach", verb: "delete" },
33
32
  ],
34
33
  },
35
- get: {
36
- handler: this.get.bind(this),
37
- http: [
38
- { path: "device-manager/:engineId/devices/:_id", verb: "get" },
39
- ],
40
- },
41
34
  importDevices: {
42
35
  handler: this.importDevices.bind(this),
43
36
  http: [{ path: "device-manager/devices/_import", verb: "post" }],
@@ -114,16 +107,6 @@ class DeviceController extends kuzzle_plugin_commons_1.CRUDController {
114
107
  };
115
108
  /* eslint-enable sort-keys */
116
109
  }
117
- get sdk() {
118
- return this.context.accessors.sdk;
119
- }
120
- async get(request) {
121
- const id = request.getId();
122
- const engineId = request.getString("engineId");
123
- const document = await this.sdk.document.get(engineId, this.collection, id);
124
- this.assetCategoryService.formatDocumentMetadata(document);
125
- return document._source;
126
- }
127
110
  /**
128
111
  * Create and provision a new device
129
112
  */
@@ -131,8 +114,7 @@ class DeviceController extends kuzzle_plugin_commons_1.CRUDController {
131
114
  const engineId = request.getString("engineId");
132
115
  const model = request.getBodyString("model");
133
116
  const reference = request.getBodyString("reference");
134
- const rawMetadata = request.getBodyObject("metadata", {});
135
- const metadata = this.assetCategoryService.formatMetadataForES(rawMetadata);
117
+ const metadata = request.getBodyObject("metadata", {});
136
118
  const refresh = request.getRefresh();
137
119
  const assetId = request.getBodyString("assetId", "");
138
120
  const measureNamesLinks = request.getBodyArray("measureNamesLinks", []);
@@ -167,9 +149,6 @@ class DeviceController extends kuzzle_plugin_commons_1.CRUDController {
167
149
  }
168
150
  async update(request) {
169
151
  request.input.args.index = request.getString("engineId");
170
- const rawMetadata = request.getBodyObject("metadata", {});
171
- const metadata = this.assetCategoryService.formatMetadataForES(rawMetadata);
172
- request.input.body.metadata = metadata;
173
152
  return super.update(request);
174
153
  }
175
154
  async search(request) {
@@ -22,53 +22,7 @@ export declare const devicesMappings: {
22
22
  };
23
23
  metadata: {
24
24
  dynamic: string;
25
- properties: {
26
- key: {
27
- type: string;
28
- };
29
- value: {
30
- properties: {
31
- boolean: {
32
- type: string;
33
- };
34
- geo_point: {
35
- type: string;
36
- };
37
- integer: {
38
- type: string;
39
- };
40
- keyword: {
41
- type: string;
42
- };
43
- object: {
44
- dynamic: string;
45
- properties: {
46
- key: {
47
- type: string;
48
- };
49
- value: {
50
- properties: {
51
- boolean: {
52
- type: string;
53
- };
54
- geo_point: {
55
- type: string;
56
- };
57
- integer: {
58
- type: string;
59
- };
60
- keyword: {
61
- type: string;
62
- };
63
- };
64
- };
65
- };
66
- type: string;
67
- };
68
- };
69
- };
70
- };
71
- type: string;
25
+ properties: {};
72
26
  };
73
27
  model: {
74
28
  fields: {
@@ -1,7 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.devicesMappings = void 0;
4
- const metadata_1 = require("../../../modules/metadata");
5
4
  exports.devicesMappings = {
6
5
  dynamic: "strict",
7
6
  properties: {
@@ -22,7 +21,10 @@ exports.devicesMappings = {
22
21
  // measures mappings will be injected by the plugin
23
22
  },
24
23
  },
25
- metadata: metadata_1.metadataValue,
24
+ metadata: {
25
+ dynamic: "false",
26
+ properties: {},
27
+ },
26
28
  model: {
27
29
  fields: {
28
30
  text: { type: "text" },
@@ -1,10 +1,9 @@
1
1
  import { JSONObject, KDocumentContent } from "kuzzle";
2
- import { FormattedMetadata } from "../../asset-category";
3
2
  import { MeasureContent } from "../../measure/";
4
3
  /**
5
4
  * Device document content
6
5
  */
7
- export interface BaseDeviceContent extends KDocumentContent {
6
+ export interface DeviceContent extends KDocumentContent {
8
7
  /**
9
8
  * Device model
10
9
  * (This will be auto-filled by Kuzzle)
@@ -18,6 +17,10 @@ export interface BaseDeviceContent extends KDocumentContent {
18
17
  * Each most recent measures with a different `deviceMeasureName`
19
18
  */
20
19
  measures?: MeasureContent[];
20
+ /**
21
+ * Device metadata
22
+ */
23
+ metadata?: JSONObject;
21
24
  /**
22
25
  * Linked asset unique identifier
23
26
  */
@@ -27,15 +30,3 @@ export interface BaseDeviceContent extends KDocumentContent {
27
30
  */
28
31
  engineId?: string;
29
32
  }
30
- export interface DeviceContent extends BaseDeviceContent {
31
- /**
32
- * Device metadata
33
- */
34
- metadata?: JSONObject;
35
- }
36
- export interface EsDeviceContent extends BaseDeviceContent {
37
- /**
38
- * Device metadata
39
- */
40
- metadata?: FormattedMetadata[];
41
- }
@@ -56,8 +56,7 @@ class MeasureService {
56
56
  continue;
57
57
  }
58
58
  const measures = this.buildMeasures(device, asset, measurements, payloadUuids);
59
- const deviceMetadata = this.assetCategoryService.formatMetadataForES(decodedPayload.getMetadata(device._source.reference));
60
- device.updateMetadata(deviceMetadata);
59
+ device.updateMetadata(decodedPayload.getMetadata(device._source.reference));
61
60
  /**
62
61
  * Event before starting to process new measures.
63
62
  *
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "kuzzle-device-manager",
3
- "version": "2.0.0-rc27",
3
+ "version": "2.0.0-rc28",
4
4
  "description": "Manage your IoT devices and assets. Choose a provisioning strategy, receive and decode payload, handle your IoT business logic.",
5
5
  "author": "The Kuzzle Team (support@kuzzle.io)",
6
6
  "repository": {