@justair/justair-library 4.7.27 → 4.8.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@justair/justair-library",
3
- "version": "4.7.27",
3
+ "version": "4.8.0",
4
4
  "description": "JustAir Internal Library",
5
5
  "main": "src/index.js",
6
6
  "type": "module",
@@ -22,9 +22,6 @@ adminSchema.index({ email: 1, isActive: 1 });
22
22
  // Permission-based queries
23
23
  adminSchema.index({ orgId: 1, permissionName: 1 });
24
24
 
25
- // Keep individual email index for backward compatibility
26
- adminSchema.index({ email: 1 });
27
-
28
25
 
29
26
  const Admin = mongoose.model('Admin', adminSchema);
30
27
 
@@ -56,9 +56,6 @@ alertsSchema.index({ orgId: 1, status: 1, updatedAt: -1 });
56
56
  // Alert configuration matching - already optimal
57
57
  alertsSchema.index({ alertConfigurationId: 1 });
58
58
 
59
- // Keep individual indexes for backward compatibility
60
- alertsSchema.index({ orgId: 1 });
61
- alertsSchema.index({ monitorId: 1 });
62
59
  alertsSchema.index({ type: 1 });
63
60
 
64
61
  const alertsAuditSchema = mongoose.Schema(
@@ -26,13 +26,6 @@ dataCompletenessSchema.index({
26
26
  measurementsStartTime: 1
27
27
  });
28
28
 
29
-
30
- dataCompletenessSchema.index({
31
- monitorId: 1,
32
- measurementsStartTime: 1
33
- });
34
-
35
-
36
29
  dataCompletenessSchema.index({
37
30
  monitorId: 1,
38
31
  measurementsStartTime: 1,
@@ -50,8 +50,6 @@ eventsSchema.index({ monitorId: 1, createdAt: -1 });
50
50
  // Date range filtering index
51
51
  eventsSchema.index({ monitorId: 1, updatedAt: -1 });
52
52
 
53
- // Keep individual indexes for other query patterns
54
- eventsSchema.index({ monitorId: 1 });
55
53
  eventsSchema.index({ parameter: 1 });
56
54
 
57
55
  // Pre-hook to log single document deletions
@@ -32,18 +32,12 @@ const jobsSchema = mongoose.Schema(
32
32
 
33
33
  const Jobs = mongoose.model("Jobs", jobsSchema);
34
34
 
35
- // Requestor-based queries with category filtering
36
- jobsSchema.index({ requestorId: 1, category: 1 });
37
35
  // Exclude specific categories efficiently with timestamp ordering
38
36
  jobsSchema.index({ requestorId: 1, category: 1, createdAt: -1 });
39
37
  // Monitor-based job lookups (if monitorId field exists in resourceMetaData)
40
38
  // Note: This may need to be adjusted based on actual schema structure
41
- // jobsSchema.index({ "resourceMetaData.monitorId": 1, updatedAt: -1 });
39
+ jobsSchema.index({ "resourceMetaData.monitorId": 1, updatedAt: -1 });
42
40
 
43
- // Keep individual indexes for backward compatibility
44
- jobsSchema.index({ requestorId: 1 });
45
- jobsSchema.index({ createdAt: 1 });
46
- jobsSchema.index({ category: 1 });
47
41
  jobsSchema.index({ jobStatus: 1 });
48
42
 
49
43
  export { jobsSchema, Jobs };
@@ -4,13 +4,13 @@ const correctionSnapshotSchema = new mongoose.Schema(
4
4
  {
5
5
  equationType: {
6
6
  type: String,
7
- enum: ['custom', 'linear'],
7
+ enum: ["custom", "linear"],
8
8
  required: true,
9
9
  },
10
10
  equation: {
11
11
  type: String,
12
- required: function() {
13
- return this.equationType === 'custom';
12
+ required: function () {
13
+ return this.equationType === "custom";
14
14
  },
15
15
  },
16
16
  dateCreated: {
@@ -36,17 +36,17 @@ const annotationSchema = new mongoose.Schema(
36
36
  trim: true,
37
37
  },
38
38
  adminId: {
39
- type: mongoose.Types.ObjectId,
40
- ref: "Admin",
41
- required: function() {
42
- return this.source === 'admin';
39
+ type: mongoose.Types.ObjectId,
40
+ ref: "Admin",
41
+ required: function () {
42
+ return this.source === "admin";
43
43
  },
44
44
  },
45
45
  source: {
46
46
  type: String,
47
- enum: ['admin', 'processing_engine'],
47
+ enum: ["admin", "processing_engine"],
48
48
  required: true,
49
- default: 'admin'
49
+ default: "admin",
50
50
  },
51
51
  timestamp: {
52
52
  type: Date,
@@ -120,16 +120,10 @@ const measurementsSchema = mongoose.Schema(
120
120
  // CRITICAL: Add compound indexes for monitorId + timeUpdated
121
121
  // Primary query pattern index (descending timeUpdated for latest data first)
122
122
  measurementsSchema.index({ monitorId: 1, timeUpdated: -1 });
123
- // Date range query index (ascending timeUpdated for range queries)
124
- measurementsSchema.index({ monitorId: 1, timeUpdated: 1 });
125
123
 
126
124
  // Flag-based query index for filtering by monitor and flags
127
125
  measurementsSchema.index({ monitorId: 1, flags: 1 });
128
126
 
129
- // Keep the individual indexes as they may still be useful for other queries
130
- measurementsSchema.index({ monitorId: 1 });
131
- measurementsSchema.index({ timeUpdated: 1 });
132
-
133
127
  // Annotation-related indexes
134
128
  measurementsSchema.index({
135
129
  "annotations.measurementIdentifier": 1,
@@ -20,13 +20,19 @@ const monitorSuppliersSchema = mongoose.Schema(
20
20
  runFrequencyMinutes: { type: Number, default: 5 },
21
21
  lastSuccessfulRun: Date,
22
22
  lastFailedRun: Date,
23
- orgAPICount: {
24
- monthlyApiCallCount: { type: Number, default: 0 },
25
- monthlyLimit: Number,
26
- },
27
- rateLimit: {
28
- requestsPerSecond: { type: Number, default: 10 },
29
- },
23
+ rateLimits: [
24
+ {
25
+ type: {
26
+ type: String,
27
+ required: true,
28
+ enum: ["second", "hourly", "daily", "weekly", "monthly"]
29
+ },
30
+ limit: { type: Number, required: true },
31
+ currentCount: { type: Number, default: 0 },
32
+ resetTime: { type: Date },
33
+ _id: false
34
+ }
35
+ ],
30
36
  latestErrorLogs: {
31
37
  type: [errorLogSchema],
32
38
  },
@@ -272,16 +272,8 @@ monitorsSchema.index({ monitorSupplier: 1, monitorState: 1 });
272
272
  monitorsSchema.index({ context: 1 });
273
273
  monitorsSchema.index({ parameters: 1 });
274
274
 
275
- // Monitor lookups by supplier
276
- monitorsSchema.index({ sponsor: 1, monitorSupplier: 1 });
277
-
278
- // Keep existing single-field indexes for backward compatibility
279
- monitorsSchema.index({ monitorSupplier: 1 });
280
- monitorsSchema.index({ monitorIdFromSupplier: 1 });
281
- monitorsSchema.index({ monitorState: 1 });
282
-
283
275
  //network metrics for anomalies
284
- monitorsSchema.index({ sponsor: 1, isActive: 1, monitorSupplier: 1 })
276
+ monitorsSchema.index({ sponsor: 1, isActive: 1, monitorSupplier: 1 });
285
277
 
286
278
  // Pre-hook to log single document deletions
287
279
  monitorsSchema.pre("findOneAndDelete", async function () {