@ciscode/database-kit 1.0.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/CHANGELOG.md +206 -0
- package/LICENSE +21 -0
- package/README.md +446 -0
- package/dist/adapters/mongo.adapter.d.ts +44 -0
- package/dist/adapters/mongo.adapter.d.ts.map +1 -0
- package/dist/adapters/mongo.adapter.js +146 -0
- package/dist/adapters/mongo.adapter.js.map +1 -0
- package/dist/adapters/postgres.adapter.d.ts +49 -0
- package/dist/adapters/postgres.adapter.d.ts.map +1 -0
- package/dist/adapters/postgres.adapter.js +229 -0
- package/dist/adapters/postgres.adapter.js.map +1 -0
- package/dist/config/database.config.d.ts +55 -0
- package/dist/config/database.config.d.ts.map +1 -0
- package/dist/config/database.config.js +122 -0
- package/dist/config/database.config.js.map +1 -0
- package/dist/config/database.constants.d.ts +41 -0
- package/dist/config/database.constants.d.ts.map +1 -0
- package/dist/config/database.constants.js +45 -0
- package/dist/config/database.constants.js.map +1 -0
- package/dist/contracts/database.contracts.d.ts +191 -0
- package/dist/contracts/database.contracts.d.ts.map +1 -0
- package/dist/contracts/database.contracts.js +21 -0
- package/dist/contracts/database.contracts.js.map +1 -0
- package/dist/database-kit.module.d.ts +71 -0
- package/dist/database-kit.module.d.ts.map +1 -0
- package/dist/database-kit.module.js +158 -0
- package/dist/database-kit.module.js.map +1 -0
- package/dist/filters/database-exception.filter.d.ts +51 -0
- package/dist/filters/database-exception.filter.d.ts.map +1 -0
- package/dist/filters/database-exception.filter.js +236 -0
- package/dist/filters/database-exception.filter.js.map +1 -0
- package/dist/index.d.ts +19 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +78 -0
- package/dist/index.js.map +1 -0
- package/dist/middleware/database.decorators.d.ts +31 -0
- package/dist/middleware/database.decorators.d.ts.map +1 -0
- package/dist/middleware/database.decorators.js +39 -0
- package/dist/middleware/database.decorators.js.map +1 -0
- package/dist/services/database.service.d.ts +99 -0
- package/dist/services/database.service.d.ts.map +1 -0
- package/dist/services/database.service.js +205 -0
- package/dist/services/database.service.js.map +1 -0
- package/dist/services/logger.service.d.ts +63 -0
- package/dist/services/logger.service.d.ts.map +1 -0
- package/dist/services/logger.service.js +93 -0
- package/dist/services/logger.service.js.map +1 -0
- package/dist/utils/pagination.utils.d.ts +57 -0
- package/dist/utils/pagination.utils.d.ts.map +1 -0
- package/dist/utils/pagination.utils.js +113 -0
- package/dist/utils/pagination.utils.js.map +1 -0
- package/dist/utils/validation.utils.d.ts +60 -0
- package/dist/utils/validation.utils.d.ts.map +1 -0
- package/dist/utils/validation.utils.js +117 -0
- package/dist/utils/validation.utils.js.map +1 -0
- package/package.json +83 -0
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Injection token for the main DatabaseService instance.
|
|
3
|
+
* Use with @Inject(DATABASE_TOKEN) or @InjectDatabase() decorator.
|
|
4
|
+
*/
|
|
5
|
+
export declare const DATABASE_TOKEN = "DATABASE_KIT_DEFAULT";
|
|
6
|
+
/**
|
|
7
|
+
* Injection token for DatabaseKit module options.
|
|
8
|
+
* Used internally for async configuration.
|
|
9
|
+
*/
|
|
10
|
+
export declare const DATABASE_OPTIONS_TOKEN = "DATABASE_KIT_OPTIONS";
|
|
11
|
+
/**
|
|
12
|
+
* Environment variable names used by DatabaseKit.
|
|
13
|
+
*/
|
|
14
|
+
export declare const ENV_KEYS: {
|
|
15
|
+
/** MongoDB connection string */
|
|
16
|
+
readonly MONGO_URI: "MONGO_URI";
|
|
17
|
+
/** PostgreSQL connection string */
|
|
18
|
+
readonly POSTGRES_URI: "DATABASE_URL";
|
|
19
|
+
/** Database type ('mongo' or 'postgres') */
|
|
20
|
+
readonly DATABASE_TYPE: "DATABASE_TYPE";
|
|
21
|
+
/** Connection pool size */
|
|
22
|
+
readonly POOL_SIZE: "DATABASE_POOL_SIZE";
|
|
23
|
+
/** Connection timeout in milliseconds */
|
|
24
|
+
readonly CONNECTION_TIMEOUT: "DATABASE_CONNECTION_TIMEOUT";
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* Default configuration values.
|
|
28
|
+
*/
|
|
29
|
+
export declare const DEFAULTS: {
|
|
30
|
+
/** Default page size for pagination */
|
|
31
|
+
readonly PAGE_SIZE: 10;
|
|
32
|
+
/** Maximum allowed page size */
|
|
33
|
+
readonly MAX_PAGE_SIZE: 100;
|
|
34
|
+
/** Default connection pool size */
|
|
35
|
+
readonly POOL_SIZE: 10;
|
|
36
|
+
/** Default connection timeout in milliseconds */
|
|
37
|
+
readonly CONNECTION_TIMEOUT: 5000;
|
|
38
|
+
/** Default server selection timeout for MongoDB */
|
|
39
|
+
readonly SERVER_SELECTION_TIMEOUT: 5000;
|
|
40
|
+
};
|
|
41
|
+
//# sourceMappingURL=database.constants.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"database.constants.d.ts","sourceRoot":"","sources":["../../src/config/database.constants.ts"],"names":[],"mappings":"AAEA;;;GAGG;AACH,eAAO,MAAM,cAAc,yBAAyB,CAAC;AAErD;;;GAGG;AACH,eAAO,MAAM,sBAAsB,yBAAyB,CAAC;AAE7D;;GAEG;AACH,eAAO,MAAM,QAAQ;IACnB,gCAAgC;;IAEhC,mCAAmC;;IAEnC,4CAA4C;;IAE5C,2BAA2B;;IAE3B,yCAAyC;;CAEjC,CAAC;AAEX;;GAEG;AACH,eAAO,MAAM,QAAQ;IACnB,uCAAuC;;IAEvC,gCAAgC;;IAEhC,mCAAmC;;IAEnC,iDAAiD;;IAEjD,mDAAmD;;CAE3C,CAAC"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// src/config/database.constants.ts
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.DEFAULTS = exports.ENV_KEYS = exports.DATABASE_OPTIONS_TOKEN = exports.DATABASE_TOKEN = void 0;
|
|
5
|
+
/**
|
|
6
|
+
* Injection token for the main DatabaseService instance.
|
|
7
|
+
* Use with @Inject(DATABASE_TOKEN) or @InjectDatabase() decorator.
|
|
8
|
+
*/
|
|
9
|
+
exports.DATABASE_TOKEN = 'DATABASE_KIT_DEFAULT';
|
|
10
|
+
/**
|
|
11
|
+
* Injection token for DatabaseKit module options.
|
|
12
|
+
* Used internally for async configuration.
|
|
13
|
+
*/
|
|
14
|
+
exports.DATABASE_OPTIONS_TOKEN = 'DATABASE_KIT_OPTIONS';
|
|
15
|
+
/**
|
|
16
|
+
* Environment variable names used by DatabaseKit.
|
|
17
|
+
*/
|
|
18
|
+
exports.ENV_KEYS = {
|
|
19
|
+
/** MongoDB connection string */
|
|
20
|
+
MONGO_URI: 'MONGO_URI',
|
|
21
|
+
/** PostgreSQL connection string */
|
|
22
|
+
POSTGRES_URI: 'DATABASE_URL',
|
|
23
|
+
/** Database type ('mongo' or 'postgres') */
|
|
24
|
+
DATABASE_TYPE: 'DATABASE_TYPE',
|
|
25
|
+
/** Connection pool size */
|
|
26
|
+
POOL_SIZE: 'DATABASE_POOL_SIZE',
|
|
27
|
+
/** Connection timeout in milliseconds */
|
|
28
|
+
CONNECTION_TIMEOUT: 'DATABASE_CONNECTION_TIMEOUT',
|
|
29
|
+
};
|
|
30
|
+
/**
|
|
31
|
+
* Default configuration values.
|
|
32
|
+
*/
|
|
33
|
+
exports.DEFAULTS = {
|
|
34
|
+
/** Default page size for pagination */
|
|
35
|
+
PAGE_SIZE: 10,
|
|
36
|
+
/** Maximum allowed page size */
|
|
37
|
+
MAX_PAGE_SIZE: 100,
|
|
38
|
+
/** Default connection pool size */
|
|
39
|
+
POOL_SIZE: 10,
|
|
40
|
+
/** Default connection timeout in milliseconds */
|
|
41
|
+
CONNECTION_TIMEOUT: 5000,
|
|
42
|
+
/** Default server selection timeout for MongoDB */
|
|
43
|
+
SERVER_SELECTION_TIMEOUT: 5000,
|
|
44
|
+
};
|
|
45
|
+
//# sourceMappingURL=database.constants.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"database.constants.js","sourceRoot":"","sources":["../../src/config/database.constants.ts"],"names":[],"mappings":";AAAA,mCAAmC;;;AAEnC;;;GAGG;AACU,QAAA,cAAc,GAAG,sBAAsB,CAAC;AAErD;;;GAGG;AACU,QAAA,sBAAsB,GAAG,sBAAsB,CAAC;AAE7D;;GAEG;AACU,QAAA,QAAQ,GAAG;IACtB,gCAAgC;IAChC,SAAS,EAAE,WAAW;IACtB,mCAAmC;IACnC,YAAY,EAAE,cAAc;IAC5B,4CAA4C;IAC5C,aAAa,EAAE,eAAe;IAC9B,2BAA2B;IAC3B,SAAS,EAAE,oBAAoB;IAC/B,yCAAyC;IACzC,kBAAkB,EAAE,6BAA6B;CACzC,CAAC;AAEX;;GAEG;AACU,QAAA,QAAQ,GAAG;IACtB,uCAAuC;IACvC,SAAS,EAAE,EAAE;IACb,gCAAgC;IAChC,aAAa,EAAE,GAAG;IAClB,mCAAmC;IACnC,SAAS,EAAE,EAAE;IACb,iDAAiD;IACjD,kBAAkB,EAAE,IAAI;IACxB,mDAAmD;IACnD,wBAAwB,EAAE,IAAI;CACtB,CAAC"}
|
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Database configuration types and interfaces for DatabaseKit.
|
|
3
|
+
* These contracts define the public API surface for the package.
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Supported database types.
|
|
7
|
+
*/
|
|
8
|
+
export type DatabaseType = 'mongo' | 'postgres';
|
|
9
|
+
/**
|
|
10
|
+
* Base configuration for all database types.
|
|
11
|
+
*/
|
|
12
|
+
export interface DatabaseConfigBase {
|
|
13
|
+
/** Which adapter to use */
|
|
14
|
+
type: DatabaseType;
|
|
15
|
+
/** Connection string for the database */
|
|
16
|
+
connectionString: string;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* MongoDB-specific configuration.
|
|
20
|
+
*/
|
|
21
|
+
export interface MongoDatabaseConfig extends DatabaseConfigBase {
|
|
22
|
+
type: 'mongo';
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* PostgreSQL-specific configuration.
|
|
26
|
+
*/
|
|
27
|
+
export interface PostgresDatabaseConfig extends DatabaseConfigBase {
|
|
28
|
+
type: 'postgres';
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Discriminated union for database configuration.
|
|
32
|
+
* TypeScript will narrow the type based on the `type` property.
|
|
33
|
+
*/
|
|
34
|
+
export type DatabaseConfig = MongoDatabaseConfig | PostgresDatabaseConfig;
|
|
35
|
+
/**
|
|
36
|
+
* Result of a paginated query.
|
|
37
|
+
*/
|
|
38
|
+
export interface PageResult<T> {
|
|
39
|
+
/** Array of entities for the current page */
|
|
40
|
+
data: T[];
|
|
41
|
+
/** Current page number (1-indexed) */
|
|
42
|
+
page: number;
|
|
43
|
+
/** Number of items per page */
|
|
44
|
+
limit: number;
|
|
45
|
+
/** Total number of items matching the filter */
|
|
46
|
+
total: number;
|
|
47
|
+
/** Total number of pages */
|
|
48
|
+
pages: number;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Options for paginated queries.
|
|
52
|
+
*/
|
|
53
|
+
export interface PageOptions<Filter = Record<string, unknown>> {
|
|
54
|
+
/** Filter criteria */
|
|
55
|
+
filter?: Filter;
|
|
56
|
+
/** Page number (1-indexed, default: 1) */
|
|
57
|
+
page?: number;
|
|
58
|
+
/** Items per page (default: 10) */
|
|
59
|
+
limit?: number;
|
|
60
|
+
/** Sort order (string or object) */
|
|
61
|
+
sort?: string | Record<string, 1 | -1 | 'asc' | 'desc'>;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Generic repository interface for CRUD operations.
|
|
65
|
+
* Implemented by both MongoDB and PostgreSQL adapters.
|
|
66
|
+
*
|
|
67
|
+
* @typeParam T - The entity type
|
|
68
|
+
* @typeParam Filter - The filter type (defaults to Record<string, unknown>)
|
|
69
|
+
*/
|
|
70
|
+
export interface Repository<T = unknown, Filter = Record<string, unknown>> {
|
|
71
|
+
/**
|
|
72
|
+
* Creates a new entity.
|
|
73
|
+
* @param data - Partial entity data
|
|
74
|
+
* @returns The created entity
|
|
75
|
+
*/
|
|
76
|
+
create(data: Partial<T>): Promise<T>;
|
|
77
|
+
/**
|
|
78
|
+
* Finds an entity by its ID.
|
|
79
|
+
* @param id - The entity ID
|
|
80
|
+
* @returns The entity or null if not found
|
|
81
|
+
*/
|
|
82
|
+
findById(id: string | number): Promise<T | null>;
|
|
83
|
+
/**
|
|
84
|
+
* Finds all entities matching the filter.
|
|
85
|
+
* @param filter - Optional filter criteria
|
|
86
|
+
* @returns Array of matching entities
|
|
87
|
+
*/
|
|
88
|
+
findAll(filter?: Filter): Promise<T[]>;
|
|
89
|
+
/**
|
|
90
|
+
* Finds entities with pagination support.
|
|
91
|
+
* @param options - Pagination options
|
|
92
|
+
* @returns Paginated result
|
|
93
|
+
*/
|
|
94
|
+
findPage(options?: PageOptions<Filter>): Promise<PageResult<T>>;
|
|
95
|
+
/**
|
|
96
|
+
* Updates an entity by its ID.
|
|
97
|
+
* @param id - The entity ID
|
|
98
|
+
* @param update - Partial update data
|
|
99
|
+
* @returns The updated entity or null if not found
|
|
100
|
+
*/
|
|
101
|
+
updateById(id: string | number, update: Partial<T>): Promise<T | null>;
|
|
102
|
+
/**
|
|
103
|
+
* Deletes an entity by its ID.
|
|
104
|
+
* @param id - The entity ID
|
|
105
|
+
* @returns True if deleted, false if not found
|
|
106
|
+
*/
|
|
107
|
+
deleteById(id: string | number): Promise<boolean>;
|
|
108
|
+
/**
|
|
109
|
+
* Counts entities matching the filter.
|
|
110
|
+
* @param filter - Optional filter criteria
|
|
111
|
+
* @returns Number of matching entities
|
|
112
|
+
*/
|
|
113
|
+
count(filter?: Filter): Promise<number>;
|
|
114
|
+
/**
|
|
115
|
+
* Checks if any entity matches the filter.
|
|
116
|
+
* @param filter - Optional filter criteria
|
|
117
|
+
* @returns True if at least one entity matches
|
|
118
|
+
*/
|
|
119
|
+
exists(filter?: Filter): Promise<boolean>;
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Options for creating a MongoDB repository.
|
|
123
|
+
*/
|
|
124
|
+
export interface MongoRepositoryOptions {
|
|
125
|
+
/** Mongoose Model instance */
|
|
126
|
+
model: unknown;
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Options for creating a PostgreSQL repository.
|
|
130
|
+
*/
|
|
131
|
+
export interface PostgresEntityConfig {
|
|
132
|
+
/** Table name in PostgreSQL */
|
|
133
|
+
table: string;
|
|
134
|
+
/** Primary key column (default: "id") */
|
|
135
|
+
primaryKey?: string;
|
|
136
|
+
/**
|
|
137
|
+
* Whitelist of allowed columns for select/filter/sort.
|
|
138
|
+
* If empty, all columns are allowed (not recommended for public APIs).
|
|
139
|
+
*/
|
|
140
|
+
columns?: string[];
|
|
141
|
+
/**
|
|
142
|
+
* Base filter automatically applied on every query.
|
|
143
|
+
* Useful for soft-delete patterns (e.g., { is_deleted: false }).
|
|
144
|
+
*/
|
|
145
|
+
defaultFilter?: Record<string, unknown>;
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* Configuration options for DatabaseKitModule.forRoot().
|
|
149
|
+
*/
|
|
150
|
+
export interface DatabaseKitModuleOptions {
|
|
151
|
+
/** Database configuration */
|
|
152
|
+
config: DatabaseConfig;
|
|
153
|
+
/** Whether to auto-connect on module initialization (default: true) */
|
|
154
|
+
autoConnect?: boolean;
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* Type for NestJS injection tokens (compatible with @nestjs/common InjectionToken).
|
|
158
|
+
*/
|
|
159
|
+
export type InjectionToken = string | symbol | Function;
|
|
160
|
+
/**
|
|
161
|
+
* Optional factory dependency for async module configuration.
|
|
162
|
+
*/
|
|
163
|
+
export interface OptionalFactoryDependency {
|
|
164
|
+
token: InjectionToken;
|
|
165
|
+
optional?: boolean;
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* Async configuration options for DatabaseKitModule.forRootAsync().
|
|
169
|
+
*/
|
|
170
|
+
export interface DatabaseKitModuleAsyncOptions {
|
|
171
|
+
/** Modules to import for dependency injection */
|
|
172
|
+
imports?: unknown[];
|
|
173
|
+
/** Factory function that returns the configuration */
|
|
174
|
+
useFactory: (...args: unknown[]) => Promise<DatabaseKitModuleOptions> | DatabaseKitModuleOptions;
|
|
175
|
+
/** Dependencies to inject into the factory function */
|
|
176
|
+
inject?: Array<InjectionToken | OptionalFactoryDependency>;
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* Default values and constants for DatabaseKit.
|
|
180
|
+
*/
|
|
181
|
+
export declare const DATABASE_KIT_CONSTANTS: {
|
|
182
|
+
/** Default page size for pagination */
|
|
183
|
+
readonly DEFAULT_PAGE_SIZE: 10;
|
|
184
|
+
/** Default maximum page size */
|
|
185
|
+
readonly MAX_PAGE_SIZE: 100;
|
|
186
|
+
/** Default connection pool size */
|
|
187
|
+
readonly DEFAULT_POOL_SIZE: 10;
|
|
188
|
+
/** Default connection timeout in milliseconds */
|
|
189
|
+
readonly DEFAULT_CONNECTION_TIMEOUT: 5000;
|
|
190
|
+
};
|
|
191
|
+
//# sourceMappingURL=database.contracts.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"database.contracts.d.ts","sourceRoot":"","sources":["../../src/contracts/database.contracts.ts"],"names":[],"mappings":"AAEA;;;GAGG;AAMH;;GAEG;AACH,MAAM,MAAM,YAAY,GAAG,OAAO,GAAG,UAAU,CAAC;AAEhD;;GAEG;AACH,MAAM,WAAW,kBAAkB;IAC/B,2BAA2B;IAC3B,IAAI,EAAE,YAAY,CAAC;IACnB,yCAAyC;IACzC,gBAAgB,EAAE,MAAM,CAAC;CAC5B;AAED;;GAEG;AACH,MAAM,WAAW,mBAAoB,SAAQ,kBAAkB;IAC3D,IAAI,EAAE,OAAO,CAAC;CACjB;AAED;;GAEG;AACH,MAAM,WAAW,sBAAuB,SAAQ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CAAC,EAAE,OAAO,CAAC;CACtB;AAED;;GAEG;AACH,MAAM,WAAW,6BAA6B;IAC1C,iDAAiD;IACjD,OAAO,CAAC,EAAE,OAAO,EAAE,CAAC;IACpB,sDAAsD;IACtD,UAAU,EAAE,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,OAAO,CAAC,wBAAwB,CAAC,GAAG,wBAAwB,CAAC;IACjG,uDAAuD;IACvD,MAAM,CAAC,EAAE,KAAK,CAAC,cAAc,GAAG,yBAAyB,CAAC,CAAC;CAC9D;AAMD;;GAEG;AACH,eAAO,MAAM,sBAAsB;IAC/B,uCAAuC;;IAEvC,gCAAgC;;IAEhC,mCAAmC;;IAEnC,iDAAiD;;CAE3C,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// src/contracts/database.contracts.ts
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.DATABASE_KIT_CONSTANTS = void 0;
|
|
5
|
+
// -----------------------------
|
|
6
|
+
// Constants
|
|
7
|
+
// -----------------------------
|
|
8
|
+
/**
|
|
9
|
+
* Default values and constants for DatabaseKit.
|
|
10
|
+
*/
|
|
11
|
+
exports.DATABASE_KIT_CONSTANTS = {
|
|
12
|
+
/** Default page size for pagination */
|
|
13
|
+
DEFAULT_PAGE_SIZE: 10,
|
|
14
|
+
/** Default maximum page size */
|
|
15
|
+
MAX_PAGE_SIZE: 100,
|
|
16
|
+
/** Default connection pool size */
|
|
17
|
+
DEFAULT_POOL_SIZE: 10,
|
|
18
|
+
/** Default connection timeout in milliseconds */
|
|
19
|
+
DEFAULT_CONNECTION_TIMEOUT: 5000,
|
|
20
|
+
};
|
|
21
|
+
//# sourceMappingURL=database.contracts.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"database.contracts.js","sourceRoot":"","sources":["../../src/contracts/database.contracts.ts"],"names":[],"mappings":";AAAA,sCAAsC;;;AA8NtC,gCAAgC;AAChC,YAAY;AACZ,gCAAgC;AAEhC;;GAEG;AACU,QAAA,sBAAsB,GAAG;IAClC,uCAAuC;IACvC,iBAAiB,EAAE,EAAE;IACrB,gCAAgC;IAChC,aAAa,EAAE,GAAG;IAClB,mCAAmC;IACnC,iBAAiB,EAAE,EAAE;IACrB,iDAAiD;IACjD,0BAA0B,EAAE,IAAI;CAC1B,CAAC"}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { DynamicModule } from '@nestjs/common';
|
|
2
|
+
import { DatabaseConfig, DatabaseKitModuleOptions, DatabaseKitModuleAsyncOptions } from './contracts/database.contracts';
|
|
3
|
+
/**
|
|
4
|
+
* DatabaseKitModule - Main NestJS module for DatabaseKit.
|
|
5
|
+
*
|
|
6
|
+
* Provides a unified database access layer for MongoDB and PostgreSQL.
|
|
7
|
+
* Use forRoot() for synchronous configuration or forRootAsync() for
|
|
8
|
+
* configuration that depends on other providers (e.g., ConfigService).
|
|
9
|
+
*
|
|
10
|
+
* @example Synchronous configuration
|
|
11
|
+
* ```typescript
|
|
12
|
+
* @Module({
|
|
13
|
+
* imports: [
|
|
14
|
+
* DatabaseKitModule.forRoot({
|
|
15
|
+
* config: {
|
|
16
|
+
* type: 'mongo',
|
|
17
|
+
* connectionString: process.env.MONGO_URI!,
|
|
18
|
+
* },
|
|
19
|
+
* }),
|
|
20
|
+
* ],
|
|
21
|
+
* })
|
|
22
|
+
* export class AppModule {}
|
|
23
|
+
* ```
|
|
24
|
+
*
|
|
25
|
+
* @example Async configuration with ConfigService
|
|
26
|
+
* ```typescript
|
|
27
|
+
* @Module({
|
|
28
|
+
* imports: [
|
|
29
|
+
* DatabaseKitModule.forRootAsync({
|
|
30
|
+
* imports: [ConfigModule],
|
|
31
|
+
* useFactory: (config: ConfigService) => ({
|
|
32
|
+
* config: {
|
|
33
|
+
* type: 'postgres',
|
|
34
|
+
* connectionString: config.get('DATABASE_URL')!,
|
|
35
|
+
* },
|
|
36
|
+
* }),
|
|
37
|
+
* inject: [ConfigService],
|
|
38
|
+
* }),
|
|
39
|
+
* ],
|
|
40
|
+
* })
|
|
41
|
+
* export class AppModule {}
|
|
42
|
+
* ```
|
|
43
|
+
*/
|
|
44
|
+
export declare class DatabaseKitModule {
|
|
45
|
+
private static readonly logger;
|
|
46
|
+
/**
|
|
47
|
+
* Configures DatabaseKitModule with synchronous options.
|
|
48
|
+
*
|
|
49
|
+
* @param options - Module configuration options
|
|
50
|
+
* @returns Dynamic module configuration
|
|
51
|
+
*/
|
|
52
|
+
static forRoot(options: DatabaseKitModuleOptions): DynamicModule;
|
|
53
|
+
/**
|
|
54
|
+
* Configures DatabaseKitModule with asynchronous options.
|
|
55
|
+
* Useful when configuration depends on other providers like ConfigService.
|
|
56
|
+
*
|
|
57
|
+
* @param options - Async module configuration options
|
|
58
|
+
* @returns Dynamic module configuration
|
|
59
|
+
*/
|
|
60
|
+
static forRootAsync(options: DatabaseKitModuleAsyncOptions): DynamicModule;
|
|
61
|
+
/**
|
|
62
|
+
* Creates a feature module for additional database connections.
|
|
63
|
+
* Useful for multi-database scenarios.
|
|
64
|
+
*
|
|
65
|
+
* @param token - Unique token for this database connection
|
|
66
|
+
* @param config - Database configuration
|
|
67
|
+
* @returns Dynamic module configuration
|
|
68
|
+
*/
|
|
69
|
+
static forFeature(token: string, config: DatabaseConfig): DynamicModule;
|
|
70
|
+
}
|
|
71
|
+
//# sourceMappingURL=database-kit.module.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"database-kit.module.d.ts","sourceRoot":"","sources":["../src/database-kit.module.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,aAAa,EAAoC,MAAM,gBAAgB,CAAC;AAGjF,OAAO,EACH,cAAc,EACd,wBAAwB,EACxB,6BAA6B,EAChC,MAAM,gCAAgC,CAAC;AAGxC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwCG;AACH,qBAEa,iBAAiB;IAC1B,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAsC;IAEpE;;;;;OAKG;IACH,MAAM,CAAC,OAAO,CAAC,OAAO,EAAE,wBAAwB,GAAG,aAAa;IA6BhE;;;;;;OAMG;IACH,MAAM,CAAC,YAAY,CAAC,OAAO,EAAE,6BAA6B,GAAG,aAAa;IAiC1E;;;;;;;OAOG;IACH,MAAM,CAAC,UAAU,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,cAAc,GAAG,aAAa;CAmB1E"}
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// src/database-kit.module.ts
|
|
3
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
4
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
5
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
6
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
7
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
8
|
+
};
|
|
9
|
+
var DatabaseKitModule_1;
|
|
10
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
|
+
exports.DatabaseKitModule = void 0;
|
|
12
|
+
const common_1 = require("@nestjs/common");
|
|
13
|
+
const database_service_1 = require("./services/database.service");
|
|
14
|
+
const logger_service_1 = require("./services/logger.service");
|
|
15
|
+
const database_constants_1 = require("./config/database.constants");
|
|
16
|
+
/**
|
|
17
|
+
* DatabaseKitModule - Main NestJS module for DatabaseKit.
|
|
18
|
+
*
|
|
19
|
+
* Provides a unified database access layer for MongoDB and PostgreSQL.
|
|
20
|
+
* Use forRoot() for synchronous configuration or forRootAsync() for
|
|
21
|
+
* configuration that depends on other providers (e.g., ConfigService).
|
|
22
|
+
*
|
|
23
|
+
* @example Synchronous configuration
|
|
24
|
+
* ```typescript
|
|
25
|
+
* @Module({
|
|
26
|
+
* imports: [
|
|
27
|
+
* DatabaseKitModule.forRoot({
|
|
28
|
+
* config: {
|
|
29
|
+
* type: 'mongo',
|
|
30
|
+
* connectionString: process.env.MONGO_URI!,
|
|
31
|
+
* },
|
|
32
|
+
* }),
|
|
33
|
+
* ],
|
|
34
|
+
* })
|
|
35
|
+
* export class AppModule {}
|
|
36
|
+
* ```
|
|
37
|
+
*
|
|
38
|
+
* @example Async configuration with ConfigService
|
|
39
|
+
* ```typescript
|
|
40
|
+
* @Module({
|
|
41
|
+
* imports: [
|
|
42
|
+
* DatabaseKitModule.forRootAsync({
|
|
43
|
+
* imports: [ConfigModule],
|
|
44
|
+
* useFactory: (config: ConfigService) => ({
|
|
45
|
+
* config: {
|
|
46
|
+
* type: 'postgres',
|
|
47
|
+
* connectionString: config.get('DATABASE_URL')!,
|
|
48
|
+
* },
|
|
49
|
+
* }),
|
|
50
|
+
* inject: [ConfigService],
|
|
51
|
+
* }),
|
|
52
|
+
* ],
|
|
53
|
+
* })
|
|
54
|
+
* export class AppModule {}
|
|
55
|
+
* ```
|
|
56
|
+
*/
|
|
57
|
+
let DatabaseKitModule = DatabaseKitModule_1 = class DatabaseKitModule {
|
|
58
|
+
/**
|
|
59
|
+
* Configures DatabaseKitModule with synchronous options.
|
|
60
|
+
*
|
|
61
|
+
* @param options - Module configuration options
|
|
62
|
+
* @returns Dynamic module configuration
|
|
63
|
+
*/
|
|
64
|
+
static forRoot(options) {
|
|
65
|
+
const providers = [
|
|
66
|
+
{
|
|
67
|
+
provide: database_constants_1.DATABASE_OPTIONS_TOKEN,
|
|
68
|
+
useValue: options,
|
|
69
|
+
},
|
|
70
|
+
{
|
|
71
|
+
provide: database_constants_1.DATABASE_TOKEN,
|
|
72
|
+
useFactory: async () => {
|
|
73
|
+
const db = new database_service_1.DatabaseService(options.config);
|
|
74
|
+
if (options.autoConnect !== false) {
|
|
75
|
+
await db.connect();
|
|
76
|
+
this.logger.log(`Database connected: ${options.config.type}`);
|
|
77
|
+
}
|
|
78
|
+
return db;
|
|
79
|
+
},
|
|
80
|
+
},
|
|
81
|
+
logger_service_1.LoggerService,
|
|
82
|
+
];
|
|
83
|
+
return {
|
|
84
|
+
module: DatabaseKitModule_1,
|
|
85
|
+
providers,
|
|
86
|
+
exports: [database_constants_1.DATABASE_TOKEN, logger_service_1.LoggerService],
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Configures DatabaseKitModule with asynchronous options.
|
|
91
|
+
* Useful when configuration depends on other providers like ConfigService.
|
|
92
|
+
*
|
|
93
|
+
* @param options - Async module configuration options
|
|
94
|
+
* @returns Dynamic module configuration
|
|
95
|
+
*/
|
|
96
|
+
static forRootAsync(options) {
|
|
97
|
+
const providers = [
|
|
98
|
+
{
|
|
99
|
+
provide: database_constants_1.DATABASE_OPTIONS_TOKEN,
|
|
100
|
+
useFactory: options.useFactory,
|
|
101
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-function-type
|
|
102
|
+
inject: (options.inject || []),
|
|
103
|
+
},
|
|
104
|
+
{
|
|
105
|
+
provide: database_constants_1.DATABASE_TOKEN,
|
|
106
|
+
useFactory: async (moduleOptions) => {
|
|
107
|
+
const db = new database_service_1.DatabaseService(moduleOptions.config);
|
|
108
|
+
if (moduleOptions.autoConnect !== false) {
|
|
109
|
+
await db.connect();
|
|
110
|
+
this.logger.log(`Database connected: ${moduleOptions.config.type}`);
|
|
111
|
+
}
|
|
112
|
+
return db;
|
|
113
|
+
},
|
|
114
|
+
inject: [database_constants_1.DATABASE_OPTIONS_TOKEN],
|
|
115
|
+
},
|
|
116
|
+
logger_service_1.LoggerService,
|
|
117
|
+
];
|
|
118
|
+
return {
|
|
119
|
+
module: DatabaseKitModule_1,
|
|
120
|
+
imports: (options.imports || []),
|
|
121
|
+
providers,
|
|
122
|
+
exports: [database_constants_1.DATABASE_TOKEN, logger_service_1.LoggerService],
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Creates a feature module for additional database connections.
|
|
127
|
+
* Useful for multi-database scenarios.
|
|
128
|
+
*
|
|
129
|
+
* @param token - Unique token for this database connection
|
|
130
|
+
* @param config - Database configuration
|
|
131
|
+
* @returns Dynamic module configuration
|
|
132
|
+
*/
|
|
133
|
+
static forFeature(token, config) {
|
|
134
|
+
const providers = [
|
|
135
|
+
{
|
|
136
|
+
provide: token,
|
|
137
|
+
useFactory: async () => {
|
|
138
|
+
const db = new database_service_1.DatabaseService(config);
|
|
139
|
+
await db.connect();
|
|
140
|
+
this.logger.log(`Feature database connected: ${token} (${config.type})`);
|
|
141
|
+
return db;
|
|
142
|
+
},
|
|
143
|
+
},
|
|
144
|
+
];
|
|
145
|
+
return {
|
|
146
|
+
module: DatabaseKitModule_1,
|
|
147
|
+
providers,
|
|
148
|
+
exports: [token],
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
};
|
|
152
|
+
exports.DatabaseKitModule = DatabaseKitModule;
|
|
153
|
+
DatabaseKitModule.logger = new common_1.Logger(DatabaseKitModule_1.name);
|
|
154
|
+
exports.DatabaseKitModule = DatabaseKitModule = DatabaseKitModule_1 = __decorate([
|
|
155
|
+
(0, common_1.Global)(),
|
|
156
|
+
(0, common_1.Module)({})
|
|
157
|
+
], DatabaseKitModule);
|
|
158
|
+
//# sourceMappingURL=database-kit.module.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"database-kit.module.js","sourceRoot":"","sources":["../src/database-kit.module.ts"],"names":[],"mappings":";AAAA,6BAA6B;;;;;;;;;;AAE7B,2CAAiF;AACjF,kEAA8D;AAC9D,8DAA0D;AAM1D,oEAAqF;AAErF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwCG;AAGI,IAAM,iBAAiB,yBAAvB,MAAM,iBAAiB;IAG1B;;;;;OAKG;IACH,MAAM,CAAC,OAAO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C,CAAC;oBACxE,CAAC;oBAED,OAAO,EAAE,CAAC;gBACd,CAAC;gBACD,MAAM,EAAE,CAAC,2CAAsB,CAAC;aACnC;YACD,8BAAa;SAChB,CAAC;QAEF,OAAO;YACH,MAAM,EAAE,mBAAiB;YACzB,OAAO,EAAE,CAAC,OAAO,CAAC,OAAO,IAAI,EAAE,CAA6B;YAC5D,SAAS;YACT,OAAO,EAAE,CAAC,mCAAc,EAAE,8BAAa,CAAC;SAC3C,CAAC;IACN,CAAC;IAED;;;;;;;OAOG;IACH,MAAM,CAAC,UAAU,CAAC,KAAa,EAAE,MAAsB;QACnD,MAAM,SAAS,GAAe;YAC1B;gBACI,OAAO,EAAE,KAAK;gBACd,UAAU,EAAE,KAAK,IAAI,EAAE;oBACnB,MAAM,EAAE,GAAG,IAAI,kCAAe,CAAC,MAAM,CAAC,CAAC;oBACvC,MAAM,EAAE,CAAC,OAAO,EAAE,CAAC;oBACnB,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,+BAA+B,KAAK,KAAK,MAAM,CAAC,IAAI,GAAG,CAAC,CAAC;oBACzE,OAAO,EAAE,CAAC;gBACd,CAAC;aACJ;SACJ,CAAC;QAEF,OAAO;YACH,MAAM,EAAE,mBAAiB;YACzB,SAAS;YACT,OAAO,EAAE,CAAC,KAAK,CAAC;SACnB,CAAC;IACN,CAAC;;AAxGQ,8CAAiB;AACF,wBAAM,GAAG,IAAI,eAAM,CAAC,mBAAiB,CAAC,IAAI,CAAC,AAArC,CAAsC;4BAD3D,iBAAiB;IAF7B,IAAA,eAAM,GAAE;IACR,IAAA,eAAM,EAAC,EAAE,CAAC;GACE,iBAAiB,CAyG7B"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { ExceptionFilter, ArgumentsHost } from '@nestjs/common';
|
|
2
|
+
/**
|
|
3
|
+
* Global exception filter for handling database-related errors.
|
|
4
|
+
* Catches and formats various database errors into consistent HTTP responses.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* ```typescript
|
|
8
|
+
* // In main.ts or a module
|
|
9
|
+
* app.useGlobalFilters(new DatabaseExceptionFilter());
|
|
10
|
+
*
|
|
11
|
+
* // Or in a module
|
|
12
|
+
* @Module({
|
|
13
|
+
* providers: [
|
|
14
|
+
* { provide: APP_FILTER, useClass: DatabaseExceptionFilter },
|
|
15
|
+
* ],
|
|
16
|
+
* })
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
export declare class DatabaseExceptionFilter implements ExceptionFilter {
|
|
20
|
+
private readonly logger;
|
|
21
|
+
catch(exception: unknown, host: ArgumentsHost): void;
|
|
22
|
+
/**
|
|
23
|
+
* Parses an exception and extracts status code, message, and error type.
|
|
24
|
+
*/
|
|
25
|
+
private parseException;
|
|
26
|
+
/**
|
|
27
|
+
* Checks if the exception is a MongoDB error.
|
|
28
|
+
*/
|
|
29
|
+
private isMongoError;
|
|
30
|
+
/**
|
|
31
|
+
* Parses MongoDB-specific errors.
|
|
32
|
+
*/
|
|
33
|
+
private parseMongoError;
|
|
34
|
+
/**
|
|
35
|
+
* Checks if the exception is a Knex/PostgreSQL error.
|
|
36
|
+
*/
|
|
37
|
+
private isKnexError;
|
|
38
|
+
/**
|
|
39
|
+
* Parses PostgreSQL/Knex-specific errors.
|
|
40
|
+
*/
|
|
41
|
+
private parseKnexError;
|
|
42
|
+
/**
|
|
43
|
+
* Checks if the exception is a validation error.
|
|
44
|
+
*/
|
|
45
|
+
private isValidationError;
|
|
46
|
+
/**
|
|
47
|
+
* Logs the error with appropriate level and context.
|
|
48
|
+
*/
|
|
49
|
+
private logError;
|
|
50
|
+
}
|
|
51
|
+
//# sourceMappingURL=database-exception.filter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"database-exception.filter.d.ts","sourceRoot":"","sources":["../../src/filters/database-exception.filter.ts"],"names":[],"mappings":"AAEA,OAAO,EACH,eAAe,EAEf,aAAa,EAIhB,MAAM,gBAAgB,CAAC;AAaxB;;;;;;;;;;;;;;;;GAgBG;AACH,qBACa,uBAAwB,YAAW,eAAe;IAC3D,OAAO,CAAC,QAAQ,CAAC,MAAM,CAA4C;IAEnE,KAAK,CAAC,SAAS,EAAE,OAAO,EAAE,IAAI,EAAE,aAAa,GAAG,IAAI;IAqBpD;;OAEG;IACH,OAAO,CAAC,cAAc;IAuDtB;;OAEG;IACH,OAAO,CAAC,YAAY;IAYpB;;OAEG;IACH,OAAO,CAAC,eAAe;IAyCvB;;OAEG;IACH,OAAO,CAAC,WAAW;IAOnB;;OAEG;IACH,OAAO,CAAC,cAAc;IA2DtB;;OAEG;IACH,OAAO,CAAC,iBAAiB;IAMzB;;OAEG;IACH,OAAO,CAAC,QAAQ;CAcnB"}
|