@ciscode/database-kit 1.0.0 → 1.0.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.
- package/CHANGELOG.md +50 -4
- package/README.md +487 -148
- package/dist/adapters/mongo.adapter.d.ts +53 -3
- package/dist/adapters/mongo.adapter.d.ts.map +1 -1
- package/dist/adapters/mongo.adapter.js +410 -27
- package/dist/adapters/mongo.adapter.js.map +1 -1
- package/dist/adapters/postgres.adapter.d.ts +50 -3
- package/dist/adapters/postgres.adapter.d.ts.map +1 -1
- package/dist/adapters/postgres.adapter.js +439 -45
- package/dist/adapters/postgres.adapter.js.map +1 -1
- package/dist/config/database.config.d.ts +1 -1
- package/dist/config/database.config.d.ts.map +1 -1
- package/dist/config/database.config.js +13 -13
- package/dist/config/database.config.js.map +1 -1
- package/dist/config/database.constants.js +7 -7
- package/dist/contracts/database.contracts.d.ts +283 -6
- package/dist/contracts/database.contracts.d.ts.map +1 -1
- package/dist/contracts/database.contracts.js +6 -1
- package/dist/contracts/database.contracts.js.map +1 -1
- package/dist/database-kit.module.d.ts +2 -2
- package/dist/database-kit.module.d.ts.map +1 -1
- package/dist/database-kit.module.js +1 -2
- package/dist/database-kit.module.js.map +1 -1
- package/dist/filters/database-exception.filter.d.ts +1 -1
- package/dist/filters/database-exception.filter.d.ts.map +1 -1
- package/dist/filters/database-exception.filter.js +43 -43
- package/dist/filters/database-exception.filter.js.map +1 -1
- package/dist/index.d.ts +10 -10
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/middleware/database.decorators.d.ts.map +1 -1
- package/dist/middleware/database.decorators.js.map +1 -1
- package/dist/services/database.service.d.ts +83 -5
- package/dist/services/database.service.d.ts.map +1 -1
- package/dist/services/database.service.js +136 -16
- package/dist/services/database.service.js.map +1 -1
- package/dist/services/logger.service.d.ts +1 -1
- package/dist/services/logger.service.d.ts.map +1 -1
- package/dist/services/logger.service.js +1 -1
- package/dist/services/logger.service.js.map +1 -1
- package/dist/utils/pagination.utils.d.ts +2 -2
- package/dist/utils/pagination.utils.d.ts.map +1 -1
- package/dist/utils/pagination.utils.js +9 -6
- package/dist/utils/pagination.utils.js.map +1 -1
- package/dist/utils/validation.utils.d.ts.map +1 -1
- package/dist/utils/validation.utils.js +5 -5
- package/dist/utils/validation.utils.js.map +1 -1
- package/package.json +28 -8
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Knex } from
|
|
2
|
-
import { PostgresDatabaseConfig, PostgresEntityConfig, Repository } from
|
|
1
|
+
import { Knex } from "knex";
|
|
2
|
+
import { PostgresDatabaseConfig, PostgresEntityConfig, PostgresTransactionContext, Repository, TransactionOptions, TransactionCallback, HealthCheckResult } from "../contracts/database.contracts";
|
|
3
3
|
/**
|
|
4
4
|
* PostgreSQL adapter for DatabaseKit.
|
|
5
5
|
* Handles PostgreSQL connection and repository creation via Knex.
|
|
@@ -37,13 +37,60 @@ export declare class PostgresAdapter {
|
|
|
37
37
|
* Checks if connected to PostgreSQL.
|
|
38
38
|
*/
|
|
39
39
|
isConnected(): boolean;
|
|
40
|
+
/**
|
|
41
|
+
* Performs a health check on the PostgreSQL connection.
|
|
42
|
+
* Executes a simple query to verify the database is responsive.
|
|
43
|
+
*
|
|
44
|
+
* @returns Health check result with status and response time
|
|
45
|
+
*
|
|
46
|
+
* @example
|
|
47
|
+
* ```typescript
|
|
48
|
+
* const health = await adapter.healthCheck();
|
|
49
|
+
* if (!health.healthy) {
|
|
50
|
+
* console.error('Database unhealthy:', health.error);
|
|
51
|
+
* }
|
|
52
|
+
* ```
|
|
53
|
+
*/
|
|
54
|
+
healthCheck(): Promise<HealthCheckResult>;
|
|
40
55
|
/**
|
|
41
56
|
* Creates a repository for a PostgreSQL table.
|
|
42
57
|
* The repository provides a standardized CRUD interface.
|
|
43
58
|
*
|
|
44
59
|
* @param cfg - Configuration for the entity/table
|
|
60
|
+
* @param trx - Optional Knex transaction for transaction support
|
|
45
61
|
* @returns Repository instance with CRUD methods
|
|
46
62
|
*/
|
|
47
|
-
createRepository<T = unknown>(cfg: PostgresEntityConfig): Repository<T>;
|
|
63
|
+
createRepository<T = unknown>(cfg: PostgresEntityConfig<T>, trx?: Knex.Transaction): Repository<T>;
|
|
64
|
+
/**
|
|
65
|
+
* Executes a callback within a PostgreSQL transaction.
|
|
66
|
+
* All database operations within the callback are atomic.
|
|
67
|
+
*
|
|
68
|
+
* @param callback - Function to execute within the transaction
|
|
69
|
+
* @param options - Transaction options including isolation level
|
|
70
|
+
* @returns Result of the callback function
|
|
71
|
+
* @throws Error if transaction fails after all retries
|
|
72
|
+
*
|
|
73
|
+
* @example
|
|
74
|
+
* ```typescript
|
|
75
|
+
* const result = await postgresAdapter.withTransaction(async (ctx) => {
|
|
76
|
+
* const usersRepo = ctx.createRepository<User>({ table: 'users' });
|
|
77
|
+
* const ordersRepo = ctx.createRepository<Order>({ table: 'orders' });
|
|
78
|
+
*
|
|
79
|
+
* const [user] = await usersRepo.create({ name: 'John' });
|
|
80
|
+
* const [order] = await ordersRepo.create({ user_id: user.id, total: 100 });
|
|
81
|
+
*
|
|
82
|
+
* return { user, order };
|
|
83
|
+
* }, { isolationLevel: 'serializable' });
|
|
84
|
+
* ```
|
|
85
|
+
*/
|
|
86
|
+
withTransaction<TResult>(callback: TransactionCallback<PostgresTransactionContext, TResult>, options?: TransactionOptions): Promise<TResult>;
|
|
87
|
+
/**
|
|
88
|
+
* Checks if a PostgreSQL error is retryable.
|
|
89
|
+
*/
|
|
90
|
+
private isRetryableError;
|
|
91
|
+
/**
|
|
92
|
+
* Simple sleep utility for retry backoff.
|
|
93
|
+
*/
|
|
94
|
+
private sleep;
|
|
48
95
|
}
|
|
49
96
|
//# sourceMappingURL=postgres.adapter.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"postgres.adapter.d.ts","sourceRoot":"","sources":["../../src/adapters/postgres.adapter.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"postgres.adapter.d.ts","sourceRoot":"","sources":["../../src/adapters/postgres.adapter.ts"],"names":[],"mappings":"AACA,OAAa,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAElC,OAAO,EACL,sBAAsB,EACtB,oBAAoB,EACpB,0BAA0B,EAC1B,UAAU,EAGV,kBAAkB,EAClB,mBAAmB,EACnB,iBAAiB,EAElB,MAAM,iCAAiC,CAAC;AAEzC;;;;;;;;;;GAUG;AACH,qBACa,eAAe;IAC1B,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAoC;IAC3D,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAyB;IAChD,OAAO,CAAC,YAAY,CAAC,CAAO;gBAEhB,MAAM,EAAE,sBAAsB;IAI1C;;;;;;OAMG;IACH,OAAO,CAAC,SAAS,GAAE,IAAI,CAAC,MAAW,GAAG,IAAI;IA2B1C;;OAEG;IACG,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IAQjC;;;OAGG;IACH,OAAO,IAAI,IAAI;IAOf;;OAEG;IACH,WAAW,IAAI,OAAO;IAItB;;;;;;;;;;;;;OAaG;IACG,WAAW,IAAI,OAAO,CAAC,iBAAiB,CAAC;IA8C/C;;;;;;;OAOG;IACH,gBAAgB,CAAC,CAAC,GAAG,OAAO,EAC1B,GAAG,EAAE,oBAAoB,CAAC,CAAC,CAAC,EAC5B,GAAG,CAAC,EAAE,IAAI,CAAC,WAAW,GACrB,UAAU,CAAC,CAAC,CAAC;IAgehB;;;;;;;;;;;;;;;;;;;;;OAqBG;IACG,eAAe,CAAC,OAAO,EAC3B,QAAQ,EAAE,mBAAmB,CAAC,0BAA0B,EAAE,OAAO,CAAC,EAClE,OAAO,GAAE,kBAAuB,GAC/B,OAAO,CAAC,OAAO,CAAC;IAsDnB;;OAEG;IACH,OAAO,CAAC,gBAAgB;IAoBxB;;OAEG;IACH,OAAO,CAAC,KAAK;CAGd"}
|