@bernierllc/database-adapter-core 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.
Files changed (68) hide show
  1. package/README.md +467 -0
  2. package/dist/base/BaseDatabaseAdapter.d.ts +34 -0
  3. package/dist/base/BaseDatabaseAdapter.d.ts.map +1 -0
  4. package/dist/base/BaseDatabaseAdapter.js +52 -0
  5. package/dist/base/BaseMigrationManager.d.ts +41 -0
  6. package/dist/base/BaseMigrationManager.d.ts.map +1 -0
  7. package/dist/base/BaseMigrationManager.js +113 -0
  8. package/dist/base/BaseQueryBuilder.d.ts +68 -0
  9. package/dist/base/BaseQueryBuilder.d.ts.map +1 -0
  10. package/dist/base/BaseQueryBuilder.js +103 -0
  11. package/dist/base/BaseTransaction.d.ts +13 -0
  12. package/dist/base/BaseTransaction.d.ts.map +1 -0
  13. package/dist/base/BaseTransaction.js +17 -0
  14. package/dist/base/index.d.ts +5 -0
  15. package/dist/base/index.d.ts.map +1 -0
  16. package/dist/base/index.js +27 -0
  17. package/dist/errors/ConnectionError.d.ts +17 -0
  18. package/dist/errors/ConnectionError.d.ts.map +1 -0
  19. package/dist/errors/ConnectionError.js +27 -0
  20. package/dist/errors/DatabaseError.d.ts +16 -0
  21. package/dist/errors/DatabaseError.d.ts.map +1 -0
  22. package/dist/errors/DatabaseError.js +27 -0
  23. package/dist/errors/QueryError.d.ts +17 -0
  24. package/dist/errors/QueryError.d.ts.map +1 -0
  25. package/dist/errors/QueryError.js +27 -0
  26. package/dist/errors/index.d.ts +4 -0
  27. package/dist/errors/index.d.ts.map +1 -0
  28. package/dist/errors/index.js +26 -0
  29. package/dist/index.d.ts +11 -0
  30. package/dist/index.d.ts.map +1 -0
  31. package/dist/index.js +37 -0
  32. package/dist/interfaces/IConnectionPool.d.ts +41 -0
  33. package/dist/interfaces/IConnectionPool.d.ts.map +1 -0
  34. package/dist/interfaces/IConnectionPool.js +9 -0
  35. package/dist/interfaces/IDatabaseAdapter.d.ts +45 -0
  36. package/dist/interfaces/IDatabaseAdapter.d.ts.map +1 -0
  37. package/dist/interfaces/IDatabaseAdapter.js +9 -0
  38. package/dist/interfaces/IDatabaseConfig.d.ts +40 -0
  39. package/dist/interfaces/IDatabaseConfig.d.ts.map +1 -0
  40. package/dist/interfaces/IDatabaseConfig.js +9 -0
  41. package/dist/interfaces/IDatabaseHealth.d.ts +16 -0
  42. package/dist/interfaces/IDatabaseHealth.d.ts.map +1 -0
  43. package/dist/interfaces/IDatabaseHealth.js +9 -0
  44. package/dist/interfaces/IMigration.d.ts +54 -0
  45. package/dist/interfaces/IMigration.d.ts.map +1 -0
  46. package/dist/interfaces/IMigration.js +9 -0
  47. package/dist/interfaces/IQueryBuilder.d.ts +106 -0
  48. package/dist/interfaces/IQueryBuilder.d.ts.map +1 -0
  49. package/dist/interfaces/IQueryBuilder.js +9 -0
  50. package/dist/interfaces/IQueryResult.d.ts +28 -0
  51. package/dist/interfaces/IQueryResult.d.ts.map +1 -0
  52. package/dist/interfaces/IQueryResult.js +9 -0
  53. package/dist/interfaces/IRLSContext.d.ts +15 -0
  54. package/dist/interfaces/IRLSContext.d.ts.map +1 -0
  55. package/dist/interfaces/IRLSContext.js +9 -0
  56. package/dist/interfaces/ITransaction.d.ts +32 -0
  57. package/dist/interfaces/ITransaction.d.ts.map +1 -0
  58. package/dist/interfaces/ITransaction.js +9 -0
  59. package/dist/interfaces/index.d.ts +10 -0
  60. package/dist/interfaces/index.d.ts.map +1 -0
  61. package/dist/interfaces/index.js +32 -0
  62. package/dist/rls/RLSContextManager.d.ts +45 -0
  63. package/dist/rls/RLSContextManager.d.ts.map +1 -0
  64. package/dist/rls/RLSContextManager.js +88 -0
  65. package/dist/rls/index.d.ts +2 -0
  66. package/dist/rls/index.d.ts.map +1 -0
  67. package/dist/rls/index.js +24 -0
  68. package/package.json +55 -0
