s3db.js 12.2.2 → 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 +25 -24
- package/dist/s3db.cjs.js.map +1 -1
- package/dist/s3db.es.js +25 -24
- package/dist/s3db.es.js.map +1 -1
- package/package.json +1 -1
- package/src/plugins/costs.plugin.js +38 -32
package/dist/s3db.es.js
CHANGED
|
@@ -6976,18 +6976,13 @@ class CachePlugin extends Plugin {
|
|
|
6976
6976
|
}
|
|
6977
6977
|
}
|
|
6978
6978
|
|
|
6979
|
-
|
|
6980
|
-
|
|
6981
|
-
|
|
6982
|
-
|
|
6983
|
-
|
|
6984
|
-
|
|
6985
|
-
|
|
6986
|
-
considerFreeTier: false,
|
|
6987
|
-
// Flag to consider AWS free tier in calculations
|
|
6988
|
-
region: "us-east-1",
|
|
6989
|
-
// AWS region for pricing (future use)
|
|
6990
|
-
...options
|
|
6979
|
+
class CostsPlugin extends Plugin {
|
|
6980
|
+
constructor(config = {}) {
|
|
6981
|
+
super(config);
|
|
6982
|
+
this.config = {
|
|
6983
|
+
considerFreeTier: config.considerFreeTier !== void 0 ? config.considerFreeTier : false,
|
|
6984
|
+
region: config.region || "us-east-1",
|
|
6985
|
+
...config
|
|
6991
6986
|
};
|
|
6992
6987
|
this.map = {
|
|
6993
6988
|
PutObjectCommand: "put",
|
|
@@ -7081,14 +7076,20 @@ const CostsPlugin = {
|
|
|
7081
7076
|
// Data transfer out cost
|
|
7082
7077
|
}
|
|
7083
7078
|
};
|
|
7079
|
+
}
|
|
7080
|
+
async onInstall() {
|
|
7081
|
+
if (!this.database || !this.database.client) {
|
|
7082
|
+
return;
|
|
7083
|
+
}
|
|
7084
|
+
this.client = this.database.client;
|
|
7084
7085
|
this.client.costs = JSON.parse(JSON.stringify(this.costs));
|
|
7085
|
-
}
|
|
7086
|
-
async
|
|
7086
|
+
}
|
|
7087
|
+
async onStart() {
|
|
7087
7088
|
if (this.client) {
|
|
7088
7089
|
this.client.on("command.response", (name, response, input) => this.addRequest(name, this.map[name], response, input));
|
|
7089
7090
|
this.client.on("command.error", (name, response, input) => this.addRequest(name, this.map[name], response, input));
|
|
7090
7091
|
}
|
|
7091
|
-
}
|
|
7092
|
+
}
|
|
7092
7093
|
addRequest(name, method, response = {}, input = {}) {
|
|
7093
7094
|
if (!method) return;
|
|
7094
7095
|
this.costs.requests.totalEvents++;
|
|
@@ -7128,7 +7129,7 @@ const CostsPlugin = {
|
|
|
7128
7129
|
this.client.costs.requests.subtotal += requestCost;
|
|
7129
7130
|
}
|
|
7130
7131
|
this.updateTotal();
|
|
7131
|
-
}
|
|
7132
|
+
}
|
|
7132
7133
|
trackStorage(bytes) {
|
|
7133
7134
|
this.costs.storage.totalBytes += bytes;
|
|
7134
7135
|
this.costs.storage.totalGB = this.costs.storage.totalBytes / (1024 * 1024 * 1024);
|
|
@@ -7139,7 +7140,7 @@ const CostsPlugin = {
|
|
|
7139
7140
|
this.client.costs.storage.subtotal = this.calculateStorageCost(this.client.costs.storage);
|
|
7140
7141
|
}
|
|
7141
7142
|
this.updateTotal();
|
|
7142
|
-
}
|
|
7143
|
+
}
|
|
7143
7144
|
trackDataTransferIn(bytes) {
|
|
7144
7145
|
this.costs.dataTransfer.inBytes += bytes;
|
|
7145
7146
|
this.costs.dataTransfer.inGB = this.costs.dataTransfer.inBytes / (1024 * 1024 * 1024);
|
|
@@ -7148,7 +7149,7 @@ const CostsPlugin = {
|
|
|
7148
7149
|
this.client.costs.dataTransfer.inGB = this.client.costs.dataTransfer.inBytes / (1024 * 1024 * 1024);
|
|
7149
7150
|
}
|
|
7150
7151
|
this.updateTotal();
|
|
7151
|
-
}
|
|
7152
|
+
}
|
|
7152
7153
|
trackDataTransferOut(bytes) {
|
|
7153
7154
|
this.costs.dataTransfer.outBytes += bytes;
|
|
7154
7155
|
this.costs.dataTransfer.outGB = this.costs.dataTransfer.outBytes / (1024 * 1024 * 1024);
|
|
@@ -7159,7 +7160,7 @@ const CostsPlugin = {
|
|
|
7159
7160
|
this.client.costs.dataTransfer.subtotal = this.calculateDataTransferCost(this.client.costs.dataTransfer);
|
|
7160
7161
|
}
|
|
7161
7162
|
this.updateTotal();
|
|
7162
|
-
}
|
|
7163
|
+
}
|
|
7163
7164
|
calculateStorageCost(storage) {
|
|
7164
7165
|
const totalGB = storage.totalGB;
|
|
7165
7166
|
let cost = 0;
|
|
@@ -7178,11 +7179,11 @@ const CostsPlugin = {
|
|
|
7178
7179
|
}
|
|
7179
7180
|
}
|
|
7180
7181
|
return cost;
|
|
7181
|
-
}
|
|
7182
|
+
}
|
|
7182
7183
|
calculateDataTransferCost(dataTransfer) {
|
|
7183
7184
|
let totalGB = dataTransfer.outGB;
|
|
7184
7185
|
let cost = 0;
|
|
7185
|
-
if (this.
|
|
7186
|
+
if (this.config && this.config.considerFreeTier) {
|
|
7186
7187
|
const freeTierRemaining = dataTransfer.freeTierGB - dataTransfer.freeTierUsed;
|
|
7187
7188
|
if (freeTierRemaining > 0 && totalGB > 0) {
|
|
7188
7189
|
const gbToDeduct = Math.min(totalGB, freeTierRemaining);
|
|
@@ -7205,14 +7206,14 @@ const CostsPlugin = {
|
|
|
7205
7206
|
}
|
|
7206
7207
|
}
|
|
7207
7208
|
return cost;
|
|
7208
|
-
}
|
|
7209
|
+
}
|
|
7209
7210
|
updateTotal() {
|
|
7210
7211
|
this.costs.total = this.costs.requests.subtotal + this.costs.storage.subtotal + this.costs.dataTransfer.subtotal;
|
|
7211
7212
|
if (this.client && this.client.costs) {
|
|
7212
7213
|
this.client.costs.total = this.client.costs.requests.subtotal + this.client.costs.storage.subtotal + this.client.costs.dataTransfer.subtotal;
|
|
7213
7214
|
}
|
|
7214
7215
|
}
|
|
7215
|
-
}
|
|
7216
|
+
}
|
|
7216
7217
|
|
|
7217
7218
|
function createConfig(options, detectedTimezone) {
|
|
7218
7219
|
const consolidation = options.consolidation || {};
|
|
@@ -21030,7 +21031,7 @@ class Database extends EventEmitter {
|
|
|
21030
21031
|
this.id = idGenerator(7);
|
|
21031
21032
|
this.version = "1";
|
|
21032
21033
|
this.s3dbVersion = (() => {
|
|
21033
|
-
const [ok, err, version] = tryFn(() => true ? "12.2.
|
|
21034
|
+
const [ok, err, version] = tryFn(() => true ? "12.2.3" : "latest");
|
|
21034
21035
|
return ok ? version : "latest";
|
|
21035
21036
|
})();
|
|
21036
21037
|
this._resourcesMap = {};
|