s3db.js 13.0.0 → 13.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.
@@ -280,6 +280,4 @@ export class Plugin extends EventEmitter {
280
280
  afterUninstall() {
281
281
  this.emit("plugin.afterUninstall", new Date());
282
282
  }
283
- }
284
-
285
- export default Plugin;
283
+ }
@@ -138,6 +138,4 @@ export class QueueConsumerPlugin extends Plugin {
138
138
 
139
139
  _handleError(err, raw, resourceName) {
140
140
  }
141
- }
142
-
143
- export default QueueConsumerPlugin;
141
+ }
@@ -1,4 +1,4 @@
1
- import Plugin from "./plugin.class.js";
1
+ import { Plugin } from "./plugin.class.js";
2
2
  import tryFn from "../concerns/try-fn.js";
3
3
  import {
4
4
  RelationError,
@@ -1373,5 +1373,3 @@ export class RelationPlugin extends Plugin {
1373
1373
  this.clearCache();
1374
1374
  }
1375
1375
  }
1376
-
1377
- export default RelationPlugin;
@@ -1,4 +1,4 @@
1
- import Plugin from "./plugin.class.js";
1
+ import { Plugin } from "./plugin.class.js";
2
2
  import tryFn from "../concerns/try-fn.js";
3
3
  import { createReplicator, validateReplicatorConfig } from "./replicators/index.js";
4
4
  import { ReplicationError } from "./replicator.errors.js";
@@ -777,6 +777,4 @@ export class ReplicatorPlugin extends Plugin {
777
777
  });
778
778
  }
779
779
  }
780
- }
781
-
782
- export default ReplicatorPlugin;
780
+ }
@@ -1,4 +1,4 @@
1
- import Plugin from "./plugin.class.js";
1
+ import { Plugin } from "./plugin.class.js";
2
2
  import tryFn from "../concerns/try-fn.js";
3
3
  import { idGenerator } from "../concerns/id.js";
4
4
 
@@ -673,5 +673,3 @@ export class S3QueuePlugin extends Plugin {
673
673
  }
674
674
  }
675
675
  }
676
-
677
- export default S3QueuePlugin;
@@ -1,4 +1,4 @@
1
- import Plugin from "./plugin.class.js";
1
+ import { Plugin } from "./plugin.class.js";
2
2
  import tryFn from "../concerns/try-fn.js";
3
3
  import { idGenerator } from "../concerns/id.js";
4
4
  import { SchedulerError } from "./scheduler.errors.js";
@@ -921,6 +921,4 @@ export class SchedulerPlugin extends Plugin {
921
921
  this.activeJobs.clear();
922
922
  this.removeAllListeners();
923
923
  }
924
- }
925
-
926
- export default SchedulerPlugin;
924
+ }
@@ -1,4 +1,4 @@
1
- import Plugin from "./plugin.class.js";
1
+ import { Plugin } from "./plugin.class.js";
2
2
  import tryFn from "../concerns/try-fn.js";
3
3
  import { StateMachineError } from "./state-machine.errors.js";
4
4
 
@@ -684,6 +684,4 @@ export class StateMachinePlugin extends Plugin {
684
684
  this.machines.clear();
685
685
  this.removeAllListeners();
686
686
  }
687
- }
688
-
689
- export default StateMachinePlugin;
687
+ }
@@ -2630,5 +2630,3 @@ export class TfStatePlugin extends Plugin {
2630
2630
  };
2631
2631
  }
2632
2632
  }
2633
-
2634
- export default TfStatePlugin;
@@ -1,7 +1,24 @@
1
- import Plugin from "./plugin.class.js";
1
+ import { Plugin } from "./plugin.class.js";
2
2
  import tryFn from "../concerns/try-fn.js";
3
3
  import { idGenerator } from "../concerns/id.js";
4
4
 
