s3db.js 12.2.1 → 12.2.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/dist/s3db.cjs.js +1152 -24
- package/dist/s3db.cjs.js.map +1 -1
- package/dist/s3db.es.js +1151 -25
- package/dist/s3db.es.js.map +1 -1
- package/package.json +1 -1
- package/src/plugins/costs.plugin.js +38 -32
- package/src/plugins/geo.plugin.js +1 -1
- package/src/plugins/relation.plugin.js +1 -2
- package/src/plugins/ttl.plugin.js +1 -1
package/package.json
CHANGED
|
@@ -1,15 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
async setup (db, options = {}) {
|
|
3
|
-
if (!db || !db.client) {
|
|
4
|
-
return; // Handle null/invalid database gracefully
|
|
5
|
-
}
|
|
1
|
+
import { Plugin } from './plugin.class.js';
|
|
6
2
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
3
|
+
export class CostsPlugin extends Plugin {
|
|
4
|
+
constructor(config = {}) {
|
|
5
|
+
super(config);
|
|
6
|
+
|
|
7
|
+
this.config = {
|
|
8
|
+
considerFreeTier: config.considerFreeTier !== undefined ? config.considerFreeTier : false,
|
|
9
|
+
region: config.region || 'us-east-1',
|
|
10
|
+
...config
|
|
11
|
+
};
|
|
13
12
|
|
|
14
13
|
this.map = {
|
|
15
14
|
PutObjectCommand: 'put',
|
|
@@ -19,7 +18,7 @@ export const CostsPlugin = {
|
|
|
19
18
|
DeleteObjectCommand: 'delete',
|
|
20
19
|
DeleteObjectsCommand: 'delete',
|
|
21
20
|
ListObjectsV2Command: 'list',
|
|
22
|
-
}
|
|
21
|
+
};
|
|
23
22
|
|
|
24
23
|
this.costs = {
|
|
25
24
|
total: 0,
|
|
@@ -97,19 +96,26 @@ export const CostsPlugin = {
|
|
|
97
96
|
currentTier: 0,
|
|
98
97
|
subtotal: 0 // Data transfer out cost
|
|
99
98
|
}
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
async onInstall() {
|
|
103
|
+
if (!this.database || !this.database.client) {
|
|
104
|
+
return; // Handle null/invalid database gracefully
|
|
100
105
|
}
|
|
101
106
|
|
|
107
|
+
this.client = this.database.client;
|
|
102
108
|
this.client.costs = JSON.parse(JSON.stringify(this.costs));
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
async
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
async onStart() {
|
|
106
112
|
if (this.client) {
|
|
107
113
|
this.client.on("command.response", (name, response, input) => this.addRequest(name, this.map[name], response, input));
|
|
108
114
|
this.client.on("command.error", (name, response, input) => this.addRequest(name, this.map[name], response, input));
|
|
109
115
|
}
|
|
110
|
-
}
|
|
116
|
+
}
|
|
111
117
|
|
|
112
|
-
addRequest
|
|
118
|
+
addRequest(name, method, response = {}, input = {}) {
|
|
113
119
|
if (!method) return; // Skip if no mapping found
|
|
114
120
|
|
|
115
121
|
// Track request counts
|
|
@@ -167,9 +173,9 @@ export const CostsPlugin = {
|
|
|
167
173
|
|
|
168
174
|
// Update total cost (must be after mirroring request counters)
|
|
169
175
|
this.updateTotal();
|
|
170
|
-
}
|
|
176
|
+
}
|
|
171
177
|
|
|
172
|
-
trackStorage
|
|
178
|
+
trackStorage(bytes) {
|
|
173
179
|
this.costs.storage.totalBytes += bytes;
|
|
174
180
|
this.costs.storage.totalGB = this.costs.storage.totalBytes / (1024 * 1024 * 1024);
|
|
175
181
|
this.costs.storage.subtotal = this.calculateStorageCost(this.costs.storage);
|
|
@@ -183,9 +189,9 @@ export const CostsPlugin = {
|
|
|
183
189
|
|
|
184
190
|
// Update total cost
|
|
185
191
|
this.updateTotal();
|
|
186
|
-
}
|
|
192
|
+
}
|
|
187
193
|
|
|
188
|
-
trackDataTransferIn
|
|
194
|
+
trackDataTransferIn(bytes) {
|
|
189
195
|
this.costs.dataTransfer.inBytes += bytes;
|
|
190
196
|
this.costs.dataTransfer.inGB = this.costs.dataTransfer.inBytes / (1024 * 1024 * 1024);
|
|
191
197
|
// inCost is always $0
|
|
@@ -198,9 +204,9 @@ export const CostsPlugin = {
|
|
|
198
204
|
|
|
199
205
|
// Update total cost
|
|
200
206
|
this.updateTotal();
|
|
201
|
-
}
|
|
207
|
+
}
|
|
202
208
|
|
|
203
|
-
trackDataTransferOut
|
|
209
|
+
trackDataTransferOut(bytes) {
|
|
204
210
|
this.costs.dataTransfer.outBytes += bytes;
|
|
205
211
|
this.costs.dataTransfer.outGB = this.costs.dataTransfer.outBytes / (1024 * 1024 * 1024);
|
|
206
212
|
this.costs.dataTransfer.subtotal = this.calculateDataTransferCost(this.costs.dataTransfer);
|
|
@@ -214,9 +220,9 @@ export const CostsPlugin = {
|
|
|
214
220
|
|
|
215
221
|
// Update total cost
|
|
216
222
|
this.updateTotal();
|
|
217
|
-
}
|
|
223
|
+
}
|
|
218
224
|
|
|
219
|
-
calculateStorageCost
|
|
225
|
+
calculateStorageCost(storage) {
|
|
220
226
|
const totalGB = storage.totalGB;
|
|
221
227
|
let cost = 0;
|
|
222
228
|
let remaining = totalGB;
|
|
@@ -239,14 +245,14 @@ export const CostsPlugin = {
|
|
|
239
245
|
}
|
|
240
246
|
|
|
241
247
|
return cost;
|
|
242
|
-
}
|
|
248
|
+
}
|
|
243
249
|
|
|
244
|
-
calculateDataTransferCost
|
|
250
|
+
calculateDataTransferCost(dataTransfer) {
|
|
245
251
|
let totalGB = dataTransfer.outGB;
|
|
246
252
|
let cost = 0;
|
|
247
253
|
|
|
248
254
|
// Apply free tier if enabled
|
|
249
|
-
if (this.
|
|
255
|
+
if (this.config && this.config.considerFreeTier) {
|
|
250
256
|
const freeTierRemaining = dataTransfer.freeTierGB - dataTransfer.freeTierUsed;
|
|
251
257
|
|
|
252
258
|
if (freeTierRemaining > 0 && totalGB > 0) {
|
|
@@ -276,9 +282,9 @@ export const CostsPlugin = {
|
|
|
276
282
|
}
|
|
277
283
|
|
|
278
284
|
return cost;
|
|
279
|
-
}
|
|
285
|
+
}
|
|
280
286
|
|
|
281
|
-
updateTotal
|
|
287
|
+
updateTotal() {
|
|
282
288
|
this.costs.total =
|
|
283
289
|
this.costs.requests.subtotal +
|
|
284
290
|
this.costs.storage.subtotal +
|
|
@@ -291,7 +297,7 @@ export const CostsPlugin = {
|
|
|
291
297
|
this.client.costs.storage.subtotal +
|
|
292
298
|
this.client.costs.dataTransfer.subtotal;
|
|
293
299
|
}
|
|
294
|
-
}
|
|
300
|
+
}
|
|
295
301
|
}
|
|
296
302
|
|
|
297
|
-
export default CostsPlugin
|
|
303
|
+
export default CostsPlugin;
|
|
@@ -276,7 +276,7 @@ import {
|
|
|
276
276
|
* });
|
|
277
277
|
* ```
|
|
278
278
|
*/
|
|
279
|
-
class RelationPlugin extends Plugin {
|
|
279
|
+
export class RelationPlugin extends Plugin {
|
|
280
280
|
constructor(config = {}) {
|
|
281
281
|
super(config);
|
|
282
282
|
|
|
@@ -1374,5 +1374,4 @@ class RelationPlugin extends Plugin {
|
|
|
1374
1374
|
}
|
|
1375
1375
|
}
|
|
1376
1376
|
|
|
1377
|
-
export { RelationPlugin };
|
|
1378
1377
|
export default RelationPlugin;
|