{"_id":"@ace-common/database","_rev":"2-056aa3f004aa9b2669bea13c86452c37","name":"@ace-common/database","dist-tags":{"latest":"2.0.1"},"versions":{"2.0.0":{"name":"@ace-common/database","version":"2.0.0","keywords":["nestjs","typeorm","database","health-check","migrations"],"license":"MIT","_id":"@ace-common/database@2.0.0","maintainers":[{"name":"mohamedmostafa0","email":"mohamed.it.999@hotmail.com"}],"dist":{"shasum":"a14c58df2f88b9925cc4a5143cb9d08b1c78c1e9","tarball":"https://registry.npmjs.org/@ace-common/database/-/database-2.0.0.tgz","fileCount":27,"integrity":"sha512-1aFi1rsxa9gov/s2Qm2EKpsJ09Icg7qAmsNHvQMlrKF3TooLSaO8AY3OhmHcAORJNJA68fslmwaWpwfl5gp+tw==","signatures":[{"sig":"MEUCIQC/SqewV+1ctxESSBeD3Mpm69E3dm6GH4zHYalMVi7DmwIgTgnd+GQtuKS5PImg+q+BSFGNWbrXL1O/jllE9tC+RII=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":25723},"main":"dist/index.js","types":"dist/index.d.ts","exports":{".":{"types":"./dist/index.d.ts","default":"./dist/index.js"}},"gitHead":"b3f6d37a33aa983160be31c2391fbca0188452b3","scripts":{"lint":"eslint 'src/**/*.ts'","build":"tsc","clean":"rm -rf dist","lint:fix":"eslint 'src/**/*.ts' --fix","prepublishOnly":"npm run clean && npm run lint && npm run build"},"_npmUser":{"name":"mohamedmostafa0","email":"mohamed.it.999@hotmail.com"},"_npmVersion":"10.9.7","description":"TypeORM wrapper for NestJS with health checks and auto-migrations","directories":{},"_nodeVersion":"22.22.2","_hasShrinkwrap":false,"packageManager":"pnpm@10.30.1+sha512.3590e550d5384caa39bd5c7c739f72270234b2f6059e13018f975c313b1eb9fefcc09714048765d4d9efe961382c312e624572c0420762bdc5d5940cdf9be73a","devDependencies":{"eslint":"^9.17.0","@eslint/js":"^9.0.0","typescript":"^5.5.0","@types/node":">=18","typescript-eslint":"^8.0.0"},"peerDependencies":{"typeorm":">=0.3.0","@nestjs/core":">=10.0.0","@nestjs/common":">=10.0.0","@nestjs/typeorm":">=10.0.0","reflect-metadata":">=0.1.13"},"_npmOperationalInternal":{"tmp":"tmp/database_2.0.0_1775306830297_0.839206287353812","host":"s3://npm-registry-packages-npm-production"}},"2.0.1":{"name":"@ace-common/database","version":"2.0.1","description":"TypeORM wrapper for NestJS with health checks and auto-migrations","license":"MIT","keywords":["nestjs","typeorm","database","health-check","migrations"],"main":"dist/index.js","types":"dist/index.d.ts","exports":{".":{"types":"./dist/index.d.ts","default":"./dist/index.js"}},"scripts":{"build":"tsc","lint":"eslint 'src/**/*.ts'","lint:fix":"eslint 'src/**/*.ts' --fix","clean":"rm -rf dist","prepublishOnly":"npm run clean && npm run lint && npm run build"},"peerDependencies":{"@nestjs/common":">=10.0.0","@nestjs/core":">=10.0.0","@nestjs/typeorm":">=10.0.0","typeorm":">=0.3.0","reflect-metadata":">=0.1.13"},"devDependencies":{"@eslint/js":"^9.0.0","@types/node":">=18","eslint":"^9.17.0","typescript":"^5.5.0","typescript-eslint":"^8.0.0"},"packageManager":"pnpm@10.30.1+sha512.3590e550d5384caa39bd5c7c739f72270234b2f6059e13018f975c313b1eb9fefcc09714048765d4d9efe961382c312e624572c0420762bdc5d5940cdf9be73a","_id":"@ace-common/database@2.0.1","gitHead":"7bccf73cf8e992c5608ca75b0b5bb81edbfc3f00","_nodeVersion":"22.22.2","_npmVersion":"10.9.7","dist":{"integrity":"sha512-e3Dvbtl1DD1TQgQJ4nty0e8TVOL3M5DW+y/lTFqPRxhWgoo0PAZLt62mvA90UF3OYxNR6DDBGeb8OF8lix7GmA==","shasum":"e69c2fdfa28134bc39ebc022c2af17c39757b404","tarball":"https://registry.npmjs.org/@ace-common/database/-/database-2.0.1.tgz","fileCount":27,"unpackedSize":25783,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCIHQHoWDbUGO85FBF8M2vHmSZt6RlRgmCbYFqGUGTGw2zAiEAhsHBxZpYv4OZ8LfXipjMP5Kn8cbGKDkAOGlQOUVh5qI="}]},"_npmUser":{"name":"mohamedmostafa0","email":"mohamed.it.999@hotmail.com"},"directories":{},"maintainers":[{"name":"mohamedmostafa0","email":"mohamed.it.999@hotmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/database_2.0.1_1776033974746_0.37004964976775967"},"_hasShrinkwrap":false}},"time":{"created":"2026-04-04T12:47:10.212Z","modified":"2026-04-12T22:46:15.037Z","2.0.0":"2026-04-04T12:47:10.449Z","2.0.1":"2026-04-12T22:46:14.914Z"},"license":"MIT","keywords":["nestjs","typeorm","database","health-check","migrations"],"description":"TypeORM wrapper for NestJS with health checks and auto-migrations","maintainers":[{"name":"mohamedmostafa0","email":"mohamed.it.999@hotmail.com"}],"readme":"# @ace-common/database\n\nTypeORM wrapper for NestJS with health checks and auto-migrations.\n\n## Installation\n\n```bash\npnpm add @ace-common/database\n```\n\nPeer dependencies: `@nestjs/common`, `@nestjs/core`, `@nestjs/typeorm`, `typeorm`, `reflect-metadata`.\n\n## Quick Start\n\n### Sync config\n\n```typescript\nimport { configureDatabase } from '@ace-common/database';\n\n@Module({\n  imports: [\n    configureDatabase({\n      type: 'mysql',\n      host: '127.0.0.1',\n      port: 3306,\n      username: 'root',\n      password: '',\n      database: 'myapp',\n      entities: [UserEntity],\n      synchronize: true,\n    }),\n  ],\n})\nexport class AppModule {}\n```\n\n### Async config (with `@ace-common/config`)\n\n```typescript\nimport { configureDatabaseAsync } from '@ace-common/database';\nimport { ACE_CONFIG } from '@ace-common/config';\n\n@Module({\n  imports: [\n    configureConfig({ schema: AppConfig }),\n    configureDatabaseAsync({\n      inject: [ACE_CONFIG],\n      useFactory: (config: AppConfig) => ({\n        type: 'mysql',\n        host: config.MYSQL_HOST,\n        port: config.MYSQL_PORT,\n        username: config.MYSQL_USER,\n        password: config.MYSQL_PASSWORD,\n        database: config.MYSQL_DATABASE,\n        entities: [UserEntity],\n        synchronize: config.NODE_ENV !== 'production',\n        runMigrations: config.NODE_ENV === 'production',\n      }),\n    }),\n  ],\n})\nexport class AppModule {}\n```\n\n### Registering entities per module\n\nUse `TypeOrmModule.forFeature()` from `@nestjs/typeorm` as usual:\n\n```typescript\n@Module({\n  imports: [TypeOrmModule.forFeature([UserEntity])],\n  providers: [UserService],\n})\nexport class UserModule {}\n```\n\n## Health Check\n\n`DatabaseHealthIndicator` is registered globally and can be injected anywhere:\n\n```typescript\nimport { DatabaseHealthIndicator } from '@ace-common/database';\n\n@Controller('health')\nexport class HealthController {\n  constructor(private readonly dbHealth: DatabaseHealthIndicator) {}\n\n  @Get()\n  async check() {\n    return this.dbHealth.check();\n    // { \"database\": { \"status\": \"up\" } }\n  }\n}\n```\n\nMethods:\n\n| Method | Returns | Description |\n|---|---|---|\n| `isHealthy()` | `Promise<boolean>` | Simple boolean ping |\n| `check(key?)` | `Promise<Record<string, HealthCheckResult>>` | Structured result with status and error message |\n\n## Auto-Migrations\n\nSet `runMigrations: true` to automatically run pending TypeORM migrations when the app starts:\n\n```typescript\nconfigureDatabase({\n  // ...connection options\n  migrations: ['dist/migrations/*.js'],\n  runMigrations: true,\n});\n```\n\nEach migration runs in its own transaction. The app logs applied migration names on startup.\n\n## Options\n\nAll standard `TypeOrmModuleOptions` are supported, plus:\n\n| Option | Default | Description |\n|---|---|---|\n| `runMigrations` | `false` | Run pending migrations on startup |\n\n## Exports\n\n| Export | Description |\n|---|---|\n| `configureDatabase` | Sync module configuration helper |\n| `configureDatabaseAsync` | Async module configuration helper |\n| `AceDatabaseModule` | NestJS dynamic module (`forRoot` / `forRootAsync`) |\n| `DatabaseHealthIndicator` | Injectable health check service |\n| `MigrationRunner` | Startup migration runner |\n| `DatabaseModuleOptions` | Options type (extends `TypeOrmModuleOptions`) |\n| `DatabaseAsyncOptions` | Async options type |\n\n## License\n\nMIT\n","readmeFilename":"README.md"}