@@ -0,0 +1,113 @@
1
+ "use strict";
2
+ /*
3
+ Copyright (c) 2025 Bernier LLC
4
+
5
+ This file is licensed to the client under a limited-use license.
6
+ The client may use and modify this code *only within the scope of the project it was delivered for*.
7
+ Redistribution or use in other products or commercial offerings is not permitted without written consent from Bernier LLC.
8
+ */
9
+ Object.defineProperty(exports, "__esModule", { value: true });
10
+ exports.BaseMigrationManager = void 0;
11
+ /**
12
+ * Base migration manager implementation
13
+ * Tracks and executes schema migrations
14
+ */
15
+ class BaseMigrationManager {
16
+ constructor(adapter, migrations) {
17
+ this.adapter = adapter;
18
+ this.migrations = migrations;
19
+ }
20
+ /**
21
+ * Run all pending migrations
22
+ * @throws Error if any migration fails
23
+ */
24
+ async up() {
25
+ await this.ensureMigrationsTable();
26
+ const applied = await this.getAppliedMigrations();
27
+ const pending = this.migrations.filter(m => !applied.includes(m.id));
28
+ for (const migration of pending) {
29
+ const transaction = await this.adapter.beginTransaction();
30
+ try {
31
+ await migration.up(this.adapter);
32
+ await this.recordMigration(migration.id, migration.name);
33
+ await transaction.commit();
34
+ }
35
+ catch (error) {
36
+ await transaction.rollback();
37
+ const message = error instanceof Error ? error.message : String(error);
38
+ throw new Error(`Migration ${migration.name} failed: ${message}`);
39
+ }
40
+ }
41
+ }
42
+ /**
43
+ * Rollback last applied migration
44
+ * @throws Error if no migrations to rollback or rollback fails
45
+ */
46
+ async down() {
47
+ const applied = await this.getAppliedMigrations();
48
+ if (applied.length === 0) {
49
+ throw new Error('No migrations to rollback');
50
+ }
51
+ const lastMigrationId = applied[applied.length - 1];
52
+ const migration = this.migrations.find(m => m.id === lastMigrationId);
53
+ if (!migration) {
54
+ throw new Error(`Migration ${lastMigrationId} not found`);
55
+ }
56
+ const transaction = await this.adapter.beginTransaction();
57
+ try {
58
+ await migration.down(this.adapter);
59
+ await this.removeMigration(migration.id);
60
+ await transaction.commit();
61
+ }
62
+ catch (error) {
63
+ await transaction.rollback();
64
+ const message = error instanceof Error ? error.message : String(error);
65
+ throw new Error(`Rollback of ${migration.name} failed: ${message}`);
66
+ }
67
+ }
68
+ /**
69
+ * Get status of all migrations
70
+ */
71
+ async status() {
72
+ await this.ensureMigrationsTable();
73
+ const applied = await this.getAppliedMigrations();
74
+ return this.migrations.map(m => ({
75
+ id: m.id,
76
+ name: m.name,
77
+ appliedAt: applied.includes(m.id) ? new Date() : null,
78
+ status: applied.includes(m.id) ? 'applied' : 'pending'
79
+ }));
80
+ }
81
+ /**
82
+ * Ensure migrations table exists
83
+ */
84
+ async ensureMigrationsTable() {
85
+ await this.adapter.query(`
86
+ CREATE TABLE IF NOT EXISTS migrations (
87
+ id VARCHAR(255) PRIMARY KEY,
88
+ name VARCHAR(255) NOT NULL,
89
+ applied_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
90
+ )
91
+ `);
92
+ }
93
+ /**
94
+ * Get list of applied migration IDs in order
95
+ */
96
+ async getAppliedMigrations() {
97
+ const result = await this.adapter.query('SELECT id FROM migrations ORDER BY applied_at ASC');
98
+ return result.rows.map(r => r.id);
99
+ }
100
+ /**
101
+ * Record a migration as applied
102
+ */
103
+ async recordMigration(id, name) {
104
+ await this.adapter.query('INSERT INTO migrations (id, name) VALUES ($1, $2)', [id, name]);
105
+ }
106
+ /**
107
+ * Remove a migration record
108
+ */
109
+ async removeMigration(id) {
110
+ await this.adapter.query('DELETE FROM migrations WHERE id = $1', [id]);
111
+ }
112
+ }
113
+ exports.BaseMigrationManager = BaseMigrationManager;
@@ -0,0 +1,68 @@
1
+ import { IQueryBuilder, IDatabaseAdapter, IQueryResult } from '../interfaces';
2
+ /**
3
+ * Base query builder implementation
4
+ * Provides common functionality for all SQL dialects
5
+ * @template T - Type of entity being queried
6
+ */
7
+ export declare abstract class BaseQueryBuilder<T = any> implements IQueryBuilder<T> {
8
+ protected _select: string[];
9
+ protected _from: string;
10
+ protected _where: string[];
11
+ protected _params: any[];
12
+ protected _orderBy: string[];
13
+ protected _limit?: number;
14
+ protected _offset?: number;
15
+ protected _joins: string[];
16
+ /**
17
+ * Select specific columns
18
+ */
19
+ select(...columns: string[]): IQueryBuilder<T>;
20
+ /**
21
+ * Specify table to query from
22
+ */
23
+ from(table: string): IQueryBuilder<T>;
24
+ /**
25
+ * Add WHERE condition with parameters
26
+ */
27
+ where(condition: string, params?: readonly unknown[]): IQueryBuilder<T>;
28
+ /**
29
+ * Add WHERE IN condition
30
+ */
31
+ whereIn(column: string, values: readonly unknown[]): IQueryBuilder<T>;
32
+ /**
33
+ * Add ORDER BY clause
34
+ */
35
+ orderBy(column: string, direction?: 'ASC' | 'DESC'): IQueryBuilder<T>;
36
+ /**
37
+ * Limit number of results
38
+ */
39
+ limit(count: number): IQueryBuilder<T>;
40
+ /**
41
+ * Offset results (skip rows)
42
+ */
43
+ offset(count: number): IQueryBuilder<T>;
44
+ /**
45
+ * Add INNER JOIN
46
+ */
47
+ join(table: string, condition: string): IQueryBuilder<T>;
48
+ /**
49
+ * Add LEFT JOIN
50
+ */
51
+ leftJoin(table: string, condition: string): IQueryBuilder<T>;
52
+ /**
53
+ * Execute the query using provided adapter
54
+ */
55
+ execute(adapter: IDatabaseAdapter): Promise<IQueryResult<T>>;
56
+ /**
57
+ * Abstract methods - MUST be implemented by dialect-specific builders
58
+ */
59
+ abstract insert(data: Partial<T>): IQueryBuilder<T>;
60
+ abstract insertMany(data: Partial<T>[]): IQueryBuilder<T>;
61
+ abstract update(data: Partial<T>): IQueryBuilder<T>;
62
+ abstract delete(): IQueryBuilder<T>;
63
+ abstract build(): {
64
+ sql: string;
65
+ params: any[];
66
+ };
67
+ }
68
+ //# sourceMappingURL=BaseQueryBuilder.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"BaseQueryBuilder.d.ts","sourceRoot":"","sources":["../../src/base/BaseQueryBuilder.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,aAAa,EAAE,gBAAgB,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAE9E;;;;GAIG;AACH,8BAAsB,gBAAgB,CAAC,CAAC,GAAG,GAAG,CAAE,YAAW,aAAa,CAAC,CAAC,CAAC;IACzE,SAAS,CAAC,OAAO,EAAE,MAAM,EAAE,CAAM;IACjC,SAAS,CAAC,KAAK,EAAE,MAAM,CAAM;IAC7B,SAAS,CAAC,MAAM,EAAE,MAAM,EAAE,CAAM;IAChC,SAAS,CAAC,OAAO,EAAE,GAAG,EAAE,CAAM;IAC9B,SAAS,CAAC,QAAQ,EAAE,MAAM,EAAE,CAAM;IAClC,SAAS,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IAC1B,SAAS,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC;IAC3B,SAAS,CAAC,MAAM,EAAE,MAAM,EAAE,CAAM;IAEhC;;OAEG;IACI,MAAM,CAAC,GAAG,OAAO,EAAE,MAAM,EAAE,GAAG,aAAa,CAAC,CAAC,CAAC;IAKrD;;OAEG;IACI,IAAI,CAAC,KAAK,EAAE,MAAM,GAAG,aAAa,CAAC,CAAC,CAAC;IAK5C;;OAEG;IACI,KAAK,CAAC,SAAS,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,SAAS,OAAO,EAAE,GAAG,aAAa,CAAC,CAAC,CAAC;IAQ9E;;OAEG;IACI,OAAO,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,SAAS,OAAO,EAAE,GAAG,aAAa,CAAC,CAAC,CAAC;IAS5E;;OAEG;IACI,OAAO,CAAC,MAAM,EAAE,MAAM,EAAE,SAAS,GAAE,KAAK,GAAG,MAAc,GAAG,aAAa,CAAC,CAAC,CAAC;IAKnF;;OAEG;IACI,KAAK,CAAC,KAAK,EAAE,MAAM,GAAG,aAAa,CAAC,CAAC,CAAC;IAK7C;;OAEG;IACI,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,aAAa,CAAC,CAAC,CAAC;IAK9C;;OAEG;IACI,IAAI,CAAC,KAAK,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,aAAa,CAAC,CAAC,CAAC;IAK/D;;OAEG;IACI,QAAQ,CAAC,KAAK,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,aAAa,CAAC,CAAC,CAAC;IAKnE;;OAEG;IACU,OAAO,CAAC,OAAO,EAAE,gBAAgB,GAAG,OAAO,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC;IAKzE;;OAEG;IACH,QAAQ,CAAC,MAAM,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC,CAAC,GAAG,aAAa,CAAC,CAAC,CAAC;IACnD,QAAQ,CAAC,UAAU,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC,CAAC,EAAE,GAAG,aAAa,CAAC,CAAC,CAAC;IACzD,QAAQ,CAAC,MAAM,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC,CAAC,GAAG,aAAa,CAAC,CAAC,CAAC;IACnD,QAAQ,CAAC,MAAM,IAAI,aAAa,CAAC,CAAC,CAAC;IACnC,QAAQ,CAAC,KAAK,IAAI;QAAE,GAAG,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,GAAG,EAAE,CAAA;KAAE;CACjD"}
@@ -0,0 +1,103 @@
1
+ "use strict";
2
+ /*
3
+ Copyright (c) 2025 Bernier LLC
4
+
5
+ This file is licensed to the client under a limited-use license.
6
+ The client may use and modify this code *only within the scope of the project it was delivered for*.
7
+ Redistribution or use in other products or commercial offerings is not permitted without written consent from Bernier LLC.
8
+ */
9
+ Object.defineProperty(exports, "__esModule", { value: true });
10
+ exports.BaseQueryBuilder = void 0;
11
+ /**
12
+ * Base query builder implementation
13
+ * Provides common functionality for all SQL dialects
14
+ * @template T - Type of entity being queried
15
+ */
16
+ class BaseQueryBuilder {
17
+ constructor() {
18
+ this._select = [];
19
+ this._from = '';
20
+ this._where = [];
21
+ this._params = [];
22
+ this._orderBy = [];
23
+ this._joins = [];
24
+ }
25
+ /**
26
+ * Select specific columns
27
+ */
28
+ select(...columns) {
29
+ this._select.push(...columns);
30
+ return this;
31
+ }
32
+ /**
33
+ * Specify table to query from
34
+ */
35
+ from(table) {
36
+ this._from = table;
37
+ return this;
38
+ }
39
+ /**
40
+ * Add WHERE condition with parameters
41
+ */
42
+ where(condition, params) {
43
+ this._where.push(condition);
44
+ if (params) {
45
+ this._params.push(...params);
46
+ }
47
+ return this;
48
+ }
49
+ /**
50
+ * Add WHERE IN condition
51
+ */
52
+ whereIn(column, values) {
53
+ const placeholders = values
54
+ .map((_, i) => `$${this._params.length + i + 1}`)
55
+ .join(', ');
56
+ this._where.push(`${column} IN (${placeholders})`);
57
+ this._params.push(...values);
58
+ return this;
59
+ }
60
+ /**
61
+ * Add ORDER BY clause
62
+ */
63
+ orderBy(column, direction = 'ASC') {
64
+ this._orderBy.push(`${column} ${direction}`);
65
+ return this;
66
+ }
67
+ /**
68
+ * Limit number of results
69
+ */
70
+ limit(count) {
71
+ this._limit = count;
72
+ return this;
73
+ }
74
+ /**
75
+ * Offset results (skip rows)
76
+ */
77
+ offset(count) {
78
+ this._offset = count;
79
+ return this;
80
+ }
81
+ /**
82
+ * Add INNER JOIN
83
+ */
84
+ join(table, condition) {
85
+ this._joins.push(`JOIN ${table} ON ${condition}`);
86
+ return this;
87
+ }
88
+ /**
89
+ * Add LEFT JOIN
90
+ */
91
+ leftJoin(table, condition) {
92
+ this._joins.push(`LEFT JOIN ${table} ON ${condition}`);
93
+ return this;
94
+ }
95
+ /**
96
+ * Execute the query using provided adapter
97
+ */
98
+ async execute(adapter) {
99
+ const { sql, params } = this.build();
100
+ return adapter.query(sql, params);
101
+ }
102
+ }
103
+ exports.BaseQueryBuilder = BaseQueryBuilder;
@@ -0,0 +1,13 @@
1
+ import { ITransaction, IQueryResult } from '../interfaces';
2
+ /**
3
+ * Abstract transaction base class
4
+ * Provides base structure for transaction implementations
5
+ */
6
+ export declare abstract class BaseTransaction implements ITransaction {
7
+ abstract id: string;
8
+ abstract query<T = any>(sql: string, params?: any[]): Promise<IQueryResult<T>>;
9
+ abstract commit(): Promise<void>;
10
+ abstract rollback(): Promise<void>;
11
+ abstract isActive(): boolean;
12
+ }
13
+ //# sourceMappingURL=BaseTransaction.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"BaseTransaction.d.ts","sourceRoot":"","sources":["../../src/base/BaseTransaction.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAE3D;;;GAGG;AACH,8BAAsB,eAAgB,YAAW,YAAY;IAC3D,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,KAAK,CAAC,CAAC,GAAG,GAAG,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,GAAG,EAAE,GAAG,OAAO,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC;IAC9E,QAAQ,CAAC,MAAM,IAAI,OAAO,CAAC,IAAI,CAAC;IAChC,QAAQ,CAAC,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC;IAClC,QAAQ,CAAC,QAAQ,IAAI,OAAO;CAC7B"}
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ /*
3
+ Copyright (c) 2025 Bernier LLC
4
+
5
+ This file is licensed to the client under a limited-use license.
6
+ The client may use and modify this code *only within the scope of the project it was delivered for*.
7
+ Redistribution or use in other products or commercial offerings is not permitted without written consent from Bernier LLC.
8
+ */
9
+ Object.defineProperty(exports, "__esModule", { value: true });
10
+ exports.BaseTransaction = void 0;
11
+ /**
12
+ * Abstract transaction base class
13
+ * Provides base structure for transaction implementations
14
+ */
15
+ class BaseTransaction {
16
+ }
17
+ exports.BaseTransaction = BaseTransaction;
@@ -0,0 +1,5 @@
1
+ export * from './BaseDatabaseAdapter';
2
+ export * from './BaseTransaction';
3
+ export * from './BaseQueryBuilder';
4
+ export * from './BaseMigrationManager';
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/base/index.ts"],"names":[],"mappings":"AAQA,cAAc,uBAAuB,CAAC;AACtC,cAAc,mBAAmB,CAAC;AAClC,cAAc,oBAAoB,CAAC;AACnC,cAAc,wBAAwB,CAAC"}
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ /*
3
+ Copyright (c) 2025 Bernier LLC
4
+
5
+ This file is licensed to the client under a limited-use license.
6
+ The client may use and modify this code *only within the scope of the project it was delivered for*.
7
+ Redistribution or use in other products or commercial offerings is not permitted without written consent from Bernier LLC.
8
+ */
9
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ var desc = Object.getOwnPropertyDescriptor(m, k);
12
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
13
+ desc = { enumerable: true, get: function() { return m[k]; } };
14
+ }
15
+ Object.defineProperty(o, k2, desc);
16
+ }) : (function(o, m, k, k2) {
17
+ if (k2 === undefined) k2 = k;
18
+ o[k2] = m[k];
19
+ }));
20
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
21
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
22
+ };
23
+ Object.defineProperty(exports, "__esModule", { value: true });
24
+ __exportStar(require("./BaseDatabaseAdapter"), exports);
25
+ __exportStar(require("./BaseTransaction"), exports);
26
+ __exportStar(require("./BaseQueryBuilder"), exports);
27
+ __exportStar(require("./BaseMigrationManager"), exports);
@@ -0,0 +1,17 @@
1
+ import { DatabaseError } from './DatabaseError';
2
+ /**
3
+ * Connection-specific database error
4
+ * Thrown when connection operations fail
5
+ */
6
+ export declare class ConnectionError extends DatabaseError {
7
+ /**
8
+ * Host that failed to connect
9
+ */
10
+ readonly host?: string;
11
+ /**
12
+ * Port that failed to connect
13
+ */
14
+ readonly port?: number;
15
+ constructor(message: string, code?: string, originalError?: Error, host?: string, port?: number);
16
+ }
17
+ //# sourceMappingURL=ConnectionError.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ConnectionError.d.ts","sourceRoot":"","sources":["../../src/errors/ConnectionError.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAEhD;;;GAGG;AACH,qBAAa,eAAgB,SAAQ,aAAa;IAChD;;OAEG;IACH,SAAgB,IAAI,CAAC,EAAE,MAAM,CAAC;IAE9B;;OAEG;IACH,SAAgB,IAAI,CAAC,EAAE,MAAM,CAAC;gBAG5B,OAAO,EAAE,MAAM,EACf,IAAI,CAAC,EAAE,MAAM,EACb,aAAa,CAAC,EAAE,KAAK,EACrB,IAAI,CAAC,EAAE,MAAM,EACb,IAAI,CAAC,EAAE,MAAM;CAWhB"}
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ /*
3
+ Copyright (c) 2025 Bernier LLC
4
+
5
+ This file is licensed to the client under a limited-use license.
6
+ The client may use and modify this code *only within the scope of the project it was delivered for*.
7
+ Redistribution or use in other products or commercial offerings is not permitted without written consent from Bernier LLC.
8
+ */
9
+ Object.defineProperty(exports, "__esModule", { value: true });
10
+ exports.ConnectionError = void 0;
11
+ const DatabaseError_1 = require("./DatabaseError");
12
+ /**
13
+ * Connection-specific database error
14
+ * Thrown when connection operations fail
15
+ */
16
+ class ConnectionError extends DatabaseError_1.DatabaseError {
17
+ constructor(message, code, originalError, host, port) {
18
+ super(message, code, originalError);
19
+ this.name = 'ConnectionError';
20
+ this.host = host;
21
+ this.port = port;
22
+ if (Error.captureStackTrace) {
23
+ Error.captureStackTrace(this, ConnectionError);
24
+ }
25
+ }
26
+ }
27
+ exports.ConnectionError = ConnectionError;
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Base database error class
3
+ * All database-specific errors inherit from this
4
+ */
5
+ export declare class DatabaseError extends Error {
6
+ /**
7
+ * Error code (database-specific)
8
+ */
9
+ readonly code?: string;
10
+ /**
11
+ * Original error if wrapped
12
+ */
13
+ readonly originalError?: Error;
14
+ constructor(message: string, code?: string, originalError?: Error);
15
+ }
16
+ //# sourceMappingURL=DatabaseError.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DatabaseError.d.ts","sourceRoot":"","sources":["../../src/errors/DatabaseError.ts"],"names":[],"mappings":"AAQA;;;GAGG;AACH,qBAAa,aAAc,SAAQ,KAAK;IACtC;;OAEG;IACH,SAAgB,IAAI,CAAC,EAAE,MAAM,CAAC;IAE9B;;OAEG;IACH,SAAgB,aAAa,CAAC,EAAE,KAAK,CAAC;gBAE1B,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,EAAE,aAAa,CAAC,EAAE,KAAK;CAWlE"}
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ /*
3
+ Copyright (c) 2025 Bernier LLC
4
+
5
+ This file is licensed to the client under a limited-use license.
6
+ The client may use and modify this code *only within the scope of the project it was delivered for*.
7
+ Redistribution or use in other products or commercial offerings is not permitted without written consent from Bernier LLC.
8
+ */
9
+ Object.defineProperty(exports, "__esModule", { value: true });
10
+ exports.DatabaseError = void 0;
11
+ /**
12
+ * Base database error class
13
+ * All database-specific errors inherit from this
14
+ */
15
+ class DatabaseError extends Error {
16
+ constructor(message, code, originalError) {
17
+ super(message);
18
+ this.name = 'DatabaseError';
19
+ this.code = code;
20
+ this.originalError = originalError;
21
+ // Maintain proper stack trace in V8 environments
22
+ if (Error.captureStackTrace) {
23
+ Error.captureStackTrace(this, DatabaseError);
24
+ }
25
+ }
26
+ }
27
+ exports.DatabaseError = DatabaseError;
@@ -0,0 +1,17 @@
1
+ import { DatabaseError } from './DatabaseError';
2
+ /**
3
+ * Query-specific database error
4
+ * Thrown when query execution fails
5
+ */
6
+ export declare class QueryError extends DatabaseError {
7
+ /**
8
+ * SQL query that failed
9
+ */
10
+ readonly query?: string;
11
+ /**
12
+ * Query parameters
13
+ */
14
+ readonly params?: any[];
15
+ constructor(message: string, code?: string, originalError?: Error, query?: string, params?: any[]);
16
+ }
17
+ //# sourceMappingURL=QueryError.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"QueryError.d.ts","sourceRoot":"","sources":["../../src/errors/QueryError.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAEhD;;;GAGG;AACH,qBAAa,UAAW,SAAQ,aAAa;IAC3C;;OAEG;IACH,SAAgB,KAAK,CAAC,EAAE,MAAM,CAAC;IAE/B;;OAEG;IACH,SAAgB,MAAM,CAAC,EAAE,GAAG,EAAE,CAAC;gBAG7B,OAAO,EAAE,MAAM,EACf,IAAI,CAAC,EAAE,MAAM,EACb,aAAa,CAAC,EAAE,KAAK,EACrB,KAAK,CAAC,EAAE,MAAM,EACd,MAAM,CAAC,EAAE,GAAG,EAAE;CAWjB"}
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ /*
3
+ Copyright (c) 2025 Bernier LLC
4
+
5
+ This file is licensed to the client under a limited-use license.
6
+ The client may use and modify this code *only within the scope of the project it was delivered for*.
7
+ Redistribution or use in other products or commercial offerings is not permitted without written consent from Bernier LLC.
8
+ */
9
+ Object.defineProperty(exports, "__esModule", { value: true });
10
+ exports.QueryError = void 0;
11
+ const DatabaseError_1 = require("./DatabaseError");
12
+ /**
13
+ * Query-specific database error
14
+ * Thrown when query execution fails
15
+ */
16
+ class QueryError extends DatabaseError_1.DatabaseError {
17
+ constructor(message, code, originalError, query, params) {
18
+ super(message, code, originalError);
19
+ this.name = 'QueryError';
20
+ this.query = query;
21
+ this.params = params;
22
+ if (Error.captureStackTrace) {
23
+ Error.captureStackTrace(this, QueryError);
24
+ }
25
+ }
26
+ }
27
+ exports.QueryError = QueryError;
@@ -0,0 +1,4 @@
1
+ export * from './DatabaseError';
2
+ export * from './ConnectionError';
3
+ export * from './QueryError';
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/errors/index.ts"],"names":[],"mappings":"AAQA,cAAc,iBAAiB,CAAC;AAChC,cAAc,mBAAmB,CAAC;AAClC,cAAc,cAAc,CAAC"}
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ /*
3
+ Copyright (c) 2025 Bernier LLC
4
+
5
+ This file is licensed to the client under a limited-use license.
6
+ The client may use and modify this code *only within the scope of the project it was delivered for*.
7
+ Redistribution or use in other products or commercial offerings is not permitted without written consent from Bernier LLC.
8
+ */
9
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ var desc = Object.getOwnPropertyDescriptor(m, k);
12
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
13
+ desc = { enumerable: true, get: function() { return m[k]; } };
14
+ }
15
+ Object.defineProperty(o, k2, desc);
16
+ }) : (function(o, m, k, k2) {
17
+ if (k2 === undefined) k2 = k;
18
+ o[k2] = m[k];
19
+ }));
20
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
21
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
22
+ };
23
+ Object.defineProperty(exports, "__esModule", { value: true });
24
+ __exportStar(require("./DatabaseError"), exports);
25
+ __exportStar(require("./ConnectionError"), exports);
26
+ __exportStar(require("./QueryError"), exports);
@@ -0,0 +1,11 @@
1
+ /**
2
+ * @bernierllc/database-adapter-core
3
+ *
4
+ * Abstract Database Interface for MECE Architecture
5
+ * Provides database-agnostic interfaces and base implementations for all database operations
6
+ */
7
+ export * from './interfaces';
8
+ export * from './base';
9
+ export * from './rls';
10
+ export * from './errors';
11
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAQA;;;;;GAKG;AAGH,cAAc,cAAc,CAAC;AAG7B,cAAc,QAAQ,CAAC;AAGvB,cAAc,OAAO,CAAC;AAGtB,cAAc,UAAU,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,37 @@
1
+ "use strict";
2
+ /*
3
+ Copyright (c) 2025 Bernier LLC
4
+
5
+ This file is licensed to the client under a limited-use license.
6
+ The client may use and modify this code *only within the scope of the project it was delivered for*.
7
+ Redistribution or use in other products or commercial offerings is not permitted without written consent from Bernier LLC.
8
+ */
9
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ var desc = Object.getOwnPropertyDescriptor(m, k);
12
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
13
+ desc = { enumerable: true, get: function() { return m[k]; } };
14
+ }
15
+ Object.defineProperty(o, k2, desc);
16
+ }) : (function(o, m, k, k2) {
17
+ if (k2 === undefined) k2 = k;
18
+ o[k2] = m[k];
19
+ }));
20
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
21
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
22
+ };
23
+ Object.defineProperty(exports, "__esModule", { value: true });
24
+ /**
25
+ * @bernierllc/database-adapter-core
26
+ *
27
+ * Abstract Database Interface for MECE Architecture
28
+ * Provides database-agnostic interfaces and base implementations for all database operations
29
+ */
30
+ // Interfaces
31
+ __exportStar(require("./interfaces"), exports);
32
+ // Base classes
33
+ __exportStar(require("./base"), exports);
34
+ // RLS support
35
+ __exportStar(require("./rls"), exports);
36
+ // Errors
37
+ __exportStar(require("./errors"), exports);
@@ -0,0 +1,41 @@
1
+ import { IDatabaseAdapter } from './IDatabaseAdapter';
2
+ /**
3
+ * Connection pool statistics
4
+ */
5
+ export interface IPoolStats {
6
+ /** Total number of connections in pool */
7
+ totalConnections: number;
8
+ /** Number of active (in-use) connections */
9
+ activeConnections: number;
10
+ /** Number of idle (available) connections */
11
+ idleConnections: number;
12
+ /** Number of requests waiting for a connection */
13
+ waitingRequests: number;
14
+ }
15
+ /**
16
+ * Connection pool interface
17
+ * Manages database connection lifecycle
18
+ */
19
+ export interface IConnectionPool {
20
+ /**
21
+ * Acquire a connection from the pool
22
+ * @returns Database adapter connection
23
+ * @throws Error if pool is exhausted or timeout occurs
24
+ */
25
+ acquire(): Promise<IDatabaseAdapter>;
26
+ /**
27
+ * Return a connection to the pool
28
+ * @param connection - Connection to release
29
+ */
30
+ release(connection: IDatabaseAdapter): Promise<void>;
31
+ /**
32
+ * Close all connections in the pool
33
+ */
34
+ closeAll(): Promise<void>;
35
+ /**
36
+ * Get pool statistics
37
+ * @returns Current pool statistics
38
+ */
39
+ stats(): IPoolStats;
40
+ }
41
+ //# sourceMappingURL=IConnectionPool.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"IConnectionPool.d.ts","sourceRoot":"","sources":["../../src/interfaces/IConnectionPool.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAEtD;;GAEG;AACH,MAAM,WAAW,UAAU;IACzB,0CAA0C;IAC1C,gBAAgB,EAAE,MAAM,CAAC;IAEzB,4CAA4C;IAC5C,iBAAiB,EAAE,MAAM,CAAC;IAE1B,6CAA6C;IAC7C,eAAe,EAAE,MAAM,CAAC;IAExB,kDAAkD;IAClD,eAAe,EAAE,MAAM,CAAC;CACzB;AAED;;;GAGG;AACH,MAAM,WAAW,eAAe;IAC9B;;;;OAIG;IACH,OAAO,IAAI,OAAO,CAAC,gBAAgB,CAAC,CAAC;IAErC;;;OAGG;IACH,OAAO,CAAC,UAAU,EAAE,gBAAgB,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAErD;;OAEG;IACH,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IAE1B;;;OAGG;IACH,KAAK,IAAI,UAAU,CAAC;CACrB"}
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ /*
3
+ Copyright (c) 2025 Bernier LLC
4
+
5
+ This file is licensed to the client under a limited-use license.
6
+ The client may use and modify this code *only within the scope of the project it was delivered for*.
7
+ Redistribution or use in other products or commercial offerings is not permitted without written consent from Bernier LLC.
8
+ */
9
+ Object.defineProperty(exports, "__esModule", { value: true });