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 CHANGED
@@ -6999,18 +6999,13 @@ class CachePlugin extends Plugin {
6999
6999
  }
7000
7000
  }
7001
7001
 
7002
- const CostsPlugin = {
7003
- async setup(db, options = {}) {
7004
- if (!db || !db.client) {
7005
- return;
7006
- }
7007
- this.client = db.client;
7008
- this.options = {
7009
- considerFreeTier: false,
7010
- // Flag to consider AWS free tier in calculations
7011
- region: "us-east-1",
7012
- // AWS region for pricing (future use)
7013
- ...options
7002
+ class CostsPlugin extends Plugin {
7003
+ constructor(config = {}) {
7004
+ super(config);
7005
+ this.config = {
7006
+ considerFreeTier: config.considerFreeTier !== void 0 ? config.considerFreeTier : false,
7007
+ region: config.region || "us-east-1",
7008
+ ...config
7014
7009
  };
7015
7010
  this.map = {
7016
7011
  PutObjectCommand: "put",
@@ -7104,14 +7099,20 @@ const CostsPlugin = {
7104
7099
  // Data transfer out cost
7105
7100
  }
7106
7101
  };
7102
+ }
7103
+ async onInstall() {
7104
+ if (!this.database || !this.database.client) {
7105
+ return;
7106
+ }
7107
+ this.client = this.database.client;
7107
7108
  this.client.costs = JSON.parse(JSON.stringify(this.costs));
7108
- },
7109
- async start() {
7109
+ }
7110
+ async onStart() {
7110
7111
  if (this.client) {
7111
7112
  this.client.on("command.response", (name, response, input) => this.addRequest(name, this.map[name], response, input));
7112
7113
  this.client.on("command.error", (name, response, input) => this.addRequest(name, this.map[name], response, input));
7113
7114
  }
7114
- },
7115
+ }
7115
7116
  addRequest(name, method, response = {}, input = {}) {
7116
7117
  if (!method) return;
7117
7118
  this.costs.requests.totalEvents++;
@@ -7151,7 +7152,7 @@ const CostsPlugin = {
7151
7152
  this.client.costs.requests.subtotal += requestCost;
7152
7153
  }
7153
7154
  this.updateTotal();
7154
- },
7155
+ }
7155
7156
  trackStorage(bytes) {
7156
7157
  this.costs.storage.totalBytes += bytes;
7157
7158
  this.costs.storage.totalGB = this.costs.storage.totalBytes / (1024 * 1024 * 1024);
@@ -7162,7 +7163,7 @@ const CostsPlugin = {
7162
7163
  this.client.costs.storage.subtotal = this.calculateStorageCost(this.client.costs.storage);
7163
7164
  }
7164
7165
  this.updateTotal();
7165
- },
7166
+ }
7166
7167
  trackDataTransferIn(bytes) {
7167
7168
  this.costs.dataTransfer.inBytes += bytes;
7168
7169
  this.costs.dataTransfer.inGB = this.costs.dataTransfer.inBytes / (1024 * 1024 * 1024);
@@ -7171,7 +7172,7 @@ const CostsPlugin = {
7171
7172
  this.client.costs.dataTransfer.inGB = this.client.costs.dataTransfer.inBytes / (1024 * 1024 * 1024);
7172
7173
  }
7173
7174
  this.updateTotal();
7174
- },
7175
+ }
7175
7176
  trackDataTransferOut(bytes) {
7176
7177
  this.costs.dataTransfer.outBytes += bytes;
7177
7178
  this.costs.dataTransfer.outGB = this.costs.dataTransfer.outBytes / (1024 * 1024 * 1024);
@@ -7182,7 +7183,7 @@ const CostsPlugin = {
7182
7183
  this.client.costs.dataTransfer.subtotal = this.calculateDataTransferCost(this.client.costs.dataTransfer);
7183
7184
  }
7184
7185
  this.updateTotal();
7185
- },
7186
+ }
7186
7187
  calculateStorageCost(storage) {
7187
7188
  const totalGB = storage.totalGB;
7188
7189
  let cost = 0;
@@ -7201,11 +7202,11 @@ const CostsPlugin = {
7201
7202
  }
7202
7203
  }
7203
7204
  return cost;
7204
- },
7205
+ }
7205
7206
  calculateDataTransferCost(dataTransfer) {
7206
7207
  let totalGB = dataTransfer.outGB;
7207
7208
  let cost = 0;
7208
- if (this.options && this.options.considerFreeTier) {
7209
+ if (this.config && this.config.considerFreeTier) {
7209
7210
  const freeTierRemaining = dataTransfer.freeTierGB - dataTransfer.freeTierUsed;
7210
7211
  if (freeTierRemaining > 0 && totalGB > 0) {
7211
7212
  const gbToDeduct = Math.min(totalGB, freeTierRemaining);
@@ -7228,14 +7229,14 @@ const CostsPlugin = {
7228
7229
  }
7229
7230
  }
7230
7231
  return cost;
7231
- },
7232
+ }
7232
7233
  updateTotal() {
7233
7234
  this.costs.total = this.costs.requests.subtotal + this.costs.storage.subtotal + this.costs.dataTransfer.subtotal;
7234
7235
  if (this.client && this.client.costs) {
7235
7236
  this.client.costs.total = this.client.costs.requests.subtotal + this.client.costs.storage.subtotal + this.client.costs.dataTransfer.subtotal;
7236
7237
  }
7237
7238
  }
7238
- };
7239
+ }
7239
7240
 
7240
7241
  function createConfig(options, detectedTimezone) {
7241
7242
  const consolidation = options.consolidation || {};
@@ -21053,7 +21054,7 @@ class Database extends EventEmitter {
21053
21054
  this.id = idGenerator(7);
21054
21055
  this.version = "1";
21055
21056
  this.s3dbVersion = (() => {
21056
- const [ok, err, version] = tryFn(() => true ? "12.2.2" : "latest");
21057
+ const [ok, err, version] = tryFn(() => true ? "12.2.3" : "latest");
21057
21058
  return ok ? version : "latest";
21058
21059
  })();
21059
21060
  this._resourcesMap = {};