Commit 20f8adb
authored
Develop (#2)
* chore: add comprehensive security-focused .gitignore
- Added protection for secrets, credentials, and keys
- Included patterns for environment files
- Added coverage for IDE files, OS files, and build artifacts
- Security-first approach to prevent accidental credential commits
* chore: remove Azure DevOps pipeline
- Removed azure-pipelines.yml (migrating to GitHub Actions)
- All CI/CD now handled via GitHub Actions workflows
* ci: add GitHub Actions CI/CD workflows
- Added ci.yml for PR/push validation (lint, test, build)
- Updated publish.yml with npm provenance support
- Multi-node version testing (18, 20, 22)
- Artifact upload for build outputs
* docs: add AI assistant guidelines for DatabaseKit
- Added comprehensive copilot-instructions.md
- Includes architecture overview, naming conventions
- Code patterns, anti-patterns, testing requirements
- Security practices and release checklist
* refactor: remove old core/ and nest/ directory structure
- Deleted src/core/adapters/mongo.adapter.ts
- Deleted src/core/adapters/postgres.adapter.ts
- Deleted src/core/contracts.ts
- Deleted src/core/database.ts
- Deleted src/nest/database.decorators.ts
- Deleted src/nest/database.module.ts
BREAKING CHANGE: Complete restructure to new architecture
* feat: add TypeScript contracts layer
- Added database.contracts.ts with all interfaces and types
- DatabaseConfig discriminated union (mongo | postgres)
- Repository<T> interface for unified CRUD operations
- PageResult and PageOptions for pagination
- Module configuration types
* feat: add database adapters layer
- Added mongo.adapter.ts with Mongoose integration
- Added postgres.adapter.ts with Knex integration
- Both implement Repository<T> interface
- Connection pooling and lifecycle management
- Pagination support built-in
* feat: add services layer
- Added database.service.ts as main facade service
- Added logger.service.ts for consistent logging
- DatabaseService manages adapters and repositories
- Implements NestJS OnModuleDestroy lifecycle hook
* feat: add configuration layer
- Added database.constants.ts with DI tokens
- Added database.config.ts with config helpers
- Environment-driven configuration support
- DATABASE_TOKEN and DATABASE_OPTIONS_TOKEN for DI
* feat: add middleware and filters
- Added database.decorators.ts with @InjectDatabase()
- Added database-exception.filter.ts for error handling
- Global exception filter for database errors
- Custom DI decorator for clean injection
* feat: add utility functions
- Added pagination.utils.ts with pagination helpers
- Added validation.utils.ts with validation helpers
- Added comprehensive unit tests for utilities
- isValidMongoId, isValidUuid, sanitizeFilter, etc.
* feat: add DatabaseKitModule
- NestJS DynamicModule with forRoot() and forRootAsync()
- forFeature() for feature module registration
- Auto-connect option with graceful shutdown
- Proper provider configuration and exports
* feat: update public API exports
- Clean barrel exports in index.ts
- Exports only public API surface
- Internal implementations kept private
- Comprehensive type exports for consumers
* chore: update package configuration
- Upgraded to latest dependencies (ESLint 9, TS 5.8)
- Updated tsconfig.json with path aliases
- Added proper scripts for build, test, lint
- Updated package.json metadata and peer deps
* chore: add tooling configuration
- Added eslint.config.mjs (ESLint 9 flat config)
- Added jest.config.js for testing
- Added .env.example with sample environment vars
* docs: update project documentation
- Updated README.md with new architecture
- Updated CHANGELOG.md with v1.0.0 changes
- Updated SECURITY.md with security policy
- Updated CONTRIBUTING.md with contribution guide
- Added TROUBLESHOOTING.md for common issues
* feat: add transaction support for MongoDB and PostgreSQL
- Add TransactionOptions, TransactionContext, MongoTransactionContext,
PostgresTransactionContext types to contracts
- Implement withTransaction() in MongoAdapter using Mongoose sessions
- Implement withTransaction() in PostgresAdapter using Knex transactions
- Support transaction isolation levels for PostgreSQL
- Add retry logic with exponential backoff for transient failures
- Expose withTransaction(), withMongoTransaction(), withPostgresTransaction()
methods in DatabaseService
- Add comprehensive tests for transaction functionality
- Export all transaction types from public API
Tests: 74 passed
* feat: add bulk operations (insertMany, updateMany, deleteMany)
- Add insertMany, updateMany, deleteMany methods to Repository interface
- Implement bulk operations in MongoAdapter with session/transaction support
- Implement bulk operations in PostgresAdapter with Knex support
- Add comprehensive tests for all bulk operations
- Both adapters support empty array handling for insertMany
Repository interface now supports:
- insertMany(data[]) -> T[] - Create multiple entities
- updateMany(filter, update) -> number - Update matching entities
- deleteMany(filter) -> number - Delete matching entities
Tests: 82 passed
* feat: add health check support for production monitoring
- Add HealthCheckResult interface with healthy, responseTimeMs, type, error, details
- Implement healthCheck() in MongoAdapter using admin.ping() command
- Implement healthCheck() in PostgresAdapter using SELECT version() query
- Expose healthCheck() method in DatabaseService facade
- Include pool status and database version in health check details
- Export HealthCheckResult type from public API
- Add comprehensive tests for health check functionality
Useful for:
- Load balancer health endpoints
- Kubernetes liveness/readiness probes
- Application monitoring dashboards
Tests: 92 passed
* feat: add soft delete pattern support
- Add softDelete and softDeleteField options to MongoRepositoryOptions
- Add softDelete and softDeleteField options to PostgresEntityConfig
- Implement soft delete in MongoAdapter:
- All query methods filter out deleted records by default
- deleteById/deleteMany set deletedAt instead of hard delete
- softDelete(), softDeleteMany() for explicit soft delete
- restore(), restoreMany() to recover soft-deleted records
- findDeleted() and findAllWithDeleted() for querying deleted records
- Implement soft delete in PostgresAdapter:
- Same functionality with deleted_at as default field
- Respects column whitelisting for security
- Add 17 new tests for soft delete functionality
- Total tests: 109 passing
* feat: add automatic timestamp support (createdAt/updatedAt)
- Add timestamps, createdAtField, updatedAtField to MongoRepositoryOptions
- Add timestamps, createdAtField, updatedAtField to PostgresEntityConfig
- Implement timestamp injection in MongoAdapter:
- create() and insertMany() set createdAt automatically
- updateById() and updateMany() set updatedAt automatically
- Default field: 'createdAt', 'updatedAt' for MongoDB
- Implement timestamp injection in PostgresAdapter:
- Same behavior with 'created_at', 'updated_at' defaults
- Respects custom field name configuration
- Works seamlessly with soft delete feature
- Add 11 new tests for timestamp functionality
- Total tests: 120 passing
* feat: add v1.0.0 production-ready features
- Add findOne() method for single record lookup by filter
- Add upsert() for update-or-insert operations
- Add distinct() for unique field values
- Add select() for field projection
- Add PoolConfig interface for connection pool tuning
- Add RepositoryHooks system (beforeCreate, afterCreate, beforeUpdate,
afterUpdate, beforeDelete, afterDelete)
- Implement hooks in both MongoDB and PostgreSQL adapters
- Add comprehensive tests for all new features (133 total tests)
- Update CHANGELOG for v1.0.0 release
* docs: comprehensive README for v1.0.0 release
* docs: add comprehensive Copilot instruction files
- general.instructions.md: Main guidelines, architecture, patterns
- adapters.instructions.md: Database adapter implementation guide
- testing.instructions.md: Testing patterns and requirements
- features.instructions.md: Feature implementation workflow
- bugfix.instructions.md: Bug investigation and fix process
All files updated to February 20261 parent 4a866ed commit 20f8adb
File tree
22 files changed
+5394
-206
lines changed- .github/instructions
- src
- adapters
- contracts
- services
22 files changed
+5394
-206
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
0 commit comments