seedcord 0.1.0-alpha.2 → 0.1.1

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,12 +137,26 @@ 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() {
146
144
  return this._component;
147
145
  }
146
+ /**
147
+ * Builds a customId string for interactive components
148
+ *
149
+ * Creates customIds in the format "prefix:arg1-arg2-arg3" for buttons, modals, etc.
150
+ * Arguments are joined with hyphens and separated from prefix with a colon.
151
+ *
152
+ * @param prefix - The route prefix that handlers will match against
153
+ * @param args - Additional arguments to encode in the customId
154
+ * @returns Formatted customId string
155
+ */
156
+ buildCustomId(prefix, ...args) {
157
+ if (args.length === 0) return prefix;
158
+ return `${prefix}:${args.join("-")}`;
159
+ }
148
160
  };
149
161
  var BuilderComponent = class extends BaseComponent {
150
162
  static {
@@ -161,20 +173,6 @@ var BuilderComponent = class extends BaseComponent {
161
173
  get component() {
162
174
  return this.instance;
163
175
  }
164
- /**
165
- * Builds a customId string for interactive components
166
- *
167
- * Creates customIds in the format "prefix:arg1-arg2-arg3" for buttons, modals, etc.
168
- * Arguments are joined with hyphens and separated from prefix with a colon.
169
- *
170
- * @param prefix - The route prefix that handlers will match against
171
- * @param args - Additional arguments to encode in the customId
172
- * @returns Formatted customId string
173
- */
174
- buildCustomId(prefix, ...args) {
175
- if (args.length === 0) return prefix;
176
- return `${prefix}:${args.join("-")}`;
177
- }
178
176
  };
179
177
  var RowComponent = class extends BaseComponent {
180
178
  static {
@@ -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.");
@@ -1625,13 +1626,17 @@ var CoordinatedShutdown = class extends CoordinatedLifecycle {
1625
1626
  async executeTasksInPhase(phase, tasks) {
1626
1627
  const results = [];
1627
1628
  for (const task of tasks) {
1628
- results.push(await Promise.resolve().then(() => this.runTaskWithTimeout(phase, task)).then(() => ({
1629
- status: "fulfilled",
1630
- value: void 0
1631
- }), (reason) => ({
1632
- status: "rejected",
1633
- reason
1634
- })));
1629
+ results.push(await Promise.resolve().then(() => this.runTaskWithTimeout(phase, task)).then(
1630
+ () => ({
1631
+ status: "fulfilled",
1632
+ value: void 0
1633
+ }),
1634
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
1635
+ (reason) => ({
1636
+ status: "rejected",
1637
+ reason
1638
+ })
1639
+ ));
1635
1640
  }
1636
1641
  return results;
1637
1642
  }
@@ -1773,7 +1778,6 @@ var Bot = class extends Plugin {
1773
1778
  }
1774
1779
  /**
1775
1780
  * Logs the bot into Discord using the configured token
1776
- * @private
1777
1781
  */
1778
1782
  async login() {
1779
1783
  await this._client.login(Globals.botToken);
@@ -1782,7 +1786,6 @@ var Bot = class extends Plugin {
1782
1786
  }
1783
1787
  /**
1784
1788
  * Logs out and destroys the Discord client connection
1785
- * @private
1786
1789
  */
1787
1790
  async logout() {
1788
1791
  await this._client.destroy();
@@ -1904,7 +1907,7 @@ var EffectsEmitter = class {
1904
1907
  /**
1905
1908
  * Registers a listener for the specified side effect.
1906
1909
  *
1907
- * @template KeyOfEffects - The side effect name type
1910
+ * @typeParam KeyOfEffects - The side effect name type
1908
1911
  * @param event - The side effect name to listen for
1909
1912
  * @param listener - Function to call when the event is emitted
1910
1913
  * @returns This EffectsEmitter instance for chaining
@@ -1916,7 +1919,7 @@ var EffectsEmitter = class {
1916
1919
  /**
1917
1920
  * Registers a one-time listener for the specified side effect.
1918
1921
  *
1919
- * @template KeyOfEffects - The side effect name type
1922
+ * @typeParam KeyOfEffects - The side effect name type
1920
1923
  * @param event - The side effect name to listen for once
1921
1924
  * @param listener - Function to call when the event is emitted
1922
1925
  * @returns This EffectsEmitter instance for chaining
@@ -1928,7 +1931,7 @@ var EffectsEmitter = class {
1928
1931
  /**
1929
1932
  * Emits a side effect with the provided data.
1930
1933
  *
1931
- * @template KeyOfEffects - The side effect name type
1934
+ * @typeParam KeyOfEffects - The side effect name type
1932
1935
  * @param event - The side effect name to emit
1933
1936
  * @param data - The data to pass to registered listeners
1934
1937
  * @returns True if the event had listeners, false otherwise
@@ -2126,13 +2129,17 @@ var CoordinatedStartup = class extends CoordinatedLifecycle {
2126
2129
  async executeTasksInPhase(phase, tasks) {
2127
2130
  const results = [];
2128
2131
  for (const task of tasks) {
2129
- results.push(await Promise.resolve().then(() => this.runTaskWithTimeout(phase, task)).then(() => ({
2130
- status: "fulfilled",
2131
- value: void 0
2132
- }), (reason) => ({
2133
- status: "rejected",
2134
- reason
2135
- })));
2132
+ results.push(await Promise.resolve().then(() => this.runTaskWithTimeout(phase, task)).then(
2133
+ () => ({
2134
+ status: "fulfilled",
2135
+ value: void 0
2136
+ }),
2137
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
2138
+ (reason) => ({
2139
+ status: "rejected",
2140
+ reason
2141
+ })
2142
+ ));
2136
2143
  }
2137
2144
  return results;
2138
2145
  }
@@ -2377,137 +2384,10 @@ var CooldownManager = class {
2377
2384
  this.map.delete(key);
2378
2385
  }
2379
2386
  };
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
2387
 
2507
2388
  exports.AutocompleteHandler = AutocompleteHandler;
2508
2389
  exports.AutocompleteRoute = AutocompleteRoute;
2509
2390
  exports.BaseErrorEmbed = BaseErrorEmbed;
2510
- exports.BaseService = BaseService;
2511
2391
  exports.Bot = Bot;
2512
2392
  exports.BuilderComponent = BuilderComponent;
2513
2393
  exports.ButtonRoute = ButtonRoute;
@@ -2519,9 +2399,7 @@ exports.CooldownManager = CooldownManager;
2519
2399
  exports.CoordinatedShutdown = CoordinatedShutdown;
2520
2400
  exports.CoordinatedStartup = CoordinatedStartup;
2521
2401
  exports.CustomError = CustomError;
2522
- exports.DBCatchable = DBCatchable;
2523
- exports.DatabaseModel = DatabaseModel;
2524
- exports.DatabaseService = DatabaseService;
2402
+ exports.DatabaseError = DatabaseError;
2525
2403
  exports.EffectMetadataKey = EffectMetadataKey;
2526
2404
  exports.EffectsEmitter = EffectsEmitter;
2527
2405
  exports.EffectsHandler = EffectsHandler;
@@ -2538,8 +2416,6 @@ exports.InteractionRoutes = InteractionRoutes;
2538
2416
  exports.Logger = Logger;
2539
2417
  exports.ModalComponent = ModalComponent;
2540
2418
  exports.ModalRoute = ModalRoute;
2541
- exports.ModelMetadataKey = ModelMetadataKey;
2542
- exports.Mongo = Mongo;
2543
2419
  exports.Pluggable = Pluggable;
2544
2420
  exports.Plugin = Plugin;
2545
2421
  exports.RegisterCommand = RegisterCommand;
@@ -2549,7 +2425,6 @@ exports.RowComponent = RowComponent;
2549
2425
  exports.Seedcord = Seedcord;
2550
2426
  exports.SelectMenuRoute = SelectMenuRoute;
2551
2427
  exports.SelectMenuType = SelectMenuType;
2552
- exports.ServiceMetadataKey = ServiceMetadataKey;
2553
2428
  exports.ShutdownPhase = ShutdownPhase;
2554
2429
  exports.SlashRoute = SlashRoute;
2555
2430
  exports.StartupPhase = StartupPhase;