@sedni/cloud_common 1.0.7 → 1.1.0
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/app/models/Channel.js +4 -7
- package/app/models/ChannelDataBucket.js +19 -1
- package/app/models/Event.js +12 -10
- package/app/models/History.js +9 -3
- package/app/models/Unit.js +2 -3
- package/package.json +13 -13
package/app/models/Channel.js
CHANGED
|
@@ -7,13 +7,10 @@ const channelSchema = new mongoose.Schema({
|
|
|
7
7
|
channel_tag: {
|
|
8
8
|
type: String,
|
|
9
9
|
required: true,
|
|
10
|
-
unique: true,
|
|
11
|
-
index: true,
|
|
12
10
|
},
|
|
13
11
|
channel_description: {
|
|
14
12
|
type: String,
|
|
15
13
|
required: true,
|
|
16
|
-
index: true,
|
|
17
14
|
},
|
|
18
15
|
channel_unit_id: {
|
|
19
16
|
type: mongoose.Schema.Types.ObjectId,
|
|
@@ -54,14 +51,14 @@ const channelSchema = new mongoose.Schema({
|
|
|
54
51
|
*/
|
|
55
52
|
|
|
56
53
|
/**
|
|
57
|
-
* Index used primarily for filtering by
|
|
54
|
+
* Index used primarily for filtering by channel_tag
|
|
58
55
|
*/
|
|
59
|
-
channelSchema.index({ "
|
|
56
|
+
channelSchema.index({ "channel_tag" : 1 }, { unique: true });
|
|
60
57
|
|
|
61
58
|
/**
|
|
62
|
-
* Index used primarily for filtering by
|
|
59
|
+
* Index used primarily for filtering by channel_description
|
|
63
60
|
*/
|
|
64
|
-
channelSchema.index({ "
|
|
61
|
+
channelSchema.index({ "channel_description" : 1 });
|
|
65
62
|
|
|
66
63
|
|
|
67
64
|
/**
|
|
@@ -77,6 +77,18 @@ const channeldataBucketSchema = new mongoose.Schema({
|
|
|
77
77
|
*/
|
|
78
78
|
channeldataBucketSchema.index({ start_date: 1, end_date: 1 });
|
|
79
79
|
|
|
80
|
+
/**
|
|
81
|
+
* Index used to delete old buckets automatically.
|
|
82
|
+
* This function will need to be called to create the TTL index.
|
|
83
|
+
* The index will expire documents after the specified time in seconds.
|
|
84
|
+
* The default is set to one year, but it can be changed by passing the expirationTimeInSeconds parameter.
|
|
85
|
+
*/
|
|
86
|
+
const oneYear = 60 * 60 * 24 * 365; // One year in seconds
|
|
87
|
+
channeldataBucketSchema.addTTLIndex = function(ttlField, expirationTimeInSeconds = oneYear)
|
|
88
|
+
{
|
|
89
|
+
this.index({ [ttlField]: 1 }, { expireAfterSeconds: expirationTimeInSeconds });
|
|
90
|
+
}
|
|
91
|
+
|
|
80
92
|
/**
|
|
81
93
|
* ///////////////////////////////////////////////
|
|
82
94
|
* ///////////// PLUGINS /////////////////
|
|
@@ -240,10 +252,16 @@ channeldataBucketSchema.statics.getNotUploadedData = async function(options)
|
|
|
240
252
|
*/
|
|
241
253
|
channeldataBucketSchema.statics.getData = async function(start_date, end_date, plain = false)
|
|
242
254
|
{
|
|
255
|
+
// Truncate the timestamp to the nearest hour
|
|
256
|
+
const date = new Date(start_date);
|
|
257
|
+
date.setMinutes(0);
|
|
258
|
+
date.setSeconds(0);
|
|
259
|
+
date.setMilliseconds(0);
|
|
260
|
+
|
|
243
261
|
// Get the data in the specified date range
|
|
244
262
|
const data = await this.find({
|
|
245
263
|
start_date: {
|
|
246
|
-
$gte:
|
|
264
|
+
$gte: date,
|
|
247
265
|
$lt: new Date(end_date)
|
|
248
266
|
}
|
|
249
267
|
});
|
package/app/models/Event.js
CHANGED
|
@@ -29,7 +29,6 @@ const eventSchema = new mongoose.Schema({
|
|
|
29
29
|
event_timestamp: {
|
|
30
30
|
type: Date,
|
|
31
31
|
default: Date.now,
|
|
32
|
-
expires: 60 * 60 * 24 * 7 * 365 // 1 year
|
|
33
32
|
},
|
|
34
33
|
event_data: {
|
|
35
34
|
type: Object
|
|
@@ -40,10 +39,6 @@ const eventSchema = new mongoose.Schema({
|
|
|
40
39
|
updatedAt: false
|
|
41
40
|
},
|
|
42
41
|
versionKey: false,
|
|
43
|
-
capped: {
|
|
44
|
-
size: 1000000,
|
|
45
|
-
max: 10000
|
|
46
|
-
},
|
|
47
42
|
toJSON: {
|
|
48
43
|
transform: function (doc, ret)
|
|
49
44
|
{
|
|
@@ -61,11 +56,6 @@ const eventSchema = new mongoose.Schema({
|
|
|
61
56
|
* ///////////////////////////////////////////////
|
|
62
57
|
*/
|
|
63
58
|
|
|
64
|
-
/**
|
|
65
|
-
* Index used primarily for filtering by timestamp
|
|
66
|
-
*/
|
|
67
|
-
eventSchema.index({ "event_timestamp" : 1 });
|
|
68
|
-
|
|
69
59
|
/**
|
|
70
60
|
* Index used primarily for filtering by event_type
|
|
71
61
|
*/
|
|
@@ -76,6 +66,18 @@ eventSchema.index({ "event_type" : 1 });
|
|
|
76
66
|
*/
|
|
77
67
|
eventSchema.index({ "event_category" : 1 });
|
|
78
68
|
|
|
69
|
+
/**
|
|
70
|
+
* Index used to delete old events automatically.
|
|
71
|
+
* This function will need to be called to create the TTL index.
|
|
72
|
+
* The index will expire documents after the specified time in seconds.
|
|
73
|
+
* The default is set to one year, but it can be changed by passing the expirationTimeInSeconds parameter.
|
|
74
|
+
*/
|
|
75
|
+
const oneYear = 60 * 60 * 24 * 365; // One year in seconds
|
|
76
|
+
eventSchema.addTTLIndex = function(ttlField, expirationTimeInSeconds = oneYear)
|
|
77
|
+
{
|
|
78
|
+
this.index({ [ttlField]: 1 }, { expireAfterSeconds: expirationTimeInSeconds });
|
|
79
|
+
}
|
|
80
|
+
|
|
79
81
|
/**
|
|
80
82
|
* ///////////////////////////////////////////////
|
|
81
83
|
* ///////////// PLUGINS /////////////////
|
package/app/models/History.js
CHANGED
|
@@ -83,10 +83,16 @@ const historySchema = new mongoose.Schema({
|
|
|
83
83
|
historySchema.index({ "channel_tag" : 1 });
|
|
84
84
|
|
|
85
85
|
/**
|
|
86
|
-
* Index used
|
|
86
|
+
* Index used to delete old alarms automatically.
|
|
87
|
+
* This function will need to be called to create the TTL index.
|
|
88
|
+
* The index will expire documents after the specified time in seconds.
|
|
89
|
+
* The default is set to one year, but it can be changed by passing the expirationTimeInSeconds parameter.
|
|
87
90
|
*/
|
|
88
|
-
|
|
89
|
-
|
|
91
|
+
const oneYear = 60 * 60 * 24 * 365; // One year in seconds
|
|
92
|
+
historySchema.addTTLIndex = function(ttlField, expirationTimeInSeconds = oneYear)
|
|
93
|
+
{
|
|
94
|
+
this.index({ [ttlField]: 1 }, { expireAfterSeconds: expirationTimeInSeconds });
|
|
95
|
+
}
|
|
90
96
|
|
|
91
97
|
/**
|
|
92
98
|
* ///////////////////////////////////////////////
|
package/app/models/Unit.js
CHANGED
|
@@ -8,7 +8,6 @@ const unitSchema = new mongoose.Schema({
|
|
|
8
8
|
unit_id: {
|
|
9
9
|
type: String,
|
|
10
10
|
required: true,
|
|
11
|
-
unique: true,
|
|
12
11
|
},
|
|
13
12
|
unit_enabled: {
|
|
14
13
|
type: Boolean,
|
|
@@ -47,9 +46,9 @@ const unitSchema = new mongoose.Schema({
|
|
|
47
46
|
*/
|
|
48
47
|
|
|
49
48
|
/**
|
|
50
|
-
* Index used primarily for filtering by unit_id
|
|
49
|
+
* Index used primarily for filtering by unit_id and ensuring uniqueness
|
|
51
50
|
*/
|
|
52
|
-
unitSchema.index({ "unit_id" : 1 });
|
|
51
|
+
unitSchema.index({ "unit_id" : 1 }, { unique: true });
|
|
53
52
|
|
|
54
53
|
/**
|
|
55
54
|
* Index used primarily for filtering by unit_internal_description
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sedni/cloud_common",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"description": "Common package for all types, resources and tools of Diamar Cloud",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -13,21 +13,21 @@
|
|
|
13
13
|
"author": "Jose Luis Silvestre García",
|
|
14
14
|
"license": "ISC",
|
|
15
15
|
"dependencies": {
|
|
16
|
-
"mongoose": "^8.
|
|
17
|
-
"mongoose-aggregate-paginate-v2": "^1.1.
|
|
16
|
+
"mongoose": "^8.17.0",
|
|
17
|
+
"mongoose-aggregate-paginate-v2": "^1.1.4",
|
|
18
18
|
"mongoose-autopopulate": "^1.1.0",
|
|
19
|
-
"mongoose-paginate-v2": "^1.
|
|
19
|
+
"mongoose-paginate-v2": "^1.9.1"
|
|
20
20
|
},
|
|
21
21
|
"devDependencies": {
|
|
22
|
-
"@eslint/js": "^9.
|
|
23
|
-
"chai": "^
|
|
24
|
-
"eslint": "^9.
|
|
25
|
-
"eslint-plugin-n": "^17.
|
|
26
|
-
"globals": "^
|
|
27
|
-
"mocha": "^
|
|
28
|
-
"nyc": "^17.
|
|
22
|
+
"@eslint/js": "^9.32.0",
|
|
23
|
+
"chai": "^5.2.1",
|
|
24
|
+
"eslint": "^9.32.0",
|
|
25
|
+
"eslint-plugin-n": "^17.21.0",
|
|
26
|
+
"globals": "^16.3.0",
|
|
27
|
+
"mocha": "^11.7.1",
|
|
28
|
+
"nyc": "^17.1.0",
|
|
29
29
|
"proxyquire": "^2.1.3",
|
|
30
|
-
"sinon": "^
|
|
31
|
-
"supertest": "^7.
|
|
30
|
+
"sinon": "^21.0.0",
|
|
31
|
+
"supertest": "^7.1.4"
|
|
32
32
|
}
|
|
33
33
|
}
|