s3db.js 8.0.1 → 8.0.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.es.js CHANGED
@@ -6623,8 +6623,8 @@ class MemoryCache extends Cache {
6623
6623
  super(config);
6624
6624
  this.cache = {};
6625
6625
  this.meta = {};
6626
- this.maxSize = config.maxSize || 0;
6627
- this.ttl = config.ttl || 0;
6626
+ this.maxSize = config.maxSize !== void 0 ? config.maxSize : 1e3;
6627
+ this.ttl = config.ttl !== void 0 ? config.ttl : 3e5;
6628
6628
  }
6629
6629
  async _set(key, data) {
6630
6630
  if (this.maxSize > 0 && Object.keys(this.cache).length >= this.maxSize) {
@@ -7482,37 +7482,81 @@ class PartitionAwareFilesystemCache extends FilesystemCache {
7482
7482
  class CachePlugin extends plugin_class_default {
7483
7483
  constructor(options = {}) {
7484
7484
  super(options);
7485
- this.driver = options.driver;
7486
- this.config = {
7487
- includePartitions: options.includePartitions !== false,
7488
- partitionStrategy: options.partitionStrategy || "hierarchical",
7489
- partitionAware: options.partitionAware !== false,
7490
- trackUsage: options.trackUsage !== false,
7491
- preloadRelated: options.preloadRelated !== false,
7492
- ...options
7485
+ this.driverName = options.driver || "s3";
7486
+ this.ttl = options.ttl;
7487
+ this.maxSize = options.maxSize;
7488
+ this.config = options.config || {};
7489
+ this.includePartitions = options.includePartitions !== false;
7490
+ this.partitionStrategy = options.partitionStrategy || "hierarchical";
7491
+ this.partitionAware = options.partitionAware !== false;
7492
+ this.trackUsage = options.trackUsage !== false;
7493
+ this.preloadRelated = options.preloadRelated !== false;
7494
+ this.legacyConfig = {
7495
+ memoryOptions: options.memoryOptions,
7496
+ filesystemOptions: options.filesystemOptions,
7497
+ s3Options: options.s3Options,
7498
+ driver: options.driver
7493
7499
  };
7494
7500
  }
7495
7501
  async setup(database) {
7496
7502
  await super.setup(database);
7497
7503
  }
7498
7504
  async onSetup() {
7499
- if (this.config.driver && typeof this.config.driver === "object") {
7500
- this.driver = this.config.driver;
7501
- } else if (this.config.driver === "memory") {
7502
- this.driver = new memory_cache_class_default(this.config.memoryOptions || {});
7503
- } else if (this.config.driver === "filesystem") {
7504
- if (this.config.partitionAware) {
7505
+ if (this.driverName && typeof this.driverName === "object") {
7506
+ this.driver = this.driverName;
7507
+ } else if (this.driverName === "memory") {
7508
+ const driverConfig = {
7509
+ ...this.legacyConfig.memoryOptions,
7510
+ // Legacy support (lowest priority)
7511
+ ...this.config
7512
+ // New config format (medium priority)
7513
+ };
7514
+ if (this.ttl !== void 0) {
7515
+ driverConfig.ttl = this.ttl;
7516
+ }
7517
+ if (this.maxSize !== void 0) {
7518
+ driverConfig.maxSize = this.maxSize;
7519
+ }
7520
+ this.driver = new memory_cache_class_default(driverConfig);
7521
+ } else if (this.driverName === "filesystem") {
7522
+ const driverConfig = {
7523
+ ...this.legacyConfig.filesystemOptions,
7524
+ // Legacy support (lowest priority)
7525
+ ...this.config
7526
+ // New config format (medium priority)
7527
+ };
7528
+ if (this.ttl !== void 0) {
7529
+ driverConfig.ttl = this.ttl;
7530
+ }
7531
+ if (this.maxSize !== void 0) {
7532
+ driverConfig.maxSize = this.maxSize;
7533
+ }
7534
+ if (this.partitionAware) {
7505
7535
  this.driver = new PartitionAwareFilesystemCache({
7506
- partitionStrategy: this.config.partitionStrategy,
7507
- trackUsage: this.config.trackUsage,
7508
- preloadRelated: this.config.preloadRelated,
7509
- ...this.config.filesystemOptions
7536
+ partitionStrategy: this.partitionStrategy,
7537
+ trackUsage: this.trackUsage,
7538
+ preloadRelated: this.preloadRelated,
7539
+ ...driverConfig
7510
7540
  });
7511
7541
  } else {
7512
- this.driver = new FilesystemCache(this.config.filesystemOptions || {});
7542
+ this.driver = new FilesystemCache(driverConfig);
7513
7543
  }
7514
7544
  } else {
7515
- this.driver = new s3_cache_class_default({ client: this.database.client, ...this.config.s3Options || {} });
7545
+ const driverConfig = {
7546
+ client: this.database.client,
7547
+ // Required for S3Cache
7548
+ ...this.legacyConfig.s3Options,
7549
+ // Legacy support (lowest priority)
7550
+ ...this.config
7551
+ // New config format (medium priority)
7552
+ };
7553
+ if (this.ttl !== void 0) {
7554
+ driverConfig.ttl = this.ttl;
7555
+ }
7556
+ if (this.maxSize !== void 0) {
7557
+ driverConfig.maxSize = this.maxSize;
7558
+ }
7559
+ this.driver = new s3_cache_class_default(driverConfig);
7516
7560
  }
7517
7561
  this.installDatabaseHooks();
7518
7562
  this.installResourceHooks();
@@ -9617,7 +9661,7 @@ class Client extends EventEmitter {
9617
9661
  }) {
9618
9662
  super();
9619
9663
  this.verbose = verbose;
9620
- this.id = id ?? idGenerator();
9664
+ this.id = id ?? idGenerator(77);
9621
9665
  this.parallelism = parallelism;
9622
9666
  this.config = new ConnectionString(connectionString);
9623
9667
  this.httpClientOptions = {
@@ -11204,10 +11248,18 @@ class Resource extends EventEmitter {
11204
11248
  */
11205
11249
  constructor(config = {}) {
11206
11250
  super();
11207
- this._instanceId = Math.random().toString(36).slice(2, 8);
11251
+ this._instanceId = idGenerator(7);
11208
11252
  const validation = validateResourceConfig(config);
11209
11253
  if (!validation.isValid) {
11210
- throw new ResourceError(`Invalid Resource ${config.name} configuration`, { resourceName: config.name, validation: validation.errors, operation: "constructor", suggestion: "Check resource config and attributes." });
11254
+ const errorDetails = validation.errors.map((err) => ` \u2022 ${err}`).join("\n");
11255
+ throw new ResourceError(
11256
+ `Invalid Resource ${config.name || "[unnamed]"} configuration:
11257
+ ${errorDetails}`,
11258
+ {
11259
+ resourceName: config.name,
11260
+ validation: validation.errors
11261
+ }
11262
+ );
11211
11263
  }
11212
11264
  const {
11213
11265
  name,
@@ -13378,9 +13430,10 @@ var resource_class_default = Resource;
13378
13430
  class Database extends EventEmitter {
13379
13431
  constructor(options) {
13380
13432
  super();
13433
+ this.id = idGenerator(7);
13381
13434
  this.version = "1";
13382
13435
  this.s3dbVersion = (() => {
13383
- const [ok, err, version] = try_fn_default(() => true ? "8.0.0" : "latest");
13436
+ const [ok, err, version] = try_fn_default(() => true ? "8.0.2" : "latest");
13384
13437
  return ok ? version : "latest";
13385
13438
  })();
13386
13439
  this.resources = {};