kuzzle-device-manager 0.4.15 → 2.0.0-rc4
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 +1 -0
- package/index.js +1 -0
- package/lib/DeviceManagerPlugin.d.ts +43 -68
- package/lib/DeviceManagerPlugin.js +168 -131
- package/lib/InternalCollection.d.ts +5 -0
- package/lib/InternalCollection.js +10 -0
- package/lib/controllers/AssetCategoryController.d.ts +28 -0
- package/lib/controllers/AssetCategoryController.js +189 -0
- package/lib/controllers/AssetController.d.ts +46 -5
- package/lib/controllers/AssetController.js +212 -24
- package/lib/controllers/DecodersController.d.ts +16 -0
- package/lib/controllers/DecodersController.js +27 -0
- package/lib/controllers/DeviceController.d.ts +40 -22
- package/lib/controllers/DeviceController.js +223 -112
- package/lib/controllers/MeasureDefinitionController.d.ts +0 -0
- package/lib/controllers/MeasureDefinitionController.js +1 -0
- package/lib/controllers/MetadataController.d.ts +16 -0
- package/lib/controllers/MetadataController.js +70 -0
- package/lib/controllers/RelationalController.d.ts +155 -0
- package/lib/controllers/RelationalController.js +410 -0
- package/lib/controllers/index.d.ts +1 -1
- package/lib/controllers/index.js +1 -1
- package/lib/core-classes/AssetCategoryService.d.ts +20 -0
- package/lib/core-classes/AssetCategoryService.js +178 -0
- package/lib/core-classes/AssetService.d.ts +40 -0
- package/lib/core-classes/AssetService.js +97 -0
- package/lib/core-classes/Decoder.d.ts +18 -60
- package/lib/core-classes/Decoder.js +22 -87
- package/lib/core-classes/DeviceManagerEngine.d.ts +11 -9
- package/lib/core-classes/DeviceManagerEngine.js +30 -32
- package/lib/core-classes/DeviceService.d.ts +98 -24
- package/lib/core-classes/DeviceService.js +239 -221
- package/lib/core-classes/MeasureService.d.ts +77 -0
- package/lib/core-classes/MeasureService.js +302 -0
- package/lib/core-classes/PayloadService.d.ts +19 -42
- package/lib/core-classes/PayloadService.js +21 -158
- package/lib/core-classes/index.d.ts +7 -6
- package/lib/core-classes/index.js +7 -6
- package/lib/core-classes/{CustomMappings/AssetMappingsManager.d.ts → registers/AssetsRegister.d.ts} +8 -9
- package/lib/core-classes/{CustomMappings/AssetMappingsManager.js → registers/AssetsRegister.js} +17 -28
- package/lib/core-classes/registers/DecodersRegister.d.ts +48 -0
- package/lib/core-classes/registers/DecodersRegister.js +171 -0
- package/lib/core-classes/registers/DevicesRegister.d.ts +20 -0
- package/lib/core-classes/registers/DevicesRegister.js +37 -0
- package/lib/core-classes/registers/MeasuresRegister.d.ts +30 -0
- package/lib/core-classes/registers/MeasuresRegister.js +56 -0
- package/lib/mappings/assetCategoryMappings.d.ts +69 -0
- package/lib/mappings/assetCategoryMappings.js +23 -0
- package/lib/mappings/assetsMappings.d.ts +130 -0
- package/lib/mappings/assetsMappings.js +72 -0
- package/lib/mappings/deviceMappings.d.ts +44 -0
- package/lib/mappings/deviceMappings.js +42 -0
- package/lib/mappings/fieldpathMappings.d.ts +17 -0
- package/lib/mappings/fieldpathMappings.js +21 -0
- package/lib/mappings/genericEmbeddedMapping.d.ts +1 -0
- package/lib/mappings/genericEmbeddedMapping.js +11 -0
- package/lib/mappings/index.d.ts +4 -0
- package/lib/{core-classes/BatchProcessing → mappings}/index.js +4 -3
- package/lib/mappings/measuresMappings.d.ts +82 -0
- package/lib/mappings/measuresMappings.js +72 -0
- package/lib/mappings/metadataMappings.d.ts +149 -0
- package/lib/mappings/metadataMappings.js +64 -0
- package/lib/mappings/payloadsMappings.d.ts +22 -0
- package/lib/mappings/payloadsMappings.js +20 -0
- package/lib/measures/BatteryMeasure.d.ts +7 -0
- package/lib/measures/BatteryMeasure.js +12 -0
- package/lib/measures/HumidityMeasure.d.ts +7 -0
- package/lib/measures/HumidityMeasure.js +12 -0
- package/lib/measures/MovementMeasure.d.ts +7 -0
- package/lib/measures/MovementMeasure.js +12 -0
- package/lib/measures/PositionMeasure.d.ts +12 -0
- package/lib/measures/PositionMeasure.js +16 -0
- package/lib/measures/TemperatureMeasure.d.ts +7 -0
- package/lib/measures/TemperatureMeasure.js +12 -0
- package/lib/measures/index.d.ts +5 -0
- package/lib/measures/index.js +22 -0
- package/lib/models/BaseAsset.d.ts +11 -49
- package/lib/models/BaseAsset.js +49 -43
- package/lib/models/Config.d.ts +1 -13
- package/lib/models/Device.d.ts +10 -97
- package/lib/models/Device.js +26 -72
- package/lib/models/index.d.ts +0 -1
- package/lib/models/index.js +0 -1
- package/lib/types/AssetCategoryContent.d.ts +29 -0
- package/lib/types/{AssetsHistoryContent.js → AssetCategoryContent.js} +1 -1
- package/lib/types/BaseAssetContent.d.ts +41 -4
- package/lib/types/DecodedPayload.d.ts +53 -0
- package/lib/types/DecodedPayload.js +3 -0
- package/lib/types/DecoderContent.d.ts +5 -0
- package/lib/types/DecoderContent.js +3 -0
- package/lib/types/DeviceContent.d.ts +15 -45
- package/lib/types/DeviceManagerConfiguration.d.ts +40 -0
- package/lib/types/DeviceManagerConfiguration.js +3 -0
- package/lib/types/MetadataContent.d.ts +30 -0
- package/lib/types/MetadataContent.js +15 -0
- package/lib/types/Request.d.ts +26 -0
- package/lib/types/{Measure.js → Request.js} +1 -1
- package/lib/types/index.d.ts +6 -2
- package/lib/types/index.js +6 -2
- package/lib/types/measures/MeasureContent.d.ts +79 -0
- package/lib/types/measures/MeasureContent.js +12 -0
- package/lib/types/measures/MeasureDefinition.d.ts +40 -0
- package/lib/types/measures/MeasureDefinition.js +3 -0
- package/lib/utils/index.d.ts +1 -1
- package/lib/utils/index.js +1 -1
- package/lib/utils/writeMany.d.ts +13 -0
- package/lib/utils/writeMany.js +39 -0
- package/package.json +15 -20
- package/lib/controllers/CRUDController.d.ts +0 -38
- package/lib/controllers/CRUDController.js +0 -65
- package/lib/core-classes/BatchProcessing/BatchController.d.ts +0 -34
- package/lib/core-classes/BatchProcessing/BatchController.js +0 -115
- package/lib/core-classes/BatchProcessing/BatchWriter.d.ts +0 -110
- package/lib/core-classes/BatchProcessing/BatchWriter.js +0 -264
- package/lib/core-classes/BatchProcessing/InstrumentablePromise.d.ts +0 -6
- package/lib/core-classes/BatchProcessing/InstrumentablePromise.js +0 -13
- package/lib/core-classes/BatchProcessing/index.d.ts +0 -3
- package/lib/core-classes/CustomMappings/DeviceMappingsManager.d.ts +0 -43
- package/lib/core-classes/CustomMappings/DeviceMappingsManager.js +0 -71
- package/lib/core-classes/MigrationService.d.ts +0 -13
- package/lib/core-classes/MigrationService.js +0 -49
- package/lib/models/Catalog.d.ts +0 -55
- package/lib/models/Catalog.js +0 -38
- package/lib/types/AssetsHistoryContent.d.ts +0 -9
- package/lib/types/Measure.d.ts +0 -54
- package/lib/utils/events.d.ts +0 -8
- package/lib/utils/events.js +0 -17
package/index.d.ts
CHANGED
package/index.js
CHANGED
|
@@ -17,5 +17,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
17
17
|
__exportStar(require("./lib/DeviceManagerPlugin"), exports);
|
|
18
18
|
__exportStar(require("./lib/core-classes"), exports);
|
|
19
19
|
__exportStar(require("./lib/models"), exports);
|
|
20
|
+
__exportStar(require("./lib/measures"), exports);
|
|
20
21
|
__exportStar(require("./lib/types"), exports);
|
|
21
22
|
//# sourceMappingURL=index.js.map
|
|
@@ -1,85 +1,61 @@
|
|
|
1
|
-
import { Plugin, PluginContext, JSONObject,
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Administration index name
|
|
6
|
-
*/
|
|
7
|
-
adminIndex: string;
|
|
8
|
-
/**
|
|
9
|
-
* Config collection name (in admin index)
|
|
10
|
-
*/
|
|
11
|
-
configCollection: string;
|
|
12
|
-
/**
|
|
13
|
-
* Administration collections mappings (in admin index)
|
|
14
|
-
*/
|
|
15
|
-
adminCollections: {
|
|
16
|
-
config: JSONObject;
|
|
17
|
-
devices: JSONObject;
|
|
18
|
-
payloads: JSONObject;
|
|
19
|
-
};
|
|
20
|
-
/**
|
|
21
|
-
* Tenants collections
|
|
22
|
-
*/
|
|
23
|
-
collections: {
|
|
24
|
-
assets: JSONObject;
|
|
25
|
-
devices: JSONObject;
|
|
26
|
-
'asset-history': JSONObject;
|
|
27
|
-
};
|
|
28
|
-
/**
|
|
29
|
-
* Interval to write documents from the buffer
|
|
30
|
-
*/
|
|
31
|
-
writerInterval: number;
|
|
32
|
-
};
|
|
1
|
+
import { Plugin, PluginContext, JSONObject, KuzzleRequest } from 'kuzzle';
|
|
2
|
+
import { AssetsRegister, DevicesRegister, MeasuresRegister, DecodersRegister } from './core-classes';
|
|
3
|
+
import { DeviceManagerConfiguration } from './types';
|
|
33
4
|
export declare class DeviceManagerPlugin extends Plugin {
|
|
34
|
-
config:
|
|
35
|
-
private defaultConfig;
|
|
5
|
+
config: DeviceManagerConfiguration;
|
|
36
6
|
private assetController;
|
|
37
7
|
private deviceController;
|
|
8
|
+
private decodersController;
|
|
38
9
|
private engineController;
|
|
39
|
-
|
|
10
|
+
private assetCategoryController;
|
|
11
|
+
private metadataController;
|
|
12
|
+
private treeNodeController;
|
|
13
|
+
private batchController;
|
|
14
|
+
private assetService;
|
|
15
|
+
private assetCategoryService;
|
|
16
|
+
private payloadService;
|
|
40
17
|
private deviceManagerEngine;
|
|
41
18
|
private deviceService;
|
|
42
|
-
private
|
|
43
|
-
|
|
44
|
-
|
|
19
|
+
private measuresService;
|
|
20
|
+
private decodersRegister;
|
|
21
|
+
private measuresRegister;
|
|
22
|
+
private devicesRegister;
|
|
23
|
+
private assetsRegister;
|
|
24
|
+
private adminConfigManager;
|
|
25
|
+
private engineConfigManager;
|
|
26
|
+
private get sdk();
|
|
27
|
+
/**
|
|
28
|
+
* Manager assets customization.
|
|
29
|
+
*
|
|
30
|
+
* @method register
|
|
31
|
+
*/
|
|
32
|
+
get assets(): AssetsRegister;
|
|
33
|
+
/**
|
|
34
|
+
* Manage devices customization.
|
|
35
|
+
*
|
|
36
|
+
* @method registerMetadata
|
|
37
|
+
*/
|
|
38
|
+
get devices(): DevicesRegister;
|
|
45
39
|
/**
|
|
46
|
-
*
|
|
47
|
-
*
|
|
40
|
+
* Manage measures customization.
|
|
41
|
+
*
|
|
42
|
+
* @method register
|
|
43
|
+
* @method get
|
|
48
44
|
*/
|
|
49
|
-
|
|
50
|
-
private deviceMappings;
|
|
51
|
-
private assetMappings;
|
|
52
|
-
get assets(): AssetMappingsManager;
|
|
53
|
-
get devices(): DeviceMappingsManager;
|
|
45
|
+
get measures(): MeasuresRegister;
|
|
54
46
|
/**
|
|
55
|
-
*
|
|
47
|
+
* Manage decoders customization.
|
|
48
|
+
*
|
|
49
|
+
* @method register
|
|
50
|
+
* @method list
|
|
56
51
|
*/
|
|
52
|
+
get decoders(): DecodersRegister;
|
|
57
53
|
constructor();
|
|
54
|
+
unknowPayload(request: KuzzleRequest): Promise<void>;
|
|
58
55
|
/**
|
|
59
56
|
* Init the plugin
|
|
60
57
|
*/
|
|
61
58
|
init(config: JSONObject, context: PluginContext): Promise<void>;
|
|
62
|
-
/**
|
|
63
|
-
* Registers a new decoder for a device model.
|
|
64
|
-
*
|
|
65
|
-
* This will register a new API action:
|
|
66
|
-
* - controller: `"device-manager/payload"`
|
|
67
|
-
* - action: `action` property of the decoder or the device model in kebab-case
|
|
68
|
-
*
|
|
69
|
-
* If a custom payload handler is given then it will be used to process payloads
|
|
70
|
-
* instead of the PayloadService.process method.
|
|
71
|
-
*
|
|
72
|
-
* @param decoder Instantiated decoder
|
|
73
|
-
* @param options.handler Custom payload handler
|
|
74
|
-
*
|
|
75
|
-
* @returns Corresponding API action requestPayload
|
|
76
|
-
*/
|
|
77
|
-
registerDecoder(decoder: Decoder, { handler }?: {
|
|
78
|
-
handler?: PayloadHandler;
|
|
79
|
-
}): {
|
|
80
|
-
controller: string;
|
|
81
|
-
action: string;
|
|
82
|
-
};
|
|
83
59
|
/**
|
|
84
60
|
* Initialize the administration index of the plugin
|
|
85
61
|
*/
|
|
@@ -96,5 +72,4 @@ export declare class DeviceManagerPlugin extends Plugin {
|
|
|
96
72
|
*/
|
|
97
73
|
private initializeConfig;
|
|
98
74
|
private pipeCheckEngine;
|
|
99
|
-
private generateConfigID;
|
|
100
75
|
}
|
|
@@ -9,139 +9,183 @@ const kuzzle_1 = require("kuzzle");
|
|
|
9
9
|
const kuzzle_plugin_commons_1 = require("kuzzle-plugin-commons");
|
|
10
10
|
const controllers_1 = require("./controllers");
|
|
11
11
|
const core_classes_1 = require("./core-classes");
|
|
12
|
-
const
|
|
12
|
+
const measures_1 = require("./measures");
|
|
13
|
+
const mappings_1 = require("./mappings");
|
|
14
|
+
const AssetCategoryController_1 = require("./controllers/AssetCategoryController");
|
|
15
|
+
const MetadataController_1 = require("./controllers/MetadataController");
|
|
16
|
+
const AssetCategoryService_1 = require("./core-classes/AssetCategoryService");
|
|
17
|
+
const MeasureService_1 = require("./core-classes/MeasureService");
|
|
13
18
|
class DeviceManagerPlugin extends kuzzle_1.Plugin {
|
|
14
|
-
/**
|
|
15
|
-
* Constructor
|
|
16
|
-
*/
|
|
17
19
|
constructor() {
|
|
18
20
|
super({
|
|
19
|
-
kuzzleVersion: '>=2.
|
|
21
|
+
kuzzleVersion: '>=2.16.8 <3'
|
|
20
22
|
});
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
this.decoders = new Map();
|
|
26
|
-
this.deviceMappings = new core_classes_1.DeviceMappingsManager(models_1.devicesMappings);
|
|
27
|
-
this.assetMappings = new core_classes_1.AssetMappingsManager(models_1.assetsMappings, this.deviceMappings);
|
|
23
|
+
this.decodersRegister = new core_classes_1.DecodersRegister();
|
|
24
|
+
this.measuresRegister = new core_classes_1.MeasuresRegister();
|
|
25
|
+
this.devicesRegister = new core_classes_1.DevicesRegister(this.measuresRegister);
|
|
26
|
+
this.assetsRegister = new core_classes_1.AssetsRegister(this.measuresRegister);
|
|
28
27
|
this.api = {
|
|
29
28
|
'device-manager/payload': {
|
|
30
29
|
actions: {}
|
|
31
30
|
}
|
|
32
31
|
};
|
|
33
|
-
|
|
32
|
+
/* eslint-disable sort-keys */
|
|
33
|
+
this.config = {
|
|
34
34
|
adminIndex: 'device-manager',
|
|
35
|
-
configCollection: 'config',
|
|
36
35
|
adminCollections: {
|
|
37
36
|
config: {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
properties: {
|
|
50
|
-
autoProvisionning: { type: 'boolean' },
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
}
|
|
37
|
+
name: 'config',
|
|
38
|
+
mappings: {
|
|
39
|
+
dynamic: 'strict',
|
|
40
|
+
properties: {}
|
|
41
|
+
},
|
|
42
|
+
settings: {},
|
|
43
|
+
},
|
|
44
|
+
devices: {
|
|
45
|
+
name: 'devices',
|
|
46
|
+
mappings: mappings_1.devicesMappings,
|
|
47
|
+
settings: {},
|
|
54
48
|
},
|
|
55
|
-
devices: models_1.devicesMappings,
|
|
56
49
|
payloads: {
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
valid: { type: 'boolean' },
|
|
61
|
-
deviceModel: { type: 'keyword' },
|
|
62
|
-
payload: {
|
|
63
|
-
dynamic: 'false',
|
|
64
|
-
properties: {}
|
|
65
|
-
}
|
|
66
|
-
}
|
|
50
|
+
name: 'payloads',
|
|
51
|
+
mappings: mappings_1.payloadsMappings,
|
|
52
|
+
settings: {},
|
|
67
53
|
}
|
|
68
54
|
},
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
55
|
+
engineCollections: {
|
|
56
|
+
config: {
|
|
57
|
+
name: 'config',
|
|
58
|
+
mappings: {
|
|
59
|
+
dynamic: 'strict',
|
|
60
|
+
properties: {}
|
|
61
|
+
},
|
|
62
|
+
settings: {}
|
|
63
|
+
}
|
|
73
64
|
},
|
|
74
|
-
|
|
65
|
+
batchInterval: 10
|
|
75
66
|
};
|
|
67
|
+
/* eslint-enable sort-keys */
|
|
68
|
+
this.measures.register('temperature', measures_1.temperatureMeasure);
|
|
69
|
+
this.measures.register('position', measures_1.positionMeasure);
|
|
70
|
+
this.measures.register('movement', measures_1.movementMeasure);
|
|
71
|
+
this.measures.register('humidity', measures_1.humidityMeasure);
|
|
72
|
+
this.measures.register('battery', measures_1.batteryMeasure);
|
|
76
73
|
}
|
|
77
74
|
get sdk() {
|
|
78
75
|
return this.context.accessors.sdk;
|
|
79
76
|
}
|
|
77
|
+
/**
|
|
78
|
+
* Manager assets customization.
|
|
79
|
+
*
|
|
80
|
+
* @method register
|
|
81
|
+
*/
|
|
80
82
|
get assets() {
|
|
81
|
-
return this.
|
|
83
|
+
return this.assetsRegister;
|
|
82
84
|
}
|
|
85
|
+
/**
|
|
86
|
+
* Manage devices customization.
|
|
87
|
+
*
|
|
88
|
+
* @method registerMetadata
|
|
89
|
+
*/
|
|
83
90
|
get devices() {
|
|
84
|
-
return this.
|
|
91
|
+
return this.devicesRegister;
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Manage measures customization.
|
|
95
|
+
*
|
|
96
|
+
* @method register
|
|
97
|
+
* @method get
|
|
98
|
+
*/
|
|
99
|
+
get measures() {
|
|
100
|
+
return this.measuresRegister;
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Manage decoders customization.
|
|
104
|
+
*
|
|
105
|
+
* @method register
|
|
106
|
+
* @method list
|
|
107
|
+
*/
|
|
108
|
+
get decoders() {
|
|
109
|
+
return this.decodersRegister;
|
|
110
|
+
}
|
|
111
|
+
async unknowPayload(request) {
|
|
112
|
+
const body = request.getBody();
|
|
113
|
+
const device = request.getString('device');
|
|
114
|
+
const documentContent = {
|
|
115
|
+
deviceModel: device,
|
|
116
|
+
rawPayload: body
|
|
117
|
+
};
|
|
118
|
+
this.sdk.document.create('device-manager', 'payloads', documentContent);
|
|
85
119
|
}
|
|
86
120
|
/**
|
|
87
121
|
* Init the plugin
|
|
88
122
|
*/
|
|
89
123
|
async init(config, context) {
|
|
90
|
-
this.config = lodash_1.default.merge({}, this.
|
|
124
|
+
this.config = lodash_1.default.merge({}, this.config, config);
|
|
91
125
|
this.context = context;
|
|
92
|
-
|
|
93
|
-
this.
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
126
|
+
/* eslint-disable sort-keys */
|
|
127
|
+
this.pipes = {
|
|
128
|
+
'device-manager/asset:before*': this.pipeCheckEngine.bind(this),
|
|
129
|
+
'device-manager/device:beforeAttachEngine': this.pipeCheckEngine.bind(this),
|
|
130
|
+
'device-manager/device:beforeSearch': this.pipeCheckEngine.bind(this),
|
|
131
|
+
'device-manager/device:beforeUpdate': this.pipeCheckEngine.bind(this),
|
|
132
|
+
'generic:document:beforeWrite': [],
|
|
133
|
+
};
|
|
134
|
+
/* eslint-enable sort-keys */
|
|
135
|
+
this.adminConfigManager = new kuzzle_plugin_commons_1.ConfigManager(this, {
|
|
136
|
+
mappings: this.config.adminCollections.config.mappings,
|
|
137
|
+
settings: this.config.adminCollections.config.settings,
|
|
138
|
+
});
|
|
139
|
+
this.adminConfigManager.register('device-manager', {
|
|
140
|
+
properties: {
|
|
141
|
+
provisioningStrategy: { type: 'keyword' },
|
|
142
|
+
}
|
|
143
|
+
});
|
|
144
|
+
this.adminConfigManager.register('engine', {
|
|
145
|
+
properties: {
|
|
146
|
+
group: { type: 'keyword' },
|
|
147
|
+
index: { type: 'keyword' },
|
|
148
|
+
name: { type: 'keyword' },
|
|
149
|
+
}
|
|
150
|
+
});
|
|
151
|
+
this.engineConfigManager = new kuzzle_plugin_commons_1.ConfigManager(this, {
|
|
152
|
+
mappings: this.config.engineCollections.config.mappings,
|
|
153
|
+
settings: this.config.engineCollections.config.settings,
|
|
154
|
+
});
|
|
155
|
+
this.assetCategoryService = new AssetCategoryService_1.AssetCategoryService(this);
|
|
156
|
+
this.batchController = new kuzzle_1.BatchController(this.sdk, {
|
|
157
|
+
interval: this.config.batchInterval
|
|
158
|
+
});
|
|
159
|
+
this.assetService = new core_classes_1.AssetService(this, this.batchController);
|
|
160
|
+
this.deviceService = new core_classes_1.DeviceService(this, this.batchController, this.assetService, this.decodersRegister);
|
|
161
|
+
this.measuresService = new MeasureService_1.MeasureService(this, this.batchController, this.deviceService, this.assetService, this.measuresRegister);
|
|
162
|
+
this.payloadService = new core_classes_1.PayloadService(this, this.batchController, this.measuresRegister, this.measuresService);
|
|
163
|
+
this.deviceManagerEngine = new core_classes_1.DeviceManagerEngine(this, this.assetsRegister, this.devicesRegister, this.measuresRegister, this.adminConfigManager, this.engineConfigManager);
|
|
164
|
+
this.decodersRegister.init(this.context);
|
|
165
|
+
this.assetController = new controllers_1.AssetController(this, this.assetService, this.deviceService, this.assetCategoryService, this.measuresService);
|
|
99
166
|
this.deviceController = new controllers_1.DeviceController(this, this.deviceService);
|
|
167
|
+
this.decodersController = new controllers_1.DecodersController(this, this.decodersRegister);
|
|
100
168
|
this.engineController = new kuzzle_plugin_commons_1.EngineController('device-manager', this, this.deviceManagerEngine);
|
|
169
|
+
this.assetCategoryController = new AssetCategoryController_1.AssetCategoryController(this, this.assetCategoryService);
|
|
170
|
+
this.metadataController = new MetadataController_1.MetadataController(this, this.assetCategoryService);
|
|
171
|
+
this.api['device-manager/payload'] = this.decodersRegister.getPayloadController(this.payloadService);
|
|
101
172
|
this.api['device-manager/asset'] = this.assetController.definition;
|
|
102
173
|
this.api['device-manager/device'] = this.deviceController.definition;
|
|
103
|
-
this.
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
};
|
|
110
|
-
await this.initDatabase();
|
|
111
|
-
await this.migrationService.run();
|
|
112
|
-
for (const decoder of this.decoders.values()) {
|
|
113
|
-
this.context.log.info(`Register API action "device-manager/payload:${decoder.action}" with decoder "${decoder.constructor.name}" for device "${decoder.deviceModel}"`);
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
/**
|
|
117
|
-
* Registers a new decoder for a device model.
|
|
118
|
-
*
|
|
119
|
-
* This will register a new API action:
|
|
120
|
-
* - controller: `"device-manager/payload"`
|
|
121
|
-
* - action: `action` property of the decoder or the device model in kebab-case
|
|
122
|
-
*
|
|
123
|
-
* If a custom payload handler is given then it will be used to process payloads
|
|
124
|
-
* instead of the PayloadService.process method.
|
|
125
|
-
*
|
|
126
|
-
* @param decoder Instantiated decoder
|
|
127
|
-
* @param options.handler Custom payload handler
|
|
128
|
-
*
|
|
129
|
-
* @returns Corresponding API action requestPayload
|
|
130
|
-
*/
|
|
131
|
-
registerDecoder(decoder, { handler } = {}) {
|
|
132
|
-
decoder.action = decoder.action || kuzzle_1.Inflector.kebabCase(decoder.deviceModel);
|
|
133
|
-
if (this.api['device-manager/payload'].actions[decoder.action]) {
|
|
134
|
-
throw new kuzzle_1.PluginImplementationError(`A decoder for "${decoder.deviceModel}" has already been registered.`);
|
|
135
|
-
}
|
|
136
|
-
this.api['device-manager/payload'].actions[decoder.action] = {
|
|
137
|
-
handler: request => handler ? handler(request, decoder) : this.payloadService.process(request, decoder),
|
|
138
|
-
http: decoder.http,
|
|
174
|
+
this.api['device-manager/decoders'] = this.decodersController.definition;
|
|
175
|
+
this.api['device-manager/assetCategory'] = this.assetCategoryController.definition;
|
|
176
|
+
this.api['device-manager/metadata'] = this.metadataController.definition;
|
|
177
|
+
this.api['device-manager/payload'].actions.generic = {
|
|
178
|
+
handler: this.unknowPayload.bind(this),
|
|
179
|
+
http: [{ path: 'device-manager/payload/:device', verb: 'post' }]
|
|
139
180
|
};
|
|
140
|
-
this.
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
181
|
+
this.hooks = {
|
|
182
|
+
'kuzzle:state:live': async () => {
|
|
183
|
+
await this.decodersRegister.createDefaultRights();
|
|
184
|
+
this.context.log.info('Default rights for payload controller has been registered.');
|
|
185
|
+
}
|
|
144
186
|
};
|
|
187
|
+
this.decodersRegister.printDecoders();
|
|
188
|
+
await this.initDatabase();
|
|
145
189
|
}
|
|
146
190
|
/**
|
|
147
191
|
* Initialize the administration index of the plugin
|
|
@@ -164,19 +208,21 @@ class DeviceManagerPlugin extends kuzzle_1.Plugin {
|
|
|
164
208
|
}
|
|
165
209
|
}
|
|
166
210
|
await Promise.all([
|
|
167
|
-
this.
|
|
168
|
-
|
|
169
|
-
|
|
211
|
+
this.adminConfigManager.createCollection(this.config.adminIndex)
|
|
212
|
+
.catch(error => {
|
|
213
|
+
throw new kuzzle_1.PluginImplementationError(`Cannot create admin "config" collection: ${error}`);
|
|
214
|
+
}),
|
|
215
|
+
this.sdk.collection.create(this.config.adminIndex, 'devices', this.devicesRegister.getMappings())
|
|
216
|
+
.catch(error => {
|
|
217
|
+
throw new kuzzle_1.PluginImplementationError(`Cannot create admin "devices" collection: ${error}`);
|
|
218
|
+
}),
|
|
219
|
+
this.sdk.collection.create(this.config.adminIndex, 'payloads', this.getPayloadsMappings())
|
|
220
|
+
.catch(error => {
|
|
221
|
+
throw new kuzzle_1.PluginImplementationError(`Cannot create admin "payloads" collection: ${error}`);
|
|
222
|
+
}),
|
|
170
223
|
]);
|
|
171
224
|
await this.initializeConfig();
|
|
172
225
|
}
|
|
173
|
-
catch (error) {
|
|
174
|
-
// When nodes are starting at the same time, the index cache synchronization
|
|
175
|
-
// message is received too late so index.exists returns false
|
|
176
|
-
if (error.id !== 'services.storage.index_already_exists') {
|
|
177
|
-
throw error;
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
226
|
finally {
|
|
181
227
|
await mutex.unlock();
|
|
182
228
|
}
|
|
@@ -188,8 +234,8 @@ class DeviceManagerPlugin extends kuzzle_1.Plugin {
|
|
|
188
234
|
* Those custom mappings allow to search raw payloads more efficiently.
|
|
189
235
|
*/
|
|
190
236
|
getPayloadsMappings() {
|
|
191
|
-
const mappings = JSON.parse(JSON.stringify(this.config.adminCollections.payloads));
|
|
192
|
-
for (const decoder of this.decoders
|
|
237
|
+
const { mappings } = JSON.parse(JSON.stringify(this.config.adminCollections.payloads));
|
|
238
|
+
for (const decoder of this.decodersRegister.decoders) {
|
|
193
239
|
mappings.properties.payload.properties = {
|
|
194
240
|
...mappings.properties.payload.properties,
|
|
195
241
|
...decoder.payloadsMappings
|
|
@@ -201,35 +247,26 @@ class DeviceManagerPlugin extends kuzzle_1.Plugin {
|
|
|
201
247
|
* Initialize the config document if it does not exists
|
|
202
248
|
*/
|
|
203
249
|
async initializeConfig() {
|
|
204
|
-
const exists = await this.sdk.document.exists(this.config.adminIndex, this.
|
|
250
|
+
const exists = await this.sdk.document.exists(this.config.adminIndex, this.adminConfigManager.collection, 'plugin--device-manager');
|
|
205
251
|
if (!exists) {
|
|
206
|
-
await this.sdk.document.create(this.config.adminIndex, this.
|
|
207
|
-
|
|
208
|
-
'device-manager'
|
|
252
|
+
await this.sdk.document.create(this.config.adminIndex, this.adminConfigManager.collection, {
|
|
253
|
+
'device-manager': { provisioningStrategy: 'auto' },
|
|
254
|
+
type: 'device-manager'
|
|
209
255
|
}, 'plugin--device-manager');
|
|
210
256
|
}
|
|
211
257
|
}
|
|
212
258
|
async pipeCheckEngine(request) {
|
|
213
|
-
const
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
}
|
|
224
|
-
async generateConfigID(request) {
|
|
225
|
-
if (request.getCollection() !== this.config.configCollection) {
|
|
226
|
-
return request;
|
|
227
|
-
}
|
|
228
|
-
const document = request.getBody();
|
|
229
|
-
if (document.type !== 'catalog' || request.getId(({ ifMissing: 'ignore' }))) {
|
|
230
|
-
return request;
|
|
259
|
+
const engineId = request.getString('engineId');
|
|
260
|
+
if (engineId !== this.config.adminIndex) {
|
|
261
|
+
const { result: { exists } } = await this.sdk.query({
|
|
262
|
+
action: 'exists',
|
|
263
|
+
controller: 'device-manager/engine',
|
|
264
|
+
index: engineId,
|
|
265
|
+
});
|
|
266
|
+
if (!exists) {
|
|
267
|
+
throw new kuzzle_1.BadRequestError(`Tenant "${engineId}" does not have a device-manager engine`);
|
|
268
|
+
}
|
|
231
269
|
}
|
|
232
|
-
request.input.args._id = `catalog--${document.catalog.deviceId}`;
|
|
233
270
|
return request;
|
|
234
271
|
}
|
|
235
272
|
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.InternalCollection = void 0;
|
|
4
|
+
var InternalCollection;
|
|
5
|
+
(function (InternalCollection) {
|
|
6
|
+
InternalCollection["ASSETS"] = "assets";
|
|
7
|
+
InternalCollection["DEVICES"] = "devices";
|
|
8
|
+
InternalCollection["MEASURES"] = "measures";
|
|
9
|
+
})(InternalCollection = exports.InternalCollection || (exports.InternalCollection = {}));
|
|
10
|
+
//# sourceMappingURL=InternalCollection.js.map
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { KuzzleRequest, Plugin } from 'kuzzle';
|
|
2
|
+
import { RelationalController } from './RelationalController';
|
|
3
|
+
import { ProcessedAssetCategoryContent } from '../types/AssetCategoryContent';
|
|
4
|
+
import { AssetCategoryService } from '../core-classes/AssetCategoryService';
|
|
5
|
+
export declare class AssetCategoryController extends RelationalController {
|
|
6
|
+
private assetCategoryService;
|
|
7
|
+
constructor(plugin: Plugin, assetCategoryService: AssetCategoryService);
|
|
8
|
+
create(request: KuzzleRequest): Promise<import("kuzzle").KDocument<{
|
|
9
|
+
[x: string]: any;
|
|
10
|
+
}>>;
|
|
11
|
+
update(request: KuzzleRequest): Promise<import("kuzzle").KDocument<{
|
|
12
|
+
[x: string]: any;
|
|
13
|
+
}>>;
|
|
14
|
+
delete(request: KuzzleRequest): Promise<string>;
|
|
15
|
+
linkParent(request: KuzzleRequest): Promise<import("kuzzle").KDocument<{
|
|
16
|
+
[x: string]: any;
|
|
17
|
+
}>>;
|
|
18
|
+
unlinkParent(request: KuzzleRequest): Promise<import("kuzzle").KDocument<{
|
|
19
|
+
[x: string]: any;
|
|
20
|
+
}>>;
|
|
21
|
+
unlinkMetadata(request: KuzzleRequest): Promise<import("kuzzle").KDocument<{
|
|
22
|
+
[x: string]: any;
|
|
23
|
+
}>>;
|
|
24
|
+
linkMetadata(request: KuzzleRequest): Promise<import("kuzzle").KDocument<{
|
|
25
|
+
[x: string]: any;
|
|
26
|
+
}>>;
|
|
27
|
+
get(request: KuzzleRequest): Promise<ProcessedAssetCategoryContent>;
|
|
28
|
+
}
|