@transitive-sdk/clickhouse 0.3.2 → 0.3.3
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.js +13 -25
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -260,35 +260,26 @@ class ClickHouse {
|
|
|
260
260
|
* @param {string} topic - MQTT topic to register
|
|
261
261
|
*/
|
|
262
262
|
async registerMqttTopicForStorage(selector, ttlDays = DEFAULT_TTL_DAYS) {
|
|
263
|
-
this.topics[selector] = true;
|
|
264
|
-
|
|
265
|
-
// ---------------------------------------------------------------
|
|
266
|
-
// Set/update TTL for this capability and sub-topic
|
|
267
263
|
|
|
268
264
|
const path = topicToPath(selector);
|
|
269
265
|
|
|
270
266
|
if (path.length < 4) {
|
|
271
267
|
// underspecified, don't set TTL
|
|
268
|
+
console.warn('Not registering topic as it is too short', selector);
|
|
272
269
|
return;
|
|
273
270
|
}
|
|
274
271
|
|
|
275
|
-
|
|
276
|
-
// const topicPartSelectors = [
|
|
277
|
-
// [2, path[2]],
|
|
278
|
-
// [3, path[3]]
|
|
279
|
-
// ];
|
|
272
|
+
this.topics[selector] = true;
|
|
280
273
|
|
|
281
|
-
//
|
|
274
|
+
// ---------------------------------------------------------------
|
|
275
|
+
// Set/update TTL for this capability and sub-topic
|
|
282
276
|
|
|
283
|
-
//
|
|
284
|
-
// // filter out wildcards
|
|
285
|
-
// .filter(([i, value]) => !['+','#'].includes(value[0]))
|
|
286
|
-
// // map to WHERE conditions
|
|
287
|
-
// .map(([i, value]) => `((TopicParts[${i + 1}]) = '${value}')`);
|
|
277
|
+
// Derive WHERE conditions for TTL expression from non-wildcards
|
|
288
278
|
const where = path2where(path);
|
|
289
279
|
|
|
290
280
|
if (where.length == 0) {
|
|
291
281
|
// underspecified, don't set TTL
|
|
282
|
+
console.warn('Not setting TTL as topic is under specified', selector);
|
|
292
283
|
return;
|
|
293
284
|
}
|
|
294
285
|
|
|
@@ -307,17 +298,14 @@ class ClickHouse {
|
|
|
307
298
|
const newTTLStatement =
|
|
308
299
|
`toDateTime(Timestamp) + toIntervalDay(${ttlDays}) ${whereStatement}`;
|
|
309
300
|
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
ttls.forEach((ttl, i) => {
|
|
313
|
-
if (ttl.replace(/[()]/g, '').endsWith(whereStatement)) {
|
|
314
|
-
// condition already present, just replace it to update time
|
|
315
|
-
ttls[i] = newTTLStatement;
|
|
316
|
-
present = true;
|
|
317
|
-
}
|
|
318
|
-
});
|
|
301
|
+
const currentIndex =
|
|
302
|
+
ttls.findIndex(ttl => ttl.replace(/[()]/g, '').endsWith(whereStatement));
|
|
319
303
|
|
|
320
|
-
if (
|
|
304
|
+
if (currentIndex >= 0) {
|
|
305
|
+
// replace existing
|
|
306
|
+
ttls[currentIndex] = newTTLStatement;
|
|
307
|
+
} else {
|
|
308
|
+
// add new
|
|
321
309
|
ttls.push(newTTLStatement);
|
|
322
310
|
}
|
|
323
311
|
|
package/package.json
CHANGED