accio-orm 0.1.0 → 0.1.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/README.md +1 -0
- package/dist/connection/Connection.d.ts +6 -0
- package/dist/connection/Connection.js +60 -11
- package/dist/connection/types.d.ts +2 -0
- package/dist/decorators/Column.d.ts +3 -2
- package/dist/decorators/PrimaryColumn.d.ts +1 -1
- package/dist/decorators/PrimaryColumn.js +3 -0
- package/dist/errors/AccioError.d.ts +44 -0
- package/dist/errors/AccioError.js +55 -0
- package/dist/errors/ConnectionError.d.ts +27 -0
- package/dist/errors/ConnectionError.js +33 -0
- package/dist/errors/DatabaseError.d.ts +35 -0
- package/dist/errors/DatabaseError.js +35 -0
- package/dist/errors/QueryError.d.ts +36 -0
- package/dist/errors/QueryError.js +36 -0
- package/dist/errors/ValidationError.d.ts +35 -0
- package/dist/errors/ValidationError.js +35 -0
- package/dist/errors/index.d.ts +11 -0
- package/dist/errors/index.js +19 -0
- package/dist/index.d.ts +6 -3
- package/dist/index.js +17 -1
- package/dist/logger/LogLevel.d.ts +47 -0
- package/dist/logger/LogLevel.js +57 -0
- package/dist/logger/Logger.d.ts +171 -0
- package/dist/logger/Logger.js +207 -0
- package/dist/logger/index.d.ts +8 -0
- package/dist/logger/index.js +14 -0
- package/dist/metadata/MetadataStorage.d.ts +1 -1
- package/dist/metadata/MetadataStorage.js +12 -11
- package/dist/query/QueryBuilder.d.ts +0 -5
- package/dist/query/QueryBuilder.js +10 -31
- package/dist/repository/Repository.js +12 -11
- package/dist/types/PostgresTypes.d.ts +74 -0
- package/dist/types/PostgresTypes.js +98 -0
- package/dist/types/index.d.ts +6 -0
- package/dist/types/index.js +12 -0
- package/dist/validation/ConnectionValidation.d.ts +27 -0
- package/dist/validation/ConnectionValidation.js +58 -0
- package/dist/validation/IdentifierValidator.d.ts +101 -0
- package/dist/validation/IdentifierValidator.js +127 -0
- package/dist/validation/QueryValidator.d.ts +61 -0
- package/dist/validation/QueryValidator.js +81 -0
- package/dist/validation/index.d.ts +9 -0
- package/dist/validation/index.js +15 -0
- package/package.json +3 -2
package/README.md
CHANGED
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
Accio is a lightweight, type-safe TypeScript ORM for PostgreSQL, built from first principles with a focus on simplicity and developer experience.
|
|
6
6
|
|
|
7
|
+
[](https://www.npmjs.com/package/accio-orm)
|
|
7
8
|
[](https://www.typescriptlang.org/)
|
|
8
9
|
[](https://opensource.org/licenses/MIT)
|
|
9
10
|
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { type QueryResult } from 'pg';
|
|
2
|
+
import { Logger } from '@/logger/Logger';
|
|
2
3
|
import { Repository } from '../repository/Repository';
|
|
3
4
|
import type { ConnectionConfig } from './types';
|
|
4
5
|
export declare class Connection {
|
|
5
6
|
private pool;
|
|
7
|
+
private logger;
|
|
6
8
|
constructor(config: ConnectionConfig);
|
|
7
9
|
/**
|
|
8
10
|
* Get a repository for an entity class
|
|
@@ -22,6 +24,10 @@ export declare class Connection {
|
|
|
22
24
|
* Test the connection
|
|
23
25
|
*/
|
|
24
26
|
testConnection(): Promise<boolean>;
|
|
27
|
+
/**
|
|
28
|
+
* Get the logger instance
|
|
29
|
+
*/
|
|
30
|
+
getLogger(): Logger;
|
|
25
31
|
}
|
|
26
32
|
/**
|
|
27
33
|
* Factory function to create a connection
|
|
@@ -3,16 +3,41 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.Connection = void 0;
|
|
4
4
|
exports.connect = connect;
|
|
5
5
|
const pg_1 = require("pg");
|
|
6
|
+
const errors_1 = require("@/errors");
|
|
7
|
+
const Logger_1 = require("@/logger/Logger");
|
|
8
|
+
const validation_1 = require("@/validation");
|
|
6
9
|
const Repository_1 = require("../repository/Repository");
|
|
7
10
|
class Connection {
|
|
8
11
|
constructor(config) {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
12
|
+
// validate connection configuration
|
|
13
|
+
validation_1.ConnectionValidator.validate(config);
|
|
14
|
+
// initialize logger
|
|
15
|
+
this.logger = new Logger_1.Logger(config.logger);
|
|
16
|
+
try {
|
|
17
|
+
this.pool = new pg_1.Pool({
|
|
18
|
+
host: config.host,
|
|
19
|
+
port: config.port ?? 5432,
|
|
20
|
+
database: config.database,
|
|
21
|
+
user: config.user,
|
|
22
|
+
password: config.password
|
|
23
|
+
});
|
|
24
|
+
this.logger.info('Database connection pool created', {
|
|
25
|
+
host: config.host,
|
|
26
|
+
database: config.database,
|
|
27
|
+
port: config.database ?? 5432
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
catch (error) {
|
|
31
|
+
this.logger.error('Failed to create connection pool', error, {
|
|
32
|
+
host: config.host,
|
|
33
|
+
database: config.database
|
|
34
|
+
});
|
|
35
|
+
throw new errors_1.ConnectionError('Failed to create database connection pool', {
|
|
36
|
+
host: config.host,
|
|
37
|
+
database: config.database,
|
|
38
|
+
port: config.database ?? 5432
|
|
39
|
+
}, error);
|
|
40
|
+
}
|
|
16
41
|
}
|
|
17
42
|
/**
|
|
18
43
|
* Get a repository for an entity class
|
|
@@ -26,19 +51,35 @@ class Connection {
|
|
|
26
51
|
* Execute a raw SQL query
|
|
27
52
|
*/
|
|
28
53
|
async query(sql, params) {
|
|
54
|
+
const startTime = Date.now();
|
|
29
55
|
try {
|
|
30
|
-
|
|
56
|
+
const result = await this.pool.query(sql, params);
|
|
57
|
+
const duration = Date.now() - startTime;
|
|
58
|
+
this.logger.query(sql, params, duration);
|
|
59
|
+
return result;
|
|
31
60
|
}
|
|
32
61
|
catch (error) {
|
|
33
|
-
|
|
34
|
-
|
|
62
|
+
const duration = Date.now() - startTime;
|
|
63
|
+
this.logger.error('Query execution failed', error, {
|
|
64
|
+
sql,
|
|
65
|
+
params,
|
|
66
|
+
duration
|
|
67
|
+
});
|
|
68
|
+
throw new errors_1.QueryError('Query Execution failed', sql, params, error);
|
|
35
69
|
}
|
|
36
70
|
}
|
|
37
71
|
/**
|
|
38
72
|
* Close all connections in the pool
|
|
39
73
|
*/
|
|
40
74
|
async close() {
|
|
41
|
-
|
|
75
|
+
try {
|
|
76
|
+
await this.pool.end();
|
|
77
|
+
this.logger.info('Database connection pool closed');
|
|
78
|
+
}
|
|
79
|
+
catch (error) {
|
|
80
|
+
this.logger.error('Failed to close connection pool', error);
|
|
81
|
+
throw new errors_1.ConnectionError('Failed to close database connection pool', undefined, error);
|
|
82
|
+
}
|
|
42
83
|
}
|
|
43
84
|
/**
|
|
44
85
|
* Test the connection
|
|
@@ -46,13 +87,21 @@ class Connection {
|
|
|
46
87
|
async testConnection() {
|
|
47
88
|
try {
|
|
48
89
|
await this.pool.query('SELECT 1');
|
|
90
|
+
this.logger.info('Connection test successful');
|
|
49
91
|
return true;
|
|
50
92
|
}
|
|
51
93
|
catch (error) {
|
|
52
94
|
console.log('Connection test failed:', error);
|
|
95
|
+
this.logger.error('Connection test failed', error);
|
|
53
96
|
return false;
|
|
54
97
|
}
|
|
55
98
|
}
|
|
99
|
+
/**
|
|
100
|
+
* Get the logger instance
|
|
101
|
+
*/
|
|
102
|
+
getLogger() {
|
|
103
|
+
return this.logger;
|
|
104
|
+
}
|
|
56
105
|
}
|
|
57
106
|
exports.Connection = Connection;
|
|
58
107
|
/**
|
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
import 'reflect-metadata';
|
|
2
|
+
import type { PostgresType } from '@/types';
|
|
2
3
|
export declare const COLUMNS_KEY: unique symbol;
|
|
3
4
|
export interface ColumnOptions {
|
|
4
5
|
name?: string;
|
|
5
|
-
type?: string;
|
|
6
|
+
type?: PostgresType | string;
|
|
6
7
|
nullable?: boolean;
|
|
7
8
|
}
|
|
8
9
|
export interface ColumnMetadata {
|
|
9
10
|
propertyKey: string;
|
|
10
11
|
columnName: string;
|
|
11
|
-
type?: string;
|
|
12
|
+
type?: PostgresType | string;
|
|
12
13
|
isNullable?: boolean;
|
|
13
14
|
isPrimary: boolean;
|
|
14
15
|
}
|
|
@@ -6,4 +6,4 @@ import 'reflect-metadata';
|
|
|
6
6
|
* @PrimaryColumn
|
|
7
7
|
* id: number
|
|
8
8
|
*/
|
|
9
|
-
export declare function PrimaryColumn(): (target: object, propertyKey: string | symbol) => void;
|
|
9
|
+
export declare function PrimaryColumn(): (target: object | undefined, propertyKey: string | symbol) => void;
|
|
@@ -12,6 +12,9 @@ const Column_1 = require("./Column");
|
|
|
12
12
|
*/
|
|
13
13
|
function PrimaryColumn() {
|
|
14
14
|
return function (target, propertyKey) {
|
|
15
|
+
if (!target) {
|
|
16
|
+
throw new Error('PrimaryColumn decorator must be used on an instance property');
|
|
17
|
+
}
|
|
15
18
|
const constructor = target.constructor;
|
|
16
19
|
const columns = Reflect.getMetadata(Column_1.COLUMNS_KEY, constructor) ?? [];
|
|
17
20
|
const key = typeof propertyKey === 'symbol' ? propertyKey.toString() : propertyKey;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Base error class for all Accio ORM errors
|
|
3
|
+
*
|
|
4
|
+
* Provides context tracking, error chaining, and structured error information
|
|
5
|
+
* All Accio-specific errors extend from this class
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```typescript
|
|
9
|
+
* throw new AccioError(
|
|
10
|
+
* 'Operation failed',
|
|
11
|
+
* 'OPERATION_ERROR',
|
|
12
|
+
* { operation: 'INSERT', table: 'users' }
|
|
13
|
+
* )
|
|
14
|
+
* ```
|
|
15
|
+
*/
|
|
16
|
+
export declare class AccioError extends Error {
|
|
17
|
+
/**
|
|
18
|
+
* Error code for programmatic error handling
|
|
19
|
+
*/
|
|
20
|
+
readonly code: string;
|
|
21
|
+
/**
|
|
22
|
+
* Additional context about the error
|
|
23
|
+
*/
|
|
24
|
+
readonly context?: Record<string, unknown>;
|
|
25
|
+
/**
|
|
26
|
+
* Original error that caused this error (for error chaining)
|
|
27
|
+
*/
|
|
28
|
+
readonly cause?: Error;
|
|
29
|
+
/**
|
|
30
|
+
* Causes a new AccioError
|
|
31
|
+
*
|
|
32
|
+
* @param message - Human-readable error message
|
|
33
|
+
* @param code - Machine-readable error code
|
|
34
|
+
* @param context - Additional structured context about the error
|
|
35
|
+
* @param cause - Original error that caused this error
|
|
36
|
+
*/
|
|
37
|
+
constructor(message: string, code: string, context?: Record<string, unknown>, cause?: Error);
|
|
38
|
+
/**
|
|
39
|
+
* Serialize error to JSON for logging or transmission
|
|
40
|
+
*
|
|
41
|
+
* @param Structured error object
|
|
42
|
+
*/
|
|
43
|
+
toJSON(): Record<string, unknown>;
|
|
44
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AccioError = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Base error class for all Accio ORM errors
|
|
6
|
+
*
|
|
7
|
+
* Provides context tracking, error chaining, and structured error information
|
|
8
|
+
* All Accio-specific errors extend from this class
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```typescript
|
|
12
|
+
* throw new AccioError(
|
|
13
|
+
* 'Operation failed',
|
|
14
|
+
* 'OPERATION_ERROR',
|
|
15
|
+
* { operation: 'INSERT', table: 'users' }
|
|
16
|
+
* )
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
class AccioError extends Error {
|
|
20
|
+
/**
|
|
21
|
+
* Causes a new AccioError
|
|
22
|
+
*
|
|
23
|
+
* @param message - Human-readable error message
|
|
24
|
+
* @param code - Machine-readable error code
|
|
25
|
+
* @param context - Additional structured context about the error
|
|
26
|
+
* @param cause - Original error that caused this error
|
|
27
|
+
*/
|
|
28
|
+
constructor(message, code, context, cause) {
|
|
29
|
+
super(message);
|
|
30
|
+
this.name = this.constructor.name;
|
|
31
|
+
this.code = code;
|
|
32
|
+
this.context = context;
|
|
33
|
+
this.cause = cause;
|
|
34
|
+
if ('captureStackTrace' in Error &&
|
|
35
|
+
typeof Error.captureStackTrace === 'function') {
|
|
36
|
+
Error.captureStackTrace(this, this.constructor);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Serialize error to JSON for logging or transmission
|
|
41
|
+
*
|
|
42
|
+
* @param Structured error object
|
|
43
|
+
*/
|
|
44
|
+
toJSON() {
|
|
45
|
+
return {
|
|
46
|
+
name: this.name,
|
|
47
|
+
code: this.code,
|
|
48
|
+
message: this.message,
|
|
49
|
+
context: this.context,
|
|
50
|
+
cause: this.cause?.message,
|
|
51
|
+
stack: this.stack
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
exports.AccioError = AccioError;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { AccioError } from './AccioError';
|
|
2
|
+
/**
|
|
3
|
+
* Thrown when database connection operation fail
|
|
4
|
+
*
|
|
5
|
+
* This includes connection establishment failures, connection pool exhaustion,
|
|
6
|
+
* connection timeouts, and connection closing errors.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```typescript
|
|
10
|
+
* catch (error) {
|
|
11
|
+
* if (error instanceof ConnectionError) {
|
|
12
|
+
* console.error('Failed to connect to database:', error.context)
|
|
13
|
+
* }
|
|
14
|
+
* }
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
export declare class ConnectionError extends AccioError {
|
|
18
|
+
/**
|
|
19
|
+
* Creates a new QueryError
|
|
20
|
+
*
|
|
21
|
+
* @param message - Human-readable error message
|
|
22
|
+
* @param sql - The SQL query that failed (optional)
|
|
23
|
+
* @param params - The parameter bound to the query (optional)
|
|
24
|
+
* @param cause - Original error from the database driver
|
|
25
|
+
*/
|
|
26
|
+
constructor(message: string, context?: Record<string, unknown>, cause?: Error);
|
|
27
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ConnectionError = void 0;
|
|
4
|
+
const AccioError_1 = require("./AccioError");
|
|
5
|
+
/**
|
|
6
|
+
* Thrown when database connection operation fail
|
|
7
|
+
*
|
|
8
|
+
* This includes connection establishment failures, connection pool exhaustion,
|
|
9
|
+
* connection timeouts, and connection closing errors.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```typescript
|
|
13
|
+
* catch (error) {
|
|
14
|
+
* if (error instanceof ConnectionError) {
|
|
15
|
+
* console.error('Failed to connect to database:', error.context)
|
|
16
|
+
* }
|
|
17
|
+
* }
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
class ConnectionError extends AccioError_1.AccioError {
|
|
21
|
+
/**
|
|
22
|
+
* Creates a new QueryError
|
|
23
|
+
*
|
|
24
|
+
* @param message - Human-readable error message
|
|
25
|
+
* @param sql - The SQL query that failed (optional)
|
|
26
|
+
* @param params - The parameter bound to the query (optional)
|
|
27
|
+
* @param cause - Original error from the database driver
|
|
28
|
+
*/
|
|
29
|
+
constructor(message, context, cause) {
|
|
30
|
+
super(message, 'CONNECTION_ERROR', context, cause);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
exports.ConnectionError = ConnectionError;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { AccioError } from './AccioError';
|
|
2
|
+
/**
|
|
3
|
+
* Thrown for database-level errors
|
|
4
|
+
*
|
|
5
|
+
* This includes constraint violations, permission errors, database-specific
|
|
6
|
+
* errors, and other database-level failures that are not query syntax errors
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```typescript
|
|
10
|
+
* catch (error) {
|
|
11
|
+
* if (error instanceof DatabaseError) {
|
|
12
|
+
* console.error('Database error:' error.constrait, error.detail)
|
|
13
|
+
* }
|
|
14
|
+
* }
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
export declare class DatabaseError extends AccioError {
|
|
18
|
+
/**
|
|
19
|
+
* The database constraint that was violated (if applicable)
|
|
20
|
+
*/
|
|
21
|
+
readonly constraint?: string;
|
|
22
|
+
/**
|
|
23
|
+
* Detailed information from the database about the error
|
|
24
|
+
*/
|
|
25
|
+
readonly detail?: string;
|
|
26
|
+
/**
|
|
27
|
+
* Creates a new DatabaseError
|
|
28
|
+
*
|
|
29
|
+
* @param message - Human-readable error message
|
|
30
|
+
* @param constraint - The constraint that was violated (optional)
|
|
31
|
+
* @param detail - Detailed information from the database (optional)
|
|
32
|
+
* @param cause - Original error from the database driver
|
|
33
|
+
*/
|
|
34
|
+
constructor(message: string, constraint?: string, detail?: string, cause?: Error);
|
|
35
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DatabaseError = void 0;
|
|
4
|
+
const AccioError_1 = require("./AccioError");
|
|
5
|
+
/**
|
|
6
|
+
* Thrown for database-level errors
|
|
7
|
+
*
|
|
8
|
+
* This includes constraint violations, permission errors, database-specific
|
|
9
|
+
* errors, and other database-level failures that are not query syntax errors
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```typescript
|
|
13
|
+
* catch (error) {
|
|
14
|
+
* if (error instanceof DatabaseError) {
|
|
15
|
+
* console.error('Database error:' error.constrait, error.detail)
|
|
16
|
+
* }
|
|
17
|
+
* }
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
class DatabaseError extends AccioError_1.AccioError {
|
|
21
|
+
/**
|
|
22
|
+
* Creates a new DatabaseError
|
|
23
|
+
*
|
|
24
|
+
* @param message - Human-readable error message
|
|
25
|
+
* @param constraint - The constraint that was violated (optional)
|
|
26
|
+
* @param detail - Detailed information from the database (optional)
|
|
27
|
+
* @param cause - Original error from the database driver
|
|
28
|
+
*/
|
|
29
|
+
constructor(message, constraint, detail, cause) {
|
|
30
|
+
super(message, 'DATABASE_ERROR', { constraint, detail }, cause);
|
|
31
|
+
this.constraint = constraint;
|
|
32
|
+
this.detail = detail;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
exports.DatabaseError = DatabaseError;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { AccioError } from './AccioError';
|
|
2
|
+
/**
|
|
3
|
+
* Thrown when validation fails
|
|
4
|
+
*
|
|
5
|
+
* This includes configuration validation, metadata validation, input validation,
|
|
6
|
+
* and SQL identifier validation. Used to prevent invalid operations before they
|
|
7
|
+
* reach the database.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```typescript
|
|
11
|
+
* catch (error) {
|
|
12
|
+
* if (error instanceof ValidationError) {
|
|
13
|
+
* console.error('Validation failed for ${error.field}:', error.value)
|
|
14
|
+
* }
|
|
15
|
+
* }
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
export declare class QueryError extends AccioError {
|
|
19
|
+
/**
|
|
20
|
+
* The SQL query that failed
|
|
21
|
+
*/
|
|
22
|
+
readonly sql?: string;
|
|
23
|
+
/**
|
|
24
|
+
* The parameter that are bound to the query
|
|
25
|
+
*/
|
|
26
|
+
readonly params?: unknown[];
|
|
27
|
+
/**
|
|
28
|
+
* Creates a new QueryError
|
|
29
|
+
*
|
|
30
|
+
* @param message - Human-readable error message
|
|
31
|
+
* @param sql - The SQL query that failed (optional)
|
|
32
|
+
* @param params - The parameter bound to the query (optional)
|
|
33
|
+
* @param cause - Original error from the database driver
|
|
34
|
+
*/
|
|
35
|
+
constructor(message: string, sql?: string, params?: unknown[], cause?: Error);
|
|
36
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.QueryError = void 0;
|
|
4
|
+
const AccioError_1 = require("./AccioError");
|
|
5
|
+
/**
|
|
6
|
+
* Thrown when validation fails
|
|
7
|
+
*
|
|
8
|
+
* This includes configuration validation, metadata validation, input validation,
|
|
9
|
+
* and SQL identifier validation. Used to prevent invalid operations before they
|
|
10
|
+
* reach the database.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```typescript
|
|
14
|
+
* catch (error) {
|
|
15
|
+
* if (error instanceof ValidationError) {
|
|
16
|
+
* console.error('Validation failed for ${error.field}:', error.value)
|
|
17
|
+
* }
|
|
18
|
+
* }
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
class QueryError extends AccioError_1.AccioError {
|
|
22
|
+
/**
|
|
23
|
+
* Creates a new QueryError
|
|
24
|
+
*
|
|
25
|
+
* @param message - Human-readable error message
|
|
26
|
+
* @param sql - The SQL query that failed (optional)
|
|
27
|
+
* @param params - The parameter bound to the query (optional)
|
|
28
|
+
* @param cause - Original error from the database driver
|
|
29
|
+
*/
|
|
30
|
+
constructor(message, sql, params, cause) {
|
|
31
|
+
super(message, 'QUERY_ERROR', { sql, params }, cause);
|
|
32
|
+
this.sql = sql;
|
|
33
|
+
this.params = params;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
exports.QueryError = QueryError;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { AccioError } from './AccioError';
|
|
2
|
+
/**
|
|
3
|
+
* Thrown when validation fails
|
|
4
|
+
*
|
|
5
|
+
* This includes configuration validation, metadata validation, input validation,
|
|
6
|
+
* and SQL identifier validation. Used to prevent invalid operations before they
|
|
7
|
+
* reach the database.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```typescript
|
|
11
|
+
* catch (error) {
|
|
12
|
+
* if (error instanceof ValidationError) {
|
|
13
|
+
* console.error('Validation failed for ${error.field}:', error.value)
|
|
14
|
+
* }
|
|
15
|
+
* }
|
|
16
|
+
*/
|
|
17
|
+
export declare class ValidationError extends AccioError {
|
|
18
|
+
/**
|
|
19
|
+
* The field or property that failed validation
|
|
20
|
+
*/
|
|
21
|
+
readonly field?: string;
|
|
22
|
+
/**
|
|
23
|
+
* The imvalid value that caused the validation error
|
|
24
|
+
*/
|
|
25
|
+
readonly value?: unknown;
|
|
26
|
+
/**
|
|
27
|
+
* Creates a new ValidationError
|
|
28
|
+
*
|
|
29
|
+
* @param message - Human-readable error message describing the validation failure
|
|
30
|
+
* @param field - The field or property that failed validation (optional)
|
|
31
|
+
* @param value - The invalid value (optional, may be redacted for sensitive data)
|
|
32
|
+
* @param context - Additional context about the validation failure (optional)
|
|
33
|
+
*/
|
|
34
|
+
constructor(message: string, field?: string, value?: unknown, context?: Record<string, unknown>);
|
|
35
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ValidationError = void 0;
|
|
4
|
+
const AccioError_1 = require("./AccioError");
|
|
5
|
+
/**
|
|
6
|
+
* Thrown when validation fails
|
|
7
|
+
*
|
|
8
|
+
* This includes configuration validation, metadata validation, input validation,
|
|
9
|
+
* and SQL identifier validation. Used to prevent invalid operations before they
|
|
10
|
+
* reach the database.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```typescript
|
|
14
|
+
* catch (error) {
|
|
15
|
+
* if (error instanceof ValidationError) {
|
|
16
|
+
* console.error('Validation failed for ${error.field}:', error.value)
|
|
17
|
+
* }
|
|
18
|
+
* }
|
|
19
|
+
*/
|
|
20
|
+
class ValidationError extends AccioError_1.AccioError {
|
|
21
|
+
/**
|
|
22
|
+
* Creates a new ValidationError
|
|
23
|
+
*
|
|
24
|
+
* @param message - Human-readable error message describing the validation failure
|
|
25
|
+
* @param field - The field or property that failed validation (optional)
|
|
26
|
+
* @param value - The invalid value (optional, may be redacted for sensitive data)
|
|
27
|
+
* @param context - Additional context about the validation failure (optional)
|
|
28
|
+
*/
|
|
29
|
+
constructor(message, field, value, context) {
|
|
30
|
+
super(message, 'VALIDATION_ERROR', { field, value, ...context });
|
|
31
|
+
this.field = field;
|
|
32
|
+
this.value = value;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
exports.ValidationError = ValidationError;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Error classes for Accio ORM
|
|
3
|
+
*
|
|
4
|
+
* All errors extend from AccioError, which provides error chaining,
|
|
5
|
+
* context tracking, and structured error information
|
|
6
|
+
*/
|
|
7
|
+
export { AccioError } from './AccioError';
|
|
8
|
+
export { ConnectionError } from './ConnectionError';
|
|
9
|
+
export { DatabaseError } from './DatabaseError';
|
|
10
|
+
export { QueryError } from './QueryError';
|
|
11
|
+
export { ValidationError } from './ValidationError';
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Error classes for Accio ORM
|
|
4
|
+
*
|
|
5
|
+
* All errors extend from AccioError, which provides error chaining,
|
|
6
|
+
* context tracking, and structured error information
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.ValidationError = exports.QueryError = exports.DatabaseError = exports.ConnectionError = exports.AccioError = void 0;
|
|
10
|
+
var AccioError_1 = require("./AccioError");
|
|
11
|
+
Object.defineProperty(exports, "AccioError", { enumerable: true, get: function () { return AccioError_1.AccioError; } });
|
|
12
|
+
var ConnectionError_1 = require("./ConnectionError");
|
|
13
|
+
Object.defineProperty(exports, "ConnectionError", { enumerable: true, get: function () { return ConnectionError_1.ConnectionError; } });
|
|
14
|
+
var DatabaseError_1 = require("./DatabaseError");
|
|
15
|
+
Object.defineProperty(exports, "DatabaseError", { enumerable: true, get: function () { return DatabaseError_1.DatabaseError; } });
|
|
16
|
+
var QueryError_1 = require("./QueryError");
|
|
17
|
+
Object.defineProperty(exports, "QueryError", { enumerable: true, get: function () { return QueryError_1.QueryError; } });
|
|
18
|
+
var ValidationError_1 = require("./ValidationError");
|
|
19
|
+
Object.defineProperty(exports, "ValidationError", { enumerable: true, get: function () { return ValidationError_1.ValidationError; } });
|
package/dist/index.d.ts
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
export { connect, Connection } from './connection/Connection';
|
|
2
|
-
export { ConnectionConfig } from './connection/types';
|
|
3
|
-
export { Column, ColumnMetadata, ColumnOptions } from './decorators/Column';
|
|
2
|
+
export type { ConnectionConfig } from './connection/types';
|
|
3
|
+
export { Column, type ColumnMetadata, type ColumnOptions } from './decorators/Column';
|
|
4
4
|
export { PrimaryColumn } from './decorators/PrimaryColumn';
|
|
5
5
|
export { Table } from './decorators/Table';
|
|
6
6
|
export { Repository } from './repository/Repository';
|
|
7
7
|
export { QueryBuilder } from './query/QueryBuilder';
|
|
8
8
|
export { MetadataStorage } from './metadata/MetadataStorage';
|
|
9
|
-
export { EntityMetadata } from './metadata/types';
|
|
9
|
+
export type { EntityMetadata } from './metadata/types';
|
|
10
|
+
export { AccioError, ConnectionError, DatabaseError, QueryError, ValidationError } from './errors';
|
|
11
|
+
export { Logger, type LoggerConfig, LogLevel } from './logger';
|
|
12
|
+
export { getPostgresTypeForTS, isValidPostgresType, PostgresType } from './types';
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.MetadataStorage = exports.QueryBuilder = exports.Repository = exports.Table = exports.PrimaryColumn = exports.Column = exports.Connection = exports.connect = void 0;
|
|
3
|
+
exports.PostgresType = exports.isValidPostgresType = exports.getPostgresTypeForTS = exports.LogLevel = exports.Logger = exports.ValidationError = exports.QueryError = exports.DatabaseError = exports.ConnectionError = exports.AccioError = exports.MetadataStorage = exports.QueryBuilder = exports.Repository = exports.Table = exports.PrimaryColumn = exports.Column = exports.Connection = exports.connect = void 0;
|
|
4
4
|
// Connection
|
|
5
5
|
var Connection_1 = require("./connection/Connection");
|
|
6
6
|
Object.defineProperty(exports, "connect", { enumerable: true, get: function () { return Connection_1.connect; } });
|
|
@@ -21,3 +21,19 @@ Object.defineProperty(exports, "QueryBuilder", { enumerable: true, get: function
|
|
|
21
21
|
// Metadata
|
|
22
22
|
var MetadataStorage_1 = require("./metadata/MetadataStorage");
|
|
23
23
|
Object.defineProperty(exports, "MetadataStorage", { enumerable: true, get: function () { return MetadataStorage_1.MetadataStorage; } });
|
|
24
|
+
// Errors
|
|
25
|
+
var errors_1 = require("./errors");
|
|
26
|
+
Object.defineProperty(exports, "AccioError", { enumerable: true, get: function () { return errors_1.AccioError; } });
|
|
27
|
+
Object.defineProperty(exports, "ConnectionError", { enumerable: true, get: function () { return errors_1.ConnectionError; } });
|
|
28
|
+
Object.defineProperty(exports, "DatabaseError", { enumerable: true, get: function () { return errors_1.DatabaseError; } });
|
|
29
|
+
Object.defineProperty(exports, "QueryError", { enumerable: true, get: function () { return errors_1.QueryError; } });
|
|
30
|
+
Object.defineProperty(exports, "ValidationError", { enumerable: true, get: function () { return errors_1.ValidationError; } });
|
|
31
|
+
// Logger
|
|
32
|
+
var logger_1 = require("./logger");
|
|
33
|
+
Object.defineProperty(exports, "Logger", { enumerable: true, get: function () { return logger_1.Logger; } });
|
|
34
|
+
Object.defineProperty(exports, "LogLevel", { enumerable: true, get: function () { return logger_1.LogLevel; } });
|
|
35
|
+
// Types
|
|
36
|
+
var types_1 = require("./types");
|
|
37
|
+
Object.defineProperty(exports, "getPostgresTypeForTS", { enumerable: true, get: function () { return types_1.getPostgresTypeForTS; } });
|
|
38
|
+
Object.defineProperty(exports, "isValidPostgresType", { enumerable: true, get: function () { return types_1.isValidPostgresType; } });
|
|
39
|
+
Object.defineProperty(exports, "PostgresType", { enumerable: true, get: function () { return types_1.PostgresType; } });
|