kuzzle-device-manager 0.4.13 → 2.0.0-rc3
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 +6 -1
- package/lib/DeviceManagerPlugin.d.ts +33 -65
- package/lib/DeviceManagerPlugin.js +142 -131
- package/lib/controllers/AssetController.d.ts +20 -5
- package/lib/controllers/AssetController.js +78 -23
- package/lib/controllers/DecodersController.d.ts +16 -0
- package/lib/controllers/DecodersController.js +27 -0
- package/lib/controllers/DeviceController.d.ts +25 -22
- package/lib/controllers/DeviceController.js +150 -109
- package/lib/controllers/index.d.ts +1 -1
- package/lib/controllers/index.js +6 -2
- package/lib/core-classes/AssetService.d.ts +31 -0
- package/lib/core-classes/AssetService.js +82 -0
- package/lib/core-classes/Decoder.d.ts +14 -59
- package/lib/core-classes/Decoder.js +16 -86
- package/lib/core-classes/DeviceManagerEngine.d.ts +11 -9
- package/lib/core-classes/DeviceManagerEngine.js +20 -32
- package/lib/core-classes/DeviceService.d.ts +81 -24
- package/lib/core-classes/DeviceService.js +178 -220
- package/lib/core-classes/PayloadService.d.ts +39 -26
- package/lib/core-classes/PayloadService.js +132 -124
- package/lib/core-classes/index.d.ts +5 -4
- package/lib/core-classes/index.js +10 -5
- 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 +46 -0
- package/lib/core-classes/registers/DecodersRegister.js +167 -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 +29 -0
- package/lib/core-classes/registers/MeasuresRegister.js +53 -0
- package/lib/mappings/assetsMappings.d.ts +36 -0
- package/lib/mappings/assetsMappings.js +36 -0
- package/lib/mappings/deviceMappings.d.ts +44 -0
- package/lib/mappings/deviceMappings.js +42 -0
- package/lib/mappings/index.d.ts +4 -0
- package/lib/mappings/index.js +21 -0
- package/lib/mappings/measuresMappings.d.ts +53 -0
- package/lib/mappings/measuresMappings.js +48 -0
- package/lib/mappings/payloadsMappings.d.ts +18 -0
- package/lib/mappings/payloadsMappings.js +16 -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 +1 -48
- package/lib/models/BaseAsset.js +5 -43
- package/lib/models/Config.d.ts +1 -13
- package/lib/models/Device.d.ts +5 -96
- package/lib/models/Device.js +5 -73
- package/lib/models/index.d.ts +0 -1
- package/lib/models/index.js +5 -2
- package/lib/types/BaseAssetContent.d.ts +8 -3
- package/lib/types/DecodedPayload.d.ts +42 -0
- package/lib/types/{AssetsHistoryContent.js → DecodedPayload.js} +1 -1
- package/lib/types/DecoderContent.d.ts +4 -0
- package/lib/types/DecoderContent.js +3 -0
- package/lib/types/DeviceContent.d.ts +12 -44
- package/lib/types/DeviceManagerConfiguration.d.ts +40 -0
- package/lib/types/DeviceManagerConfiguration.js +3 -0
- package/lib/types/index.d.ts +7 -2
- package/lib/types/index.js +12 -3
- package/lib/types/measures/MeasureContent.d.ts +56 -0
- package/lib/types/measures/MeasureContent.js +3 -0
- package/lib/types/measures/MeasureDefinition.d.ts +40 -0
- package/lib/types/measures/MeasureDefinition.js +3 -0
- package/lib/types/measures/Measurement.d.ts +19 -0
- package/lib/types/{Measure.js → measures/Measurement.js} +1 -1
- package/lib/utils/index.d.ts +1 -1
- package/lib/utils/index.js +6 -2
- package/lib/utils/writeMany.d.ts +13 -0
- package/lib/utils/writeMany.js +37 -0
- package/package.json +14 -18
- package/lib/controllers/CRUDController.d.ts +0 -34
- 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/BatchProcessing/index.js +0 -16
- 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
|
@@ -7,23 +7,25 @@ exports.PayloadService = void 0;
|
|
|
7
7
|
const lodash_1 = __importDefault(require("lodash"));
|
|
8
8
|
const kuzzle_1 = require("kuzzle");
|
|
9
9
|
const uuid_1 = require("uuid");
|
|
10
|
+
const kuzzle_sdk_1 = require("kuzzle-sdk");
|
|
10
11
|
const models_1 = require("../models");
|
|
11
|
-
const utils_1 = require("../utils");
|
|
12
12
|
class PayloadService {
|
|
13
|
-
constructor(plugin,
|
|
13
|
+
constructor(plugin, measuresRegister) {
|
|
14
14
|
this.config = plugin.config;
|
|
15
15
|
this.context = plugin.context;
|
|
16
|
-
this.
|
|
16
|
+
this.measuresRegister = measuresRegister;
|
|
17
|
+
this.batch = new kuzzle_sdk_1.BatchController(this.sdk, {
|
|
18
|
+
interval: plugin.config.batchInterval
|
|
19
|
+
});
|
|
17
20
|
}
|
|
18
21
|
get sdk() {
|
|
19
22
|
return this.context.accessors.sdk;
|
|
20
23
|
}
|
|
24
|
+
get app() {
|
|
25
|
+
return global.app;
|
|
26
|
+
}
|
|
21
27
|
async process(request, decoder, { refresh = undefined } = {}) {
|
|
22
|
-
const payload = request.
|
|
23
|
-
if (!payload
|
|
24
|
-
|| (typeof payload === 'object' && Object.keys(payload).length === 0)) {
|
|
25
|
-
throw new kuzzle_1.BadRequestError('The body must contain the payload.');
|
|
26
|
-
}
|
|
28
|
+
const payload = request.getBody();
|
|
27
29
|
const uuid = request.input.args.uuid || (0, uuid_1.v4)();
|
|
28
30
|
let valid = true;
|
|
29
31
|
try {
|
|
@@ -31,160 +33,166 @@ class PayloadService {
|
|
|
31
33
|
if (!valid) {
|
|
32
34
|
return { valid };
|
|
33
35
|
}
|
|
34
|
-
await decoder.beforeProcessing(payload, request);
|
|
35
36
|
}
|
|
36
37
|
catch (error) {
|
|
37
38
|
valid = false;
|
|
38
39
|
throw error;
|
|
39
40
|
}
|
|
40
41
|
finally {
|
|
41
|
-
await this.
|
|
42
|
+
await this.batch.create(this.config.adminIndex, 'payloads', {
|
|
42
43
|
deviceModel: decoder.deviceModel,
|
|
44
|
+
payload,
|
|
43
45
|
uuid,
|
|
44
46
|
valid,
|
|
45
|
-
payload,
|
|
46
47
|
}, uuid);
|
|
47
48
|
}
|
|
48
|
-
const
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
49
|
+
const decodedPayload = await decoder.decode(payload, request);
|
|
50
|
+
const newMeasures = [];
|
|
51
|
+
const deviceId = models_1.Device.id(decoder.deviceModel, decodedPayload.reference);
|
|
52
|
+
for (const [type, measure] of Object.entries(decodedPayload.measures)) {
|
|
53
|
+
newMeasures.push({
|
|
54
|
+
measuredAt: measure.measuredAt,
|
|
55
|
+
origin: {
|
|
56
|
+
assetId: null,
|
|
57
|
+
id: deviceId,
|
|
58
|
+
model: decoder.deviceModel,
|
|
59
|
+
payloadUuids: [uuid],
|
|
60
|
+
type: 'device',
|
|
61
|
+
},
|
|
62
|
+
type,
|
|
63
|
+
unit: this.measuresRegister.get(type).unit,
|
|
64
|
+
values: measure.values
|
|
65
|
+
});
|
|
54
66
|
}
|
|
55
|
-
|
|
56
|
-
|
|
67
|
+
try {
|
|
68
|
+
const deviceDoc = await this.batch.get(this.config.adminIndex, 'devices', deviceId);
|
|
69
|
+
const device = new models_1.Device(deviceDoc._source);
|
|
70
|
+
if (device._source.assetId) {
|
|
71
|
+
for (const measure of newMeasures) {
|
|
72
|
+
measure.origin.assetId = device._source.assetId;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
return await this.update(device, newMeasures, { refresh });
|
|
57
76
|
}
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
77
|
+
catch (error) {
|
|
78
|
+
if (error.id === 'services.storage.not_found') {
|
|
79
|
+
return this.provisionning(decoder.deviceModel, decodedPayload.reference, newMeasures, { refresh });
|
|
80
|
+
}
|
|
81
|
+
throw error;
|
|
62
82
|
}
|
|
63
|
-
return await this.deviceProvisionning(device, decoder, request, { refresh });
|
|
64
83
|
}
|
|
65
|
-
async
|
|
66
|
-
const
|
|
67
|
-
|
|
68
|
-
|
|
84
|
+
async provisionning(model, reference, measures, { refresh }) {
|
|
85
|
+
const pluginConfig = await this.batch.get(this.config.adminIndex, this.config.adminCollections.config.name, 'plugin--device-manager');
|
|
86
|
+
const autoProvisioning = pluginConfig._source['device-manager'].provisioningStrategy === 'auto';
|
|
87
|
+
if (!autoProvisioning) {
|
|
88
|
+
throw new kuzzle_1.UnauthorizedError(`The device model "${model}" with reference "${reference}" is not registered on the platform.`);
|
|
89
|
+
}
|
|
90
|
+
const deviceId = models_1.Device.id(model, reference);
|
|
91
|
+
const deviceContent = {
|
|
92
|
+
measures,
|
|
93
|
+
model,
|
|
94
|
+
reference,
|
|
95
|
+
};
|
|
96
|
+
return this.register(deviceId, deviceContent, { refresh });
|
|
69
97
|
}
|
|
70
98
|
/**
|
|
71
|
-
*
|
|
72
|
-
*
|
|
73
|
-
* If autoProvisionning is on, device is automatically registered, otherwise
|
|
74
|
-
* we request the admin provisioning catalog to ensure this device is allowed
|
|
75
|
-
* to register.
|
|
76
|
-
*
|
|
77
|
-
* After registration, we look at the admin provisioning catalog entry to:
|
|
78
|
-
* - attach the device to a tenant
|
|
79
|
-
* - link the device to an asset of this tenant
|
|
80
|
-
*
|
|
81
|
-
* Then we look into the tenant provisioning catalog entry to:
|
|
82
|
-
* - link the device to an asset of this tenant
|
|
99
|
+
* Register a new device by creating the document in admin index
|
|
100
|
+
* @todo add before/afterRegister events
|
|
83
101
|
*/
|
|
84
|
-
async
|
|
85
|
-
const
|
|
86
|
-
const
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
throw new kuzzle_1.BadRequestError(`Device ${device._id} is not allowed for registration.`);
|
|
93
|
-
}
|
|
94
|
-
const ret = await this.register(device, decoder, request, { refresh });
|
|
95
|
-
// If there is not auto attachment to a tenant then we cannot link asset as well
|
|
96
|
-
if (!catalogEntry || !catalogEntry.content.tenantId) {
|
|
97
|
-
return ret;
|
|
98
|
-
}
|
|
99
|
-
await this.sdk.query({
|
|
100
|
-
controller: 'device-manager/device',
|
|
101
|
-
action: 'attachTenant',
|
|
102
|
-
_id: device._id,
|
|
103
|
-
index: catalogEntry.content.tenantId,
|
|
104
|
-
});
|
|
105
|
-
if (catalogEntry.content.assetId) {
|
|
106
|
-
await this.sdk.query({
|
|
107
|
-
controller: 'device-manager/device',
|
|
108
|
-
action: 'linkAsset',
|
|
109
|
-
_id: device._id,
|
|
110
|
-
assetId: catalogEntry.content.assetId,
|
|
111
|
-
});
|
|
112
|
-
}
|
|
113
|
-
const tenantCatalogEntry = await this.getCatalogEntry(catalogEntry.content.tenantId, device._id);
|
|
114
|
-
if (tenantCatalogEntry
|
|
115
|
-
&& tenantCatalogEntry.content.authorized !== false
|
|
116
|
-
&& tenantCatalogEntry.content.assetId) {
|
|
117
|
-
await this.sdk.query({
|
|
118
|
-
controller: 'device-manager/device',
|
|
119
|
-
action: 'linkAsset',
|
|
120
|
-
_id: device._id,
|
|
121
|
-
assetId: tenantCatalogEntry.content.assetId,
|
|
122
|
-
});
|
|
123
|
-
}
|
|
124
|
-
return ret;
|
|
102
|
+
async register(deviceId, deviceContent, { refresh }) {
|
|
103
|
+
const deviceDoc = await this.batch.create(this.config.adminIndex, 'devices', deviceContent, deviceId, { refresh });
|
|
104
|
+
const device = new models_1.Device(deviceDoc._source);
|
|
105
|
+
return {
|
|
106
|
+
asset: null,
|
|
107
|
+
device: device.serialize(),
|
|
108
|
+
engineId: device._source.engineId,
|
|
109
|
+
};
|
|
125
110
|
}
|
|
126
111
|
/**
|
|
127
|
-
*
|
|
112
|
+
* Updates the device with the new measures:
|
|
113
|
+
* - in admin index
|
|
114
|
+
* - in engine index
|
|
115
|
+
* - in linked asset
|
|
116
|
+
* - historize measures in engine index
|
|
117
|
+
*
|
|
118
|
+
* @todo add before/afterUpdate events
|
|
128
119
|
*/
|
|
129
|
-
async
|
|
130
|
-
try {
|
|
131
|
-
const document = await this.batchController.get(index, this.config.configCollection, `catalog--${deviceId}`);
|
|
132
|
-
return new models_1.Catalog(document);
|
|
133
|
-
}
|
|
134
|
-
catch (error) {
|
|
135
|
-
if (error.id !== 'services.storage.not_found') {
|
|
136
|
-
throw error;
|
|
137
|
-
}
|
|
138
|
-
return null;
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
async update(device, decoder, request, { refresh }) {
|
|
120
|
+
async update(device, newMeasures, { refresh }) {
|
|
142
121
|
const refreshableCollections = [];
|
|
143
|
-
const
|
|
144
|
-
const enrichedDevice = await decoder.beforeUpdate(device, request);
|
|
145
|
-
const deviceDocument = await this.batchController.update(this.config.adminIndex, 'devices', enrichedDevice._id, enrichedDevice._source, { source: true, retryOnConflict: 10 });
|
|
146
|
-
const updatedDevice = new models_1.Device(deviceDocument._source, deviceDocument._id);
|
|
122
|
+
const updatedDevice = await this.updateDevice(device, newMeasures);
|
|
147
123
|
refreshableCollections.push([this.config.adminIndex, 'devices']);
|
|
148
|
-
const
|
|
124
|
+
const engineId = updatedDevice._source.engineId;
|
|
149
125
|
let updatedAsset = null;
|
|
150
126
|
// Propagate device into tenant index
|
|
151
|
-
if (
|
|
152
|
-
await this.
|
|
153
|
-
|
|
127
|
+
if (engineId) {
|
|
128
|
+
await this.historizeMeasures(engineId, newMeasures);
|
|
129
|
+
await this.batch.update(engineId, 'devices', updatedDevice._id, updatedDevice._source, { retryOnConflict: 10 });
|
|
130
|
+
refreshableCollections.push([engineId, 'devices']);
|
|
154
131
|
// Propagate measures into linked asset
|
|
155
|
-
const assetId =
|
|
132
|
+
const assetId = updatedDevice._source.assetId;
|
|
156
133
|
if (assetId) {
|
|
157
|
-
updatedAsset = await this.propagateToAsset(
|
|
158
|
-
|
|
159
|
-
refreshableCollections.push([tenantId, 'assets']);
|
|
134
|
+
updatedAsset = await this.propagateToAsset(engineId, newMeasures, assetId);
|
|
135
|
+
refreshableCollections.push([engineId, 'assets']);
|
|
160
136
|
}
|
|
161
137
|
}
|
|
162
138
|
if (refresh === 'wait_for') {
|
|
163
139
|
await Promise.all(refreshableCollections.map(([index, collection]) => (this.sdk.collection.refresh(index, collection))));
|
|
164
140
|
}
|
|
165
|
-
return
|
|
141
|
+
return {
|
|
142
|
+
asset: updatedAsset ? updatedAsset.serialize() : null,
|
|
143
|
+
device: device.serialize(),
|
|
144
|
+
engineId,
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* Updates a device with the new measures
|
|
149
|
+
*
|
|
150
|
+
* @returns Updated device
|
|
151
|
+
*/
|
|
152
|
+
async updateDevice(device, newMeasures) {
|
|
153
|
+
// dup array reference
|
|
154
|
+
const measures = newMeasures.map(m => m);
|
|
155
|
+
// Keep previous measures that were not updated
|
|
156
|
+
for (const previousMeasure of device._source.measures) {
|
|
157
|
+
if (!measures.find(m => m.type === previousMeasure.type)) {
|
|
158
|
+
measures.push(previousMeasure);
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
device._source.measures = measures;
|
|
162
|
+
const result = await global.app.trigger(`engine:${device._source.engineId}:device:measures:new`, { device, measures: newMeasures });
|
|
163
|
+
const deviceDocument = await this.batch.update(this.config.adminIndex, 'devices', result.device._id, result.device._source, { retryOnConflict: 10, source: true });
|
|
164
|
+
return new models_1.Device(deviceDocument._source);
|
|
166
165
|
}
|
|
167
166
|
/**
|
|
168
|
-
*
|
|
167
|
+
* Save measures in engine "measures" collection
|
|
169
168
|
*/
|
|
170
|
-
async
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
asset._source.measures = lodash_1.default.merge(asset._source.measures, measures);
|
|
175
|
-
const { result } = await global.app.trigger(`engine:${tenantId}:asset:measures:new`, (0, utils_1.eventPayload)({ asset, measureTypes }));
|
|
176
|
-
const assetDocument = await this.batchController.update(tenantId, 'assets', assetId, result.asset._source, { source: true, retryOnConflict: 10 });
|
|
177
|
-
return new models_1.BaseAsset(assetDocument._source, assetDocument._id);
|
|
169
|
+
async historizeMeasures(engineId, measures) {
|
|
170
|
+
await Promise.all(measures.map(measure => {
|
|
171
|
+
return this.batch.create(engineId, 'measures', measure);
|
|
172
|
+
}));
|
|
178
173
|
}
|
|
179
174
|
/**
|
|
180
|
-
*
|
|
175
|
+
* Propagate the measures inside the linked asset document.
|
|
181
176
|
*/
|
|
182
|
-
async
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
177
|
+
async propagateToAsset(engineId, newMeasures, assetId) {
|
|
178
|
+
// dup array reference
|
|
179
|
+
const measures = newMeasures.map(m => m);
|
|
180
|
+
const asset = await this.batch.get(engineId, 'assets', assetId);
|
|
181
|
+
if (!lodash_1.default.isArray(asset._source.measures)) {
|
|
182
|
+
throw new kuzzle_1.BadRequestError(`Asset "${assetId}" measures property is not an array.`);
|
|
183
|
+
}
|
|
184
|
+
// Keep previous measures that were not updated
|
|
185
|
+
// array are updated in place so we need to keep previous elements
|
|
186
|
+
for (const previousMeasure of asset._source.measures) {
|
|
187
|
+
if (!measures.find(m => m.type === previousMeasure.type)) {
|
|
188
|
+
measures.push(previousMeasure);
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
asset._source.measures = measures;
|
|
192
|
+
// Give the list of new measures types in event payload
|
|
193
|
+
const result = await global.app.trigger(`engine:${engineId}:asset:measures:new`, { asset, measures: newMeasures });
|
|
194
|
+
const assetDocument = await this.batch.update(engineId, 'assets', assetId, result.asset._source, { retryOnConflict: 10, source: true });
|
|
195
|
+
return new models_1.BaseAsset(assetDocument._source, assetDocument._id);
|
|
188
196
|
}
|
|
189
197
|
}
|
|
190
198
|
exports.PayloadService = PayloadService;
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
export * from './PayloadService';
|
|
2
2
|
export * from './DeviceManagerEngine';
|
|
3
3
|
export * from './DeviceService';
|
|
4
|
-
export * from './MigrationService';
|
|
5
|
-
export * from './BatchProcessing';
|
|
6
4
|
export * from './Decoder';
|
|
7
|
-
export * from './
|
|
8
|
-
export * from './
|
|
5
|
+
export * from './AssetService';
|
|
6
|
+
export * from './registers/AssetsRegister';
|
|
7
|
+
export * from './registers/DevicesRegister';
|
|
8
|
+
export * from './registers/MeasuresRegister';
|
|
9
|
+
export * from './registers/DecodersRegister';
|
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
3
|
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
5
9
|
}) : (function(o, m, k, k2) {
|
|
6
10
|
if (k2 === undefined) k2 = k;
|
|
7
11
|
o[k2] = m[k];
|
|
@@ -13,9 +17,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
13
17
|
__exportStar(require("./PayloadService"), exports);
|
|
14
18
|
__exportStar(require("./DeviceManagerEngine"), exports);
|
|
15
19
|
__exportStar(require("./DeviceService"), exports);
|
|
16
|
-
__exportStar(require("./MigrationService"), exports);
|
|
17
|
-
__exportStar(require("./BatchProcessing"), exports);
|
|
18
20
|
__exportStar(require("./Decoder"), exports);
|
|
19
|
-
__exportStar(require("./
|
|
20
|
-
__exportStar(require("./
|
|
21
|
+
__exportStar(require("./AssetService"), exports);
|
|
22
|
+
__exportStar(require("./registers/AssetsRegister"), exports);
|
|
23
|
+
__exportStar(require("./registers/DevicesRegister"), exports);
|
|
24
|
+
__exportStar(require("./registers/MeasuresRegister"), exports);
|
|
25
|
+
__exportStar(require("./registers/DecodersRegister"), exports);
|
|
21
26
|
//# sourceMappingURL=index.js.map
|
package/lib/core-classes/{CustomMappings/AssetMappingsManager.d.ts → registers/AssetsRegister.d.ts}
RENAMED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { JSONObject } from 'kuzzle';
|
|
2
|
-
import {
|
|
3
|
-
export declare class
|
|
2
|
+
import { MeasuresRegister } from './MeasuresRegister';
|
|
3
|
+
export declare class AssetsRegister {
|
|
4
4
|
private baseMappings;
|
|
5
|
-
private
|
|
5
|
+
private measuresRegister;
|
|
6
6
|
private assetByName;
|
|
7
7
|
private assetByGroup;
|
|
8
|
-
constructor(
|
|
8
|
+
constructor(measuresRegister: MeasuresRegister);
|
|
9
9
|
/**
|
|
10
10
|
* Register an asset type with custom metadata.
|
|
11
11
|
*
|
|
@@ -16,16 +16,15 @@ export declare class AssetMappingsManager {
|
|
|
16
16
|
* @param metadata Asset type custom metadata
|
|
17
17
|
* @param options.group Only inject this asset type to engine of this group
|
|
18
18
|
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
19
|
+
* ```js
|
|
21
20
|
* plugin.assets.register('container', {
|
|
22
21
|
* size: { type: 'integer' },
|
|
23
22
|
* serial: { type: 'keyword' },
|
|
24
23
|
* });
|
|
25
|
-
*
|
|
24
|
+
* ```
|
|
26
25
|
*/
|
|
27
|
-
register(
|
|
26
|
+
register(type: string, metadata: JSONObject, { group }?: {
|
|
28
27
|
group?: string;
|
|
29
28
|
}): void;
|
|
30
|
-
|
|
29
|
+
getMappings(group?: string): JSONObject;
|
|
31
30
|
}
|
package/lib/core-classes/{CustomMappings/AssetMappingsManager.js → registers/AssetsRegister.js}
RENAMED
|
@@ -3,15 +3,16 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.
|
|
6
|
+
exports.AssetsRegister = void 0;
|
|
7
7
|
const lodash_1 = __importDefault(require("lodash"));
|
|
8
8
|
const kuzzle_1 = require("kuzzle");
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
const mappings_1 = require("../../mappings");
|
|
10
|
+
class AssetsRegister {
|
|
11
|
+
constructor(measuresRegister) {
|
|
11
12
|
this.assetByName = new Map();
|
|
12
13
|
this.assetByGroup = new Map();
|
|
13
|
-
this.baseMappings =
|
|
14
|
-
this.
|
|
14
|
+
this.baseMappings = JSON.parse(JSON.stringify(mappings_1.assetsMappings));
|
|
15
|
+
this.measuresRegister = measuresRegister;
|
|
15
16
|
this.assetByGroup.set('commons', []);
|
|
16
17
|
}
|
|
17
18
|
/**
|
|
@@ -24,44 +25,32 @@ class AssetMappingsManager {
|
|
|
24
25
|
* @param metadata Asset type custom metadata
|
|
25
26
|
* @param options.group Only inject this asset type to engine of this group
|
|
26
27
|
*
|
|
27
|
-
*
|
|
28
|
-
*
|
|
28
|
+
* ```js
|
|
29
29
|
* plugin.assets.register('container', {
|
|
30
30
|
* size: { type: 'integer' },
|
|
31
31
|
* serial: { type: 'keyword' },
|
|
32
32
|
* });
|
|
33
|
-
*
|
|
33
|
+
* ```
|
|
34
34
|
*/
|
|
35
|
-
register(
|
|
36
|
-
if (this.assetByName.has(
|
|
37
|
-
throw new kuzzle_1.PluginImplementationError(`Asset of type "${
|
|
35
|
+
register(type, metadata, { group = 'commons' } = {}) {
|
|
36
|
+
if (this.assetByName.has(type)) {
|
|
37
|
+
throw new kuzzle_1.PluginImplementationError(`Asset of type "${type}" has already been registered.`);
|
|
38
38
|
}
|
|
39
39
|
const definition = {
|
|
40
|
-
name,
|
|
41
40
|
group,
|
|
42
41
|
metadata,
|
|
42
|
+
type,
|
|
43
43
|
};
|
|
44
|
-
this.assetByName.set(
|
|
44
|
+
this.assetByName.set(type, definition);
|
|
45
45
|
if (!this.assetByGroup.has(group)) {
|
|
46
46
|
this.assetByGroup.set(group, []);
|
|
47
47
|
}
|
|
48
48
|
this.assetByGroup.get(group).push(definition);
|
|
49
49
|
}
|
|
50
|
-
|
|
50
|
+
getMappings(group = 'commons') {
|
|
51
51
|
const mappings = JSON.parse(JSON.stringify(this.baseMappings));
|
|
52
|
-
const deviceMappings = this.deviceMappings.get();
|
|
53
52
|
mappings.properties.measures.dynamic = 'false';
|
|
54
|
-
|
|
55
|
-
mappings.properties.measures.properties[name] = {
|
|
56
|
-
properties: {
|
|
57
|
-
id: { type: 'keyword' },
|
|
58
|
-
model: { type: 'keyword' },
|
|
59
|
-
reference: { type: 'keyword' },
|
|
60
|
-
qos: deviceMappings.properties.qos,
|
|
61
|
-
...measure.properties,
|
|
62
|
-
}
|
|
63
|
-
};
|
|
64
|
-
}
|
|
53
|
+
mappings.properties.measures = this.measuresRegister.getMappings();
|
|
65
54
|
if (this.assetByGroup.has('commons')) {
|
|
66
55
|
for (const definition of this.assetByGroup.get('commons')) {
|
|
67
56
|
mappings.properties.metadata.properties = lodash_1.default.merge({}, mappings.properties.metadata.properties, definition.metadata);
|
|
@@ -75,5 +64,5 @@ class AssetMappingsManager {
|
|
|
75
64
|
return mappings;
|
|
76
65
|
}
|
|
77
66
|
}
|
|
78
|
-
exports.
|
|
79
|
-
//# sourceMappingURL=
|
|
67
|
+
exports.AssetsRegister = AssetsRegister;
|
|
68
|
+
//# sourceMappingURL=AssetsRegister.js.map
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { ControllerDefinition, PluginContext } from 'kuzzle';
|
|
2
|
+
import { Decoder } from '../Decoder';
|
|
3
|
+
import { DecoderContent } from '../../types/DecoderContent';
|
|
4
|
+
import { PayloadService } from '../PayloadService';
|
|
5
|
+
export declare class DecodersRegister {
|
|
6
|
+
private context;
|
|
7
|
+
private _decoders;
|
|
8
|
+
private get sdk();
|
|
9
|
+
get decoders(): Decoder[];
|
|
10
|
+
init(context: PluginContext): void;
|
|
11
|
+
list(): Promise<DecoderContent[]>;
|
|
12
|
+
/**
|
|
13
|
+
* Registers a new decoder for a device model.
|
|
14
|
+
*
|
|
15
|
+
* This will register a new API action:
|
|
16
|
+
* - controller: `device-manager/payload`
|
|
17
|
+
* - action: `action` property of the decoder or the device model in kebab-case
|
|
18
|
+
*
|
|
19
|
+
* @param decoder Instantiated decoder
|
|
20
|
+
*
|
|
21
|
+
* @returns Corresponding API action requestPayload
|
|
22
|
+
*/
|
|
23
|
+
register(decoder: Decoder): {
|
|
24
|
+
action: string;
|
|
25
|
+
controller: string;
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* Build the PayloadController with registered decoders
|
|
29
|
+
*
|
|
30
|
+
* @todo generate OpenAPI specification
|
|
31
|
+
*
|
|
32
|
+
* @internal
|
|
33
|
+
*/
|
|
34
|
+
getPayloadController(payloadService: PayloadService): ControllerDefinition;
|
|
35
|
+
printDecoders(): void;
|
|
36
|
+
/**
|
|
37
|
+
* Creates default roles, profiles and users associated to the generated actions
|
|
38
|
+
* in the Payload controller.
|
|
39
|
+
*
|
|
40
|
+
* This method never returns a rejected promise.
|
|
41
|
+
*/
|
|
42
|
+
createDefaultRights(): Promise<void>;
|
|
43
|
+
private createDefaultUsers;
|
|
44
|
+
private createDefaultProfiles;
|
|
45
|
+
private createDefaultRoles;
|
|
46
|
+
}
|