s3db.js 7.3.3 → 7.3.5

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.iife.js CHANGED
@@ -1,4 +1,4 @@
1
- var S3DB = (function (exports, nanoid, zlib, promisePool, web, lodashEs, crypto, jsonStableStringify, clientS3, flat, FastestValidator) {
1
+ var S3DB = (function (exports, nanoid, zlib, promisePool, web, promises, crypto, lodashEs, jsonStableStringify, clientS3, flat, FastestValidator) {
2
2
  'use strict';
3
3
 
4
4
  const alphabet = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
@@ -2069,16 +2069,6 @@ ${JSON.stringify(validation, null, 2)}`,
2069
2069
  // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
2070
2070
  // USE OR OTHER DEALINGS IN THE SOFTWARE.
2071
2071
 
2072
- var getOwnPropertyDescriptors = Object.getOwnPropertyDescriptors ||
2073
- function getOwnPropertyDescriptors(obj) {
2074
- var keys = Object.keys(obj);
2075
- var descriptors = {};
2076
- for (var i = 0; i < keys.length; i++) {
2077
- descriptors[keys[i]] = Object.getOwnPropertyDescriptor(obj, keys[i]);
2078
- }
2079
- return descriptors;
2080
- };
2081
-
2082
2072
  var formatRegExp = /%[sdj%]/g;
2083
2073
  function format(f) {
2084
2074
  if (!isString(f)) {
@@ -2564,64 +2554,6 @@ ${JSON.stringify(validation, null, 2)}`,
2564
2554
  return Object.prototype.hasOwnProperty.call(obj, prop);
2565
2555
  }
2566
2556
 
2567
- var kCustomPromisifiedSymbol = typeof Symbol !== 'undefined' ? Symbol('util.promisify.custom') : undefined;
2568
-
2569
- function promisify(original) {
2570
- if (typeof original !== 'function')
2571
- throw new TypeError('The "original" argument must be of type Function');
2572
-
2573
- if (kCustomPromisifiedSymbol && original[kCustomPromisifiedSymbol]) {
2574
- var fn = original[kCustomPromisifiedSymbol];
2575
- if (typeof fn !== 'function') {
2576
- throw new TypeError('The "util.promisify.custom" argument must be of type Function');
2577
- }
2578
- Object.defineProperty(fn, kCustomPromisifiedSymbol, {
2579
- value: fn, enumerable: false, writable: false, configurable: true
2580
- });
2581
- return fn;
2582
- }
2583
-
2584
- function fn() {
2585
- var promiseResolve, promiseReject;
2586
- var promise = new Promise(function (resolve, reject) {
2587
- promiseResolve = resolve;
2588
- promiseReject = reject;
2589
- });
2590
-
2591
- var args = [];
2592
- for (var i = 0; i < arguments.length; i++) {
2593
- args.push(arguments[i]);
2594
- }
2595
- args.push(function (err, value) {
2596
- if (err) {
2597
- promiseReject(err);
2598
- } else {
2599
- promiseResolve(value);
2600
- }
2601
- });
2602
-
2603
- try {
2604
- original.apply(this, args);
2605
- } catch (err) {
2606
- promiseReject(err);
2607
- }
2608
-
2609
- return promise;
2610
- }
2611
-
2612
- Object.setPrototypeOf(fn, Object.getPrototypeOf(original));
2613
-
2614
- if (kCustomPromisifiedSymbol) Object.defineProperty(fn, kCustomPromisifiedSymbol, {
2615
- value: fn, enumerable: false, writable: false, configurable: true
2616
- });
2617
- return Object.defineProperties(
2618
- fn,
2619
- getOwnPropertyDescriptors(original)
2620
- );
2621
- }
2622
-
2623
- promisify.custom = kCustomPromisifiedSymbol;
2624
-
2625
2557
  var lookup = [];
2626
2558
  var revLookup = [];
2627
2559
  var Arr = typeof Uint8Array !== 'undefined' ? Uint8Array : Array;
@@ -6874,12 +6806,6 @@ ${JSON.stringify(validation, null, 2)}`,
6874
6806
 
6875
6807
  var fs = {};
6876
6808
 
6877
- const readFile$1 = promisify(fs.readFile);
6878
- const writeFile$1 = promisify(fs.writeFile);
6879
- const unlink = promisify(fs.unlink);
6880
- const readdir$1 = promisify(fs.readdir);
6881
- const stat$1 = promisify(fs.stat);
6882
- const mkdir = promisify(fs.mkdir);
6883
6809
  class FilesystemCache extends Cache {
6884
6810
  constructor({
6885
6811
  directory,
@@ -6956,7 +6882,7 @@ ${JSON.stringify(validation, null, 2)}`,
6956
6882
  }
6957
6883
  async _ensureDirectory(dir) {
6958
6884
  const [ok, err] = await try_fn_default(async () => {
6959
- await mkdir(dir, { recursive: true });
6885
+ await promises.mkdir(dir, { recursive: true });
6960
6886
  });
6961
6887
  if (!ok && err.code !== "EEXIST") {
6962
6888
  throw new Error(`Failed to create cache directory: ${err.message}`);
@@ -6993,7 +6919,7 @@ ${JSON.stringify(validation, null, 2)}`,
6993
6919
  await this._acquireLock(filePath);
6994
6920
  }
6995
6921
  try {
6996
- await writeFile$1(filePath, finalData, {
6922
+ await promises.writeFile(filePath, finalData, {
6997
6923
  encoding: compressed ? "utf8" : this.encoding,
6998
6924
  mode: this.fileMode
6999
6925
  });
@@ -7007,7 +6933,7 @@ ${JSON.stringify(validation, null, 2)}`,
7007
6933
  compressedSize: compressed ? Buffer.byteLength(finalData, "utf8") : originalSize,
7008
6934
  compressionRatio: compressed ? (Buffer.byteLength(finalData, "utf8") / originalSize).toFixed(2) : 1
7009
6935
  };
7010
- await writeFile$1(this._getMetadataPath(filePath), JSON.stringify(metadata), {
6936
+ await promises.writeFile(this._getMetadataPath(filePath), JSON.stringify(metadata), {
7011
6937
  encoding: this.encoding,
7012
6938
  mode: this.fileMode
7013
6939
  });
@@ -7045,7 +6971,7 @@ ${JSON.stringify(validation, null, 2)}`,
7045
6971
  const metadataPath = this._getMetadataPath(filePath);
7046
6972
  if (await this._fileExists(metadataPath)) {
7047
6973
  const [ok, err, metadata] = await try_fn_default(async () => {
7048
- const metaContent = await readFile$1(metadataPath, this.encoding);
6974
+ const metaContent = await promises.readFile(metadataPath, this.encoding);
7049
6975
  return JSON.parse(metaContent);
7050
6976
  });
7051
6977
  if (ok && metadata.ttl > 0) {
@@ -7054,7 +6980,7 @@ ${JSON.stringify(validation, null, 2)}`,
7054
6980
  }
7055
6981
  }
7056
6982
  } else if (this.ttl > 0) {
7057
- const stats = await stat$1(filePath);
6983
+ const stats = await promises.stat(filePath);
7058
6984
  const age = Date.now() - stats.mtime.getTime();
7059
6985
  isExpired = age > this.ttl;
7060
6986
  }
@@ -7069,13 +6995,13 @@ ${JSON.stringify(validation, null, 2)}`,
7069
6995
  await this._acquireLock(filePath);
7070
6996
  }
7071
6997
  try {
7072
- const content = await readFile$1(filePath, this.encoding);
6998
+ const content = await promises.readFile(filePath, this.encoding);
7073
6999
  let isCompressed = false;
7074
7000
  if (this.enableMetadata) {
7075
7001
  const metadataPath = this._getMetadataPath(filePath);
7076
7002
  if (await this._fileExists(metadataPath)) {
7077
7003
  const [ok, err, metadata] = await try_fn_default(async () => {
7078
- const metaContent = await readFile$1(metadataPath, this.encoding);
7004
+ const metaContent = await promises.readFile(metadataPath, this.encoding);
7079
7005
  return JSON.parse(metaContent);
7080
7006
  });
7081
7007
  if (ok) {
@@ -7114,18 +7040,18 @@ ${JSON.stringify(validation, null, 2)}`,
7114
7040
  const filePath = this._getFilePath(key);
7115
7041
  try {
7116
7042
  if (await this._fileExists(filePath)) {
7117
- await unlink(filePath);
7043
+ await promises.unlink(filePath);
7118
7044
  }
7119
7045
  if (this.enableMetadata) {
7120
7046
  const metadataPath = this._getMetadataPath(filePath);
7121
7047
  if (await this._fileExists(metadataPath)) {
7122
- await unlink(metadataPath);
7048
+ await promises.unlink(metadataPath);
7123
7049
  }
7124
7050
  }
7125
7051
  if (this.enableBackup) {
7126
7052
  const backupPath = filePath + this.backupSuffix;
7127
7053
  if (await this._fileExists(backupPath)) {
7128
- await unlink(backupPath);
7054
+ await promises.unlink(backupPath);
7129
7055
  }
7130
7056
  }
7131
7057
  if (this.enableStats) {
@@ -7144,7 +7070,7 @@ ${JSON.stringify(validation, null, 2)}`,
7144
7070
  }
7145
7071
  async _clear(prefix) {
7146
7072
  try {
7147
- const files = await readdir$1(this.directory);
7073
+ const files = await promises.readdir(this.directory);
7148
7074
  const cacheFiles = files.filter((file) => {
7149
7075
  if (!file.startsWith(this.prefix)) return false;
7150
7076
  if (!file.endsWith(this.fileExtension)) return false;
@@ -7157,18 +7083,18 @@ ${JSON.stringify(validation, null, 2)}`,
7157
7083
  for (const file of cacheFiles) {
7158
7084
  const filePath = path.join(this.directory, file);
7159
7085
  if (await this._fileExists(filePath)) {
7160
- await unlink(filePath);
7086
+ await promises.unlink(filePath);
7161
7087
  }
7162
7088
  if (this.enableMetadata) {
7163
7089
  const metadataPath = this._getMetadataPath(filePath);
7164
7090
  if (await this._fileExists(metadataPath)) {
7165
- await unlink(metadataPath);
7091
+ await promises.unlink(metadataPath);
7166
7092
  }
7167
7093
  }
7168
7094
  if (this.enableBackup) {
7169
7095
  const backupPath = filePath + this.backupSuffix;
7170
7096
  if (await this._fileExists(backupPath)) {
7171
- await unlink(backupPath);
7097
+ await promises.unlink(backupPath);
7172
7098
  }
7173
7099
  }
7174
7100
  }
@@ -7192,7 +7118,7 @@ ${JSON.stringify(validation, null, 2)}`,
7192
7118
  }
7193
7119
  async keys() {
7194
7120
  try {
7195
- const files = await readdir$1(this.directory);
7121
+ const files = await promises.readdir(this.directory);
7196
7122
  const cacheFiles = files.filter(
7197
7123
  (file) => file.startsWith(this.prefix) && file.endsWith(this.fileExtension)
7198
7124
  );
@@ -7209,14 +7135,14 @@ ${JSON.stringify(validation, null, 2)}`,
7209
7135
  // Helper methods
7210
7136
  async _fileExists(filePath) {
7211
7137
  const [ok] = await try_fn_default(async () => {
7212
- await stat$1(filePath);
7138
+ await promises.stat(filePath);
7213
7139
  });
7214
7140
  return ok;
7215
7141
  }
7216
7142
  async _copyFile(src, dest) {
7217
7143
  const [ok, err] = await try_fn_default(async () => {
7218
- const content = await readFile$1(src);
7219
- await writeFile$1(dest, content);
7144
+ const content = await promises.readFile(src);
7145
+ await promises.writeFile(dest, content);
7220
7146
  });
7221
7147
  if (!ok) {
7222
7148
  console.warn("FilesystemCache: Failed to create backup:", err.message);
@@ -7225,7 +7151,7 @@ ${JSON.stringify(validation, null, 2)}`,
7225
7151
  async _cleanup() {
7226
7152
  if (!this.ttl || this.ttl <= 0) return;
7227
7153
  try {
7228
- const files = await readdir$1(this.directory);
7154
+ const files = await promises.readdir(this.directory);
7229
7155
  const now = Date.now();
7230
7156
  for (const file of files) {
7231
7157
  if (!file.startsWith(this.prefix) || !file.endsWith(this.fileExtension)) {
@@ -7237,7 +7163,7 @@ ${JSON.stringify(validation, null, 2)}`,
7237
7163
  const metadataPath = this._getMetadataPath(filePath);
7238
7164
  if (await this._fileExists(metadataPath)) {
7239
7165
  const [ok, err, metadata] = await try_fn_default(async () => {
7240
- const metaContent = await readFile$1(metadataPath, this.encoding);
7166
+ const metaContent = await promises.readFile(metadataPath, this.encoding);
7241
7167
  return JSON.parse(metaContent);
7242
7168
  });
7243
7169
  if (ok && metadata.ttl > 0) {
@@ -7247,7 +7173,7 @@ ${JSON.stringify(validation, null, 2)}`,
7247
7173
  }
7248
7174
  } else {
7249
7175
  const [ok, err, stats] = await try_fn_default(async () => {
7250
- return await stat$1(filePath);
7176
+ return await promises.stat(filePath);
7251
7177
  });
7252
7178
  if (ok) {
7253
7179
  const age = now - stats.mtime.getTime();
@@ -7317,12 +7243,6 @@ ${JSON.stringify(validation, null, 2)}`,
7317
7243
  }
7318
7244
  }
7319
7245
 
7320
- promisify(fs.mkdir);
7321
- const rmdir = promisify(fs.rm);
7322
- const readdir = promisify(fs.readdir);
7323
- const stat = promisify(fs.stat);
7324
- const writeFile = promisify(fs.writeFile);
7325
- const readFile = promisify(fs.readFile);
7326
7246
  class PartitionAwareFilesystemCache extends FilesystemCache {
7327
7247
  constructor({
7328
7248
  partitionStrategy = "hierarchical",
@@ -7444,7 +7364,7 @@ ${JSON.stringify(validation, null, 2)}`,
7444
7364
  const partitionDir = this._getPartitionDirectory(resource, partition, partitionValues);
7445
7365
  const [ok, err] = await try_fn_default(async () => {
7446
7366
  if (await this._fileExists(partitionDir)) {
7447
- await rmdir(partitionDir, { recursive: true });
7367
+ await promises.rm(partitionDir, { recursive: true });
7448
7368
  }
7449
7369
  });
7450
7370
  if (!ok) {
@@ -7462,7 +7382,7 @@ ${JSON.stringify(validation, null, 2)}`,
7462
7382
  const resourceDir = path.join(this.directory, `resource=${resource}`);
7463
7383
  const [ok, err] = await try_fn_default(async () => {
7464
7384
  if (await this._fileExists(resourceDir)) {
7465
- await rmdir(resourceDir, { recursive: true });
7385
+ await promises.rm(resourceDir, { recursive: true });
7466
7386
  }
7467
7387
  });
7468
7388
  for (const [key] of this.partitionUsage.entries()) {
@@ -7594,11 +7514,11 @@ ${JSON.stringify(validation, null, 2)}`,
7594
7514
  return filename.replace(/[<>:"/\\|?*]/g, "_");
7595
7515
  }
7596
7516
  async _calculateDirectoryStats(dir, stats) {
7597
- const [ok, err, files] = await try_fn_default(() => readdir(dir));
7517
+ const [ok, err, files] = await try_fn_default(() => promises.readdir(dir));
7598
7518
  if (!ok) return;
7599
7519
  for (const file of files) {
7600
7520
  const filePath = path.join(dir, file);
7601
- const [statOk, statErr, fileStat] = await try_fn_default(() => stat(filePath));
7521
+ const [statOk, statErr, fileStat] = await try_fn_default(() => promises.stat(filePath));
7602
7522
  if (statOk) {
7603
7523
  if (fileStat.isDirectory()) {
7604
7524
  await this._calculateDirectoryStats(filePath, stats);
@@ -7611,7 +7531,7 @@ ${JSON.stringify(validation, null, 2)}`,
7611
7531
  }
7612
7532
  async loadUsageStats() {
7613
7533
  const [ok, err, content] = await try_fn_default(async () => {
7614
- const data = await readFile(this.usageStatsFile, "utf8");
7534
+ const data = await promises.readFile(this.usageStatsFile, "utf8");
7615
7535
  return JSON.parse(data);
7616
7536
  });
7617
7537
  if (ok && content) {
@@ -7621,7 +7541,7 @@ ${JSON.stringify(validation, null, 2)}`,
7621
7541
  async _saveUsageStats() {
7622
7542
  const statsObject = Object.fromEntries(this.partitionUsage);
7623
7543
  await try_fn_default(async () => {
7624
- await writeFile(
7544
+ await promises.writeFile(
7625
7545
  this.usageStatsFile,
7626
7546
  JSON.stringify(statsObject, null, 2),
7627
7547
  "utf8"
@@ -7631,7 +7551,7 @@ ${JSON.stringify(validation, null, 2)}`,
7631
7551
  async _writeFileWithMetadata(filePath, data) {
7632
7552
  const content = JSON.stringify(data);
7633
7553
  const [ok, err] = await try_fn_default(async () => {
7634
- await writeFile(filePath, content, {
7554
+ await promises.writeFile(filePath, content, {
7635
7555
  encoding: this.encoding,
7636
7556
  mode: this.fileMode
7637
7557
  });
@@ -7643,7 +7563,7 @@ ${JSON.stringify(validation, null, 2)}`,
7643
7563
  }
7644
7564
  async _readFileWithMetadata(filePath) {
7645
7565
  const [ok, err, content] = await try_fn_default(async () => {
7646
- return await readFile(filePath, this.encoding);
7566
+ return await promises.readFile(filePath, this.encoding);
7647
7567
  });
7648
7568
  if (!ok || !content) return null;
7649
7569
  try {
@@ -8420,7 +8340,7 @@ ${JSON.stringify(validation, null, 2)}`,
8420
8340
  }
8421
8341
  async setup(database) {
8422
8342
  this.database = database;
8423
- if (process.env.NODE_ENV === "test") return;
8343
+ if (typeof process !== "undefined" && process.env.NODE_ENV === "test") return;
8424
8344
  const [ok, err] = await try_fn_default(async () => {
8425
8345
  const [ok1, err1, metricsResource] = await try_fn_default(() => database.createResource({
8426
8346
  name: "metrics",
@@ -8470,7 +8390,7 @@ ${JSON.stringify(validation, null, 2)}`,
8470
8390
  this.performanceResource = database.resources.performance_logs;
8471
8391
  }
8472
8392
  this.installMetricsHooks();
8473
- if (process.env.NODE_ENV !== "test") {
8393
+ if (typeof process !== "undefined" && process.env.NODE_ENV !== "test") {
8474
8394
  this.startFlushTimer();
8475
8395
  }
8476
8396
  }
@@ -8481,7 +8401,7 @@ ${JSON.stringify(validation, null, 2)}`,
8481
8401
  clearInterval(this.flushTimer);
8482
8402
  this.flushTimer = null;
8483
8403
  }
8484
- if (process.env.NODE_ENV !== "test") {
8404
+ if (typeof process !== "undefined" && process.env.NODE_ENV !== "test") {
8485
8405
  await this.flushMetrics();
8486
8406
  }
8487
8407
  }
@@ -8660,10 +8580,18 @@ ${JSON.stringify(validation, null, 2)}`,
8660
8580
  async flushMetrics() {
8661
8581
  if (!this.metricsResource) return;
8662
8582
  const [ok, err] = await try_fn_default(async () => {
8663
- const metadata = process.env.NODE_ENV === "test" ? {} : { global: "true" };
8664
- const perfMetadata = process.env.NODE_ENV === "test" ? {} : { perf: "true" };
8665
- const errorMetadata = process.env.NODE_ENV === "test" ? {} : { error: "true" };
8666
- const resourceMetadata = process.env.NODE_ENV === "test" ? {} : { resource: "true" };
8583
+ let metadata, perfMetadata, errorMetadata, resourceMetadata;
8584
+ if (typeof process !== "undefined" && process.env.NODE_ENV === "test") {
8585
+ metadata = {};
8586
+ perfMetadata = {};
8587
+ errorMetadata = {};
8588
+ resourceMetadata = {};
8589
+ } else {
8590
+ metadata = { global: "true" };
8591
+ perfMetadata = { perf: "true" };
8592
+ errorMetadata = { error: "true" };
8593
+ resourceMetadata = { resource: "true" };
8594
+ }
8667
8595
  for (const [operation, data] of Object.entries(this.metrics.operations)) {
8668
8596
  if (data.count > 0) {
8669
8597
  await this.metricsResource.insert({
@@ -13196,7 +13124,7 @@ ${JSON.stringify(validation, null, 2)}`,
13196
13124
  super();
13197
13125
  this.version = "1";
13198
13126
  this.s3dbVersion = (() => {
13199
- const [ok, err, version] = try_fn_default(() => true ? "7.3.3" : "latest");
13127
+ const [ok, err, version] = try_fn_default(() => true ? "7.3.4" : "latest");
13200
13128
  return ok ? version : "latest";
13201
13129
  })();
13202
13130
  this.resources = {};
@@ -13239,14 +13167,16 @@ ${JSON.stringify(validation, null, 2)}`,
13239
13167
  this.keyPrefix = this.client.keyPrefix;
13240
13168
  if (!this._exitListenerRegistered) {
13241
13169
  this._exitListenerRegistered = true;
13242
- process.on("exit", async () => {
13243
- if (this.isConnected()) {
13244
- try {
13245
- await this.disconnect();
13246
- } catch (err) {
13170
+ if (typeof process !== "undefined") {
13171
+ process.on("exit", async () => {
13172
+ if (this.isConnected()) {
13173
+ try {
13174
+ await this.disconnect();
13175
+ } catch (err) {
13176
+ }
13247
13177
  }
13248
- }
13249
- });
13178
+ });
13179
+ }
13250
13180
  }
13251
13181
  }
13252
13182
  async connect() {
@@ -13829,7 +13759,7 @@ ${JSON.stringify(validation, null, 2)}`,
13829
13759
  if (typeof entry[0] === "function") return resource;
13830
13760
  }
13831
13761
  if (typeof entry === "string") return entry;
13832
- if (resource && !targetResourceName) targetResourceName = resource;
13762
+ if (typeof entry === "function") return resource;
13833
13763
  if (typeof entry === "object" && entry.resource) return entry.resource;
13834
13764
  return resource;
13835
13765
  }
@@ -14378,31 +14308,11 @@ ${JSON.stringify(validation, null, 2)}`,
14378
14308
  }
14379
14309
  async stop() {
14380
14310
  }
14381
- filterInternalFields(data) {
14382
- if (!data || typeof data !== "object") return data;
14383
- const filtered = {};
14384
- for (const [key, value] of Object.entries(data)) {
14385
- if (!key.startsWith("_") && !key.startsWith("$")) {
14386
- filtered[key] = value;
14387
- }
14388
- }
14389
- return filtered;
14390
- }
14391
14311
  async uploadMetadataFile(database) {
14392
14312
  if (typeof database.uploadMetadataFile === "function") {
14393
14313
  await database.uploadMetadataFile();
14394
14314
  }
14395
14315
  }
14396
- async getCompleteData(resource, data) {
14397
- try {
14398
- const [ok, err, record] = await try_fn_default(() => resource.get(data.id));
14399
- if (ok && record) {
14400
- return record;
14401
- }
14402
- } catch (error) {
14403
- }
14404
- return data;
14405
- }
14406
14316
  async retryWithBackoff(operation, maxRetries = 3) {
14407
14317
  let lastError;
14408
14318
  for (let attempt = 1; attempt <= maxRetries; attempt++) {
@@ -14746,4 +14656,4 @@ ${JSON.stringify(validation, null, 2)}`,
14746
14656
 
14747
14657
  return exports;
14748
14658
 
14749
- })({}, nanoid, zlib, PromisePool, streams, _, crypto, stringify, AWS, flat, FastestValidator);
14659
+ })({}, nanoid, zlib, PromisePool, streams, promises, crypto, _, stringify, AWS, flat, FastestValidator);