@seedcord/plugins 0.2.1 → 0.3.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.
Files changed (2) hide show
  1. package/package.json +15 -18
  2. package/dist/index.d.mts +0 -179
package/package.json CHANGED
@@ -1,23 +1,20 @@
1
1
  {
2
2
  "name": "@seedcord/plugins",
3
3
  "type": "module",
4
- "version": "0.2.1",
4
+ "version": "0.3.0",
5
5
  "description": "Official plugins for Seedcord Discord bot framework",
6
6
  "repository": {
7
7
  "type": "git",
8
8
  "url": "https://github.com/materwelondhruv/seedcord.git",
9
9
  "directory": "packages/plugins"
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": [
@@ -30,20 +27,20 @@
30
27
  "typescript": "5.9.2"
31
28
  },
32
29
  "dependencies": {
33
- "chalk": "5.6.0",
34
- "mongoose": "8.18.0",
35
- "envapt": "3.0.0",
30
+ "chalk": "5.6.2",
31
+ "mongoose": "8.18.3",
32
+ "envapt": "3.0.2",
36
33
  "reflect-metadata": "0.2.2",
37
- "@seedcord/types": "^0.1.3",
38
- "seedcord": "^0.2.1"
34
+ "@seedcord/types": "^0.2.0",
35
+ "seedcord": "^0.4.0"
39
36
  },
40
37
  "devDependencies": {
41
- "@seedcord/tsconfig": "^1.0.2",
42
- "@seedcord/eslint-config": "^1.1.1",
43
- "@seedcord/tsup-config": "^1.0.2"
38
+ "@seedcord/tsconfig": "^1.0.3",
39
+ "@seedcord/tsup-config": "^1.0.3",
40
+ "@seedcord/eslint-config": "^1.2.0"
44
41
  },
45
42
  "scripts": {
46
- "build": "tsup && cp dist/index.d.cts dist/index.d.mts",
43
+ "build": "tsup",
47
44
  "clean": "rm -rf dist",
48
45
  "lint": "eslint 'src/**/*.{ts,tsx}' --cache",
49
46
  "lint:fix": "eslint 'src/**/*.{ts,tsx}' --fix --cache",
package/dist/index.d.mts DELETED
@@ -1,179 +0,0 @@
1
- import { Plugin, Core, Logger } from 'seedcord';
2
- import { TypedConstructor, ConstructorFunction } from '@seedcord/types';
3
- import mongoose from 'mongoose';
4
-
5
- /**
6
- * Registry of available database services.
7
- *
8
- * This interface can be augmented via declaration merging to add
9
- * type-safe service definitions when using the \@DatabaseService and \@DatabaseModel decorator.
10
- *
11
- * @example
12
- * ```typescript
13
- * declare module 'seedcord' {
14
- * interface Services {
15
- * 'user': UserService;
16
- * 'guild': GuildService;
17
- * }
18
- * }
19
- * ```
20
- */
21
- interface Services {
22
- }
23
- /**
24
- * Helper type to extract service keys from the Services interface.
25
- */
26
- type ServiceKeys = keyof Services;
27
-
28
- /**
29
- * Basic document interface with MongoDB ObjectId field.
30
- *
31
- * Represents the minimal structure of a MongoDB document
32
- * with the required `_id` field.
33
- */
34
- interface IDocument {
35
- /** MongoDB document identifier */
36
- _id: string;
37
- }
38
- /**
39
- * Helper type to extract the type of a document that extends IDocument.
40
- *
41
- * @typeParam Doc - The document type extending IDocument
42
- */
43
- type TypeOfIDocument<Doc extends IDocument = IDocument> = Doc;
44
-
45
- /**
46
- * Configuration options for MongoDB connection and service loading.
47
- */
48
- interface MongoOptions {
49
- /** Directory path containing database service classes */
50
- dir: string;
51
- /** MongoDB connection URI */
52
- uri: string;
53
- /** Database name to use */
54
- name: string;
55
- }
56
- /**
57
- * MongoDB integration plugin for Seedcord.
58
- *
59
- * Manages MongoDB connections, service loading, and provides type-safe
60
- * access to database services through service registration decorators.
61
- */
62
- declare class Mongo extends Plugin {
63
- readonly core: Core;
64
- private readonly options;
65
- readonly logger: Logger;
66
- private isInitialised;
67
- private readonly uri;
68
- /**
69
- * Map of all loaded services.
70
- * Keys come from `@DatabaseService('key')`
71
- */
72
- readonly services: Services;
73
- constructor(core: Core, options: MongoOptions);
74
- init(): Promise<void>;
75
- stop(): Promise<void>;
76
- private connect;
77
- private disconnect;
78
- private loadServices;
79
- private isServiceClass;
80
- _register<SKey extends keyof Services>(key: SKey, instance: Services[SKey]): void;
81
- }
82
-
83
- /**
84
- * Base class for MongoDB service layers
85
- *
86
- * Provides typed access to MongoDB collections through Mongoose models.
87
- * Services are automatically registered with the Mongo plugin when instantiated.
88
- *
89
- * @typeParam Doc - The document type this service manages
90
- * @example
91
- * ```typescript
92
- * \@DatabaseService('users')
93
- * export class Users extends BaseService<IUser> {
94
- * \@DatabaseModel('users')
95
- * public static schema = new mongoose.Schema<IUser>({
96
- * username: { type: String, required: true, unique: true }
97
- * });
98
- *
99
- * // Custom methods here
100
- * public async findByUsername(username: string) {
101
- * return this.model.findOne({ username });
102
- * }
103
- * }
104
- * ```
105
- */
106
- declare abstract class BaseService<Doc extends IDocument = IDocument> {
107
- protected readonly db: Mongo;
108
- protected readonly core: Core;
109
- readonly model: mongoose.Model<Doc>;
110
- constructor(db: Mongo, core: Core);
111
- }
112
- /** Constructor type for BaseService classes */
113
- type BaseServiceConstructor = TypedConstructor<typeof BaseService>;
114
-
115
- /**
116
- * Catches and wraps database operation errors.
117
- *
118
- * Automatically wraps non-CustomError exceptions in DatabaseError instances
119
- * with UUID tracking. Should be applied to database service methods.
120
- *
121
- * @param errorMessage - Message to include when wrapping errors
122
- * @decorator
123
- * @example
124
- * ```typescript
125
- * class UserService extends BaseService {
126
- * \@DBCatchable('Failed to find user')
127
- * async findById(id: string) {
128
- * return this.model.findById(id);
129
- * }
130
- * }
131
- * ```
132
- */
133
- declare function DBCatchable<TypeReturn>(errorMessage: string): (_target: unknown, _propertyKey: string, descriptor: TypedPropertyDescriptor<(...args: any[]) => Promise<TypeReturn>>) => void;
134
-
135
- declare const ModelMetadataKey: unique symbol;
136
- /**
137
- * Associates a Mongoose model with a database service
138
- *
139
- * Creates a Mongoose model from the decorated static schema property and stores it
140
- * for service registration. The model becomes available as `this.model` in the service.
141
- * Must be applied to a `public static schema` property in the service class.
142
- *
143
- * @param collection - Collection name for the Mongoose model
144
- * @decorator
145
- * @example
146
- * ```typescript
147
- * \@DatabaseService('users')
148
- * export class Users extends BaseService<IUser> {
149
- * \@DatabaseModel('users')
150
- * public static schema = new mongoose.Schema<IUser>({
151
- * username: { type: String, required: true, unique: true }
152
- * });
153
- * }
154
- * ```
155
- */
156
- declare function DatabaseModel<TService extends ServiceKeys>(collection: TService): <SchemaObj extends Record<KeyOfSchema, mongoose.Schema>, KeyOfSchema extends keyof SchemaObj & (string | symbol)>(target: SchemaObj, propertyKey: KeyOfSchema) => void;
157
-
158
- declare const ServiceMetadataKey: unique symbol;
159
- /**
160
- * Registers a database service with a typed key
161
- *
162
- * Associates a service class with a key for dependency injection.
163
- * The service becomes available via `core.db.services[key]`.
164
- *
165
- * @param key - Service key for registration and type-safe access
166
- * @decorator
167
- * @example
168
- * ```typescript
169
- * \@DatabaseService('users')
170
- * export class Users<Doc extends IUser = IUser> extends BaseService<Doc> {
171
- * // Some code
172
- * }
173
- * ```
174
- */
175
- declare function DatabaseService<TService extends ServiceKeys>(key: TService): <DatabaseCtor extends ConstructorFunction & {
176
- prototype: BaseService;
177
- }>(ctor: DatabaseCtor) => void;
178
-
179
- export { BaseService, type BaseServiceConstructor, DBCatchable, DatabaseModel, DatabaseService, type IDocument, ModelMetadataKey, Mongo, type ServiceKeys, ServiceMetadataKey, type Services, type TypeOfIDocument };