s3db.js 8.1.1 → 8.1.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "s3db.js",
3
- "version": "8.1.1",
3
+ "version": "8.1.3",
4
4
  "description": "Use AWS S3, the world's most reliable document storage, as a database with this ORM.",
5
5
  "main": "dist/s3db.cjs.js",
6
6
  "module": "dist/s3db.es.js",
@@ -28,7 +28,7 @@ export class Database extends EventEmitter {
28
28
  this.options = options;
29
29
  this.verbose = options.verbose || false;
30
30
  this.parallelism = parseInt(options.parallelism + "") || 10;
31
- this.plugins = options.plugins || []; // Initialize plugins array
31
+ this.plugins = {}; // Initialize plugins registry
32
32
  this.pluginList = options.plugins || []; // Keep the list for backward compatibility
33
33
  this.cache = options.cache;
34
34
  this.passphrase = options.passphrase || "secret";
@@ -390,9 +390,13 @@ export class Database extends EventEmitter {
390
390
 
391
391
  const setupProms = plugins.map(async (plugin) => {
392
392
  if (plugin.beforeSetup) await plugin.beforeSetup()
393
- await plugin.setup(db)
393
+ await plugin.setup(db)
394
394
  if (plugin.afterSetup) await plugin.afterSetup()
395
- });
395
+
396
+ // Register the plugin using the same naming convention as usePlugin()
397
+ const pluginName = this._getPluginName(plugin);
398
+ this.plugins[pluginName] = plugin;
399
+ });
396
400
 
397
401
  await Promise.all(setupProms);
398
402
 
@@ -411,8 +415,16 @@ export class Database extends EventEmitter {
411
415
  * @param {Plugin} plugin - Plugin instance to register
412
416
  * @param {string} [name] - Optional name for the plugin (defaults to plugin.constructor.name)
413
417
  */
418
+ /**
419
+ * Get the normalized plugin name
420
+ * @private
421
+ */
422
+ _getPluginName(plugin, customName = null) {
423
+ return customName || plugin.constructor.name.replace('Plugin', '').toLowerCase();
424
+ }
425
+
414
426
  async usePlugin(plugin, name = null) {
415
- const pluginName = name || plugin.constructor.name.replace('Plugin', '').toLowerCase();
427
+ const pluginName = this._getPluginName(plugin, name);
416
428
 
417
429
  // Register the plugin
418
430
  this.plugins[pluginName] = plugin;