@seedcord/services 0.1.1 → 0.2.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.
Files changed (2) hide show
  1. package/package.json +14 -17
  2. package/dist/index.d.mts +0 -406
package/package.json CHANGED
@@ -1,23 +1,20 @@
1
1
  {
2
2
  "name": "@seedcord/services",
3
3
  "type": "module",
4
- "version": "0.1.1",
4
+ "version": "0.2.1",
5
5
  "description": "Services for Seedcord packages",
6
6
  "repository": {
7
7
  "type": "git",
8
8
  "url": "https://github.com/materwelondhruv/seedcord.git",
9
9
  "directory": "packages/services"
10
10
  },
11
+ "types": "./dist/index.d.ts",
11
12
  "exports": {
12
13
  ".": {
13
- "import": {
14
- "types": "./dist/index.d.mts",
15
- "default": "./dist/index.mjs"
16
- },
17
- "require": {
18
- "types": "./dist/index.d.cts",
19
- "default": "./dist/index.cjs"
20
- }
14
+ "types": "./dist/index.d.ts",
15
+ "import": "./dist/index.mjs",
16
+ "require": "./dist/index.cjs",
17
+ "default": "./dist/index.mjs"
21
18
  }
22
19
  },
23
20
  "files": [
@@ -27,22 +24,22 @@
27
24
  "LICENSE"
28
25
  ],
29
26
  "peerDependencies": {
30
- "typescript": "5.9.2"
27
+ "typescript": "5.9.3"
31
28
  },
32
29
  "dependencies": {
33
- "discord.js": "14.22.1",
34
30
  "chalk": "5.6.2",
31
+ "discord.js": "14.22.1",
35
32
  "envapt": "3.0.2",
36
- "winston": "^3.17.0",
37
- "@seedcord/types": "^0.1.4"
33
+ "winston": "^3.18.3",
34
+ "@seedcord/types": "^0.2.1"
38
35
  },
39
36
  "devDependencies": {
40
- "@seedcord/eslint-config": "^1.1.2",
41
- "@seedcord/tsup-config": "^1.0.3",
42
- "@seedcord/tsconfig": "^1.0.3"
37
+ "@seedcord/tsconfig": "^1.0.4",
38
+ "@seedcord/eslint-config": "^1.2.1",
39
+ "@seedcord/tsup-config": "^1.0.4"
43
40
  },
44
41
  "scripts": {
45
- "build": "tsup && cp dist/index.d.cts dist/index.d.mts",
42
+ "build": "tsup",
46
43
  "clean": "rm -rf dist",
47
44
  "lint": "eslint 'src/**/*.{ts,tsx}' --cache",
48
45
  "lint:fix": "eslint 'src/**/*.{ts,tsx}' --fix --cache",
package/dist/index.d.mts DELETED
@@ -1,406 +0,0 @@
1
- import { EventEmitter } from 'node:events';
2
- import { LifecycleTask, PhaseEvents, UnionToTuple } from '@seedcord/types';
3
-
4
- /**
5
- * Logging service with console and file output support
6
- *
7
- * Provides structured logging with timestamps, levels, and labels.
8
- * Instances are cached by transport name for consistent formatting.
9
- */
10
- declare class Logger {
11
- private logger;
12
- private static readonly instances;
13
- private static instance;
14
- constructor(transportName: string);
15
- private getFormatCustomizations;
16
- private createConsoleTransport;
17
- private initializeLogger;
18
- /**
19
- * Logs an error message with optional additional data.
20
- *
21
- * @param msg - The error message to log
22
- * @param args - Additional data to include in the log entry
23
- */
24
- error(msg: string, ...args: unknown[]): void;
25
- /**
26
- * Logs a warning message with optional additional data.
27
- *
28
- * @param msg - The warning message to log
29
- * @param args - Additional data to include in the log entry
30
- */
31
- warn(msg: string, ...args: unknown[]): void;
32
- /**
33
- * Logs an informational message with optional additional data.
34
- *
35
- * @param msg - The informational message to log
36
- * @param args - Additional data to include in the log entry
37
- */
38
- info(msg: string, ...args: unknown[]): void;
39
- /**
40
- * Logs an HTTP-related message with optional additional data.
41
- *
42
- * @param msg - The HTTP message to log
43
- * @param args - Additional data to include in the log entry
44
- */
45
- http(msg: string, ...args: unknown[]): void;
46
- /**
47
- * Logs a verbose message with optional additional data.
48
- *
49
- * @param msg - The verbose message to log
50
- * @param args - Additional data to include in the log entry
51
- */
52
- verbose(msg: string, ...args: unknown[]): void;
53
- /**
54
- * Logs a debug message with optional additional data.
55
- *
56
- * @param msg - The debug message to log
57
- * @param args - Additional data to include in the log entry
58
- */
59
- debug(msg: string, ...args: unknown[]): void;
60
- /**
61
- * Logs a silly/trace level message with optional additional data.
62
- *
63
- * @param msg - The silly message to log
64
- * @param args - Additional data to include in the log entry
65
- */
66
- silly(msg: string, ...args: unknown[]): void;
67
- /**
68
- * Static method to log an error message with a specific prefix.
69
- * Creates or retrieves a logger instance for the given prefix.
70
- *
71
- * @param prefix - The logger prefix/label to use
72
- * @param msg - The error message to log
73
- * @param args - Additional data to include in the log entry
74
- */
75
- static Error(prefix: string, msg: string, ...args: unknown[]): void;
76
- /**
77
- * Static method to log an informational message with a specific prefix.
78
- * Creates or retrieves a logger instance for the given prefix.
79
- *
80
- * @param prefix - The logger prefix/label to use
81
- * @param msg - The informational message to log
82
- * @param args - Additional data to include in the log entry
83
- */
84
- static Info(prefix: string, msg: string, ...args: unknown[]): void;
85
- /**
86
- * Static method to log a warning message with a specific prefix.
87
- * Creates or retrieves a logger instance for the given prefix.
88
- *
89
- * @param prefix - The logger prefix/label to use
90
- * @param msg - The warning message to log
91
- * @param args - Additional data to include in the log entry
92
- */
93
- static Warn(prefix: string, msg: string, ...args: unknown[]): void;
94
- /**
95
- * Static method to log a debug message with a specific prefix.
96
- * Creates or retrieves a logger instance for the given prefix.
97
- *
98
- * @param prefix - The logger prefix/label to use
99
- * @param msg - The debug message to log
100
- * @param args - Additional data to include in the log entry
101
- */
102
- static Debug(prefix: string, msg: string, ...args: unknown[]): void;
103
- /**
104
- * Static method to log a silly/trace level message with a specific prefix.
105
- * Creates or retrieves a logger instance for the given prefix.
106
- *
107
- * @param prefix - The logger prefix/label to use
108
- * @param msg - The silly message to log
109
- * @param args - Additional data to include in the log entry
110
- */
111
- static Silly(prefix: string, msg: string, ...args: unknown[]): void;
112
- }
113
-
114
- /**
115
- * Abstract base class for coordinated lifecycle management (startup/shutdown)
116
- */
117
- declare abstract class CoordinatedLifecycle<TPhase extends number> {
118
- protected readonly phaseOrder: TPhase[];
119
- protected readonly phaseEnum: Record<number, string>;
120
- protected readonly logger: Logger;
121
- protected readonly events: EventEmitter<[never]>;
122
- protected readonly tasksMap: Map<TPhase, LifecycleTask[]>;
123
- protected constructor(loggerName: string, phaseOrder: TPhase[], phaseEnum: Record<number, string>);
124
- /**
125
- * Adds a lifecycle task to a specific phase.
126
- *
127
- * Tasks are executed in phase order during lifecycle operations.
128
- * Each task has a timeout to prevent hanging operations.
129
- *
130
- * @param phase - The lifecycle phase to add the task to
131
- * @param taskName - Unique name for the task (used for logging and removal)
132
- * @param task - Async function to execute during the phase
133
- * @param timeoutMs - Maximum time allowed for task execution in milliseconds
134
- * @example
135
- * ```typescript
136
- * lifecycle.addTask(StartupPhase.Services, 'start-database', async () => {
137
- * await database.connect();
138
- * }, 10000);
139
- * ```
140
- */
141
- addTask(phase: TPhase, taskName: string, task: () => Promise<void>, timeoutMs: number): void;
142
- /**
143
- * Removes a lifecycle task from a specific phase.
144
- *
145
- * @param phase - The lifecycle phase to remove the task from
146
- * @param taskName - Name of the task to remove
147
- * @returns True if the task was found and removed, false otherwise
148
- */
149
- removeTask(phase: TPhase, taskName: string): boolean;
150
- /**
151
- * Run all tasks in a specific phase
152
- */
153
- protected runPhase(phase: TPhase): Promise<void>;
154
- /**
155
- * Run a single task with timeout
156
- */
157
- protected runTaskWithTimeout(phase: TPhase, task: LifecycleTask): Promise<void>;
158
- /**
159
- * Subscribe to lifecycle events
160
- */
161
- on(event: string, listener: (...args: unknown[]) => void): void;
162
- /**
163
- * Unsubscribe from lifecycle events
164
- */
165
- off(event: string, listener: (...args: unknown[]) => void): void;
166
- protected emit(event: string, ...args: unknown[]): boolean;
167
- protected abstract canAddTask(): boolean;
168
- protected abstract canRemoveTask(): boolean;
169
- protected abstract getTaskType(): string;
170
- protected abstract executeTasksInPhase(phase: TPhase, tasks: LifecycleTask[]): Promise<PromiseSettledResult<void>[]>;
171
- }
172
-
173
- /**
174
- * Shutdown phases for coordinated application shutdown.
175
- */
176
- declare enum ShutdownPhase {
177
- /** Stop accepting new requests/interactions */
178
- StopAcceptingRequests = 1,
179
- /** Stop background services (health checks, etc.) */
180
- StopServices = 2,
181
- /** Disconnect from external resources (database, APIs) */
182
- ExternalResources = 3,
183
- /** Disconnect from Discord */
184
- DiscordCleanup = 4,
185
- /** Final cleanup tasks */
186
- FinalCleanup = 5
187
- }
188
- type CoordinatedShutdownEventKey = PhaseEvents<'shutdown', UnionToTuple<ShutdownPhase>>;
189
- declare class CoordinatedShutdown extends CoordinatedLifecycle<ShutdownPhase> {
190
- private readonly isShutdownEnabled;
191
- private isShuttingDown;
192
- private exitCode;
193
- constructor();
194
- protected canAddTask(): boolean;
195
- protected canRemoveTask(): boolean;
196
- protected getTaskType(): string;
197
- protected executeTasksInPhase(phase: ShutdownPhase, tasks: LifecycleTask[]): Promise<PromiseSettledResult<void>[]>;
198
- private registerSignalHandlers;
199
- /**
200
- * Adds a task to a specific shutdown phase with timeout.
201
- *
202
- * @param phase - The shutdown phase from {@link ShutdownPhase}
203
- * @param taskName - Unique identifier for the task
204
- * @param task - Async function to execute
205
- * @param timeoutMs - Task timeout in milliseconds (default: 5000)
206
- */
207
- addTask(phase: ShutdownPhase, taskName: string, task: () => Promise<void>, timeoutMs?: number): void;
208
- /**
209
- * Removes a task from a specific shutdown phase.
210
- *
211
- * @param phase - The shutdown phase to remove from
212
- * @param taskName - Name of the task to remove
213
- * @returns True if task was found and removed
214
- */
215
- removeTask(phase: ShutdownPhase, taskName: string): boolean;
216
- /**
217
- * Executes the coordinated shutdown sequence.
218
- *
219
- * Runs all registered tasks across shutdown phases in reverse order.
220
- * Tasks within each phase are executed in parallel for faster shutdown.
221
- * Process exits with the specified code when complete.
222
- *
223
- * @param exitCode - Process exit code (default: 0)
224
- * @returns Promise that resolves when shutdown is complete
225
- * @example
226
- * ```typescript
227
- * shutdown.addTask(ShutdownPhase.Services, 'database', () => db.disconnect(), 5000);
228
- * await shutdown.run(0); // Graceful shutdown
229
- * ```
230
- */
231
- run(exitCode?: number): Promise<void>;
232
- /**
233
- * Subscribe to shutdown events
234
- */
235
- on(event: CoordinatedShutdownEventKey, listener: (...args: unknown[]) => void): void;
236
- /**
237
- * Unsubscribe from shutdown events
238
- */
239
- off(event: CoordinatedShutdownEventKey, listener: (...args: unknown[]) => void): void;
240
- }
241
-
242
- /**
243
- * HTTP health check service for monitoring bot status.
244
- *
245
- * Provides a simple HTTP endpoint that responds with JSON status
246
- * information, useful for container orchestration and monitoring.
247
- */
248
- declare class HealthCheck {
249
- readonly logger: Logger;
250
- readonly port: number;
251
- readonly path: string;
252
- private server?;
253
- constructor(shutdown: CoordinatedShutdown);
254
- /**
255
- * Starts the health check server.
256
- * @returns Promise that resolves when the server is listening
257
- */
258
- init(): Promise<void>;
259
- /**
260
- * Stops the health check server.
261
- *
262
- * @returns Promise that resolves when the server is closed
263
- */
264
- stop(): Promise<void>;
265
- }
266
-
267
- /**
268
- * Configuration options for CooldownManager.
269
- */
270
- interface CooldownOptions {
271
- /** Cooldown window in milliseconds (default 1000) */
272
- cooldown?: number;
273
- /** Custom error class to throw when a key is still cooling down */
274
- err?: new (msg: string, ...args: any[]) => Error;
275
- /** Message passed to the error constructor (default "Cooldown active") */
276
- message?: string;
277
- }
278
- /**
279
- * Lightweight utility for per-key cooldowns.
280
- *
281
- * Manages time-based restrictions on operations by key,
282
- * useful for rate limiting, command cooldowns, and spam prevention.
283
- */
284
- declare class CooldownManager {
285
- private readonly window;
286
- private readonly Err;
287
- private readonly msg;
288
- private readonly map;
289
- /**
290
- * Creates a new CooldownManager instance.
291
- *
292
- * @param opts - Configuration options for the cooldown behavior
293
- */
294
- constructor(opts?: CooldownOptions);
295
- /**
296
- * Records usage timestamp for a key without any cooldown checks.
297
- *
298
- * @param key - The unique identifier for the cooldown entry
299
- */
300
- set(key: string): void;
301
- /**
302
- * Verifies cooldown status for a key and updates timestamp if not active.
303
- *
304
- * If the cooldown is still active, throws the configured error.
305
- * If not active, updates the timestamp and returns successfully.
306
- *
307
- * @param key - The unique identifier to check cooldown for
308
- * @throws An {@link Err} When the cooldown is still active for the given key
309
- */
310
- check(key: string): void;
311
- /**
312
- * Checks if a key is currently cooling down without updating timestamp.
313
- *
314
- * @param key - The unique identifier to check
315
- * @returns True if the key is still cooling down, false otherwise
316
- */
317
- isActive(key: string): boolean;
318
- /**
319
- * Removes a key from the cooldown map.
320
- *
321
- * @param key - The unique identifier to remove (useful for manual resets)
322
- */
323
- clear(key: string): void;
324
- }
325
-
326
- /**
327
- * Startup phases for coordinated initialization
328
- *
329
- * Defines the order in which different components are initialized during bot startup.
330
- */
331
- declare enum StartupPhase {
332
- /** Validate environment variables and config files */
333
- Validation = 1,
334
- /** Discover plugin constructors via decorators or registry */
335
- Discovery = 2,
336
- /** Register plugin metadata and declared dependencies */
337
- Registration = 3,
338
- /** Inject and validate plugin-specific configuration */
339
- Configuration = 4,
340
- /** Instantiate plugin classes with Core and arguments */
341
- Instantiation = 5,
342
- /** Activate plugins by calling their init/setup effects */
343
- Activation = 6,
344
- /** Mark seedcord as ready and start handling interactions */
345
- Ready = 7
346
- }
347
- type CoordinatedStartupEventKey = PhaseEvents<'startup', UnionToTuple<StartupPhase>>;
348
- /**
349
- * Manages bot startup lifecycle with ordered phases
350
- *
351
- * Coordinates initialization of all bot components in a predictable sequence.
352
- * Tasks are executed within their designated phases to ensure proper dependency order.
353
- */
354
- declare class CoordinatedStartup extends CoordinatedLifecycle<StartupPhase> {
355
- private isStartingUp;
356
- private hasStarted;
357
- constructor();
358
- /**
359
- * Adds a task to a specific startup phase with timeout.
360
- *
361
- * @param phase - The startup phase from {@link StartupPhase}
362
- * @param taskName - Unique identifier for the task
363
- * @param task - Async function to execute
364
- * @param timeoutMs - Task timeout in milliseconds (default: 10000)
365
- */
366
- addTask(phase: StartupPhase, taskName: string, task: () => Promise<void>, timeoutMs?: number): void;
367
- protected canAddTask(): boolean;
368
- protected canRemoveTask(): boolean;
369
- protected getTaskType(): string;
370
- protected executeTasksInPhase(phase: StartupPhase, tasks: LifecycleTask[]): Promise<PromiseSettledResult<void>[]>;
371
- /**
372
- * Executes the coordinated startup sequence.
373
- *
374
- * Runs all registered tasks across startup phases in the correct order.
375
- * Each phase completes before the next phase begins. Tasks within a phase
376
- * are executed sequentially to maintain predictable initialization.
377
- *
378
- * @returns Promise that resolves when startup is complete
379
- * @throws An {@link Error} If startup fails or is called multiple times
380
- * @example
381
- * ```typescript
382
- * const startup = new CoordinatedStartup();
383
- * startup.addTask(StartupPhase.Services, 'database', () => db.connect(), 10000);
384
- * await startup.run();
385
- * ```
386
- */
387
- run(): Promise<void>;
388
- /**
389
- * Subscribe to startup events
390
- */
391
- on(event: CoordinatedStartupEventKey, listener: (...args: unknown[]) => void): void;
392
- /**
393
- * Unsubscribe from startup events
394
- */
395
- off(event: CoordinatedStartupEventKey, listener: (...args: unknown[]) => void): void;
396
- /**
397
- * Check if startup has completed
398
- */
399
- get isReady(): boolean;
400
- /**
401
- * Check if startup is currently running
402
- */
403
- get isRunning(): boolean;
404
- }
405
-
406
- export { CooldownManager, type CooldownOptions, CoordinatedLifecycle, CoordinatedShutdown, CoordinatedStartup, HealthCheck, Logger, ShutdownPhase, StartupPhase };