@bernierllc/database-adapter-core 1.1.0 → 3.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.
@@ -14,8 +14,9 @@ const errors_1 = require("../errors");
14
14
  * Provides common functionality for all implementations
15
15
  */
16
16
  class BaseDatabaseAdapter {
17
+ config;
18
+ connected = false;
17
19
  constructor(config) {
18
- this.connected = false;
19
20
  this.config = config;
20
21
  }
21
22
  /**
@@ -30,7 +31,7 @@ class BaseDatabaseAdapter {
30
31
  */
31
32
  ensureConnected() {
32
33
  if (!this.connected) {
33
- throw new errors_1.ConnectionError('Database not connected. Call connect() first.', 'NOT_CONNECTED');
34
+ throw new errors_1.ConnectionError('Database not connected. Call connect() first.', { context: { code: 'NOT_CONNECTED' } });
34
35
  }
35
36
  }
36
37
  /**
@@ -13,6 +13,8 @@ exports.BaseMigrationManager = void 0;
13
13
  * Tracks and executes schema migrations
14
14
  */
15
15
  class BaseMigrationManager {
16
+ adapter;
17
+ migrations;
16
18
  constructor(adapter, migrations) {
17
19
  this.adapter = adapter;
18
20
  this.migrations = migrations;
@@ -14,14 +14,14 @@ exports.BaseQueryBuilder = void 0;
14
14
  * @template T - Type of entity being queried
15
15
  */
16
16
  class BaseQueryBuilder {
17
- constructor() {
18
- this._select = [];
19
- this._from = '';
20
- this._where = [];
21
- this._params = [];
22
- this._orderBy = [];
23
- this._joins = [];
24
- }
17
+ _select = [];
18
+ _from = '';
19
+ _where = [];
20
+ _params = [];
21
+ _orderBy = [];
22
+ _limit;
23
+ _offset;
24
+ _joins = [];
25
25
  /**
26
26
  * Select specific columns
27
27
  */
@@ -0,0 +1,53 @@
1
+ /**
2
+ * Typed error code union for database-adapter-core errors.
3
+ */
4
+ export type DatabaseAdapterCoreErrorCode = 'DATABASE_ERROR' | 'CONNECTION_ERROR' | 'QUERY_ERROR' | 'INVALID_INPUT' | 'OPERATION_FAILED';
5
+ /**
6
+ * Options bag accepted by all database-adapter-core error classes.
7
+ *
8
+ * - `cause`: chained underlying error (ES2022 Error.cause).
9
+ * - `code`: a typed error code from {@link DatabaseAdapterCoreErrorCode}.
10
+ * - `context`: arbitrary structured context — host/port/query/params/etc.
11
+ */
12
+ export interface DatabaseAdapterCoreErrorOptions {
13
+ cause?: Error;
14
+ code?: DatabaseAdapterCoreErrorCode;
15
+ context?: Record<string, unknown>;
16
+ }
17
+ /**
18
+ * Base database error class.
19
+ * All database-specific errors inherit from this.
20
+ *
21
+ * Uses native ES2022 `Error.cause` for error chaining — read the underlying
22
+ * error via `error.cause` (not `.originalError`, which was removed in 2.0.0).
23
+ */
24
+ export declare class DatabaseError extends Error {
25
+ readonly code: DatabaseAdapterCoreErrorCode;
26
+ readonly context?: Record<string, unknown>;
27
+ constructor(message: string, options?: DatabaseAdapterCoreErrorOptions);
28
+ }
29
+ /**
30
+ * Connection-specific database error.
31
+ * Thrown when connection operations fail.
32
+ *
33
+ * Host/port and similar details should be passed via `options.context`.
34
+ */
35
+ export declare class ConnectionError extends DatabaseError {
36
+ constructor(message: string, options?: Omit<DatabaseAdapterCoreErrorOptions, 'code'>);
37
+ }
38
+ /**
39
+ * Query-specific database error.
40
+ * Thrown when query execution fails.
41
+ *
42
+ * SQL/params and similar details should be passed via `options.context`.
43
+ */
44
+ export declare class QueryError extends DatabaseError {
45
+ constructor(message: string, options?: Omit<DatabaseAdapterCoreErrorOptions, 'code'>);
46
+ }
47
+ /**
48
+ * Cross-package naming alias for {@link DatabaseError}.
49
+ * Useful when consuming code wants to disambiguate between several
50
+ * package-specific base error classes via a fully qualified name.
51
+ */
52
+ export { DatabaseError as DatabaseAdapterCoreError };
53
+ //# sourceMappingURL=errors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAQA;;GAEG;AACH,MAAM,MAAM,4BAA4B,GACpC,gBAAgB,GAChB,kBAAkB,GAClB,aAAa,GACb,eAAe,GACf,kBAAkB,CAAC;AAEvB;;;;;;GAMG;AACH,MAAM,WAAW,+BAA+B;IAC9C,KAAK,CAAC,EAAE,KAAK,CAAC;IACd,IAAI,CAAC,EAAE,4BAA4B,CAAC;IACpC,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACnC;AAED;;;;;;GAMG;AACH,qBAAa,aAAc,SAAQ,KAAK;IACtC,SAAgB,IAAI,EAAE,4BAA4B,CAAC;IACnD,SAAgB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;gBAEtC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,+BAA+B;CASvE;AAED;;;;;GAKG;AACH,qBAAa,eAAgB,SAAQ,aAAa;gBAE9C,OAAO,EAAE,MAAM,EACf,OAAO,CAAC,EAAE,IAAI,CAAC,+BAA+B,EAAE,MAAM,CAAC;CAK1D;AAED;;;;;GAKG;AACH,qBAAa,UAAW,SAAQ,aAAa;gBAEzC,OAAO,EAAE,MAAM,EACf,OAAO,CAAC,EAAE,IAAI,CAAC,+BAA+B,EAAE,MAAM,CAAC;CAK1D;AAED;;;;GAIG;AACH,OAAO,EAAE,aAAa,IAAI,wBAAwB,EAAE,CAAC"}
package/dist/errors.js ADDED
@@ -0,0 +1,58 @@
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.DatabaseAdapterCoreError = exports.QueryError = exports.ConnectionError = exports.DatabaseError = void 0;
11
+ /**
12
+ * Base database error class.
13
+ * All database-specific errors inherit from this.
14
+ *
15
+ * Uses native ES2022 `Error.cause` for error chaining — read the underlying
16
+ * error via `error.cause` (not `.originalError`, which was removed in 2.0.0).
17
+ */
18
+ class DatabaseError extends Error {
19
+ code;
20
+ context;
21
+ constructor(message, options) {
22
+ super(message, options?.cause ? { cause: options.cause } : undefined);
23
+ this.name = 'DatabaseError';
24
+ this.code = options?.code ?? 'DATABASE_ERROR';
25
+ if (options?.context !== undefined) {
26
+ this.context = options.context;
27
+ }
28
+ Error.captureStackTrace?.(this, this.constructor);
29
+ }
30
+ }
31
+ exports.DatabaseError = DatabaseError;
32
+ exports.DatabaseAdapterCoreError = DatabaseError;
33
+ /**
34
+ * Connection-specific database error.
35
+ * Thrown when connection operations fail.
36
+ *
37
+ * Host/port and similar details should be passed via `options.context`.
38
+ */
39
+ class ConnectionError extends DatabaseError {
40
+ constructor(message, options) {
41
+ super(message, { ...options, code: 'CONNECTION_ERROR' });
42
+ this.name = 'ConnectionError';
43
+ }
44
+ }
45
+ exports.ConnectionError = ConnectionError;
46
+ /**
47
+ * Query-specific database error.
48
+ * Thrown when query execution fails.
49
+ *
50
+ * SQL/params and similar details should be passed via `options.context`.
51
+ */
52
+ class QueryError extends DatabaseError {
53
+ constructor(message, options) {
54
+ super(message, { ...options, code: 'QUERY_ERROR' });
55
+ this.name = 'QueryError';
56
+ }
57
+ }
58
+ exports.QueryError = QueryError;
@@ -13,9 +13,7 @@ exports.RLSContextManager = void 0;
13
13
  * Enables multi-tenant security and user-based access control
14
14
  */
15
15
  class RLSContextManager {
16
- constructor() {
17
- this.context = null;
18
- }
16
+ context = null;
19
17
  /**
20
18
  * Set RLS context for current operation
21
19
  * Context is scoped to this manager instance
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bernierllc/database-adapter-core",
3
- "version": "1.1.0",
3
+ "version": "3.0.0",
4
4
  "description": "Abstract Database Interface for MECE Architecture - provides database-agnostic interfaces and base implementations for all database operations",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -19,8 +19,8 @@
19
19
  "author": "Bernier LLC",
20
20
  "license": "UNLICENSED",
21
21
  "dependencies": {
22
- "@bernierllc/crypto-utils": "1.3.0",
23
- "@bernierllc/logger": "1.6.0"
22
+ "@bernierllc/crypto-utils": "1.4.0",
23
+ "@bernierllc/logger": "1.7.0"
24
24
  },
25
25
  "devDependencies": {
26
26
  "@types/jest": "^29.5.0",
@@ -38,7 +38,7 @@
38
38
  "directory": "packages/core/database-adapter-core"
39
39
  },
40
40
  "files": [
41
- "dist",
41
+ "dist/**/*",
42
42
  "README.md"
43
43
  ],
44
44
  "publishConfig": {
@@ -1,17 +0,0 @@
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
@@ -1 +0,0 @@
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"}
@@ -1,27 +0,0 @@
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;
@@ -1,16 +0,0 @@
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
@@ -1 +0,0 @@
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"}
@@ -1,27 +0,0 @@
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;
@@ -1,17 +0,0 @@
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
@@ -1 +0,0 @@
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"}
@@ -1,27 +0,0 @@
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;
@@ -1,4 +0,0 @@
1
- export * from './DatabaseError';
2
- export * from './ConnectionError';
3
- export * from './QueryError';
4
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
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"}
@@ -1,26 +0,0 @@
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);