seedcord 0.1.0-alpha.2 → 0.1.0

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/index.cjs CHANGED
@@ -10,7 +10,6 @@ var winston = require('winston');
10
10
  var crypto2 = require('crypto');
11
11
  var events = require('events');
12
12
  var http = require('http');
13
- var mongoose2 = require('mongoose');
14
13
 
15
14
  function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
16
15
 
@@ -35,7 +34,6 @@ function _interopNamespace(e) {
35
34
  var chalk6__default = /*#__PURE__*/_interopDefault(chalk6);
36
35
  var path__namespace = /*#__PURE__*/_interopNamespace(path);
37
36
  var crypto2__namespace = /*#__PURE__*/_interopNamespace(crypto2);
38
- var mongoose2__default = /*#__PURE__*/_interopDefault(mongoose2);
39
37
 
40
38
  var __defProp = Object.defineProperty;
41
39
  var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
@@ -139,7 +137,7 @@ var BaseComponent = class BaseComponent2 {
139
137
  *
140
138
  * Use this to access Discord.js builder methods like setTitle(), setDescription(), etc.
141
139
  *
142
- * @protected Use this in your component classes to configure the builder
140
+ * Use this in your component classes to configure the builder
143
141
  * @example this.instance.setTitle('My Modal')
144
142
  */
145
143
  get instance() {
@@ -1440,15 +1438,18 @@ var Pluggable = class _Pluggable {
1440
1438
  *
1441
1439
  * Make sure to augment the {@link Core} interface with the plugin type to ensure TypeScript recognizes it and provides intellisense.
1442
1440
  *
1443
- * @template Key - The property name for accessing the plugin
1444
- * @template Ctor - The plugin constructor type
1441
+ * @typeParam Key - The property name for accessing the plugin
1442
+ * @typeParam Ctor - The plugin constructor type
1445
1443
  * @param key - Property name to access the plugin instance
1446
1444
  * @param Plugin - Plugin constructor class
1447
1445
  * @param startupPhase - When during startup to initialize this plugin ({@link StartupPhase})
1448
1446
  * @param args - Additional arguments to pass to the plugin constructor
1449
1447
  * @returns This instance with the plugin attached as a typed property
1450
1448
  * @throws An {@link Error} When called after initialization or if key already exists
1451
- * @example seedcord.attach('db', Mongo, StartupPhase.Configuration, { uri: 'mongodb://...' })
1449
+ * @example
1450
+ * ```typescript
1451
+ * seedcord.attach('db', Mongo, StartupPhase.Configuration, { uri: 'mongodb://...', dbName: 'seedcord' })
1452
+ * ```
1452
1453
  */
1453
1454
  attach(key, Plugin2, startupPhase, ...args) {
1454
1455
  if (this.isInitialized) throw new Error("Cannot attach a plugin after initialization.");
@@ -1773,7 +1774,6 @@ var Bot = class extends Plugin {
1773
1774
  }
1774
1775
  /**
1775
1776
  * Logs the bot into Discord using the configured token
1776
- * @private
1777
1777
  */
1778
1778
  async login() {
1779
1779
  await this._client.login(Globals.botToken);
@@ -1782,7 +1782,6 @@ var Bot = class extends Plugin {
1782
1782
  }
1783
1783
  /**
1784
1784
  * Logs out and destroys the Discord client connection
1785
- * @private
1786
1785
  */
1787
1786
  async logout() {
1788
1787
  await this._client.destroy();
@@ -1904,7 +1903,7 @@ var EffectsEmitter = class {
1904
1903
  /**
1905
1904
  * Registers a listener for the specified side effect.
1906
1905
  *
1907
- * @template KeyOfEffects - The side effect name type
1906
+ * @typeParam KeyOfEffects - The side effect name type
1908
1907
  * @param event - The side effect name to listen for
1909
1908
  * @param listener - Function to call when the event is emitted
1910
1909
  * @returns This EffectsEmitter instance for chaining
@@ -1916,7 +1915,7 @@ var EffectsEmitter = class {
1916
1915
  /**
1917
1916
  * Registers a one-time listener for the specified side effect.
1918
1917
  *
1919
- * @template KeyOfEffects - The side effect name type
1918
+ * @typeParam KeyOfEffects - The side effect name type
1920
1919
  * @param event - The side effect name to listen for once
1921
1920
  * @param listener - Function to call when the event is emitted
1922
1921
  * @returns This EffectsEmitter instance for chaining
@@ -1928,7 +1927,7 @@ var EffectsEmitter = class {
1928
1927
  /**
1929
1928
  * Emits a side effect with the provided data.
1930
1929
  *
1931
- * @template KeyOfEffects - The side effect name type
1930
+ * @typeParam KeyOfEffects - The side effect name type
1932
1931
  * @param event - The side effect name to emit
1933
1932
  * @param data - The data to pass to registered listeners
1934
1933
  * @returns True if the event had listeners, false otherwise
@@ -2377,137 +2376,10 @@ var CooldownManager = class {
2377
2376
  this.map.delete(key);
2378
2377
  }
2379
2378
  };
2380
- var ModelMetadataKey = Symbol("db:model");
2381
- function DatabaseModel(collection) {
2382
- return (target, propertyKey) => {
2383
- const schema = target[propertyKey];
2384
- const name = String(collection);
2385
- const model = mongoose2__default.default.model(name, schema);
2386
- Reflect.defineMetadata(ModelMetadataKey, model, target);
2387
- };
2388
- }
2389
- __name(DatabaseModel, "DatabaseModel");
2390
-
2391
- // src/mongo/decorators/DatabaseService.ts
2392
- var ServiceMetadataKey = Symbol("db:serviceKey");
2393
- function DatabaseService(key) {
2394
- return (ctor) => {
2395
- Reflect.defineMetadata(ServiceMetadataKey, key, ctor);
2396
- };
2397
- }
2398
- __name(DatabaseService, "DatabaseService");
2399
-
2400
- // src/mongo/BaseService.ts
2401
- var BaseService = class {
2402
- static {
2403
- __name(this, "BaseService");
2404
- }
2405
- db;
2406
- core;
2407
- model;
2408
- constructor(db, core) {
2409
- this.db = db;
2410
- this.core = core;
2411
- const ctor = this.constructor;
2412
- const key = Reflect.getMetadata(ServiceMetadataKey, ctor);
2413
- if (!key) throw new Error(`Missing @DatabaseService on ${ctor.name}`);
2414
- const model = Reflect.getMetadata(ModelMetadataKey, ctor);
2415
- if (!model) throw new Error(`Missing @DatabaseModel on ${ctor.name}`);
2416
- this.model = model;
2417
- db._register(key, this);
2418
- }
2419
- };
2420
-
2421
- // src/mongo/Mongo.ts
2422
- var Mongo = class extends Plugin {
2423
- static {
2424
- __name(this, "Mongo");
2425
- }
2426
- core;
2427
- options;
2428
- logger = new Logger("MongoDB");
2429
- isInitialised = false;
2430
- uri;
2431
- /**
2432
- * Map of all loaded services.
2433
- * Keys come from `@DatabaseService('key')`
2434
- */
2435
- services = {};
2436
- constructor(core, options) {
2437
- super(core), this.core = core, this.options = options;
2438
- this.uri = options.uri;
2439
- this.core.shutdown.addTask(ShutdownPhase.ExternalResources, "stop-database", async () => await this.stop());
2440
- }
2441
- async init() {
2442
- if (this.isInitialised) return;
2443
- this.isInitialised = true;
2444
- await this.connect();
2445
- await this.loadServices();
2446
- }
2447
- async stop() {
2448
- await this.disconnect();
2449
- }
2450
- async connect() {
2451
- await mongoose2__default.default.connect(this.uri, {
2452
- dbName: this.options.dbName,
2453
- ...Globals.isProduction && {
2454
- tls: true,
2455
- ssl: true
2456
- }
2457
- }).then((i) => this.logger.info(`Connected to MongoDB: ${chalk6__default.default.bold.magenta(i.connection.name)}`)).catch((err) => {
2458
- throw new Error(`Could not connect to MongoDB`, err);
2459
- });
2460
- }
2461
- async disconnect() {
2462
- await mongoose2__default.default.disconnect().then(() => this.logger.info(chalk6__default.default.red.bold("Disconnected from MongoDB"))).catch((err) => this.logger.error(`Could not disconnect from MongoDB: ${err.message}`));
2463
- }
2464
- async loadServices() {
2465
- const servicesDir = this.options.servicesDir;
2466
- this.logger.info(chalk6__default.default.bold(servicesDir));
2467
- await traverseDirectory(servicesDir, (_full, rel, mod) => {
2468
- for (const Service of Object.values(mod)) {
2469
- if (this.isServiceClass(Service)) {
2470
- const instance = new Service(this, this.core);
2471
- this.logger.info(`${chalk6__default.default.italic("Registered")} ${chalk6__default.default.bold.yellow(instance.constructor.name)} from ${chalk6__default.default.gray(rel)}`);
2472
- }
2473
- }
2474
- });
2475
- this.logger.info(`${chalk6__default.default.bold.green("Loaded")}: ${chalk6__default.default.magenta(Object.keys(this.services).length)} services`);
2476
- }
2477
- isServiceClass(obj) {
2478
- return typeof obj === "function" && obj.prototype instanceof BaseService && Reflect.hasMetadata(ServiceMetadataKey, obj);
2479
- }
2480
- _register(key, instance) {
2481
- this.services[key] = instance;
2482
- }
2483
- };
2484
-
2485
- // src/mongo/decorators/DBCatchable.ts
2486
- function DBCatchable(errorMessage) {
2487
- return function(_target, _propertyKey, descriptor) {
2488
- const originalMethod = descriptor.value;
2489
- descriptor.value = async function(...args) {
2490
- if (!originalMethod) {
2491
- throw new Error("Method not found");
2492
- }
2493
- try {
2494
- return await originalMethod.apply(this, args);
2495
- } catch (error) {
2496
- if (!(error instanceof CustomError)) {
2497
- throwCustomError(error, errorMessage, DatabaseError);
2498
- } else {
2499
- throw error;
2500
- }
2501
- }
2502
- };
2503
- };
2504
- }
2505
- __name(DBCatchable, "DBCatchable");
2506
2379
 
2507
2380
  exports.AutocompleteHandler = AutocompleteHandler;
2508
2381
  exports.AutocompleteRoute = AutocompleteRoute;
2509
2382
  exports.BaseErrorEmbed = BaseErrorEmbed;
2510
- exports.BaseService = BaseService;
2511
2383
  exports.Bot = Bot;
2512
2384
  exports.BuilderComponent = BuilderComponent;
2513
2385
  exports.ButtonRoute = ButtonRoute;
@@ -2519,9 +2391,7 @@ exports.CooldownManager = CooldownManager;
2519
2391
  exports.CoordinatedShutdown = CoordinatedShutdown;
2520
2392
  exports.CoordinatedStartup = CoordinatedStartup;
2521
2393
  exports.CustomError = CustomError;
2522
- exports.DBCatchable = DBCatchable;
2523
- exports.DatabaseModel = DatabaseModel;
2524
- exports.DatabaseService = DatabaseService;
2394
+ exports.DatabaseError = DatabaseError;
2525
2395
  exports.EffectMetadataKey = EffectMetadataKey;
2526
2396
  exports.EffectsEmitter = EffectsEmitter;
2527
2397
  exports.EffectsHandler = EffectsHandler;
@@ -2538,8 +2408,6 @@ exports.InteractionRoutes = InteractionRoutes;
2538
2408
  exports.Logger = Logger;
2539
2409
  exports.ModalComponent = ModalComponent;
2540
2410
  exports.ModalRoute = ModalRoute;
2541
- exports.ModelMetadataKey = ModelMetadataKey;
2542
- exports.Mongo = Mongo;
2543
2411
  exports.Pluggable = Pluggable;
2544
2412
  exports.Plugin = Plugin;
2545
2413
  exports.RegisterCommand = RegisterCommand;
@@ -2549,7 +2417,6 @@ exports.RowComponent = RowComponent;
2549
2417
  exports.Seedcord = Seedcord;
2550
2418
  exports.SelectMenuRoute = SelectMenuRoute;
2551
2419
  exports.SelectMenuType = SelectMenuType;
2552
- exports.ServiceMetadataKey = ServiceMetadataKey;
2553
2420
  exports.ShutdownPhase = ShutdownPhase;
2554
2421
  exports.SlashRoute = SlashRoute;
2555
2422
  exports.StartupPhase = StartupPhase;