kuzzle-device-manager 2.0.0-rc22 → 2.0.0-rc26
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.
- package/index.d.ts +6 -4
- package/index.js +6 -4
- package/lib/DeviceManagerPlugin.d.ts +5 -3
- package/lib/DeviceManagerPlugin.js +123 -94
- package/lib/{controllers → modules/asset}/AssetController.d.ts +10 -9
- package/lib/{controllers → modules/asset}/AssetController.js +130 -76
- package/lib/{core-classes → modules/asset}/AssetService.d.ts +4 -4
- package/lib/{core-classes → modules/asset}/AssetService.js +13 -13
- package/lib/{core-classes/registers → modules/asset}/AssetsRegister.d.ts +2 -2
- package/lib/{core-classes/registers → modules/asset}/AssetsRegister.js +9 -9
- package/lib/{models → modules/asset}/BaseAsset.d.ts +5 -4
- package/lib/{models → modules/asset}/BaseAsset.js +6 -5
- package/lib/{mappings → modules/asset/collections}/assetsMappings.d.ts +0 -0
- package/lib/{mappings → modules/asset/collections}/assetsMappings.js +24 -24
- package/lib/modules/asset/index.d.ts +7 -0
- package/lib/modules/asset/index.js +24 -0
- package/lib/{types → modules/asset/types}/BaseAssetContent.d.ts +3 -3
- package/lib/{types → modules/asset/types}/BaseAssetContent.js +0 -0
- package/lib/{types/Request.d.ts → modules/asset/types/LinkRequest.d.ts} +1 -1
- package/lib/{types/Request.js → modules/asset/types/LinkRequest.js} +1 -1
- package/lib/{controllers → modules/asset-category}/AssetCategoryController.d.ts +4 -4
- package/lib/{controllers → modules/asset-category}/AssetCategoryController.js +84 -44
- package/lib/{core-classes → modules/asset-category}/AssetCategoryService.d.ts +7 -6
- package/lib/{core-classes → modules/asset-category}/AssetCategoryService.js +26 -20
- package/lib/{mappings → modules/asset-category/collections}/assetCategoryMappings.d.ts +0 -0
- package/lib/modules/asset-category/collections/assetCategoryMappings.js +23 -0
- package/lib/modules/asset-category/index.d.ts +4 -0
- package/lib/{mappings → modules/asset-category}/index.js +4 -4
- package/lib/{types → modules/asset-category/types}/AssetCategoryContent.d.ts +2 -2
- package/lib/{types → modules/asset-category/types}/AssetCategoryContent.js +0 -0
- package/lib/{models → modules/device}/Device.d.ts +4 -3
- package/lib/{models → modules/device}/Device.js +4 -4
- package/lib/{controllers → modules/device}/DeviceController.d.ts +14 -9
- package/lib/{controllers → modules/device}/DeviceController.js +132 -69
- package/lib/{core-classes → modules/device}/DeviceService.d.ts +9 -8
- package/lib/{core-classes → modules/device}/DeviceService.js +36 -25
- package/lib/{core-classes/registers → modules/device}/DevicesRegister.d.ts +2 -2
- package/lib/{core-classes/registers → modules/device}/DevicesRegister.js +2 -2
- package/lib/modules/device/collections/deviceMappings.d.ts +90 -0
- package/lib/{mappings → modules/device/collections}/deviceMappings.js +14 -16
- package/lib/modules/device/index.d.ts +6 -0
- package/lib/{controllers → modules/device}/index.js +5 -2
- package/lib/{types → modules/device/types}/DeviceContent.d.ts +16 -7
- package/lib/{types → modules/device/types}/DeviceContent.js +0 -0
- package/lib/{core-classes → modules/engine}/DeviceManagerEngine.d.ts +7 -7
- package/lib/modules/engine/DeviceManagerEngine.js +69 -0
- package/lib/modules/engine/index.d.ts +2 -0
- package/lib/{models → modules/engine}/index.js +2 -2
- package/lib/{types → modules/engine/types}/DeviceManagerConfiguration.d.ts +1 -1
- package/lib/{types → modules/engine/types}/DeviceManagerConfiguration.js +0 -0
- package/lib/{types → modules/measure}/DecodedPayload.d.ts +4 -4
- package/lib/{types → modules/measure}/DecodedPayload.js +0 -0
- package/lib/{core-classes → modules/measure}/Decoder.d.ts +3 -3
- package/lib/{core-classes → modules/measure}/Decoder.js +3 -1
- package/lib/{controllers → modules/measure}/DecoderController.d.ts +4 -4
- package/lib/{controllers → modules/measure}/DecoderController.js +3 -3
- package/lib/{core-classes/registers → modules/measure}/DecodersRegister.d.ts +5 -5
- package/lib/{core-classes/registers → modules/measure}/DecodersRegister.js +23 -23
- package/lib/{core-classes → modules/measure}/MeasureService.d.ts +21 -8
- package/lib/{core-classes → modules/measure}/MeasureService.js +60 -34
- package/lib/{core-classes/registers → modules/measure}/MeasuresRegister.d.ts +2 -2
- package/lib/{core-classes/registers → modules/measure}/MeasuresRegister.js +4 -3
- package/lib/{core-classes → modules/measure}/PayloadService.d.ts +5 -5
- package/lib/{core-classes → modules/measure}/PayloadService.js +1 -1
- package/lib/modules/measure/collections/measuresMappings.d.ts +151 -0
- package/lib/{mappings → modules/measure/collections}/measuresMappings.js +28 -15
- package/lib/{mappings → modules/measure/collections}/payloadsMappings.d.ts +0 -0
- package/lib/modules/measure/collections/payloadsMappings.js +20 -0
- package/lib/modules/measure/index.d.ts +13 -0
- package/lib/{core-classes → modules/measure}/index.js +11 -7
- package/lib/{measures → modules/measure/measures}/BatteryMeasure.d.ts +2 -1
- package/lib/modules/measure/measures/BatteryMeasure.js +12 -0
- package/lib/{measures → modules/measure/measures}/HumidityMeasure.d.ts +2 -1
- package/lib/modules/measure/measures/HumidityMeasure.js +12 -0
- package/lib/{measures → modules/measure/measures}/MovementMeasure.d.ts +2 -1
- package/lib/{measures → modules/measure/measures}/MovementMeasure.js +3 -3
- package/lib/{measures → modules/measure/measures}/PositionMeasure.d.ts +2 -1
- package/lib/{measures → modules/measure/measures}/PositionMeasure.js +5 -5
- package/lib/{measures → modules/measure/measures}/TemperatureMeasure.d.ts +2 -1
- package/lib/modules/measure/measures/TemperatureMeasure.js +12 -0
- package/lib/modules/measure/measures/index.d.ts +5 -0
- package/lib/{measures → modules/measure/measures}/index.js +0 -0
- package/lib/{types → modules/measure/types}/DecoderContent.d.ts +1 -1
- package/lib/{types → modules/measure/types}/DecoderContent.js +0 -0
- package/lib/{types/measures → modules/measure/types}/MeasureContent.d.ts +17 -7
- package/lib/{types/measures → modules/measure/types}/MeasureContent.js +0 -0
- package/lib/{types/measures → modules/measure/types}/MeasureDefinition.d.ts +1 -1
- package/lib/{types/measures → modules/measure/types}/MeasureDefinition.js +0 -0
- package/lib/{controllers → modules/metadata}/MetadataController.d.ts +4 -4
- package/lib/{controllers → modules/metadata}/MetadataController.js +15 -9
- package/lib/{controllers → modules/metadata}/RelationalController.d.ts +11 -11
- package/lib/{controllers → modules/metadata}/RelationalController.js +58 -46
- package/lib/{mappings → modules/metadata/collections}/fieldpathMappings.d.ts +0 -0
- package/lib/{mappings → modules/metadata/collections}/fieldpathMappings.js +6 -6
- package/lib/{mappings → modules/metadata/collections}/genericEmbeddedMapping.d.ts +0 -0
- package/lib/{mappings → modules/metadata/collections}/genericEmbeddedMapping.js +2 -2
- package/lib/{mappings → modules/metadata/collections}/metadataMappings.d.ts +0 -0
- package/lib/modules/metadata/collections/metadataMappings.js +64 -0
- package/lib/modules/metadata/index.d.ts +5 -0
- package/lib/modules/metadata/index.js +22 -0
- package/lib/{types → modules/metadata/types}/MetadataContent.d.ts +2 -2
- package/lib/{types → modules/metadata/types}/MetadataContent.js +0 -0
- package/lib/utils/index.d.ts +1 -1
- package/lib/utils/writeMany.d.ts +1 -1
- package/package.json +12 -12
- package/lib/controllers/MeasureDefinitionController.d.ts +0 -0
- package/lib/controllers/MeasureDefinitionController.js +0 -1
- package/lib/controllers/index.d.ts +0 -3
- package/lib/core-classes/DeviceManagerEngine.js +0 -62
- package/lib/core-classes/index.d.ts +0 -9
- package/lib/mappings/assetCategoryMappings.js +0 -23
- package/lib/mappings/deviceMappings.d.ts +0 -44
- package/lib/mappings/index.d.ts +0 -4
- package/lib/mappings/measuresMappings.d.ts +0 -81
- package/lib/mappings/metadataMappings.js +0 -64
- package/lib/mappings/payloadsMappings.js +0 -20
- package/lib/measures/BatteryMeasure.js +0 -12
- package/lib/measures/HumidityMeasure.js +0 -12
- package/lib/measures/TemperatureMeasure.js +0 -12
- package/lib/measures/index.d.ts +0 -5
- package/lib/models/Config.d.ts +0 -21
- package/lib/models/Config.js +0 -26
- package/lib/models/index.d.ts +0 -2
- package/lib/types/index.d.ts +0 -9
- package/lib/types/index.js +0 -26
package/index.d.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
export * from './lib/DeviceManagerPlugin';
|
|
2
|
-
export * from './lib/
|
|
3
|
-
export * from './lib/
|
|
4
|
-
export * from './lib/
|
|
5
|
-
export * from './lib/
|
|
2
|
+
export * from './lib/modules/asset';
|
|
3
|
+
export * from './lib/modules/asset-category';
|
|
4
|
+
export * from './lib/modules/device';
|
|
5
|
+
export * from './lib/modules/engine';
|
|
6
|
+
export * from './lib/modules/measure';
|
|
7
|
+
export * from './lib/modules/metadata';
|
package/index.js
CHANGED
|
@@ -15,8 +15,10 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./lib/DeviceManagerPlugin"), exports);
|
|
18
|
-
__exportStar(require("./lib/
|
|
19
|
-
__exportStar(require("./lib/
|
|
20
|
-
__exportStar(require("./lib/
|
|
21
|
-
__exportStar(require("./lib/
|
|
18
|
+
__exportStar(require("./lib/modules/asset"), exports);
|
|
19
|
+
__exportStar(require("./lib/modules/asset-category"), exports);
|
|
20
|
+
__exportStar(require("./lib/modules/device"), exports);
|
|
21
|
+
__exportStar(require("./lib/modules/engine"), exports);
|
|
22
|
+
__exportStar(require("./lib/modules/measure"), exports);
|
|
23
|
+
__exportStar(require("./lib/modules/metadata"), exports);
|
|
22
24
|
//# sourceMappingURL=index.js.map
|
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
import { Plugin, PluginContext, JSONObject, KuzzleRequest } from
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import { Plugin, PluginContext, JSONObject, KuzzleRequest } from "kuzzle";
|
|
2
|
+
import { DevicesRegister } from "./modules/device";
|
|
3
|
+
import { AssetsRegister } from "./modules/asset";
|
|
4
|
+
import { DeviceManagerConfiguration } from "./modules/engine";
|
|
5
|
+
import { MeasuresRegister, DecodersRegister } from "./modules/measure";
|
|
4
6
|
export declare class DeviceManagerPlugin extends Plugin {
|
|
5
7
|
config: DeviceManagerConfiguration;
|
|
6
8
|
private assetController;
|
|
@@ -7,69 +7,67 @@ exports.DeviceManagerPlugin = void 0;
|
|
|
7
7
|
const lodash_1 = __importDefault(require("lodash"));
|
|
8
8
|
const kuzzle_1 = require("kuzzle");
|
|
9
9
|
const kuzzle_plugin_commons_1 = require("kuzzle-plugin-commons");
|
|
10
|
-
const
|
|
11
|
-
const
|
|
12
|
-
const
|
|
13
|
-
const
|
|
14
|
-
const
|
|
15
|
-
const
|
|
16
|
-
const AssetCategoryService_1 = require("./core-classes/AssetCategoryService");
|
|
17
|
-
const MeasureService_1 = require("./core-classes/MeasureService");
|
|
10
|
+
const asset_category_1 = require("./modules/asset-category");
|
|
11
|
+
const metadata_1 = require("./modules/metadata");
|
|
12
|
+
const device_1 = require("./modules/device");
|
|
13
|
+
const asset_1 = require("./modules/asset");
|
|
14
|
+
const engine_1 = require("./modules/engine");
|
|
15
|
+
const measure_1 = require("./modules/measure");
|
|
18
16
|
class DeviceManagerPlugin extends kuzzle_1.Plugin {
|
|
19
17
|
constructor() {
|
|
20
18
|
super({
|
|
21
|
-
kuzzleVersion:
|
|
19
|
+
kuzzleVersion: ">=2.16.8 <3",
|
|
22
20
|
});
|
|
23
21
|
this.api = {
|
|
24
|
-
|
|
25
|
-
actions: {}
|
|
26
|
-
}
|
|
22
|
+
"device-manager/payload": {
|
|
23
|
+
actions: {},
|
|
24
|
+
},
|
|
27
25
|
};
|
|
28
26
|
/* eslint-disable sort-keys */
|
|
29
27
|
this.config = {
|
|
30
|
-
adminIndex:
|
|
28
|
+
adminIndex: "device-manager",
|
|
31
29
|
adminCollections: {
|
|
32
30
|
config: {
|
|
33
|
-
name:
|
|
31
|
+
name: "config",
|
|
34
32
|
mappings: {
|
|
35
|
-
dynamic:
|
|
36
|
-
properties: {}
|
|
33
|
+
dynamic: "strict",
|
|
34
|
+
properties: {},
|
|
37
35
|
},
|
|
38
36
|
settings: {},
|
|
39
37
|
},
|
|
40
38
|
devices: {
|
|
41
|
-
name:
|
|
42
|
-
mappings:
|
|
39
|
+
name: "devices",
|
|
40
|
+
mappings: device_1.devicesMappings,
|
|
43
41
|
settings: {},
|
|
44
42
|
},
|
|
45
43
|
payloads: {
|
|
46
|
-
name:
|
|
47
|
-
mappings:
|
|
44
|
+
name: "payloads",
|
|
45
|
+
mappings: measure_1.payloadsMappings,
|
|
48
46
|
settings: {},
|
|
49
|
-
}
|
|
47
|
+
},
|
|
50
48
|
},
|
|
51
49
|
engineCollections: {
|
|
52
50
|
config: {
|
|
53
|
-
name:
|
|
51
|
+
name: "config",
|
|
54
52
|
mappings: {
|
|
55
|
-
dynamic:
|
|
56
|
-
properties: {}
|
|
53
|
+
dynamic: "strict",
|
|
54
|
+
properties: {},
|
|
57
55
|
},
|
|
58
|
-
settings: {}
|
|
59
|
-
}
|
|
56
|
+
settings: {},
|
|
57
|
+
},
|
|
60
58
|
},
|
|
61
|
-
batchInterval: 10
|
|
59
|
+
batchInterval: 10,
|
|
62
60
|
};
|
|
63
61
|
/* eslint-enable sort-keys */
|
|
64
|
-
this.measuresRegister = new
|
|
65
|
-
this.decodersRegister = new
|
|
66
|
-
this.devicesRegister = new
|
|
67
|
-
this.assetsRegister = new
|
|
68
|
-
this.measures.register(
|
|
69
|
-
this.measures.register(
|
|
70
|
-
this.measures.register(
|
|
71
|
-
this.measures.register(
|
|
72
|
-
this.measures.register(
|
|
62
|
+
this.measuresRegister = new measure_1.MeasuresRegister();
|
|
63
|
+
this.decodersRegister = new measure_1.DecodersRegister(this.measuresRegister);
|
|
64
|
+
this.devicesRegister = new device_1.DevicesRegister(this.measuresRegister);
|
|
65
|
+
this.assetsRegister = new asset_1.AssetsRegister(this.measuresRegister);
|
|
66
|
+
this.measures.register("temperature", measure_1.temperatureMeasure);
|
|
67
|
+
this.measures.register("position", measure_1.positionMeasure);
|
|
68
|
+
this.measures.register("movement", measure_1.movementMeasure);
|
|
69
|
+
this.measures.register("humidity", measure_1.humidityMeasure);
|
|
70
|
+
this.measures.register("battery", measure_1.batteryMeasure);
|
|
73
71
|
}
|
|
74
72
|
get sdk() {
|
|
75
73
|
return this.context.accessors.sdk;
|
|
@@ -110,12 +108,12 @@ class DeviceManagerPlugin extends kuzzle_1.Plugin {
|
|
|
110
108
|
}
|
|
111
109
|
async unknowPayload(request) {
|
|
112
110
|
const body = request.getBody();
|
|
113
|
-
const device = request.getString(
|
|
111
|
+
const device = request.getString("device");
|
|
114
112
|
const documentContent = {
|
|
115
113
|
deviceModel: device,
|
|
116
|
-
rawPayload: body
|
|
114
|
+
rawPayload: body,
|
|
117
115
|
};
|
|
118
|
-
this.sdk.document.create(this.config.adminIndex,
|
|
116
|
+
this.sdk.document.create(this.config.adminIndex, "payloads", documentContent);
|
|
119
117
|
}
|
|
120
118
|
/**
|
|
121
119
|
* Init the plugin
|
|
@@ -123,66 +121,94 @@ class DeviceManagerPlugin extends kuzzle_1.Plugin {
|
|
|
123
121
|
async init(config, context) {
|
|
124
122
|
this.config = lodash_1.default.merge({}, this.config, config);
|
|
125
123
|
this.context = context;
|
|
124
|
+
this.assetCategoryService = new asset_category_1.AssetCategoryService(this);
|
|
126
125
|
/* eslint-disable sort-keys */
|
|
127
126
|
this.pipes = {
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
127
|
+
"device-manager/asset:before*": this.pipeCheckEngine.bind(this),
|
|
128
|
+
"device-manager/device:beforeAttachEngine": this.pipeCheckEngine.bind(this),
|
|
129
|
+
"device-manager/device:beforeSearch": this.pipeCheckEngine.bind(this),
|
|
130
|
+
"device-manager/device:beforeUpdate": this.pipeCheckEngine.bind(this),
|
|
131
|
+
"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
|
+
},
|
|
133
158
|
};
|
|
134
159
|
/* eslint-enable sort-keys */
|
|
135
160
|
this.adminConfigManager = new kuzzle_plugin_commons_1.ConfigManager(this, {
|
|
136
161
|
mappings: this.config.adminCollections.config.mappings,
|
|
137
162
|
settings: this.config.adminCollections.config.settings,
|
|
138
163
|
});
|
|
139
|
-
this.adminConfigManager.register(
|
|
164
|
+
this.adminConfigManager.register("device-manager", {
|
|
140
165
|
properties: {
|
|
141
|
-
provisioningStrategy: { type:
|
|
142
|
-
}
|
|
166
|
+
provisioningStrategy: { type: "keyword" },
|
|
167
|
+
},
|
|
143
168
|
});
|
|
144
|
-
this.adminConfigManager.register(
|
|
169
|
+
this.adminConfigManager.register("engine", {
|
|
145
170
|
properties: {
|
|
146
|
-
group: { type:
|
|
147
|
-
index: { type:
|
|
148
|
-
name: { type:
|
|
149
|
-
}
|
|
171
|
+
group: { type: "keyword" },
|
|
172
|
+
index: { type: "keyword" },
|
|
173
|
+
name: { type: "keyword" },
|
|
174
|
+
},
|
|
150
175
|
});
|
|
151
176
|
this.engineConfigManager = new kuzzle_plugin_commons_1.ConfigManager(this, {
|
|
152
177
|
mappings: this.config.engineCollections.config.mappings,
|
|
153
178
|
settings: this.config.engineCollections.config.settings,
|
|
154
179
|
});
|
|
155
|
-
this.assetCategoryService = new AssetCategoryService_1.AssetCategoryService(this);
|
|
156
180
|
this.batchController = new kuzzle_1.BatchController(this.sdk, {
|
|
157
|
-
interval: this.config.batchInterval
|
|
181
|
+
interval: this.config.batchInterval,
|
|
158
182
|
});
|
|
159
|
-
this.assetService = new
|
|
160
|
-
this.deviceService = new
|
|
161
|
-
this.measuresService = new
|
|
162
|
-
this.payloadService = new
|
|
163
|
-
this.deviceManagerEngine = new
|
|
183
|
+
this.assetService = new asset_1.AssetService(this, this.batchController);
|
|
184
|
+
this.deviceService = new device_1.DeviceService(this, this.batchController, this.assetService, this.decodersRegister);
|
|
185
|
+
this.measuresService = new measure_1.MeasureService(this, this.batchController, this.assetService, this.measuresRegister, this.assetCategoryService);
|
|
186
|
+
this.payloadService = new measure_1.PayloadService(this, this.batchController, this.measuresService);
|
|
187
|
+
this.deviceManagerEngine = new engine_1.DeviceManagerEngine(this, this.assetsRegister, this.devicesRegister, this.measuresRegister, this.adminConfigManager, this.engineConfigManager);
|
|
164
188
|
this.decodersRegister.init(this.context);
|
|
165
|
-
this.assetController = new
|
|
166
|
-
this.deviceController = new
|
|
167
|
-
this.decodersController = new
|
|
168
|
-
this.engineController = new kuzzle_plugin_commons_1.EngineController(
|
|
169
|
-
this.assetCategoryController = new
|
|
170
|
-
this.metadataController = new
|
|
171
|
-
this.api[
|
|
172
|
-
|
|
173
|
-
this.api[
|
|
174
|
-
this.api[
|
|
175
|
-
this.api[
|
|
176
|
-
this.api[
|
|
177
|
-
|
|
189
|
+
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);
|
|
191
|
+
this.decodersController = new measure_1.DecoderController(this, this.decodersRegister);
|
|
192
|
+
this.engineController = new kuzzle_plugin_commons_1.EngineController("device-manager", this, this.deviceManagerEngine);
|
|
193
|
+
this.assetCategoryController = new asset_category_1.AssetCategoryController(this, this.assetCategoryService);
|
|
194
|
+
this.metadataController = new metadata_1.MetadataController(this, this.assetCategoryService);
|
|
195
|
+
this.api["device-manager/payload"] =
|
|
196
|
+
this.decodersRegister.getPayloadController(this.payloadService);
|
|
197
|
+
this.api["device-manager/asset"] = this.assetController.definition;
|
|
198
|
+
this.api["device-manager/device"] = this.deviceController.definition;
|
|
199
|
+
this.api["device-manager/decoder"] = this.decodersController.definition;
|
|
200
|
+
this.api["device-manager/assetCategory"] =
|
|
201
|
+
this.assetCategoryController.definition;
|
|
202
|
+
this.api["device-manager/metadata"] = this.metadataController.definition;
|
|
203
|
+
this.api["device-manager/payload"].actions.generic = {
|
|
178
204
|
handler: this.unknowPayload.bind(this),
|
|
179
|
-
http: [{ path:
|
|
205
|
+
http: [{ path: "device-manager/payload/:device", verb: "post" }],
|
|
180
206
|
};
|
|
181
207
|
this.hooks = {
|
|
182
|
-
|
|
208
|
+
"kuzzle:state:live": async () => {
|
|
183
209
|
await this.decodersRegister.createDefaultRights();
|
|
184
|
-
this.context.log.info(
|
|
185
|
-
}
|
|
210
|
+
this.context.log.info("Default rights for payload controller has been registered.");
|
|
211
|
+
},
|
|
186
212
|
};
|
|
187
213
|
this.decodersRegister.printDecoders();
|
|
188
214
|
await this.initDatabase();
|
|
@@ -191,10 +217,10 @@ class DeviceManagerPlugin extends kuzzle_1.Plugin {
|
|
|
191
217
|
* Initialize the administration index of the plugin
|
|
192
218
|
*/
|
|
193
219
|
async initDatabase() {
|
|
194
|
-
const mutex = new kuzzle_1.Mutex(
|
|
220
|
+
const mutex = new kuzzle_1.Mutex("device-manager/initDatabase");
|
|
195
221
|
await mutex.lock();
|
|
196
222
|
try {
|
|
197
|
-
if (!await this.sdk.index.exists(this.config.adminIndex)) {
|
|
223
|
+
if (!(await this.sdk.index.exists(this.config.adminIndex))) {
|
|
198
224
|
// Possible race condition because of index cache propagation.
|
|
199
225
|
// The index has been created but the node didn't receive the index
|
|
200
226
|
// cache update message yet, causing index:exists to returns false
|
|
@@ -202,22 +228,25 @@ class DeviceManagerPlugin extends kuzzle_1.Plugin {
|
|
|
202
228
|
await this.sdk.index.create(this.config.adminIndex);
|
|
203
229
|
}
|
|
204
230
|
catch (error) {
|
|
205
|
-
if (!error.message.includes(
|
|
231
|
+
if (!error.message.includes("already exists")) {
|
|
206
232
|
throw error;
|
|
207
233
|
}
|
|
208
234
|
}
|
|
209
235
|
}
|
|
210
236
|
await Promise.all([
|
|
211
|
-
this.adminConfigManager
|
|
212
|
-
.
|
|
237
|
+
this.adminConfigManager
|
|
238
|
+
.createCollection(this.config.adminIndex)
|
|
239
|
+
.catch((error) => {
|
|
213
240
|
throw new kuzzle_1.PluginImplementationError(`Cannot create admin "config" collection: ${error}`);
|
|
214
241
|
}),
|
|
215
|
-
this.sdk.collection
|
|
216
|
-
.
|
|
242
|
+
this.sdk.collection
|
|
243
|
+
.create(this.config.adminIndex, "devices", this.devicesRegister.getMappings())
|
|
244
|
+
.catch((error) => {
|
|
217
245
|
throw new kuzzle_1.PluginImplementationError(`Cannot create admin "devices" collection: ${error}`);
|
|
218
246
|
}),
|
|
219
|
-
this.sdk.collection
|
|
220
|
-
.
|
|
247
|
+
this.sdk.collection
|
|
248
|
+
.create(this.config.adminIndex, "payloads", this.getPayloadsMappings())
|
|
249
|
+
.catch((error) => {
|
|
221
250
|
throw new kuzzle_1.PluginImplementationError(`Cannot create admin "payloads" collection: ${error}`);
|
|
222
251
|
}),
|
|
223
252
|
]);
|
|
@@ -238,7 +267,7 @@ class DeviceManagerPlugin extends kuzzle_1.Plugin {
|
|
|
238
267
|
for (const decoder of this.decodersRegister.decoders) {
|
|
239
268
|
mappings.properties.payload.properties = {
|
|
240
269
|
...mappings.properties.payload.properties,
|
|
241
|
-
...decoder.payloadsMappings
|
|
270
|
+
...decoder.payloadsMappings,
|
|
242
271
|
};
|
|
243
272
|
}
|
|
244
273
|
return mappings;
|
|
@@ -247,20 +276,20 @@ class DeviceManagerPlugin extends kuzzle_1.Plugin {
|
|
|
247
276
|
* Initialize the config document if it does not exists
|
|
248
277
|
*/
|
|
249
278
|
async initializeConfig() {
|
|
250
|
-
const exists = await this.sdk.document.exists(this.config.adminIndex, this.adminConfigManager.collection,
|
|
279
|
+
const exists = await this.sdk.document.exists(this.config.adminIndex, this.adminConfigManager.collection, "plugin--device-manager");
|
|
251
280
|
if (!exists) {
|
|
252
281
|
await this.sdk.document.create(this.config.adminIndex, this.adminConfigManager.collection, {
|
|
253
|
-
|
|
254
|
-
type:
|
|
255
|
-
},
|
|
282
|
+
"device-manager": { provisioningStrategy: "auto" },
|
|
283
|
+
type: "device-manager",
|
|
284
|
+
}, "plugin--device-manager");
|
|
256
285
|
}
|
|
257
286
|
}
|
|
258
287
|
async pipeCheckEngine(request) {
|
|
259
|
-
const engineId = request.getString(
|
|
288
|
+
const engineId = request.getString("engineId");
|
|
260
289
|
if (engineId !== this.config.adminIndex) {
|
|
261
|
-
const { result: { exists } } = await this.sdk.query({
|
|
262
|
-
action:
|
|
263
|
-
controller:
|
|
290
|
+
const { result: { exists }, } = await this.sdk.query({
|
|
291
|
+
action: "exists",
|
|
292
|
+
controller: "device-manager/engine",
|
|
264
293
|
index: engineId,
|
|
265
294
|
});
|
|
266
295
|
if (!exists) {
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import { KuzzleRequest, Plugin } from
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import { RelationalController } from
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
1
|
+
import { KuzzleRequest, Plugin } from "kuzzle";
|
|
2
|
+
import { MeasureService } from "../measure";
|
|
3
|
+
import { AssetCategoryService } from "../asset-category";
|
|
4
|
+
import { DeviceService } from "../device";
|
|
5
|
+
import { RelationalController } from "../metadata";
|
|
6
|
+
import { BaseAsset } from "./BaseAsset";
|
|
7
|
+
import { AssetService } from "./AssetService";
|
|
8
|
+
import { BaseAssetContent } from "./types/BaseAssetContent";
|
|
8
9
|
export declare class AssetController extends RelationalController {
|
|
9
10
|
private assetService;
|
|
10
11
|
private deviceService;
|
|
@@ -22,7 +23,7 @@ export declare class AssetController extends RelationalController {
|
|
|
22
23
|
asset: BaseAsset;
|
|
23
24
|
}>;
|
|
24
25
|
getMeasures(request: KuzzleRequest): Promise<{
|
|
25
|
-
measures: import("kuzzle").KDocument<import("../
|
|
26
|
+
measures: import("kuzzle").KDocument<import("../measure").MeasureContent<import("kuzzle").JSONObject>>[];
|
|
26
27
|
}>;
|
|
27
28
|
get(request: KuzzleRequest): Promise<BaseAssetContent>;
|
|
28
29
|
unlinkCategory(request: KuzzleRequest): Promise<import("kuzzle").KDocument<{
|
|
@@ -35,7 +36,7 @@ export declare class AssetController extends RelationalController {
|
|
|
35
36
|
asset: import("kuzzle").JSONObject | (() => import("kuzzle").JSONObject);
|
|
36
37
|
engineId: string;
|
|
37
38
|
invalids: import("kuzzle").JSONObject[];
|
|
38
|
-
valids: any[] | import("../
|
|
39
|
+
valids: any[] | import("../measure").MeasureContent<import("kuzzle").JSONObject>[];
|
|
39
40
|
}>;
|
|
40
41
|
update(request: KuzzleRequest): Promise<import("kuzzle").KDocument<{
|
|
41
42
|
[x: string]: any;
|