@sedni/cloud_common 1.0.8 → 1.2.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.
@@ -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 unit_id
54
+ * Index used primarily for filtering by channel_tag
58
55
  */
59
- channelSchema.index({ "unit_id" : 1 });
56
+ channelSchema.index({ "channel_tag" : 1 }, { unique: true });
60
57
 
61
58
  /**
62
- * Index used primarily for filtering by unit_internal_description
59
+ * Index used primarily for filtering by channel_description
63
60
  */
64
- channelSchema.index({ "unit_internal_description" : 1 });
61
+ channelSchema.index({ "channel_description" : 1 });
65
62
 
66
63
 
67
64
  /**
@@ -75,7 +75,12 @@ const channeldataBucketSchema = new mongoose.Schema({
75
75
  * Index the start_date and end_date fields for faster queries.
76
76
  * The compound index will be used to query the buckets by date range.
77
77
  */
78
- channeldataBucketSchema.index({ start_date: 1, end_date: 1 });
78
+ channeldataBucketSchema.index({ start_date: 1, end_date: 1 }, { background: true });
79
+
80
+ /**
81
+ * Index used to delete old buckets automatically.
82
+ */
83
+ channeldataBucketSchema.index({ start_date: 1 }, { expireAfterSeconds: 60 * 60 * 24 * 365, background: true }); // 1 year
79
84
 
80
85
  /**
81
86
  * ///////////////////////////////////////////////
@@ -2,7 +2,7 @@ const mongoose = require("mongoose");
2
2
  const mongooseAutopopulate = require("mongoose-autopopulate");
3
3
  const mongoosePaginate = require("mongoose-paginate-v2");
4
4
  const mongooseAggregatePaginate = require("mongoose-aggregate-paginate-v2");
5
- const { EventCategories } = require("../types/event.types");
5
+ const { EventCategories, EventCriticality } = require("../types/event.types");
6
6
 
7
7
  const eventSchema = new mongoose.Schema({
8
8
  event_message: {
@@ -22,6 +22,11 @@ const eventSchema = new mongoose.Schema({
22
22
  required: true,
23
23
  enum: Object.values(EventCategories)
24
24
  },
25
+ event_criticality: {
26
+ type: String,
27
+ required: true,
28
+ enum: Object.values(EventCriticality)
29
+ },
25
30
  event_type: {
26
31
  type: String,
27
32
  required: true
@@ -29,7 +34,6 @@ const eventSchema = new mongoose.Schema({
29
34
  event_timestamp: {
30
35
  type: Date,
31
36
  default: Date.now,
32
- expires: 60 * 60 * 24 * 7 * 365 // 1 year
33
37
  },
34
38
  event_data: {
35
39
  type: Object
@@ -40,10 +44,6 @@ const eventSchema = new mongoose.Schema({
40
44
  updatedAt: false
41
45
  },
42
46
  versionKey: false,
43
- capped: {
44
- size: 1000000,
45
- max: 10000
46
- },
47
47
  toJSON: {
48
48
  transform: function (doc, ret)
49
49
  {
@@ -61,11 +61,6 @@ const eventSchema = new mongoose.Schema({
61
61
  * ///////////////////////////////////////////////
62
62
  */
63
63
 
64
- /**
65
- * Index used primarily for filtering by timestamp
66
- */
67
- eventSchema.index({ "event_timestamp" : 1 });
68
-
69
64
  /**
70
65
  * Index used primarily for filtering by event_type
71
66
  */
@@ -76,6 +71,18 @@ eventSchema.index({ "event_type" : 1 });
76
71
  */
77
72
  eventSchema.index({ "event_category" : 1 });
78
73
 
74
+ /**
75
+ * Index used to delete old events automatically.
76
+ * This function will need to be called to create the TTL index.
77
+ * The index will expire documents after the specified time in seconds.
78
+ * The default is set to one year, but it can be changed by passing the expirationTimeInSeconds parameter.
79
+ */
80
+ const oneYear = 60 * 60 * 24 * 365; // One year in seconds
81
+ eventSchema.addTTLIndex = function(ttlField, expirationTimeInSeconds = oneYear)
82
+ {
83
+ this.index({ [ttlField]: 1 }, { expireAfterSeconds: expirationTimeInSeconds });
84
+ }
85
+
79
86
  /**
80
87
  * ///////////////////////////////////////////////
81
88
  * ///////////// PLUGINS /////////////////
@@ -83,10 +83,16 @@ const historySchema = new mongoose.Schema({
83
83
  historySchema.index({ "channel_tag" : 1 });
84
84
 
85
85
  /**
86
- * Index used primarily for filtering by timestamp
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
- historySchema.index({ "timestamp" : 1 });
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
  * ///////////////////////////////////////////////
@@ -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
@@ -10,6 +10,15 @@ const EventCategories =
10
10
  POTENTIAL_ATTACK: "PotentialAttackActivity",
11
11
  };
12
12
 
13
+ const EventCriticality = {
14
+ VERBOSE: "Verbose",
15
+ INFO: "Info",
16
+ WARNING: "Warning",
17
+ ERROR: "Error",
18
+ CRITICAL: "Critical",
19
+ };
20
+
13
21
  module.exports = {
14
22
  EventCategories,
23
+ EventCriticality,
15
24
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sedni/cloud_common",
3
- "version": "1.0.8",
3
+ "version": "1.2.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.7.1",
17
- "mongoose-aggregate-paginate-v2": "^1.1.2",
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.8.5"
19
+ "mongoose-paginate-v2": "^1.9.1"
20
20
  },
21
21
  "devDependencies": {
22
- "@eslint/js": "^9.12.0",
23
- "chai": "^4.0.0",
24
- "eslint": "^9.12.0",
25
- "eslint-plugin-n": "^17.11.0",
26
- "globals": "^15.11.0",
27
- "mocha": "^10.7.3",
28
- "nyc": "^17.0.0",
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": "^19.0.2",
31
- "supertest": "^7.0.0"
30
+ "sinon": "^21.0.0",
31
+ "supertest": "^7.1.4"
32
32
  }
33
33
  }