5
+ // Time constants (in seconds)
6
+ const ONE_MINUTE_SEC = 60;
7
+ const ONE_HOUR_SEC = 3600;
8
+ const ONE_DAY_SEC = 86400;
9
+ const THIRTY_DAYS_SEC = 2592000;
10
+
11
+ // Time constants (in milliseconds)
12
+ const TEN_SECONDS_MS = 10000;
13
+ const ONE_MINUTE_MS = 60000;
14
+ const TEN_MINUTES_MS = 600000;
15
+ const ONE_HOUR_MS = 3600000;
16
+ const ONE_DAY_MS = 86400000;
17
+ const ONE_WEEK_MS = 604800000;
18
+
19
+ // Conversion factor
20
+ const SECONDS_TO_MS = 1000;
21
+
5
22
  /**
6
23
  * TTLPlugin - Time-To-Live Auto-Cleanup System v2
7
24
  *
@@ -45,27 +62,27 @@ import { idGenerator } from "../concerns/id.js";
45
62
  // Granularity configurations
46
63
  const GRANULARITIES = {
47
64
  minute: {
48
- threshold: 3600, // TTL < 1 hour
49
- interval: 10000, // Check every 10 seconds
50
- cohortsToCheck: 3, // Check last 3 minutes
65
+ threshold: ONE_HOUR_SEC, // TTL < 1 hour
66
+ interval: TEN_SECONDS_MS, // Check every 10 seconds
67
+ cohortsToCheck: 3, // Check last 3 minutes
51
68
  cohortFormat: (date) => date.toISOString().substring(0, 16) // '2024-10-25T14:30'
52
69
  },
53
70
  hour: {
54
- threshold: 86400, // TTL < 24 hours
55
- interval: 600000, // Check every 10 minutes
56
- cohortsToCheck: 2, // Check last 2 hours
71
+ threshold: ONE_DAY_SEC, // TTL < 24 hours
72
+ interval: TEN_MINUTES_MS, // Check every 10 minutes
73
+ cohortsToCheck: 2, // Check last 2 hours
57
74
  cohortFormat: (date) => date.toISOString().substring(0, 13) // '2024-10-25T14'
58
75
  },
59
76
  day: {
60
- threshold: 2592000, // TTL < 30 days
61
- interval: 3600000, // Check every 1 hour
62
- cohortsToCheck: 2, // Check last 2 days
77
+ threshold: THIRTY_DAYS_SEC, // TTL < 30 days
78
+ interval: ONE_HOUR_MS, // Check every 1 hour
79
+ cohortsToCheck: 2, // Check last 2 days
63
80
  cohortFormat: (date) => date.toISOString().substring(0, 10) // '2024-10-25'
64
81
  },
65
82
  week: {
66
- threshold: Infinity, // TTL >= 30 days
67
- interval: 86400000, // Check every 24 hours
68
- cohortsToCheck: 2, // Check last 2 weeks
83
+ threshold: Infinity, // TTL >= 30 days
84
+ interval: ONE_DAY_MS, // Check every 24 hours
85
+ cohortsToCheck: 2, // Check last 2 weeks
69
86
  cohortFormat: (date) => {
70
87
  const year = date.getUTCFullYear();
71
88
  const week = getWeekNumber(date);
@@ -82,7 +99,7 @@ function getWeekNumber(date) {
82
99
  const dayNum = d.getUTCDay() || 7;
83
100
  d.setUTCDate(d.getUTCDate() + 4 - dayNum);
84
101
  const yearStart = new Date(Date.UTC(d.getUTCFullYear(), 0, 1));
85
- return Math.ceil((((d - yearStart) / 86400000) + 1) / 7);
102
+ return Math.ceil((((d - yearStart) / ONE_DAY_MS) + 1) / 7);
86
103
  }
87
104
 
88
105
  /**
@@ -109,16 +126,16 @@ function getExpiredCohorts(granularity, count) {
109
126
 
110
127
  switch(granularity) {
111
128
  case 'minute':
112
- checkDate = new Date(now.getTime() - (i * 60000));
129
+ checkDate = new Date(now.getTime() - (i * ONE_MINUTE_MS));
113
130
  break;
114
131
  case 'hour':
115
- checkDate = new Date(now.getTime() - (i * 3600000));
132
+ checkDate = new Date(now.getTime() - (i * ONE_HOUR_MS));
116
133
  break;
117
134
  case 'day':
118
- checkDate = new Date(now.getTime() - (i * 86400000));
135
+ checkDate = new Date(now.getTime() - (i * ONE_DAY_MS));
119
136
  break;
120
137
  case 'week':
121
- checkDate = new Date(now.getTime() - (i * 604800000));
138
+ checkDate = new Date(now.getTime() - (i * ONE_WEEK_MS));
122
139
  break;
123
140
  }
124
141
 
@@ -340,7 +357,7 @@ export class TTLPlugin extends Plugin {
340
357
  // Calculate expiration timestamp
341
358
  const baseTimestamp = typeof baseTime === 'number' ? baseTime : new Date(baseTime).getTime();
342
359
  const expiresAt = config.ttl
343
- ? new Date(baseTimestamp + config.ttl * 1000)
360
+ ? new Date(baseTimestamp + config.ttl * SECONDS_TO_MS)
344
361
  : new Date(baseTimestamp);
345
362
 
346
363
  // Calculate cohort
@@ -707,5 +724,3 @@ export class TTLPlugin extends Plugin {
707
724
  }
708
725
  }
709
726
  }
710
-
711
- export default TTLPlugin;
@@ -1035,5 +1035,3 @@ export class VectorPlugin extends Plugin {
1035
1035
  return findOptimalK(vectors, options);
1036
1036
  }
1037
1037
  }
1038
-
1039
- export default VectorPlugin;