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
|
@@ -1,264 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.BatchWriter = exports.BatchBuffer = void 0;
|
|
4
|
-
const BatchController_1 = require("./BatchController");
|
|
5
|
-
const InstrumentablePromise_1 = require("./InstrumentablePromise");
|
|
6
|
-
class BatchBuffer {
|
|
7
|
-
constructor() {
|
|
8
|
-
this.indexes = {};
|
|
9
|
-
}
|
|
10
|
-
/**
|
|
11
|
-
* Add a document to the buffer of a specific collection
|
|
12
|
-
*
|
|
13
|
-
* @param index Index name
|
|
14
|
-
* @param collection Collection name
|
|
15
|
-
* @param body Document content
|
|
16
|
-
* @param _id Document ID
|
|
17
|
-
* @param options Option object passed to the m* action
|
|
18
|
-
*
|
|
19
|
-
* @returns An object containing the index of the array of results and a promise resolving to the array of results
|
|
20
|
-
*/
|
|
21
|
-
add(index, collection, body, _id = undefined, options) {
|
|
22
|
-
if (!this.indexes[index]) {
|
|
23
|
-
this.indexes[index] = {};
|
|
24
|
-
}
|
|
25
|
-
if (!this.indexes[index][collection]) {
|
|
26
|
-
this.indexes[index][collection] = {
|
|
27
|
-
documents: [],
|
|
28
|
-
promise: new InstrumentablePromise_1.InstrumentablePromise(),
|
|
29
|
-
options,
|
|
30
|
-
};
|
|
31
|
-
}
|
|
32
|
-
const idx = this.indexes[index][collection].documents.length;
|
|
33
|
-
this.indexes[index][collection].options = { ...this.indexes[index][collection].options, ...options };
|
|
34
|
-
this.indexes[index][collection].documents.push({
|
|
35
|
-
_id,
|
|
36
|
-
body
|
|
37
|
-
});
|
|
38
|
-
return {
|
|
39
|
-
idx,
|
|
40
|
-
promise: this.indexes[index][collection].promise,
|
|
41
|
-
};
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
exports.BatchBuffer = BatchBuffer;
|
|
45
|
-
/**
|
|
46
|
-
* This class handle buffers for every supported API action of the document controller:
|
|
47
|
-
* - create, update, createOrReplace, replace, get, exists, delete
|
|
48
|
-
*
|
|
49
|
-
* Each buffer is filled with documents to be write/get/delete into a collection.
|
|
50
|
-
*
|
|
51
|
-
* A timer will regularly execute the m* actions with the documents inside the buffers.
|
|
52
|
-
*
|
|
53
|
-
* If the interval is too big, buffers may contain too much documents for Kuzzle limits.
|
|
54
|
-
* (e.g. "limits.documentsWriteCount" is 200 by default)
|
|
55
|
-
*/
|
|
56
|
-
class BatchWriter {
|
|
57
|
-
/**
|
|
58
|
-
* @param sdk Connected SDK
|
|
59
|
-
* @param options.interval Timer interval in ms (50). Actions will be executed every {interval} ms
|
|
60
|
-
* @param options.maxWriteBufferSize Max write buffer size (200). (Should match "limits.documentsWriteCount")
|
|
61
|
-
* @param options.maxReadBufferSize Max read buffer size. (Should match "limits.documentsReadCount")
|
|
62
|
-
*/
|
|
63
|
-
constructor(sdk, { interval = 50, maxWriteBufferSize = 200, maxReadBufferSize = 200 } = {}) {
|
|
64
|
-
// Buffers
|
|
65
|
-
this.buffers = {
|
|
66
|
-
create: new BatchBuffer(),
|
|
67
|
-
update: new BatchBuffer(),
|
|
68
|
-
get: new BatchBuffer(),
|
|
69
|
-
exists: new BatchBuffer(),
|
|
70
|
-
delete: new BatchBuffer(),
|
|
71
|
-
replace: new BatchBuffer(),
|
|
72
|
-
createOrReplace: new BatchBuffer(),
|
|
73
|
-
};
|
|
74
|
-
this.sdk = sdk;
|
|
75
|
-
this.interval = interval;
|
|
76
|
-
this.maxWriteBufferSize = maxWriteBufferSize;
|
|
77
|
-
this.maxReadBufferSize = maxReadBufferSize;
|
|
78
|
-
this.document = new BatchController_1.BatchController(this.sdk, this);
|
|
79
|
-
}
|
|
80
|
-
get addCreate() {
|
|
81
|
-
// @todo implements the send of buffer if approaching the limit
|
|
82
|
-
return this.buffers.create.add.bind(this.buffers.create);
|
|
83
|
-
}
|
|
84
|
-
get addUpdate() {
|
|
85
|
-
return this.buffers.update.add.bind(this.buffers.update);
|
|
86
|
-
}
|
|
87
|
-
get addGet() {
|
|
88
|
-
return this.buffers.get.add.bind(this.buffers.get);
|
|
89
|
-
}
|
|
90
|
-
get addExists() {
|
|
91
|
-
return this.buffers.exists.add.bind(this.buffers.exists);
|
|
92
|
-
}
|
|
93
|
-
get addDelete() {
|
|
94
|
-
return this.buffers.delete.add.bind(this.buffers.delete);
|
|
95
|
-
}
|
|
96
|
-
get addReplace() {
|
|
97
|
-
return this.buffers.replace.add.bind(this.buffers.replace);
|
|
98
|
-
}
|
|
99
|
-
get addCreateOrReplace() {
|
|
100
|
-
return this.buffers.createOrReplace.add.bind(this.buffers.createOrReplace);
|
|
101
|
-
}
|
|
102
|
-
/**
|
|
103
|
-
* Execute API actions with documents stored in the buffers.
|
|
104
|
-
*/
|
|
105
|
-
async execute() {
|
|
106
|
-
const buffers = {};
|
|
107
|
-
// make a copy of the buffers
|
|
108
|
-
for (const [name, buffer] of Object.entries(this.buffers)) {
|
|
109
|
-
buffers[name] = buffer;
|
|
110
|
-
}
|
|
111
|
-
// prepare to enqueue documents in buffers
|
|
112
|
-
this.prepareRound();
|
|
113
|
-
await Promise.all([
|
|
114
|
-
this.sendCreateBuffer(buffers.create),
|
|
115
|
-
this.sendUpdateBuffer(buffers.update),
|
|
116
|
-
this.sendCreateOrReplaceBuffer(buffers.createOrReplace),
|
|
117
|
-
this.sendDeleteBuffer(buffers.delete),
|
|
118
|
-
this.sendExistsBuffer(buffers.exists),
|
|
119
|
-
this.sendGetBuffer(buffers.get),
|
|
120
|
-
this.sendReplaceBuffer(buffers.replace),
|
|
121
|
-
]);
|
|
122
|
-
}
|
|
123
|
-
/**
|
|
124
|
-
* Initialize the buffers and start the timer
|
|
125
|
-
*/
|
|
126
|
-
begin() {
|
|
127
|
-
this.prepareRound();
|
|
128
|
-
this.timer = setInterval(async () => {
|
|
129
|
-
await this.execute();
|
|
130
|
-
}, this.interval);
|
|
131
|
-
}
|
|
132
|
-
/**
|
|
133
|
-
* Execute pending actions from the buffers and stop the timer.
|
|
134
|
-
*/
|
|
135
|
-
async end() {
|
|
136
|
-
await this.execute();
|
|
137
|
-
clearInterval(this.timer);
|
|
138
|
-
}
|
|
139
|
-
/**
|
|
140
|
-
* Reset all the buffers
|
|
141
|
-
*/
|
|
142
|
-
prepareRound() {
|
|
143
|
-
for (const name of Object.keys(this.buffers)) {
|
|
144
|
-
this.buffers[name] = new BatchBuffer();
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
async sendCreateBuffer(buffer, options) {
|
|
148
|
-
const promises = [];
|
|
149
|
-
for (const [index, collectionBuffer] of Object.entries(buffer.indexes)) {
|
|
150
|
-
for (const [collection, { promise, documents }] of Object.entries(collectionBuffer)) {
|
|
151
|
-
if (documents.length === 0) {
|
|
152
|
-
promise.resolve();
|
|
153
|
-
continue;
|
|
154
|
-
}
|
|
155
|
-
promises.push(this.sdk.document.mCreate(index, collection, documents, { ...options, strict: true })
|
|
156
|
-
.then(promise.resolve)
|
|
157
|
-
.catch(promise.reject));
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
await Promise.all(promises);
|
|
161
|
-
}
|
|
162
|
-
async sendUpdateBuffer(buffer, options) {
|
|
163
|
-
const promises = [];
|
|
164
|
-
for (const [index, collectionBuffer] of Object.entries(buffer.indexes)) {
|
|
165
|
-
for (const [collection, { promise, documents }] of Object.entries(collectionBuffer)) {
|
|
166
|
-
if (documents.length === 0) {
|
|
167
|
-
promise.resolve();
|
|
168
|
-
continue;
|
|
169
|
-
}
|
|
170
|
-
promises.push(this.sdk.document.mUpdate(index, collection, documents, { ...options })
|
|
171
|
-
.then(promise.resolve)
|
|
172
|
-
.catch(promise.reject));
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
await Promise.all(promises);
|
|
176
|
-
}
|
|
177
|
-
async sendReplaceBuffer(buffer, options) {
|
|
178
|
-
const promises = [];
|
|
179
|
-
for (const [index, collectionBuffer] of Object.entries(buffer.indexes)) {
|
|
180
|
-
for (const [collection, { promise, documents }] of Object.entries(collectionBuffer)) {
|
|
181
|
-
if (documents.length === 0) {
|
|
182
|
-
promise.resolve();
|
|
183
|
-
continue;
|
|
184
|
-
}
|
|
185
|
-
promises.push(this.sdk.document.mReplace(index, collection, documents, { ...options })
|
|
186
|
-
.then(promise.resolve)
|
|
187
|
-
.catch(promise.reject));
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
await Promise.all(promises);
|
|
191
|
-
}
|
|
192
|
-
async sendCreateOrReplaceBuffer(buffer, options) {
|
|
193
|
-
const promises = [];
|
|
194
|
-
for (const [index, collectionBuffer] of Object.entries(buffer.indexes)) {
|
|
195
|
-
for (const [collection, { promise, documents }] of Object.entries(collectionBuffer)) {
|
|
196
|
-
if (documents.length === 0) {
|
|
197
|
-
promise.resolve();
|
|
198
|
-
continue;
|
|
199
|
-
}
|
|
200
|
-
promises.push(this.sdk.document.mCreateOrReplace(index, collection, documents, { ...options })
|
|
201
|
-
.then(promise.resolve)
|
|
202
|
-
.catch(promise.reject));
|
|
203
|
-
}
|
|
204
|
-
}
|
|
205
|
-
await Promise.all(promises);
|
|
206
|
-
}
|
|
207
|
-
async sendGetBuffer(buffer) {
|
|
208
|
-
const promises = [];
|
|
209
|
-
for (const [index, collectionBuffer] of Object.entries(buffer.indexes)) {
|
|
210
|
-
for (const [collection, { promise, documents }] of Object.entries(collectionBuffer)) {
|
|
211
|
-
if (documents.length === 0) {
|
|
212
|
-
promise.resolve();
|
|
213
|
-
continue;
|
|
214
|
-
}
|
|
215
|
-
const ids = documents.map(({ _id }) => _id);
|
|
216
|
-
promises.push(this.sdk.document.mGet(index, collection, ids)
|
|
217
|
-
.then(promise.resolve)
|
|
218
|
-
.catch(promise.reject));
|
|
219
|
-
}
|
|
220
|
-
}
|
|
221
|
-
await Promise.all(promises);
|
|
222
|
-
}
|
|
223
|
-
async sendExistsBuffer(buffer) {
|
|
224
|
-
const promises = [];
|
|
225
|
-
for (const [index, collectionBuffer] of Object.entries(buffer.indexes)) {
|
|
226
|
-
for (const [collection, { promise, documents }] of Object.entries(collectionBuffer)) {
|
|
227
|
-
if (documents.length === 0) {
|
|
228
|
-
promise.resolve();
|
|
229
|
-
continue;
|
|
230
|
-
}
|
|
231
|
-
const ids = documents.map(({ _id }) => _id);
|
|
232
|
-
promises.push(this.sdk.document.mGet(index, collection, ids)
|
|
233
|
-
.then(({ successes }) => {
|
|
234
|
-
const successesId = successes.map(({ _id }) => _id);
|
|
235
|
-
const exists = new Array(ids.length);
|
|
236
|
-
for (let i = 0; i < exists.length; i++) {
|
|
237
|
-
exists[i] = successesId.includes(ids[i]);
|
|
238
|
-
}
|
|
239
|
-
promise.resolve({ successes: exists });
|
|
240
|
-
})
|
|
241
|
-
.catch(promise.reject));
|
|
242
|
-
}
|
|
243
|
-
}
|
|
244
|
-
await Promise.all(promises);
|
|
245
|
-
}
|
|
246
|
-
async sendDeleteBuffer(buffer) {
|
|
247
|
-
const promises = [];
|
|
248
|
-
for (const [index, collectionBuffer] of Object.entries(buffer.indexes)) {
|
|
249
|
-
for (const [collection, { promise, documents }] of Object.entries(collectionBuffer)) {
|
|
250
|
-
if (documents.length === 0) {
|
|
251
|
-
promise.resolve();
|
|
252
|
-
continue;
|
|
253
|
-
}
|
|
254
|
-
const ids = documents.map(({ _id }) => _id);
|
|
255
|
-
promises.push(this.sdk.document.mDelete(index, collection, ids)
|
|
256
|
-
.then(promise.resolve)
|
|
257
|
-
.catch(promise.reject));
|
|
258
|
-
}
|
|
259
|
-
}
|
|
260
|
-
await Promise.all(promises);
|
|
261
|
-
}
|
|
262
|
-
}
|
|
263
|
-
exports.BatchWriter = BatchWriter;
|
|
264
|
-
//# sourceMappingURL=BatchWriter.js.map
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.InstrumentablePromise = void 0;
|
|
4
|
-
class InstrumentablePromise {
|
|
5
|
-
constructor() {
|
|
6
|
-
this.promise = new Promise((resolve, reject) => {
|
|
7
|
-
this.resolve = resolve;
|
|
8
|
-
this.reject = reject;
|
|
9
|
-
});
|
|
10
|
-
}
|
|
11
|
-
}
|
|
12
|
-
exports.InstrumentablePromise = InstrumentablePromise;
|
|
13
|
-
//# sourceMappingURL=InstrumentablePromise.js.map
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
-
}) : (function(o, m, k, k2) {
|
|
6
|
-
if (k2 === undefined) k2 = k;
|
|
7
|
-
o[k2] = m[k];
|
|
8
|
-
}));
|
|
9
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
10
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
11
|
-
};
|
|
12
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
-
__exportStar(require("./BatchController"), exports);
|
|
14
|
-
__exportStar(require("./BatchWriter"), exports);
|
|
15
|
-
__exportStar(require("./InstrumentablePromise"), exports);
|
|
16
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import { JSONObject } from 'kuzzle';
|
|
2
|
-
export declare class DeviceMappingsManager {
|
|
3
|
-
private mappings;
|
|
4
|
-
constructor(baseMappings: JSONObject);
|
|
5
|
-
/**
|
|
6
|
-
* Register custom metadata for devices
|
|
7
|
-
*
|
|
8
|
-
* @param metadata Device custom metadata mappings
|
|
9
|
-
*
|
|
10
|
-
* @example
|
|
11
|
-
*
|
|
12
|
-
* plugin.devices.registerMetadata({
|
|
13
|
-
* serial: { type: 'keyword' },
|
|
14
|
-
* });
|
|
15
|
-
*
|
|
16
|
-
*/
|
|
17
|
-
registerMetadata(metadata: any): void;
|
|
18
|
-
/**
|
|
19
|
-
* Register custom QoS for devices
|
|
20
|
-
*
|
|
21
|
-
* @param qos Device custom QoS mappings
|
|
22
|
-
*
|
|
23
|
-
* @example
|
|
24
|
-
*
|
|
25
|
-
* plugin.devices.registerQoS({
|
|
26
|
-
* battery: { type: 'integer' },
|
|
27
|
-
* });
|
|
28
|
-
*/
|
|
29
|
-
registerQoS(qos: JSONObject): void;
|
|
30
|
-
/**
|
|
31
|
-
* Register custom measure for devices mappings
|
|
32
|
-
*
|
|
33
|
-
* @param qos Device custom measure
|
|
34
|
-
*
|
|
35
|
-
* @example
|
|
36
|
-
*
|
|
37
|
-
* plugin.devices.registerMeasure('humidity', {
|
|
38
|
-
* value: { type: 'float' },
|
|
39
|
-
* });
|
|
40
|
-
*/
|
|
41
|
-
registerMeasure(name: string, measure: JSONObject): void;
|
|
42
|
-
get(): JSONObject;
|
|
43
|
-
}
|
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.DeviceMappingsManager = void 0;
|
|
4
|
-
const kuzzle_1 = require("kuzzle");
|
|
5
|
-
class DeviceMappingsManager {
|
|
6
|
-
constructor(baseMappings) {
|
|
7
|
-
this.mappings = JSON.parse(JSON.stringify(baseMappings));
|
|
8
|
-
}
|
|
9
|
-
/**
|
|
10
|
-
* Register custom metadata for devices
|
|
11
|
-
*
|
|
12
|
-
* @param metadata Device custom metadata mappings
|
|
13
|
-
*
|
|
14
|
-
* @example
|
|
15
|
-
*
|
|
16
|
-
* plugin.devices.registerMetadata({
|
|
17
|
-
* serial: { type: 'keyword' },
|
|
18
|
-
* });
|
|
19
|
-
*
|
|
20
|
-
*/
|
|
21
|
-
registerMetadata(metadata) {
|
|
22
|
-
for (const [name, value] of Object.entries(metadata)) {
|
|
23
|
-
this.mappings.properties.metadata.properties[name] = value;
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
/**
|
|
27
|
-
* Register custom QoS for devices
|
|
28
|
-
*
|
|
29
|
-
* @param qos Device custom QoS mappings
|
|
30
|
-
*
|
|
31
|
-
* @example
|
|
32
|
-
*
|
|
33
|
-
* plugin.devices.registerQoS({
|
|
34
|
-
* battery: { type: 'integer' },
|
|
35
|
-
* });
|
|
36
|
-
*/
|
|
37
|
-
registerQoS(qos) {
|
|
38
|
-
for (const [name, value] of Object.entries(qos)) {
|
|
39
|
-
this.mappings.properties.qos.properties[name] = value;
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
/**
|
|
43
|
-
* Register custom measure for devices mappings
|
|
44
|
-
*
|
|
45
|
-
* @param qos Device custom measure
|
|
46
|
-
*
|
|
47
|
-
* @example
|
|
48
|
-
*
|
|
49
|
-
* plugin.devices.registerMeasure('humidity', {
|
|
50
|
-
* value: { type: 'float' },
|
|
51
|
-
* });
|
|
52
|
-
*/
|
|
53
|
-
registerMeasure(name, measure) {
|
|
54
|
-
if (this.mappings.properties.measures.properties[name]) {
|
|
55
|
-
throw new kuzzle_1.PluginImplementationError(`Measure "${name}" already exists.`);
|
|
56
|
-
}
|
|
57
|
-
const newMeasure = {
|
|
58
|
-
...measure,
|
|
59
|
-
payloadUuid: { type: 'keyword' },
|
|
60
|
-
updatedAt: { type: 'date' },
|
|
61
|
-
};
|
|
62
|
-
this.mappings.properties.measures.properties[name] = {
|
|
63
|
-
properties: newMeasure
|
|
64
|
-
};
|
|
65
|
-
}
|
|
66
|
-
get() {
|
|
67
|
-
return this.mappings;
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
exports.DeviceMappingsManager = DeviceMappingsManager;
|
|
71
|
-
//# sourceMappingURL=DeviceMappingsManager.js.map
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { Plugin } from 'kuzzle';
|
|
2
|
-
export declare class MigrationService {
|
|
3
|
-
private config;
|
|
4
|
-
private context;
|
|
5
|
-
private prefix;
|
|
6
|
-
get sdk(): import("kuzzle").EmbeddedSDK;
|
|
7
|
-
constructor(pluginName: string, plugin: Plugin);
|
|
8
|
-
run(): Promise<void>;
|
|
9
|
-
/**
|
|
10
|
-
* Migrate the engine documents into the new config collection
|
|
11
|
-
*/
|
|
12
|
-
private engineCollection;
|
|
13
|
-
}
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.MigrationService = void 0;
|
|
4
|
-
class MigrationService {
|
|
5
|
-
constructor(pluginName, plugin) {
|
|
6
|
-
this.config = plugin.config;
|
|
7
|
-
this.context = plugin.context;
|
|
8
|
-
this.prefix = pluginName;
|
|
9
|
-
}
|
|
10
|
-
get sdk() {
|
|
11
|
-
return this.context.accessors.sdk;
|
|
12
|
-
}
|
|
13
|
-
async run() {
|
|
14
|
-
global.app.install(`${this.prefix}-O.3.0`, async () => {
|
|
15
|
-
await this.engineCollection();
|
|
16
|
-
});
|
|
17
|
-
}
|
|
18
|
-
/**
|
|
19
|
-
* Migrate the engine documents into the new config collection
|
|
20
|
-
*/
|
|
21
|
-
async engineCollection() {
|
|
22
|
-
if (!await this.sdk.collection.exists(this.config.adminIndex, 'engines')) {
|
|
23
|
-
return;
|
|
24
|
-
}
|
|
25
|
-
this.context.log.info('Migrate engine documents into the config collection...');
|
|
26
|
-
let result = await this.sdk.document.search(this.config.adminIndex, 'engines', {}, { scroll: '1s', size: 100 });
|
|
27
|
-
let count = 0;
|
|
28
|
-
while (result) {
|
|
29
|
-
const documents = [];
|
|
30
|
-
for (const { _id, _source } of result.hits) {
|
|
31
|
-
documents.push({
|
|
32
|
-
_id,
|
|
33
|
-
body: {
|
|
34
|
-
type: 'engine-device-manager',
|
|
35
|
-
engine: { index: _source.index },
|
|
36
|
-
},
|
|
37
|
-
});
|
|
38
|
-
}
|
|
39
|
-
await this.sdk.document.mCreate(this.config.adminIndex, this.config.configCollection, documents, {
|
|
40
|
-
strict: true,
|
|
41
|
-
});
|
|
42
|
-
count += documents.length;
|
|
43
|
-
result = await result.next();
|
|
44
|
-
}
|
|
45
|
-
this.context.log.info(`Successfully migrated ${count} documents.`);
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
exports.MigrationService = MigrationService;
|
|
49
|
-
//# sourceMappingURL=MigrationService.js.map
|
package/lib/models/Catalog.d.ts
DELETED
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
import { JSONObject } from 'kuzzle';
|
|
2
|
-
import { ConfigDocument } from './Config';
|
|
3
|
-
export declare const catalogMappings: {
|
|
4
|
-
dynamic: string;
|
|
5
|
-
properties: {
|
|
6
|
-
deviceId: {
|
|
7
|
-
type: string;
|
|
8
|
-
};
|
|
9
|
-
authorized: {
|
|
10
|
-
type: string;
|
|
11
|
-
};
|
|
12
|
-
tenantId: {
|
|
13
|
-
type: string;
|
|
14
|
-
};
|
|
15
|
-
assetId: {
|
|
16
|
-
type: string;
|
|
17
|
-
};
|
|
18
|
-
};
|
|
19
|
-
};
|
|
20
|
-
/**
|
|
21
|
-
* Provisioning catalog entry
|
|
22
|
-
*/
|
|
23
|
-
export declare type CatalogContent = {
|
|
24
|
-
/**
|
|
25
|
-
* ID of the device
|
|
26
|
-
* (e.g. "Abeeway-123456")
|
|
27
|
-
*/
|
|
28
|
-
deviceId: string;
|
|
29
|
-
/**
|
|
30
|
-
* If set to false, the device cannot register
|
|
31
|
-
*/
|
|
32
|
-
authorized: boolean;
|
|
33
|
-
/**
|
|
34
|
-
* If set, the device will be attached to this tenant
|
|
35
|
-
*/
|
|
36
|
-
tenantId?: string;
|
|
37
|
-
/**
|
|
38
|
-
* If set, the device will be linked to this asset
|
|
39
|
-
*/
|
|
40
|
-
assetId?: string;
|
|
41
|
-
};
|
|
42
|
-
/**
|
|
43
|
-
* Catalog configuration document
|
|
44
|
-
*/
|
|
45
|
-
export declare class Catalog extends ConfigDocument<CatalogContent> {
|
|
46
|
-
/**
|
|
47
|
-
* Can be build either:
|
|
48
|
-
* - with a raw config document (_id and _source properties)
|
|
49
|
-
* - with a rule definition
|
|
50
|
-
*/
|
|
51
|
-
constructor(document: CatalogContent | {
|
|
52
|
-
_id: string;
|
|
53
|
-
_source: JSONObject;
|
|
54
|
-
});
|
|
55
|
-
}
|
package/lib/models/Catalog.js
DELETED
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Catalog = exports.catalogMappings = void 0;
|
|
4
|
-
const Config_1 = require("./Config");
|
|
5
|
-
exports.catalogMappings = {
|
|
6
|
-
dynamic: 'strict',
|
|
7
|
-
properties: {
|
|
8
|
-
deviceId: { type: 'keyword' },
|
|
9
|
-
authorized: { type: 'boolean' },
|
|
10
|
-
tenantId: { type: 'keyword' },
|
|
11
|
-
assetId: { type: 'keyword' },
|
|
12
|
-
},
|
|
13
|
-
};
|
|
14
|
-
/**
|
|
15
|
-
* Catalog configuration document
|
|
16
|
-
*/
|
|
17
|
-
class Catalog extends Config_1.ConfigDocument {
|
|
18
|
-
/**
|
|
19
|
-
* Can be build either:
|
|
20
|
-
* - with a raw config document (_id and _source properties)
|
|
21
|
-
* - with a rule definition
|
|
22
|
-
*/
|
|
23
|
-
constructor(document) {
|
|
24
|
-
if (document['_id'] || document['_source']) {
|
|
25
|
-
super(document);
|
|
26
|
-
}
|
|
27
|
-
else {
|
|
28
|
-
super({
|
|
29
|
-
_source: {
|
|
30
|
-
type: 'catalog',
|
|
31
|
-
catalog: document
|
|
32
|
-
}
|
|
33
|
-
});
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
exports.Catalog = Catalog;
|
|
38
|
-
//# sourceMappingURL=Catalog.js.map
|
package/lib/types/Measure.d.ts
DELETED
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
import { JSONObject } from 'kuzzle';
|
|
2
|
-
export interface BaseMeasure {
|
|
3
|
-
/**
|
|
4
|
-
* Date of the measure
|
|
5
|
-
*/
|
|
6
|
-
updatedAt: number;
|
|
7
|
-
/**
|
|
8
|
-
* The payload uuid is auto-generated by Kuzzle
|
|
9
|
-
*/
|
|
10
|
-
payloadUuid?: string;
|
|
11
|
-
[property: string]: any;
|
|
12
|
-
}
|
|
13
|
-
export interface PositionMeasure extends BaseMeasure {
|
|
14
|
-
point: {
|
|
15
|
-
lat: number;
|
|
16
|
-
lon: number;
|
|
17
|
-
};
|
|
18
|
-
altitude?: number;
|
|
19
|
-
accuracy?: number;
|
|
20
|
-
}
|
|
21
|
-
export interface TemperatureMeasure extends BaseMeasure {
|
|
22
|
-
degree: number;
|
|
23
|
-
}
|
|
24
|
-
export interface MovementMeasure extends BaseMeasure {
|
|
25
|
-
moving: boolean;
|
|
26
|
-
}
|
|
27
|
-
export declare type Measure = BaseMeasure;
|
|
28
|
-
export declare type DeviceMeasures = {
|
|
29
|
-
position?: PositionMeasure;
|
|
30
|
-
temperature?: TemperatureMeasure;
|
|
31
|
-
movement?: MovementMeasure;
|
|
32
|
-
[measureType: string]: Measure;
|
|
33
|
-
};
|
|
34
|
-
export interface BaseAssetMeasure extends BaseMeasure {
|
|
35
|
-
/**
|
|
36
|
-
* Device ID
|
|
37
|
-
*/
|
|
38
|
-
id: string;
|
|
39
|
-
/**
|
|
40
|
-
* Device model
|
|
41
|
-
*/
|
|
42
|
-
model: string;
|
|
43
|
-
/**
|
|
44
|
-
* Device reference
|
|
45
|
-
*/
|
|
46
|
-
reference: string;
|
|
47
|
-
/**
|
|
48
|
-
* Device metadata
|
|
49
|
-
*/
|
|
50
|
-
metadata: JSONObject;
|
|
51
|
-
}
|
|
52
|
-
export declare type AssetMeasures = {
|
|
53
|
-
[measureType: string]: BaseAssetMeasure;
|
|
54
|
-
};
|
package/lib/utils/events.d.ts
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { KuzzleRequest, JSONObject } from 'kuzzle';
|
|
2
|
-
/**
|
|
3
|
-
* Returns a KuzzleRequest containing the payload in the result property.
|
|
4
|
-
*
|
|
5
|
-
* This is used to trigger event with payload that can be used by the workflow
|
|
6
|
-
* plugin.
|
|
7
|
-
*/
|
|
8
|
-
export declare function eventPayload(payload: JSONObject): KuzzleRequest;
|
package/lib/utils/events.js
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.eventPayload = void 0;
|
|
4
|
-
const kuzzle_1 = require("kuzzle");
|
|
5
|
-
/**
|
|
6
|
-
* Returns a KuzzleRequest containing the payload in the result property.
|
|
7
|
-
*
|
|
8
|
-
* This is used to trigger event with payload that can be used by the workflow
|
|
9
|
-
* plugin.
|
|
10
|
-
*/
|
|
11
|
-
function eventPayload(payload) {
|
|
12
|
-
return new kuzzle_1.KuzzleRequest({}, {
|
|
13
|
-
result: payload
|
|
14
|
-
});
|
|
15
|
-
}
|
|
16
|
-
exports.eventPayload = eventPayload;
|
|
17
|
-
//# sourceMappingURL=events.js.map
|