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/dist/s3db.cjs.js +12 -3
- package/dist/s3db.cjs.min.js +1 -1
- package/dist/s3db.es.js +12 -3
- package/dist/s3db.es.min.js +1 -1
- package/dist/s3db.iife.js +12 -3
- package/dist/s3db.iife.min.js +1 -1
- package/package.json +1 -1
- package/src/database.class.js +16 -4
package/package.json
CHANGED
package/src/database.class.js
CHANGED
|
@@ -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 =
|
|
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
|
-
|
|
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 =
|
|
427
|
+
const pluginName = this._getPluginName(plugin, name);
|
|
416
428
|
|
|
417
429
|
// Register the plugin
|
|
418
430
|
this.plugins[pluginName] = plugin;
|